blob: 6027a3b7ff0db921044a14df9157094690f46c3d [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
George Keishing85536662017-03-03 10:49:58 -06002Documentation Verify REST services Get/Put/Post/Delete.
Chris Austenb29d2e82016-06-07 12:25:35 -05003
George Keishing97651c72016-10-04 00:44:15 -05004Resource ../lib/rest_client.robot
George Keishingd55a4be2016-08-26 03:28:17 -05005Resource ../lib/openbmc_ffdc.robot
George Keishing7230bbc2016-12-14 07:02:48 -06006Resource ../lib/resource.txt
George Keishing85536662017-03-03 10:49:58 -06007Library Collections
Gunnar Millseac1af22016-11-14 15:30:09 -06008Test Teardown FFDC On Test Case Fail
Chris Austenb29d2e82016-06-07 12:25:35 -05009
Chris Austenb29d2e82016-06-07 12:25:35 -050010*** Variables ***
11
Chris Austenb29d2e82016-06-07 12:25:35 -050012*** Test Cases ***
Chris Austenb29d2e82016-06-07 12:25:35 -050013
George Keishing89f7c1f2017-05-03 16:08:37 -050014REST Login Session To BMC
15 [Documentation] Test REST session log-in.
16 [Tags] REST_Login_Session_To_BMC
17
18 Initialize OpenBMC
19 # Raw GET REST operation to verify session is established.
20 ${resp}= Get Request openbmc /xyz/openbmc_project/
21 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
22
23
24REST Logout Session To BMC
25 [Documentation] Test REST session log-out.
26 [Tags] REST_Logout_Session_To_BMC
27
28 Initialize OpenBMC
29 Log Out OpenBMC
30 # Raw GET REST operation to verify session is logout.
31 ${resp}= Get Request openbmc /xyz/openbmc_project/
32 Should Be Equal As Strings ${resp.status_code} ${HTTP_UNAUTHORIZED}
33
34
George Keishing6715f312017-05-10 03:22:40 -050035REST Delete All Sessions And Expect Error
36 [Documentation] Test REST empty cache using delete operation.
37 [Tags] REST_Delete_All_Sessions_And_Expect_Error
38
39 # Throws exception:
40 # Non-existing index or alias 'openbmc'.
41
42 Initialize OpenBMC
43 Delete All Sessions
44 # Raw GET REST operation and expect exception error.
45 Run Keyword And Expect Error
46 ... Non-existing index or alias 'openbmc'.
47 ... Get Request openbmc /xyz/openbmc_project/
48
49
George Keishing3b1f2772017-07-31 09:44:45 -050050Multiple Requests On BMC Using Single REST Session
51 [Documentation] Trigger multiple REST operations using an active
52 ... connection session.
53 [Tags] Multiple_Requests_On_BMC_Using_Single_REST_Session
54
55 Initialize OpenBMC
56
57 # Session object "openbmc".
58 ${resp}= Get Request openbmc /xyz/openbmc_project/state/
59 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
60
61 ${resp}= Get Request openbmc /xyz/openbmc_project/software/enumerate
62 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
63
64
George Keishing6715f312017-05-10 03:22:40 -050065Verify REST JSON Data On Success
66 [Documentation] Verify JSON data success response messages.
67 [Tags] Verify_REST_JSON_Data_On_Success
68 # Example:
69 # Response code:200, Content:{
70 # "data": [
71 # "/xyz/openbmc_project/sensors",
72 # "/xyz/openbmc_project/inventory",
73 # "/xyz/openbmc_project/software",
74 # "/xyz/openbmc_project/object_mapper",
75 # "/xyz/openbmc_project/logging"
76 # ],
77 # "message": "200 OK",
78 # "status": "ok"
79 # }
80
81 ${resp}= OpenBMC Get Request /xyz/openbmc_project/
82 ${jsondata}= To JSON ${resp.content}
83 Should Not Be Empty ${jsondata["data"]}
84 Should Be Equal As Strings ${jsondata["message"]} 200 OK
85 Should Be Equal As Strings ${jsondata["status"]} ok
86
87
88Verify REST JSON Data On Failure
89 [Documentation] Verify JSON data failure response messages.
90 [Tags] Verify_REST_JSON_Data_On_Failure
91 # Example:
92 # Response code:404, Content:{
93 # "data": {
94 # "description": "org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist"
95 # },
96 # "message": "404 Not Found",
97 # "status": "error"
98 # }
99
100 ${resp}= OpenBMC Get Request /xyz/idont/exist/
101 ${jsondata}= To JSON ${resp.content}
102 Should Be Equal As Strings
103 ... ${jsondata["data"]["description"]} org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist
104 Should Be Equal As Strings ${jsondata["message"]} 404 Not Found
105 Should Be Equal As Strings ${jsondata["status"]} error
106
107
George Keishingadefa262017-07-08 12:54:06 -0500108Verify REST Get Message JSON Compliant
109 [Documentation] Verify REST "GET" message is JSON format compliant.
110 [Tags] Verify_REST_Get_Message_JSON_Compliant
111 # For testing if the REST message is JSON format compliant using a
112 # generic BMC state path /xyz/openbmc_project/state object and path
113 # walking through to ensure the parent object, trailing slash and
114 # attribute message response are intact.
115
116 # Object attribute data.
117 # Example:
118 # Response code:200, Content:{
119 # "data": {
120 # "CurrentBMCState": "xyz.openbmc_project.State.BMC.BMCState.Ready",
121 # "RequestedBMCTransition": "xyz.openbmc_project.State.BMC.Transition.None"
122 # },
123 # "message": "200 OK",
124 # "status": "ok"
125 # }
126
127 Verify JSON Response Content
128 ... /xyz/openbmc_project/state/bmc0 DATA_NOT_EMPTY
129
130 # Object trailing slash attribute data.
131 # Example:
132 # Response code:200, Content:{
133 # "data": [],
134 # "message": "200 OK",
135 # "status": "ok"
136 # }
137
138 Verify JSON Response Content /xyz/openbmc_project/state/bmc0/
139
140 # Attribute data.
141 # Example:
142 # Response code:200, Content:{
143 # "data": "xyz.openbmc_project.State.BMC.BMCState.Ready",
144 # "message": "200 OK",
145 # "status": "ok"
146 # }
147
148 Verify JSON Response Content
149 ... /xyz/openbmc_project/state/bmc0/attr/CurrentBMCState DATA_NOT_EMPTY
150
151
152Verify REST Post Message JSON Compliant
153 [Documentation] Verify REST "POST" message is JSON format compliant.
154 [Tags] Verify_REST_Post_Message_JSON_Compliant
155 # Example:
156 # Response code:200, Content:{
157 # "data": null,
158 # "message": "200 OK",
159 # "status": "ok"
160 # }
161
162 # Generate 1KB file size
163 Run dd if=/dev/zero of=dummyfile bs=1 count=0 seek=1KB
164 OperatingSystem.File Should Exist dummyfile
165
166 # Get the content of the file and upload to BMC
167 ${image_data}= OperatingSystem.Get Binary File dummyfile
168
169 # Get REST session to BMC
170 Initialize OpenBMC
171
172 # Create the REST payload headers and data
173 ${data}= Create Dictionary data ${image_data}
174 ${headers}= Create Dictionary Content-Type=application/octet-stream
175 ... Accept=application/octet-stream
176 Set To Dictionary ${data} headers ${headers}
177
178 ${resp}= Post Request openbmc /upload/image &{data}
179 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
180 ${jsondata}= To JSON ${resp.content}
181 Should Be Equal ${jsondata["data"]} ${None}
182 Should Be Equal As Strings ${jsondata["message"]} 200 OK
183 Should Be Equal As Strings ${jsondata["status"]} ok
184
185 # Cleanup uploaded file.
186 BMC Execute Command rm -rf /tmp/images/*
187
188
189Verify REST Put Message JSON Compliant
190 [Documentation] Verify REST "PUT" message is JSON format compliant.
191 [Tags] REST_Put_Message_JSON_Format_Compliance_Test
192 # Example:
193 # Response code:200, Content:{
194 # "data": null,
195 # "message": "200 OK",
196 # "status": "ok"
197 # }
198
199 ${dict_data}= Create Dictionary data=${HOST_POWEROFF_TRANS}
200 ${resp}= Openbmc Put Request
201 ... ${HOST_STATE_URI}/attr/RequestedHostTransition data=${dict_data}
202 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
203 ${jsondata}= To JSON ${resp.content}
204 Should Be Equal ${jsondata["data"]} ${None}
205 Should Be Equal As Strings ${jsondata["message"]} 200 OK
206 Should Be Equal As Strings ${jsondata["status"]} ok
207 # Intention is not to test poweroff but to check the REST operation
208 # sink time allowing to kick poweroff.
209 Sleep 10s
210
211
George Keishinge6594f22017-07-06 12:10:52 -0500212Check Response Codes HTTP_UNSUPPORTED_MEDIA_TYPE
213 [Documentation] REST "Post" response status test for
214 ... HTTP_UNSUPPORTED_MEDIA_TYPE.
215 [Tags] Check_Response_Codes_415
216
217 # Example:
218 # Response code:415, Content:{
219 # "data": {
220 # "description": "Expecting content type 'application/octet-stream', got 'application/json'"
221 # },
222 # "message": "415 Unsupported Media Type",
223 # "status": "error"
224 # }
225
226 Initialize OpenBMC
227
228 # Create the REST payload headers and EMPTY data
229 ${data}= Create Dictionary data ${EMPTY}
230 ${headers}= Create Dictionary Content-Type=application/json
231 Set To Dictionary ${data} headers ${headers}
232
233 ${resp}= Post Request openbmc /upload/image &{data}
234 Should Be Equal As Strings
235 ... ${resp.status_code} ${HTTP_UNSUPPORTED_MEDIA_TYPE}
236
237 ${jsondata}= To JSON ${resp.content}
238 Should Be Equal As Strings ${jsondata["data"]["description"]}
239 ... Expecting content type 'application/octet-stream', got 'application/json'
240 Should Be Equal As Strings
241 ... ${jsondata["message"]} 415 Unsupported Media Type
242 Should Be Equal As Strings ${jsondata["status"]} error
243
244
George Keishing85536662017-03-03 10:49:58 -0600245Get Response Codes
246 [Documentation] REST "Get" response status test.
247 #--------------------------------------------------------------------
248 # Expect status URL Path
249 #--------------------------------------------------------------------
250 ${HTTP_OK} /
251 ${HTTP_OK} /xyz/
252 ${HTTP_OK} /xyz/openbmc_project/
253 ${HTTP_OK} /xyz/openbmc_project/enumerate
254 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500255
George Keishing85536662017-03-03 10:49:58 -0600256 [Tags] Get_Response_Codes
257 [Template] Execute Get And Check Response
Chris Austenb29d2e82016-06-07 12:25:35 -0500258
Chris Austenb29d2e82016-06-07 12:25:35 -0500259
George Keishing85536662017-03-03 10:49:58 -0600260Get Data
261 [Documentation] REST "Get" request url and expect the
262 ... response OK and data non empty.
263 #--------------------------------------------------------------------
264 # URL Path
265 #--------------------------------------------------------------------
266 /xyz/openbmc_project/
267 /xyz/openbmc_project/list
268 /xyz/openbmc_project/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500269
George Keishing85536662017-03-03 10:49:58 -0600270 [Tags] Get_Data
271 [Template] Execute Get And Check Data
Chris Austenb29d2e82016-06-07 12:25:35 -0500272
Chris Austenb29d2e82016-06-07 12:25:35 -0500273
George Keishing85536662017-03-03 10:49:58 -0600274Get Data Validation
275 [Documentation] REST "Get" request url and expect the
276 ... pre-defined string in response data.
277 #--------------------------------------------------------------------
278 # URL Path Expect Data
279 #--------------------------------------------------------------------
280 /xyz/openbmc_project/ /xyz/openbmc_project/logging
281 /i/dont/exist/ path or object not found: /i/dont/exist
282
283 [Tags] Get_Data_Validation
284 [Template] Execute Get And Verify Data
285
286
287Put Response Codes
288 [Documentation] REST "Put" request url and expect the REST pre-defined
289 ... codes.
290 #--------------------------------------------------------------------
291 # Expect status URL Path
292 #--------------------------------------------------------------------
293 ${HTTP_METHOD_NOT_ALLOWED} /
294 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
295 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
296 ${HTTP_METHOD_NOT_ALLOWED} /xyz/list
297 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
298
299 [Tags] Put_Response_Codes
300 [Template] Execute Put And Check Response
301
302
303Put Data Validation
304 [Documentation] REST "Put" request url and expect success.
305 #--------------------------------------------------------------------
306 # URL Path Parm Data
307 #--------------------------------------------------------------------
308 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition xyz.openbmc_project.State.Host.Transition.Off
309
310 [Tags] Put_Data_Validation
311 [Template] Execute Put And Expect Success
312
313
314Post Response Code
315 [Documentation] REST Post request url and expect the
316 ... REST response code pre define.
317 #--------------------------------------------------------------------
318 # Expect status URL Path
319 #--------------------------------------------------------------------
320 ${HTTP_METHOD_NOT_ALLOWED} /
321 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
322 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
323 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
324
325 [Tags] Post_Response_Codes
326 [Template] Execute Post And Check Response
327
328
329Delete Response Code
330 [Documentation] REST "Delete" request url and expect the
331 ... REST response code pre define.
332 #--------------------------------------------------------------------
333 # Expect status URL Path
334 #--------------------------------------------------------------------
335 ${HTTP_METHOD_NOT_ALLOWED} /
336 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
337 ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/
338 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
339 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/list
340 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/enumerate
341
342 [Tags] Delete_Response_Codes
343 [Template] Execute Delete And Check Response
344
Gunnar Mills56b32892016-11-14 13:56:17 -0600345
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600346*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600347
348Execute Get And Check Response
349 [Documentation] Request "Get" url path and expect REST response code.
350 [Arguments] ${expected_response_code} ${url_path}
351 # Description of arguments:
352 # expected_response_code Expected REST status codes.
353 # url_path URL path.
354 ${resp}= Openbmc Get Request ${url_path}
355 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
356
357Execute Get And Check Data
358 [Documentation] Request "Get" url path and expect non empty data.
359 [Arguments] ${url_path}
360 # Description of arguments:
361 # url_path URL path.
362 ${resp}= Openbmc Get Request ${url_path}
363 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
364 ${jsondata}= To JSON ${resp.content}
365 Should Not Be Empty ${jsondata["data"]}
366
367Execute Get And Verify Data
368 [Documentation] Request "Get" url path and verify data.
369 [Arguments] ${url_path} ${expected_response_code}
370 # Description of arguments:
371 # expected_response_code Expected REST status codes.
372 # url_path URL path.
373 ${resp}= Openbmc Get Request ${url_path}
374 ${jsondata}= To JSON ${resp.content}
375 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
376 ... Should Contain ${jsondata["data"]} ${expected_response_code}
377 ... ELSE
378 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
379
380Execute Put And Check Response
381 [Documentation] Request "Put" url path and expect REST response code.
382 [Arguments] ${expected_response_code} ${url_path}
383 # Description of arguments:
384 # expected_response_code Expected REST status codes.
385 # url_path URL path.
386 ${resp}= Openbmc Put Request ${url_path}
387 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
388
389Execute Put And Expect Success
390 [Documentation] Request "Put" on url path.
391 [Arguments] ${url_path} ${parm}
392 # Description of arguments:
393 # url_path URL path.
394 # parm Value/string to be set.
395 # expected_response_code Expected REST status codes.
396 ${parmDict}= Create Dictionary data=${parm}
397 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
398 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
399
400Execute Post And Check Response
401 [Documentation] Request Post url path and expect REST response code.
402 [Arguments] ${expected_response_code} ${url_path}
403 # Description of arguments:
404 # expected_response_code Expected REST status codes.
405 # url_path URL path.
406 ${resp}= Openbmc Post Request ${url_path}
407 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
408
409Execute Post And Check Data
410 [Arguments] ${url_path} ${parm}
411 [Documentation] Request Post on url path and expected non empty data.
412 # Description of arguments:
413 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500414 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600415 ${resp}= Openbmc Post Request ${url_path} data=${data}
416 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
417 ${jsondata}= To JSON ${resp.content}
418 Should Not Be Empty ${jsondata["data"]}
419
420Execute Delete And Check Response
421 [Documentation] Request "Delete" url path and expected REST response code.
422 [Arguments] ${expected_response_code} ${url_path}
423 # Description of arguments:
424 # expected_response_code Expected REST status codes.
425 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500426 ${data}= Create Dictionary data=@{EMPTY}
427 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600428 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
George Keishingadefa262017-07-08 12:54:06 -0500429
430Verify JSON Response Content
431 [Documentation] Verify JSON response data is intact.
432 [Arguments] ${url_path} ${data_empty}=${EMPTY}
433
434 # Description of argument(s):
435 # url_path URL path.
436 # data_empty JSON data element.
437
438 ${resp}= OpenBMC Get Request ${url_path}
439 ${jsondata}= To JSON ${resp.content}
440 Run Keyword If '${data_empty}' == '${EMPTY}'
441 ... Should Be Empty ${jsondata["data"]}
442 ... ELSE
443 ... Should Not Be Empty ${jsondata["data"]}
444 Should Be Equal As Strings ${jsondata["message"]} 200 OK
445 Should Be Equal As Strings ${jsondata["status"]} ok