blob: 82d621f2558b42c7045189557a67bb41f98814a3 [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
Sivas SRRa13eb202017-11-03 10:01:56 -05007Resource ../lib/utils.robot
George Keishing85536662017-03-03 10:49:58 -06008Library Collections
Sivas SRRa13eb202017-11-03 10:01:56 -05009Suite Setup Run Keyword And Ignore Error Check BMC Performance
Gunnar Millseac1af22016-11-14 15:30:09 -060010Test Teardown FFDC On Test Case Fail
Sivas SRRa13eb202017-11-03 10:01:56 -050011Suite Teardown Run Keyword And Ignore Error Check BMC Performance
Chris Austenb29d2e82016-06-07 12:25:35 -050012
Chris Austenb29d2e82016-06-07 12:25:35 -050013*** Variables ***
14
Chris Austenb29d2e82016-06-07 12:25:35 -050015*** Test Cases ***
Chris Austenb29d2e82016-06-07 12:25:35 -050016
George Keishing89f7c1f2017-05-03 16:08:37 -050017REST Login Session To BMC
18 [Documentation] Test REST session log-in.
19 [Tags] REST_Login_Session_To_BMC
20
21 Initialize OpenBMC
22 # Raw GET REST operation to verify session is established.
23 ${resp}= Get Request openbmc /xyz/openbmc_project/
24 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
25
26
27REST Logout Session To BMC
28 [Documentation] Test REST session log-out.
29 [Tags] REST_Logout_Session_To_BMC
30
31 Initialize OpenBMC
32 Log Out OpenBMC
33 # Raw GET REST operation to verify session is logout.
34 ${resp}= Get Request openbmc /xyz/openbmc_project/
35 Should Be Equal As Strings ${resp.status_code} ${HTTP_UNAUTHORIZED}
36
37
George Keishing6715f312017-05-10 03:22:40 -050038REST Delete All Sessions And Expect Error
39 [Documentation] Test REST empty cache using delete operation.
40 [Tags] REST_Delete_All_Sessions_And_Expect_Error
41
42 # Throws exception:
43 # Non-existing index or alias 'openbmc'.
44
45 Initialize OpenBMC
46 Delete All Sessions
47 # Raw GET REST operation and expect exception error.
48 Run Keyword And Expect Error
49 ... Non-existing index or alias 'openbmc'.
50 ... Get Request openbmc /xyz/openbmc_project/
51
52
George Keishing3b1f2772017-07-31 09:44:45 -050053Multiple Requests On BMC Using Single REST Session
54 [Documentation] Trigger multiple REST operations using an active
55 ... connection session.
56 [Tags] Multiple_Requests_On_BMC_Using_Single_REST_Session
57
58 Initialize OpenBMC
59
60 # Session object "openbmc".
61 ${resp}= Get Request openbmc /xyz/openbmc_project/state/
62 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
63
64 ${resp}= Get Request openbmc /xyz/openbmc_project/software/enumerate
65 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
66
67
George Keishing6715f312017-05-10 03:22:40 -050068Verify REST JSON Data On Success
69 [Documentation] Verify JSON data success response messages.
70 [Tags] Verify_REST_JSON_Data_On_Success
71 # Example:
72 # Response code:200, Content:{
73 # "data": [
74 # "/xyz/openbmc_project/sensors",
75 # "/xyz/openbmc_project/inventory",
76 # "/xyz/openbmc_project/software",
77 # "/xyz/openbmc_project/object_mapper",
78 # "/xyz/openbmc_project/logging"
79 # ],
80 # "message": "200 OK",
81 # "status": "ok"
82 # }
83
84 ${resp}= OpenBMC Get Request /xyz/openbmc_project/
85 ${jsondata}= To JSON ${resp.content}
86 Should Not Be Empty ${jsondata["data"]}
87 Should Be Equal As Strings ${jsondata["message"]} 200 OK
88 Should Be Equal As Strings ${jsondata["status"]} ok
89
90
91Verify REST JSON Data On Failure
92 [Documentation] Verify JSON data failure response messages.
93 [Tags] Verify_REST_JSON_Data_On_Failure
94 # Example:
95 # Response code:404, Content:{
96 # "data": {
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050097 # "description": "org.freedesktop.DBus.Error.FileNotFound: path or object not found:
98 # /xyz/idont/exist"
George Keishing6715f312017-05-10 03:22:40 -050099 # },
100 # "message": "404 Not Found",
101 # "status": "error"
102 # }
103
104 ${resp}= OpenBMC Get Request /xyz/idont/exist/
105 ${jsondata}= To JSON ${resp.content}
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500106 Should Be Equal As Strings ${jsondata["data"]["description"]}
107 ... org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist
George Keishing6715f312017-05-10 03:22:40 -0500108 Should Be Equal As Strings ${jsondata["message"]} 404 Not Found
109 Should Be Equal As Strings ${jsondata["status"]} error
110
111
George Keishingadefa262017-07-08 12:54:06 -0500112Verify REST Get Message JSON Compliant
113 [Documentation] Verify REST "GET" message is JSON format compliant.
114 [Tags] Verify_REST_Get_Message_JSON_Compliant
115 # For testing if the REST message is JSON format compliant using a
116 # generic BMC state path /xyz/openbmc_project/state object and path
117 # walking through to ensure the parent object, trailing slash and
118 # attribute message response are intact.
119
120 # Object attribute data.
121 # Example:
122 # Response code:200, Content:{
123 # "data": {
124 # "CurrentBMCState": "xyz.openbmc_project.State.BMC.BMCState.Ready",
125 # "RequestedBMCTransition": "xyz.openbmc_project.State.BMC.Transition.None"
126 # },
127 # "message": "200 OK",
128 # "status": "ok"
129 # }
130
131 Verify JSON Response Content
132 ... /xyz/openbmc_project/state/bmc0 DATA_NOT_EMPTY
133
134 # Object trailing slash attribute data.
135 # Example:
136 # Response code:200, Content:{
137 # "data": [],
138 # "message": "200 OK",
139 # "status": "ok"
140 # }
141
142 Verify JSON Response Content /xyz/openbmc_project/state/bmc0/
143
144 # Attribute data.
145 # Example:
146 # Response code:200, Content:{
147 # "data": "xyz.openbmc_project.State.BMC.BMCState.Ready",
148 # "message": "200 OK",
149 # "status": "ok"
150 # }
151
152 Verify JSON Response Content
153 ... /xyz/openbmc_project/state/bmc0/attr/CurrentBMCState DATA_NOT_EMPTY
154
155
156Verify REST Post Message JSON Compliant
157 [Documentation] Verify REST "POST" message is JSON format compliant.
158 [Tags] Verify_REST_Post_Message_JSON_Compliant
159 # Example:
160 # Response code:200, Content:{
161 # "data": null,
162 # "message": "200 OK",
163 # "status": "ok"
164 # }
165
George Keishingd580a9a2018-04-20 01:17:12 -0500166 # Clear existing gard records, if any.
167 ${data}= Create Dictionary data=@{EMPTY}
168 ${resp}= Openbmc Post Request ${OPENPOWER_CONTROL}gard/action/Reset
169 ... data=${data}
George Keishingadefa262017-07-08 12:54:06 -0500170 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
171 ${jsondata}= To JSON ${resp.content}
172 Should Be Equal ${jsondata["data"]} ${None}
173 Should Be Equal As Strings ${jsondata["message"]} 200 OK
174 Should Be Equal As Strings ${jsondata["status"]} ok
175
George Keishingadefa262017-07-08 12:54:06 -0500176
George Keishingf0c1af92018-04-12 08:10:43 -0500177Verify REST Bad Request Post Message JSON Compliant
178 [Documentation] Verify REST "POST" message is JSON format compliant.
179 [Tags] Verify_REST_Bad_Request_Post_Message_JSON_Compliant
180 # Example:
181 # {
182 # "data": {
183 # "description": "Version already exists or failed to be extracted"
184 # },
185 # "message": "400 Bad Request",
186 # "status": "error"
187 # }
188
189 # Generate 1KB file size
190 Run dd if=/dev/zero of=dummyfile bs=1 count=0 seek=1KB
191 OperatingSystem.File Should Exist dummyfile
192
193 # Get the content of the file and upload to BMC
194 ${image_data}= OperatingSystem.Get Binary File dummyfile
195
196 # Get REST session to BMC
197 Initialize OpenBMC
198
199 # Create the REST payload headers and data
200 ${data}= Create Dictionary data ${image_data}
201 ${headers}= Create Dictionary Content-Type=application/octet-stream
202 ... Accept=application/octet-stream
203 Set To Dictionary ${data} headers ${headers}
204
205 ${resp}= Post Request openbmc /upload/image &{data}
206 Should Be Equal As Strings ${resp.status_code} ${HTTP_BAD_REQUEST}
207 ${jsondata}= To JSON ${resp.content}
208 Should Be Equal ${jsondata["data"]["description"]}
209 ... Version already exists or failed to be extracted
210 Should Be Equal As Strings ${jsondata["message"]} 400 Bad Request
211 Should Be Equal As Strings ${jsondata["status"]} error
212 Delete All Error Logs
213
214
George Keishingadefa262017-07-08 12:54:06 -0500215Verify REST Put Message JSON Compliant
216 [Documentation] Verify REST "PUT" message is JSON format compliant.
217 [Tags] REST_Put_Message_JSON_Format_Compliance_Test
218 # Example:
219 # Response code:200, Content:{
220 # "data": null,
221 # "message": "200 OK",
222 # "status": "ok"
223 # }
224
225 ${dict_data}= Create Dictionary data=${HOST_POWEROFF_TRANS}
226 ${resp}= Openbmc Put Request
227 ... ${HOST_STATE_URI}/attr/RequestedHostTransition data=${dict_data}
228 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
229 ${jsondata}= To JSON ${resp.content}
230 Should Be Equal ${jsondata["data"]} ${None}
231 Should Be Equal As Strings ${jsondata["message"]} 200 OK
232 Should Be Equal As Strings ${jsondata["status"]} ok
233 # Intention is not to test poweroff but to check the REST operation
234 # sink time allowing to kick poweroff.
235 Sleep 10s
236
237
George Keishinge6594f22017-07-06 12:10:52 -0500238Check Response Codes HTTP_UNSUPPORTED_MEDIA_TYPE
239 [Documentation] REST "Post" response status test for
240 ... HTTP_UNSUPPORTED_MEDIA_TYPE.
241 [Tags] Check_Response_Codes_415
242
243 # Example:
244 # Response code:415, Content:{
245 # "data": {
246 # "description": "Expecting content type 'application/octet-stream', got 'application/json'"
247 # },
248 # "message": "415 Unsupported Media Type",
249 # "status": "error"
250 # }
251
252 Initialize OpenBMC
253
254 # Create the REST payload headers and EMPTY data
255 ${data}= Create Dictionary data ${EMPTY}
256 ${headers}= Create Dictionary Content-Type=application/json
257 Set To Dictionary ${data} headers ${headers}
258
259 ${resp}= Post Request openbmc /upload/image &{data}
260 Should Be Equal As Strings
261 ... ${resp.status_code} ${HTTP_UNSUPPORTED_MEDIA_TYPE}
262
263 ${jsondata}= To JSON ${resp.content}
264 Should Be Equal As Strings ${jsondata["data"]["description"]}
265 ... Expecting content type 'application/octet-stream', got 'application/json'
266 Should Be Equal As Strings
267 ... ${jsondata["message"]} 415 Unsupported Media Type
268 Should Be Equal As Strings ${jsondata["status"]} error
269
270
George Keishing85536662017-03-03 10:49:58 -0600271Get Response Codes
272 [Documentation] REST "Get" response status test.
273 #--------------------------------------------------------------------
274 # Expect status URL Path
275 #--------------------------------------------------------------------
George Keishing5cd6d042018-05-03 14:52:32 -0500276 ${HTTP_OK} /org/
George Keishing85536662017-03-03 10:49:58 -0600277 ${HTTP_OK} /xyz/
278 ${HTTP_OK} /xyz/openbmc_project/
George Keishing5cb75f82017-12-11 08:41:34 -0600279 ${HTTP_OK} /xyz/openbmc_project/state/enumerate
George Keishing85536662017-03-03 10:49:58 -0600280 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500281
George Keishing85536662017-03-03 10:49:58 -0600282 [Tags] Get_Response_Codes
283 [Template] Execute Get And Check Response
Chris Austenb29d2e82016-06-07 12:25:35 -0500284
Chris Austenb29d2e82016-06-07 12:25:35 -0500285
George Keishing85536662017-03-03 10:49:58 -0600286Get Data
287 [Documentation] REST "Get" request url and expect the
288 ... response OK and data non empty.
289 #--------------------------------------------------------------------
290 # URL Path
291 #--------------------------------------------------------------------
292 /xyz/openbmc_project/
293 /xyz/openbmc_project/list
George Keishing5cb75f82017-12-11 08:41:34 -0600294 /xyz/openbmc_project/state/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500295
George Keishing85536662017-03-03 10:49:58 -0600296 [Tags] Get_Data
297 [Template] Execute Get And Check Data
Chris Austenb29d2e82016-06-07 12:25:35 -0500298
Chris Austenb29d2e82016-06-07 12:25:35 -0500299
George Keishing85536662017-03-03 10:49:58 -0600300Get Data Validation
301 [Documentation] REST "Get" request url and expect the
302 ... pre-defined string in response data.
303 #--------------------------------------------------------------------
304 # URL Path Expect Data
305 #--------------------------------------------------------------------
306 /xyz/openbmc_project/ /xyz/openbmc_project/logging
307 /i/dont/exist/ path or object not found: /i/dont/exist
308
309 [Tags] Get_Data_Validation
310 [Template] Execute Get And Verify Data
311
312
313Put Response Codes
314 [Documentation] REST "Put" request url and expect the REST pre-defined
315 ... codes.
316 #--------------------------------------------------------------------
317 # Expect status URL Path
318 #--------------------------------------------------------------------
319 ${HTTP_METHOD_NOT_ALLOWED} /
320 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
321 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing85536662017-03-03 10:49:58 -0600322
323 [Tags] Put_Response_Codes
324 [Template] Execute Put And Check Response
325
326
327Put Data Validation
328 [Documentation] REST "Put" request url and expect success.
329 #--------------------------------------------------------------------
330 # URL Path Parm Data
331 #--------------------------------------------------------------------
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500332 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition
333 ... xyz.openbmc_project.State.Host.Transition.Off
George Keishing85536662017-03-03 10:49:58 -0600334
335 [Tags] Put_Data_Validation
336 [Template] Execute Put And Expect Success
337
338
339Post Response Code
340 [Documentation] REST Post request url and expect the
341 ... REST response code pre define.
342 #--------------------------------------------------------------------
343 # Expect status URL Path
344 #--------------------------------------------------------------------
345 ${HTTP_METHOD_NOT_ALLOWED} /
346 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
347 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing5cb75f82017-12-11 08:41:34 -0600348 ${HTTP_METHOD_NOT_ALLOWED} /xyz/login
George Keishing85536662017-03-03 10:49:58 -0600349
350 [Tags] Post_Response_Codes
351 [Template] Execute Post And Check Response
352
353
354Delete Response Code
355 [Documentation] REST "Delete" request url and expect the
356 ... REST response code pre define.
357 #--------------------------------------------------------------------
358 # Expect status URL Path
359 #--------------------------------------------------------------------
360 ${HTTP_METHOD_NOT_ALLOWED} /
361 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
362 ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/
George Keishing5cb75f82017-12-11 08:41:34 -0600363 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/state/
George Keishing85536662017-03-03 10:49:58 -0600364
365 [Tags] Delete_Response_Codes
366 [Template] Execute Delete And Check Response
367
Gunnar Mills56b32892016-11-14 13:56:17 -0600368
manasarm5f76a2d2018-01-11 11:34:41 +0530369Verify All REST Objects Are Accessible
370 [Documentation] Verify all the REST objects are accessible using "GET".
371 [Tags] Verify_All_REST_Objects_Are_Accessible
372
373 ${uri_list}= Get Sub URI List ${OPENBMC_BASE_URI}
374 ${error_uri_list}= Create List
375 :FOR ${uri} IN @{uri_list}
376 \ ${resp}= Openbmc Get Request ${uri} quiet=${1}
377 \ Run keyword if '${resp.status_code}' != '${HTTP_OK}'
378 \ ... Append To List ${error_uri_list} ${uri} : ${resp.status_code}
379 Should Be Empty ${error_uri_list}
380
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600381*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600382
manasarm5f76a2d2018-01-11 11:34:41 +0530383Get Sub URI List
384 [Documentation] Return list of sub URIs inside the URI sent by caller.
385 [Arguments] ${uri}
386 # Description of argument(s):
387 # uri The URI for which all the sub URIs are returned.
388 # Example:
389 # "/xyz/openbmc_project/"
390 ${resp}= Openbmc Get Request ${uri}list quiet=${1}
391 ${sub_uris}= Collections.Get From Dictionary ${resp.json()} data
392 [Return] ${sub_uris}
393
George Keishing85536662017-03-03 10:49:58 -0600394Execute Get And Check Response
395 [Documentation] Request "Get" url path and expect REST response code.
396 [Arguments] ${expected_response_code} ${url_path}
397 # Description of arguments:
398 # expected_response_code Expected REST status codes.
399 # url_path URL path.
400 ${resp}= Openbmc Get Request ${url_path}
401 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
402
403Execute Get And Check Data
404 [Documentation] Request "Get" url path and expect non empty data.
405 [Arguments] ${url_path}
406 # Description of arguments:
407 # url_path URL path.
408 ${resp}= Openbmc Get Request ${url_path}
409 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
410 ${jsondata}= To JSON ${resp.content}
411 Should Not Be Empty ${jsondata["data"]}
412
413Execute Get And Verify Data
414 [Documentation] Request "Get" url path and verify data.
415 [Arguments] ${url_path} ${expected_response_code}
416 # Description of arguments:
417 # expected_response_code Expected REST status codes.
418 # url_path URL path.
419 ${resp}= Openbmc Get Request ${url_path}
420 ${jsondata}= To JSON ${resp.content}
421 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
422 ... Should Contain ${jsondata["data"]} ${expected_response_code}
423 ... ELSE
424 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
425
426Execute Put And Check Response
427 [Documentation] Request "Put" url path and expect REST response code.
428 [Arguments] ${expected_response_code} ${url_path}
429 # Description of arguments:
430 # expected_response_code Expected REST status codes.
431 # url_path URL path.
432 ${resp}= Openbmc Put Request ${url_path}
433 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
434
435Execute Put And Expect Success
436 [Documentation] Request "Put" on url path.
437 [Arguments] ${url_path} ${parm}
438 # Description of arguments:
439 # url_path URL path.
440 # parm Value/string to be set.
441 # expected_response_code Expected REST status codes.
442 ${parmDict}= Create Dictionary data=${parm}
443 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
444 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
445
446Execute Post And Check Response
447 [Documentation] Request Post url path and expect REST response code.
448 [Arguments] ${expected_response_code} ${url_path}
449 # Description of arguments:
450 # expected_response_code Expected REST status codes.
451 # url_path URL path.
452 ${resp}= Openbmc Post Request ${url_path}
453 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
454
455Execute Post And Check Data
456 [Arguments] ${url_path} ${parm}
457 [Documentation] Request Post on url path and expected non empty data.
458 # Description of arguments:
459 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500460 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600461 ${resp}= Openbmc Post Request ${url_path} data=${data}
462 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
463 ${jsondata}= To JSON ${resp.content}
464 Should Not Be Empty ${jsondata["data"]}
465
466Execute Delete And Check Response
467 [Documentation] Request "Delete" url path and expected REST response code.
468 [Arguments] ${expected_response_code} ${url_path}
469 # Description of arguments:
470 # expected_response_code Expected REST status codes.
471 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500472 ${data}= Create Dictionary data=@{EMPTY}
473 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600474 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
George Keishingadefa262017-07-08 12:54:06 -0500475
476Verify JSON Response Content
477 [Documentation] Verify JSON response data is intact.
478 [Arguments] ${url_path} ${data_empty}=${EMPTY}
479
480 # Description of argument(s):
481 # url_path URL path.
482 # data_empty JSON data element.
483
484 ${resp}= OpenBMC Get Request ${url_path}
485 ${jsondata}= To JSON ${resp.content}
486 Run Keyword If '${data_empty}' == '${EMPTY}'
487 ... Should Be Empty ${jsondata["data"]}
488 ... ELSE
489 ... Should Not Be Empty ${jsondata["data"]}
490 Should Be Equal As Strings ${jsondata["message"]} 200 OK
491 Should Be Equal As Strings ${jsondata["status"]} ok