blob: 193892367705e62441534d47ae90615ad7bbdfb3 [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 Keishing5cd6d042018-05-03 14:52:32 -0500277 ${HTTP_OK} /org/
George Keishing85536662017-03-03 10:49:58 -0600278 ${HTTP_OK} /xyz/
279 ${HTTP_OK} /xyz/openbmc_project/
George Keishing5cb75f82017-12-11 08:41:34 -0600280 ${HTTP_OK} /xyz/openbmc_project/state/enumerate
George Keishing85536662017-03-03 10:49:58 -0600281 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500282
Chris Austenb29d2e82016-06-07 12:25:35 -0500283
George Keishing85536662017-03-03 10:49:58 -0600284Get Data
285 [Documentation] REST "Get" request url and expect the
286 ... response OK and data non empty.
George Keishing5abfe602018-07-05 11:54:37 -0500287 [Tags] Get_Data
288 [Template] Execute Get And Check Data
289
George Keishing85536662017-03-03 10:49:58 -0600290 # URL Path
George Keishing85536662017-03-03 10:49:58 -0600291 /xyz/openbmc_project/
292 /xyz/openbmc_project/list
George Keishing5cb75f82017-12-11 08:41:34 -0600293 /xyz/openbmc_project/state/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500294
Chris Austenb29d2e82016-06-07 12:25:35 -0500295
George Keishing85536662017-03-03 10:49:58 -0600296Get Data Validation
297 [Documentation] REST "Get" request url and expect the
298 ... pre-defined string in response data.
George Keishing85536662017-03-03 10:49:58 -0600299 [Tags] Get_Data_Validation
300 [Template] Execute Get And Verify Data
301
George Keishing5abfe602018-07-05 11:54:37 -0500302 # URL Path Expect Data
303 /xyz/openbmc_project/ /xyz/openbmc_project/logging
304 /i/dont/exist/ path or object not found: /i/dont/exist
305
George Keishing85536662017-03-03 10:49:58 -0600306
307Put Response Codes
308 [Documentation] REST "Put" request url and expect the REST pre-defined
309 ... codes.
George Keishing5abfe602018-07-05 11:54:37 -0500310 [Tags] Put_Response_Codes
311 [Template] Execute Put And Check Response
312
George Keishing85536662017-03-03 10:49:58 -0600313 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600314 ${HTTP_METHOD_NOT_ALLOWED} /
315 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
316 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing85536662017-03-03 10:49:58 -0600317
George Keishing85536662017-03-03 10:49:58 -0600318
319Put Data Validation
320 [Documentation] REST "Put" request url and expect success.
George Keishing85536662017-03-03 10:49:58 -0600321 [Tags] Put_Data_Validation
322 [Template] Execute Put And Expect Success
323
George Keishing5abfe602018-07-05 11:54:37 -0500324 # URL Path Parm Data
325 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition
326 ... xyz.openbmc_project.State.Host.Transition.Off
327
George Keishing85536662017-03-03 10:49:58 -0600328
329Post Response Code
330 [Documentation] REST Post request url and expect the
331 ... REST response code pre define.
George Keishing5abfe602018-07-05 11:54:37 -0500332 [Tags] Post_Response_Codes
333 [Template] Execute Post And Check Response
334
George Keishing85536662017-03-03 10:49:58 -0600335 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600336 ${HTTP_METHOD_NOT_ALLOWED} /
337 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
338 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing5cb75f82017-12-11 08:41:34 -0600339 ${HTTP_METHOD_NOT_ALLOWED} /xyz/login
George Keishing85536662017-03-03 10:49:58 -0600340
George Keishing85536662017-03-03 10:49:58 -0600341
342Delete Response Code
343 [Documentation] REST "Delete" request url and expect the
344 ... REST response code pre define.
George Keishing5abfe602018-07-05 11:54:37 -0500345 [Tags] Delete_Response_Codes
346 [Template] Execute Delete And Check Response
347
George Keishing85536662017-03-03 10:49:58 -0600348 # Expect status URL Path
George Keishing85536662017-03-03 10:49:58 -0600349 ${HTTP_METHOD_NOT_ALLOWED} /
350 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
351 ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/
George Keishing5cb75f82017-12-11 08:41:34 -0600352 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/state/
George Keishing85536662017-03-03 10:49:58 -0600353
Gunnar Mills56b32892016-11-14 13:56:17 -0600354
manasarm5f76a2d2018-01-11 11:34:41 +0530355Verify All REST Objects Are Accessible
356 [Documentation] Verify all the REST objects are accessible using "GET".
357 [Tags] Verify_All_REST_Objects_Are_Accessible
358
359 ${uri_list}= Get Sub URI List ${OPENBMC_BASE_URI}
360 ${error_uri_list}= Create List
361 :FOR ${uri} IN @{uri_list}
362 \ ${resp}= Openbmc Get Request ${uri} quiet=${1}
363 \ Run keyword if '${resp.status_code}' != '${HTTP_OK}'
364 \ ... Append To List ${error_uri_list} ${uri} : ${resp.status_code}
365 Should Be Empty ${error_uri_list}
366
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600367*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600368
manasarm5f76a2d2018-01-11 11:34:41 +0530369Get Sub URI List
370 [Documentation] Return list of sub URIs inside the URI sent by caller.
371 [Arguments] ${uri}
372 # Description of argument(s):
373 # uri The URI for which all the sub URIs are returned.
374 # Example:
375 # "/xyz/openbmc_project/"
376 ${resp}= Openbmc Get Request ${uri}list quiet=${1}
377 ${sub_uris}= Collections.Get From Dictionary ${resp.json()} data
378 [Return] ${sub_uris}
379
George Keishing85536662017-03-03 10:49:58 -0600380Execute Get And Check Response
381 [Documentation] Request "Get" 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 Get Request ${url_path}
387 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
388
389Execute Get And Check Data
390 [Documentation] Request "Get" url path and expect non empty data.
391 [Arguments] ${url_path}
392 # Description of arguments:
393 # url_path URL path.
394 ${resp}= Openbmc Get Request ${url_path}
395 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
396 ${jsondata}= To JSON ${resp.content}
397 Should Not Be Empty ${jsondata["data"]}
398
399Execute Get And Verify Data
400 [Documentation] Request "Get" url path and verify data.
401 [Arguments] ${url_path} ${expected_response_code}
402 # Description of arguments:
403 # expected_response_code Expected REST status codes.
404 # url_path URL path.
405 ${resp}= Openbmc Get Request ${url_path}
406 ${jsondata}= To JSON ${resp.content}
407 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
408 ... Should Contain ${jsondata["data"]} ${expected_response_code}
409 ... ELSE
410 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
411
412Execute Put And Check Response
413 [Documentation] Request "Put" url path and expect REST response code.
414 [Arguments] ${expected_response_code} ${url_path}
415 # Description of arguments:
416 # expected_response_code Expected REST status codes.
417 # url_path URL path.
418 ${resp}= Openbmc Put Request ${url_path}
419 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
420
421Execute Put And Expect Success
422 [Documentation] Request "Put" on url path.
423 [Arguments] ${url_path} ${parm}
424 # Description of arguments:
425 # url_path URL path.
426 # parm Value/string to be set.
427 # expected_response_code Expected REST status codes.
428 ${parmDict}= Create Dictionary data=${parm}
429 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
430 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
431
432Execute Post And Check Response
433 [Documentation] Request Post url path and expect REST response code.
434 [Arguments] ${expected_response_code} ${url_path}
435 # Description of arguments:
436 # expected_response_code Expected REST status codes.
437 # url_path URL path.
438 ${resp}= Openbmc Post Request ${url_path}
439 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
440
441Execute Post And Check Data
442 [Arguments] ${url_path} ${parm}
443 [Documentation] Request Post on url path and expected non empty data.
444 # Description of arguments:
445 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500446 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600447 ${resp}= Openbmc Post Request ${url_path} data=${data}
448 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
449 ${jsondata}= To JSON ${resp.content}
450 Should Not Be Empty ${jsondata["data"]}
451
452Execute Delete And Check Response
453 [Documentation] Request "Delete" url path and expected REST response code.
454 [Arguments] ${expected_response_code} ${url_path}
455 # Description of arguments:
456 # expected_response_code Expected REST status codes.
457 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500458 ${data}= Create Dictionary data=@{EMPTY}
459 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600460 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
George Keishingadefa262017-07-08 12:54:06 -0500461
462Verify JSON Response Content
463 [Documentation] Verify JSON response data is intact.
464 [Arguments] ${url_path} ${data_empty}=${EMPTY}
465
466 # Description of argument(s):
467 # url_path URL path.
468 # data_empty JSON data element.
469
470 ${resp}= OpenBMC Get Request ${url_path}
471 ${jsondata}= To JSON ${resp.content}
472 Run Keyword If '${data_empty}' == '${EMPTY}'
473 ... Should Be Empty ${jsondata["data"]}
474 ... ELSE
475 ... Should Not Be Empty ${jsondata["data"]}
476 Should Be Equal As Strings ${jsondata["message"]} 200 OK
477 Should Be Equal As Strings ${jsondata["status"]} ok