blob: 92dba38becc8eb48f91fc3030ab80a7a10881841 [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": {
97 # "description": "org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist"
98 # },
99 # "message": "404 Not Found",
100 # "status": "error"
101 # }
102
103 ${resp}= OpenBMC Get Request /xyz/idont/exist/
104 ${jsondata}= To JSON ${resp.content}
105 Should Be Equal As Strings
106 ... ${jsondata["data"]["description"]} org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist
107 Should Be Equal As Strings ${jsondata["message"]} 404 Not Found
108 Should Be Equal As Strings ${jsondata["status"]} error
109
110
George Keishingadefa262017-07-08 12:54:06 -0500111Verify REST Get Message JSON Compliant
112 [Documentation] Verify REST "GET" message is JSON format compliant.
113 [Tags] Verify_REST_Get_Message_JSON_Compliant
114 # For testing if the REST message is JSON format compliant using a
115 # generic BMC state path /xyz/openbmc_project/state object and path
116 # walking through to ensure the parent object, trailing slash and
117 # attribute message response are intact.
118
119 # Object attribute data.
120 # Example:
121 # Response code:200, Content:{
122 # "data": {
123 # "CurrentBMCState": "xyz.openbmc_project.State.BMC.BMCState.Ready",
124 # "RequestedBMCTransition": "xyz.openbmc_project.State.BMC.Transition.None"
125 # },
126 # "message": "200 OK",
127 # "status": "ok"
128 # }
129
130 Verify JSON Response Content
131 ... /xyz/openbmc_project/state/bmc0 DATA_NOT_EMPTY
132
133 # Object trailing slash attribute data.
134 # Example:
135 # Response code:200, Content:{
136 # "data": [],
137 # "message": "200 OK",
138 # "status": "ok"
139 # }
140
141 Verify JSON Response Content /xyz/openbmc_project/state/bmc0/
142
143 # Attribute data.
144 # Example:
145 # Response code:200, Content:{
146 # "data": "xyz.openbmc_project.State.BMC.BMCState.Ready",
147 # "message": "200 OK",
148 # "status": "ok"
149 # }
150
151 Verify JSON Response Content
152 ... /xyz/openbmc_project/state/bmc0/attr/CurrentBMCState DATA_NOT_EMPTY
153
154
155Verify REST Post Message JSON Compliant
156 [Documentation] Verify REST "POST" message is JSON format compliant.
157 [Tags] Verify_REST_Post_Message_JSON_Compliant
158 # Example:
159 # Response code:200, Content:{
160 # "data": null,
161 # "message": "200 OK",
162 # "status": "ok"
163 # }
164
165 # Generate 1KB file size
166 Run dd if=/dev/zero of=dummyfile bs=1 count=0 seek=1KB
167 OperatingSystem.File Should Exist dummyfile
168
169 # Get the content of the file and upload to BMC
170 ${image_data}= OperatingSystem.Get Binary File dummyfile
171
172 # Get REST session to BMC
173 Initialize OpenBMC
174
175 # Create the REST payload headers and data
176 ${data}= Create Dictionary data ${image_data}
177 ${headers}= Create Dictionary Content-Type=application/octet-stream
178 ... Accept=application/octet-stream
179 Set To Dictionary ${data} headers ${headers}
180
181 ${resp}= Post Request openbmc /upload/image &{data}
182 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
183 ${jsondata}= To JSON ${resp.content}
184 Should Be Equal ${jsondata["data"]} ${None}
185 Should Be Equal As Strings ${jsondata["message"]} 200 OK
186 Should Be Equal As Strings ${jsondata["status"]} ok
George Keishingbaae4c42018-04-04 12:13:43 -0500187 Delete All Error Logs
George Keishingadefa262017-07-08 12:54:06 -0500188
George Keishingadefa262017-07-08 12:54:06 -0500189
190Verify REST Put Message JSON Compliant
191 [Documentation] Verify REST "PUT" message is JSON format compliant.
192 [Tags] REST_Put_Message_JSON_Format_Compliance_Test
193 # Example:
194 # Response code:200, Content:{
195 # "data": null,
196 # "message": "200 OK",
197 # "status": "ok"
198 # }
199
200 ${dict_data}= Create Dictionary data=${HOST_POWEROFF_TRANS}
201 ${resp}= Openbmc Put Request
202 ... ${HOST_STATE_URI}/attr/RequestedHostTransition data=${dict_data}
203 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
204 ${jsondata}= To JSON ${resp.content}
205 Should Be Equal ${jsondata["data"]} ${None}
206 Should Be Equal As Strings ${jsondata["message"]} 200 OK
207 Should Be Equal As Strings ${jsondata["status"]} ok
208 # Intention is not to test poweroff but to check the REST operation
209 # sink time allowing to kick poweroff.
210 Sleep 10s
211
212
George Keishinge6594f22017-07-06 12:10:52 -0500213Check Response Codes HTTP_UNSUPPORTED_MEDIA_TYPE
214 [Documentation] REST "Post" response status test for
215 ... HTTP_UNSUPPORTED_MEDIA_TYPE.
216 [Tags] Check_Response_Codes_415
217
218 # Example:
219 # Response code:415, Content:{
220 # "data": {
221 # "description": "Expecting content type 'application/octet-stream', got 'application/json'"
222 # },
223 # "message": "415 Unsupported Media Type",
224 # "status": "error"
225 # }
226
227 Initialize OpenBMC
228
229 # Create the REST payload headers and EMPTY data
230 ${data}= Create Dictionary data ${EMPTY}
231 ${headers}= Create Dictionary Content-Type=application/json
232 Set To Dictionary ${data} headers ${headers}
233
234 ${resp}= Post Request openbmc /upload/image &{data}
235 Should Be Equal As Strings
236 ... ${resp.status_code} ${HTTP_UNSUPPORTED_MEDIA_TYPE}
237
238 ${jsondata}= To JSON ${resp.content}
239 Should Be Equal As Strings ${jsondata["data"]["description"]}
240 ... Expecting content type 'application/octet-stream', got 'application/json'
241 Should Be Equal As Strings
242 ... ${jsondata["message"]} 415 Unsupported Media Type
243 Should Be Equal As Strings ${jsondata["status"]} error
244
245
George Keishing85536662017-03-03 10:49:58 -0600246Get Response Codes
247 [Documentation] REST "Get" response status test.
248 #--------------------------------------------------------------------
249 # Expect status URL Path
250 #--------------------------------------------------------------------
251 ${HTTP_OK} /
252 ${HTTP_OK} /xyz/
253 ${HTTP_OK} /xyz/openbmc_project/
George Keishing5cb75f82017-12-11 08:41:34 -0600254 ${HTTP_OK} /xyz/openbmc_project/state/enumerate
George Keishing85536662017-03-03 10:49:58 -0600255 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500256
George Keishing85536662017-03-03 10:49:58 -0600257 [Tags] Get_Response_Codes
258 [Template] Execute Get And Check Response
Chris Austenb29d2e82016-06-07 12:25:35 -0500259
Chris Austenb29d2e82016-06-07 12:25:35 -0500260
George Keishing85536662017-03-03 10:49:58 -0600261Get Data
262 [Documentation] REST "Get" request url and expect the
263 ... response OK and data non empty.
264 #--------------------------------------------------------------------
265 # URL Path
266 #--------------------------------------------------------------------
267 /xyz/openbmc_project/
268 /xyz/openbmc_project/list
George Keishing5cb75f82017-12-11 08:41:34 -0600269 /xyz/openbmc_project/state/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500270
George Keishing85536662017-03-03 10:49:58 -0600271 [Tags] Get_Data
272 [Template] Execute Get And Check Data
Chris Austenb29d2e82016-06-07 12:25:35 -0500273
Chris Austenb29d2e82016-06-07 12:25:35 -0500274
George Keishing85536662017-03-03 10:49:58 -0600275Get Data Validation
276 [Documentation] REST "Get" request url and expect the
277 ... pre-defined string in response data.
278 #--------------------------------------------------------------------
279 # URL Path Expect Data
280 #--------------------------------------------------------------------
281 /xyz/openbmc_project/ /xyz/openbmc_project/logging
282 /i/dont/exist/ path or object not found: /i/dont/exist
283
284 [Tags] Get_Data_Validation
285 [Template] Execute Get And Verify Data
286
287
288Put Response Codes
289 [Documentation] REST "Put" request url and expect the REST pre-defined
290 ... codes.
291 #--------------------------------------------------------------------
292 # Expect status URL Path
293 #--------------------------------------------------------------------
294 ${HTTP_METHOD_NOT_ALLOWED} /
295 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
296 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
George Keishing85536662017-03-03 10:49:58 -0600297
298 [Tags] Put_Response_Codes
299 [Template] Execute Put And Check Response
300
301
302Put Data Validation
303 [Documentation] REST "Put" request url and expect success.
304 #--------------------------------------------------------------------
305 # URL Path Parm Data
306 #--------------------------------------------------------------------
307 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition xyz.openbmc_project.State.Host.Transition.Off
308
309 [Tags] Put_Data_Validation
310 [Template] Execute Put And Expect Success
311
312
313Post Response Code
314 [Documentation] REST Post request url and expect the
315 ... REST response code pre define.
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 Keishing5cb75f82017-12-11 08:41:34 -0600322 ${HTTP_METHOD_NOT_ALLOWED} /xyz/login
George Keishing85536662017-03-03 10:49:58 -0600323
324 [Tags] Post_Response_Codes
325 [Template] Execute Post And Check Response
326
327
328Delete Response Code
329 [Documentation] REST "Delete" request url and expect the
330 ... REST response code pre define.
331 #--------------------------------------------------------------------
332 # Expect status URL Path
333 #--------------------------------------------------------------------
334 ${HTTP_METHOD_NOT_ALLOWED} /
335 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
336 ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/
George Keishing5cb75f82017-12-11 08:41:34 -0600337 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/state/
George Keishing85536662017-03-03 10:49:58 -0600338
339 [Tags] Delete_Response_Codes
340 [Template] Execute Delete And Check Response
341
Gunnar Mills56b32892016-11-14 13:56:17 -0600342
manasarm5f76a2d2018-01-11 11:34:41 +0530343Verify All REST Objects Are Accessible
344 [Documentation] Verify all the REST objects are accessible using "GET".
345 [Tags] Verify_All_REST_Objects_Are_Accessible
346
347 ${uri_list}= Get Sub URI List ${OPENBMC_BASE_URI}
348 ${error_uri_list}= Create List
349 :FOR ${uri} IN @{uri_list}
350 \ ${resp}= Openbmc Get Request ${uri} quiet=${1}
351 \ Run keyword if '${resp.status_code}' != '${HTTP_OK}'
352 \ ... Append To List ${error_uri_list} ${uri} : ${resp.status_code}
353 Should Be Empty ${error_uri_list}
354
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600355*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600356
manasarm5f76a2d2018-01-11 11:34:41 +0530357Get Sub URI List
358 [Documentation] Return list of sub URIs inside the URI sent by caller.
359 [Arguments] ${uri}
360 # Description of argument(s):
361 # uri The URI for which all the sub URIs are returned.
362 # Example:
363 # "/xyz/openbmc_project/"
364 ${resp}= Openbmc Get Request ${uri}list quiet=${1}
365 ${sub_uris}= Collections.Get From Dictionary ${resp.json()} data
366 [Return] ${sub_uris}
367
George Keishing85536662017-03-03 10:49:58 -0600368Execute Get And Check Response
369 [Documentation] Request "Get" url path and expect REST response code.
370 [Arguments] ${expected_response_code} ${url_path}
371 # Description of arguments:
372 # expected_response_code Expected REST status codes.
373 # url_path URL path.
374 ${resp}= Openbmc Get Request ${url_path}
375 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
376
377Execute Get And Check Data
378 [Documentation] Request "Get" url path and expect non empty data.
379 [Arguments] ${url_path}
380 # Description of arguments:
381 # url_path URL path.
382 ${resp}= Openbmc Get Request ${url_path}
383 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
384 ${jsondata}= To JSON ${resp.content}
385 Should Not Be Empty ${jsondata["data"]}
386
387Execute Get And Verify Data
388 [Documentation] Request "Get" url path and verify data.
389 [Arguments] ${url_path} ${expected_response_code}
390 # Description of arguments:
391 # expected_response_code Expected REST status codes.
392 # url_path URL path.
393 ${resp}= Openbmc Get Request ${url_path}
394 ${jsondata}= To JSON ${resp.content}
395 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
396 ... Should Contain ${jsondata["data"]} ${expected_response_code}
397 ... ELSE
398 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
399
400Execute Put And Check Response
401 [Documentation] Request "Put" 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 Put Request ${url_path}
407 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
408
409Execute Put And Expect Success
410 [Documentation] Request "Put" on url path.
411 [Arguments] ${url_path} ${parm}
412 # Description of arguments:
413 # url_path URL path.
414 # parm Value/string to be set.
415 # expected_response_code Expected REST status codes.
416 ${parmDict}= Create Dictionary data=${parm}
417 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
418 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
419
420Execute Post And Check Response
421 [Documentation] Request Post url path and expect 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.
426 ${resp}= Openbmc Post Request ${url_path}
427 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
428
429Execute Post And Check Data
430 [Arguments] ${url_path} ${parm}
431 [Documentation] Request Post on url path and expected non empty data.
432 # Description of arguments:
433 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500434 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600435 ${resp}= Openbmc Post Request ${url_path} data=${data}
436 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
437 ${jsondata}= To JSON ${resp.content}
438 Should Not Be Empty ${jsondata["data"]}
439
440Execute Delete And Check Response
441 [Documentation] Request "Delete" url path and expected REST response code.
442 [Arguments] ${expected_response_code} ${url_path}
443 # Description of arguments:
444 # expected_response_code Expected REST status codes.
445 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500446 ${data}= Create Dictionary data=@{EMPTY}
447 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600448 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
George Keishingadefa262017-07-08 12:54:06 -0500449
450Verify JSON Response Content
451 [Documentation] Verify JSON response data is intact.
452 [Arguments] ${url_path} ${data_empty}=${EMPTY}
453
454 # Description of argument(s):
455 # url_path URL path.
456 # data_empty JSON data element.
457
458 ${resp}= OpenBMC Get Request ${url_path}
459 ${jsondata}= To JSON ${resp.content}
460 Run Keyword If '${data_empty}' == '${EMPTY}'
461 ... Should Be Empty ${jsondata["data"]}
462 ... ELSE
463 ... Should Not Be Empty ${jsondata["data"]}
464 Should Be Equal As Strings ${jsondata["message"]} 200 OK
465 Should Be Equal As Strings ${jsondata["status"]} ok