blob: 3f0ddbe8ac59c80230bcf1a86fcf3818f8b2b1fd [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.
George Keishing5abfe602018-07-05 11:54:37 -0500273 [Tags] Get_Response_Codes
274 [Template] Execute Get And Check Response
275
George Keishing85536662017-03-03 10:49:58 -0600276 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600277 ${HTTP_OK} /xyz/openbmc_project/
George Keishing5cb75f82017-12-11 08:41:34 -0600278 ${HTTP_OK} /xyz/openbmc_project/state/enumerate
George Keishing85536662017-03-03 10:49:58 -0600279 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500280
Chris Austenb29d2e82016-06-07 12:25:35 -0500281
George Keishing85536662017-03-03 10:49:58 -0600282Get Data
283 [Documentation] REST "Get" request url and expect the
284 ... response OK and data non empty.
George Keishing5abfe602018-07-05 11:54:37 -0500285 [Tags] Get_Data
286 [Template] Execute Get And Check Data
287
George Keishing85536662017-03-03 10:49:58 -0600288 # URL Path
George Keishing85536662017-03-03 10:49:58 -0600289 /xyz/openbmc_project/
290 /xyz/openbmc_project/list
George Keishing5cb75f82017-12-11 08:41:34 -0600291 /xyz/openbmc_project/state/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500292
Chris Austenb29d2e82016-06-07 12:25:35 -0500293
George Keishing85536662017-03-03 10:49:58 -0600294Get Data Validation
295 [Documentation] REST "Get" request url and expect the
296 ... pre-defined string in response data.
George Keishing85536662017-03-03 10:49:58 -0600297 [Tags] Get_Data_Validation
298 [Template] Execute Get And Verify Data
299
George Keishing5abfe602018-07-05 11:54:37 -0500300 # URL Path Expect Data
301 /xyz/openbmc_project/ /xyz/openbmc_project/logging
302 /i/dont/exist/ path or object not found: /i/dont/exist
303
George Keishing85536662017-03-03 10:49:58 -0600304
305Put Response Codes
306 [Documentation] REST "Put" request url and expect the REST pre-defined
307 ... codes.
George Keishing5abfe602018-07-05 11:54:37 -0500308 [Tags] Put_Response_Codes
309 [Template] Execute Put And Check Response
310
George Keishing85536662017-03-03 10:49:58 -0600311 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600312 ${HTTP_METHOD_NOT_ALLOWED} /
313 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
314 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing85536662017-03-03 10:49:58 -0600315
George Keishing85536662017-03-03 10:49:58 -0600316
317Put Data Validation
318 [Documentation] REST "Put" request url and expect success.
George Keishing85536662017-03-03 10:49:58 -0600319 [Tags] Put_Data_Validation
320 [Template] Execute Put And Expect Success
321
George Keishing5abfe602018-07-05 11:54:37 -0500322 # URL Path Parm Data
323 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition
324 ... xyz.openbmc_project.State.Host.Transition.Off
325
George Keishing85536662017-03-03 10:49:58 -0600326
327Post Response Code
328 [Documentation] REST Post request url and expect the
329 ... REST response code pre define.
George Keishing5abfe602018-07-05 11:54:37 -0500330 [Tags] Post_Response_Codes
331 [Template] Execute Post And Check Response
332
George Keishing85536662017-03-03 10:49:58 -0600333 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600334 ${HTTP_METHOD_NOT_ALLOWED} /
335 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
336 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing5cb75f82017-12-11 08:41:34 -0600337 ${HTTP_METHOD_NOT_ALLOWED} /xyz/login
George Keishing85536662017-03-03 10:49:58 -0600338
George Keishing85536662017-03-03 10:49:58 -0600339
340Delete Response Code
341 [Documentation] REST "Delete" request url and expect the
342 ... REST response code pre define.
George Keishing5abfe602018-07-05 11:54:37 -0500343 [Tags] Delete_Response_Codes
344 [Template] Execute Delete And Check Response
345
George Keishing85536662017-03-03 10:49:58 -0600346 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600347 ${HTTP_METHOD_NOT_ALLOWED} /
348 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
349 ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/
George Keishing5cb75f82017-12-11 08:41:34 -0600350 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/state/
George Keishing85536662017-03-03 10:49:58 -0600351
Gunnar Mills56b32892016-11-14 13:56:17 -0600352
manasarm5f76a2d2018-01-11 11:34:41 +0530353Verify All REST Objects Are Accessible
354 [Documentation] Verify all the REST objects are accessible using "GET".
355 [Tags] Verify_All_REST_Objects_Are_Accessible
356
357 ${uri_list}= Get Sub URI List ${OPENBMC_BASE_URI}
George Keishing32e4d172018-10-01 07:41:56 -0500358
359 # URI's which won't support GET request.
360 Remove Values From List ${uri_list}
361 ... /xyz/openbmc_project/certs/client/ldap
362 ... /xyz/openbmc_project/certs/server/https
George Keishing97ab2512018-10-12 01:47:01 -0500363 ... /xyz/openbmc_project/certs/authority/ldap
George Keishing32e4d172018-10-01 07:41:56 -0500364
manasarm5f76a2d2018-01-11 11:34:41 +0530365 ${error_uri_list}= Create List
366 :FOR ${uri} IN @{uri_list}
367 \ ${resp}= Openbmc Get Request ${uri} quiet=${1}
368 \ Run keyword if '${resp.status_code}' != '${HTTP_OK}'
369 \ ... Append To List ${error_uri_list} ${uri} : ${resp.status_code}
370 Should Be Empty ${error_uri_list}
371
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600372*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600373
manasarm5f76a2d2018-01-11 11:34:41 +0530374Get Sub URI List
375 [Documentation] Return list of sub URIs inside the URI sent by caller.
376 [Arguments] ${uri}
377 # Description of argument(s):
378 # uri The URI for which all the sub URIs are returned.
379 # Example:
380 # "/xyz/openbmc_project/"
381 ${resp}= Openbmc Get Request ${uri}list quiet=${1}
382 ${sub_uris}= Collections.Get From Dictionary ${resp.json()} data
383 [Return] ${sub_uris}
384
George Keishing85536662017-03-03 10:49:58 -0600385Execute Get And Check Response
386 [Documentation] Request "Get" url path and expect REST response code.
387 [Arguments] ${expected_response_code} ${url_path}
388 # Description of arguments:
389 # expected_response_code Expected REST status codes.
390 # url_path URL path.
391 ${resp}= Openbmc Get Request ${url_path}
392 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
393
394Execute Get And Check Data
395 [Documentation] Request "Get" url path and expect non empty data.
396 [Arguments] ${url_path}
397 # Description of arguments:
398 # url_path URL path.
399 ${resp}= Openbmc Get Request ${url_path}
400 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
401 ${jsondata}= To JSON ${resp.content}
402 Should Not Be Empty ${jsondata["data"]}
403
404Execute Get And Verify Data
405 [Documentation] Request "Get" url path and verify data.
406 [Arguments] ${url_path} ${expected_response_code}
407 # Description of arguments:
408 # expected_response_code Expected REST status codes.
409 # url_path URL path.
410 ${resp}= Openbmc Get Request ${url_path}
411 ${jsondata}= To JSON ${resp.content}
412 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
413 ... Should Contain ${jsondata["data"]} ${expected_response_code}
414 ... ELSE
415 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
416
417Execute Put And Check Response
418 [Documentation] Request "Put" url path and expect REST response code.
419 [Arguments] ${expected_response_code} ${url_path}
420 # Description of arguments:
421 # expected_response_code Expected REST status codes.
422 # url_path URL path.
423 ${resp}= Openbmc Put Request ${url_path}
424 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
425
426Execute Put And Expect Success
427 [Documentation] Request "Put" on url path.
428 [Arguments] ${url_path} ${parm}
429 # Description of arguments:
430 # url_path URL path.
431 # parm Value/string to be set.
432 # expected_response_code Expected REST status codes.
433 ${parmDict}= Create Dictionary data=${parm}
434 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
435 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
436
437Execute Post And Check Response
438 [Documentation] Request Post url path and expect REST response code.
439 [Arguments] ${expected_response_code} ${url_path}
440 # Description of arguments:
441 # expected_response_code Expected REST status codes.
442 # url_path URL path.
443 ${resp}= Openbmc Post Request ${url_path}
444 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
445
446Execute Post And Check Data
447 [Arguments] ${url_path} ${parm}
448 [Documentation] Request Post on url path and expected non empty data.
449 # Description of arguments:
450 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500451 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600452 ${resp}= Openbmc Post Request ${url_path} data=${data}
453 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
454 ${jsondata}= To JSON ${resp.content}
455 Should Not Be Empty ${jsondata["data"]}
456
457Execute Delete And Check Response
458 [Documentation] Request "Delete" url path and expected REST response code.
459 [Arguments] ${expected_response_code} ${url_path}
460 # Description of arguments:
461 # expected_response_code Expected REST status codes.
462 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500463 ${data}= Create Dictionary data=@{EMPTY}
464 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600465 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
George Keishingadefa262017-07-08 12:54:06 -0500466
467Verify JSON Response Content
468 [Documentation] Verify JSON response data is intact.
469 [Arguments] ${url_path} ${data_empty}=${EMPTY}
470
471 # Description of argument(s):
472 # url_path URL path.
473 # data_empty JSON data element.
474
475 ${resp}= OpenBMC Get Request ${url_path}
476 ${jsondata}= To JSON ${resp.content}
477 Run Keyword If '${data_empty}' == '${EMPTY}'
478 ... Should Be Empty ${jsondata["data"]}
479 ... ELSE
480 ... Should Not Be Empty ${jsondata["data"]}
481 Should Be Equal As Strings ${jsondata["message"]} 200 OK
482 Should Be Equal As Strings ${jsondata["status"]} ok