blob: fec0114be821da66368d1ce1b68c303236910138 [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
50Verify REST JSON Data On Success
51 [Documentation] Verify JSON data success response messages.
52 [Tags] Verify_REST_JSON_Data_On_Success
53 # Example:
54 # Response code:200, Content:{
55 # "data": [
56 # "/xyz/openbmc_project/sensors",
57 # "/xyz/openbmc_project/inventory",
58 # "/xyz/openbmc_project/software",
59 # "/xyz/openbmc_project/object_mapper",
60 # "/xyz/openbmc_project/logging"
61 # ],
62 # "message": "200 OK",
63 # "status": "ok"
64 # }
65
66 ${resp}= OpenBMC Get Request /xyz/openbmc_project/
67 ${jsondata}= To JSON ${resp.content}
68 Should Not Be Empty ${jsondata["data"]}
69 Should Be Equal As Strings ${jsondata["message"]} 200 OK
70 Should Be Equal As Strings ${jsondata["status"]} ok
71
72
73Verify REST JSON Data On Failure
74 [Documentation] Verify JSON data failure response messages.
75 [Tags] Verify_REST_JSON_Data_On_Failure
76 # Example:
77 # Response code:404, Content:{
78 # "data": {
79 # "description": "org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist"
80 # },
81 # "message": "404 Not Found",
82 # "status": "error"
83 # }
84
85 ${resp}= OpenBMC Get Request /xyz/idont/exist/
86 ${jsondata}= To JSON ${resp.content}
87 Should Be Equal As Strings
88 ... ${jsondata["data"]["description"]} org.freedesktop.DBus.Error.FileNotFound: path or object not found: /xyz/idont/exist
89 Should Be Equal As Strings ${jsondata["message"]} 404 Not Found
90 Should Be Equal As Strings ${jsondata["status"]} error
91
92
George Keishingadefa262017-07-08 12:54:06 -050093Verify REST Get Message JSON Compliant
94 [Documentation] Verify REST "GET" message is JSON format compliant.
95 [Tags] Verify_REST_Get_Message_JSON_Compliant
96 # For testing if the REST message is JSON format compliant using a
97 # generic BMC state path /xyz/openbmc_project/state object and path
98 # walking through to ensure the parent object, trailing slash and
99 # attribute message response are intact.
100
101 # Object attribute data.
102 # Example:
103 # Response code:200, Content:{
104 # "data": {
105 # "CurrentBMCState": "xyz.openbmc_project.State.BMC.BMCState.Ready",
106 # "RequestedBMCTransition": "xyz.openbmc_project.State.BMC.Transition.None"
107 # },
108 # "message": "200 OK",
109 # "status": "ok"
110 # }
111
112 Verify JSON Response Content
113 ... /xyz/openbmc_project/state/bmc0 DATA_NOT_EMPTY
114
115 # Object trailing slash attribute data.
116 # Example:
117 # Response code:200, Content:{
118 # "data": [],
119 # "message": "200 OK",
120 # "status": "ok"
121 # }
122
123 Verify JSON Response Content /xyz/openbmc_project/state/bmc0/
124
125 # Attribute data.
126 # Example:
127 # Response code:200, Content:{
128 # "data": "xyz.openbmc_project.State.BMC.BMCState.Ready",
129 # "message": "200 OK",
130 # "status": "ok"
131 # }
132
133 Verify JSON Response Content
134 ... /xyz/openbmc_project/state/bmc0/attr/CurrentBMCState DATA_NOT_EMPTY
135
136
137Verify REST Post Message JSON Compliant
138 [Documentation] Verify REST "POST" message is JSON format compliant.
139 [Tags] Verify_REST_Post_Message_JSON_Compliant
140 # Example:
141 # Response code:200, Content:{
142 # "data": null,
143 # "message": "200 OK",
144 # "status": "ok"
145 # }
146
147 # Generate 1KB file size
148 Run dd if=/dev/zero of=dummyfile bs=1 count=0 seek=1KB
149 OperatingSystem.File Should Exist dummyfile
150
151 # Get the content of the file and upload to BMC
152 ${image_data}= OperatingSystem.Get Binary File dummyfile
153
154 # Get REST session to BMC
155 Initialize OpenBMC
156
157 # Create the REST payload headers and data
158 ${data}= Create Dictionary data ${image_data}
159 ${headers}= Create Dictionary Content-Type=application/octet-stream
160 ... Accept=application/octet-stream
161 Set To Dictionary ${data} headers ${headers}
162
163 ${resp}= Post Request openbmc /upload/image &{data}
164 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
165 ${jsondata}= To JSON ${resp.content}
166 Should Be Equal ${jsondata["data"]} ${None}
167 Should Be Equal As Strings ${jsondata["message"]} 200 OK
168 Should Be Equal As Strings ${jsondata["status"]} ok
169
170 # Cleanup uploaded file.
171 BMC Execute Command rm -rf /tmp/images/*
172
173
174Verify REST Put Message JSON Compliant
175 [Documentation] Verify REST "PUT" message is JSON format compliant.
176 [Tags] REST_Put_Message_JSON_Format_Compliance_Test
177 # Example:
178 # Response code:200, Content:{
179 # "data": null,
180 # "message": "200 OK",
181 # "status": "ok"
182 # }
183
184 ${dict_data}= Create Dictionary data=${HOST_POWEROFF_TRANS}
185 ${resp}= Openbmc Put Request
186 ... ${HOST_STATE_URI}/attr/RequestedHostTransition data=${dict_data}
187 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
188 ${jsondata}= To JSON ${resp.content}
189 Should Be Equal ${jsondata["data"]} ${None}
190 Should Be Equal As Strings ${jsondata["message"]} 200 OK
191 Should Be Equal As Strings ${jsondata["status"]} ok
192 # Intention is not to test poweroff but to check the REST operation
193 # sink time allowing to kick poweroff.
194 Sleep 10s
195
196
George Keishinge6594f22017-07-06 12:10:52 -0500197Check Response Codes HTTP_UNSUPPORTED_MEDIA_TYPE
198 [Documentation] REST "Post" response status test for
199 ... HTTP_UNSUPPORTED_MEDIA_TYPE.
200 [Tags] Check_Response_Codes_415
201
202 # Example:
203 # Response code:415, Content:{
204 # "data": {
205 # "description": "Expecting content type 'application/octet-stream', got 'application/json'"
206 # },
207 # "message": "415 Unsupported Media Type",
208 # "status": "error"
209 # }
210
211 Initialize OpenBMC
212
213 # Create the REST payload headers and EMPTY data
214 ${data}= Create Dictionary data ${EMPTY}
215 ${headers}= Create Dictionary Content-Type=application/json
216 Set To Dictionary ${data} headers ${headers}
217
218 ${resp}= Post Request openbmc /upload/image &{data}
219 Should Be Equal As Strings
220 ... ${resp.status_code} ${HTTP_UNSUPPORTED_MEDIA_TYPE}
221
222 ${jsondata}= To JSON ${resp.content}
223 Should Be Equal As Strings ${jsondata["data"]["description"]}
224 ... Expecting content type 'application/octet-stream', got 'application/json'
225 Should Be Equal As Strings
226 ... ${jsondata["message"]} 415 Unsupported Media Type
227 Should Be Equal As Strings ${jsondata["status"]} error
228
229
George Keishing85536662017-03-03 10:49:58 -0600230Get Response Codes
231 [Documentation] REST "Get" response status test.
232 #--------------------------------------------------------------------
233 # Expect status URL Path
234 #--------------------------------------------------------------------
235 ${HTTP_OK} /
236 ${HTTP_OK} /xyz/
237 ${HTTP_OK} /xyz/openbmc_project/
238 ${HTTP_OK} /xyz/openbmc_project/enumerate
239 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500240
George Keishing85536662017-03-03 10:49:58 -0600241 [Tags] Get_Response_Codes
242 [Template] Execute Get And Check Response
Chris Austenb29d2e82016-06-07 12:25:35 -0500243
Chris Austenb29d2e82016-06-07 12:25:35 -0500244
George Keishing85536662017-03-03 10:49:58 -0600245Get Data
246 [Documentation] REST "Get" request url and expect the
247 ... response OK and data non empty.
248 #--------------------------------------------------------------------
249 # URL Path
250 #--------------------------------------------------------------------
251 /xyz/openbmc_project/
252 /xyz/openbmc_project/list
253 /xyz/openbmc_project/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500254
George Keishing85536662017-03-03 10:49:58 -0600255 [Tags] Get_Data
256 [Template] Execute Get And Check Data
Chris Austenb29d2e82016-06-07 12:25:35 -0500257
Chris Austenb29d2e82016-06-07 12:25:35 -0500258
George Keishing85536662017-03-03 10:49:58 -0600259Get Data Validation
260 [Documentation] REST "Get" request url and expect the
261 ... pre-defined string in response data.
262 #--------------------------------------------------------------------
263 # URL Path Expect Data
264 #--------------------------------------------------------------------
265 /xyz/openbmc_project/ /xyz/openbmc_project/logging
266 /i/dont/exist/ path or object not found: /i/dont/exist
267
268 [Tags] Get_Data_Validation
269 [Template] Execute Get And Verify Data
270
271
272Put Response Codes
273 [Documentation] REST "Put" request url and expect the REST pre-defined
274 ... codes.
275 #--------------------------------------------------------------------
276 # Expect status URL Path
277 #--------------------------------------------------------------------
278 ${HTTP_METHOD_NOT_ALLOWED} /
279 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
280 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
281 ${HTTP_METHOD_NOT_ALLOWED} /xyz/list
282 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
283
284 [Tags] Put_Response_Codes
285 [Template] Execute Put And Check Response
286
287
288Put Data Validation
289 [Documentation] REST "Put" request url and expect success.
290 #--------------------------------------------------------------------
291 # URL Path Parm Data
292 #--------------------------------------------------------------------
293 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition xyz.openbmc_project.State.Host.Transition.Off
294
295 [Tags] Put_Data_Validation
296 [Template] Execute Put And Expect Success
297
298
299Post Response Code
300 [Documentation] REST Post request url and expect the
301 ... REST response code pre define.
302 #--------------------------------------------------------------------
303 # Expect status URL Path
304 #--------------------------------------------------------------------
305 ${HTTP_METHOD_NOT_ALLOWED} /
306 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
307 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
308 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
309
310 [Tags] Post_Response_Codes
311 [Template] Execute Post And Check Response
312
313
314Delete Response Code
315 [Documentation] REST "Delete" 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} /xyz/nothere/
323 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
324 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/list
325 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/enumerate
326
327 [Tags] Delete_Response_Codes
328 [Template] Execute Delete And Check Response
329
Gunnar Mills56b32892016-11-14 13:56:17 -0600330
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600331*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600332
333Execute Get And Check Response
334 [Documentation] Request "Get" url path and expect REST response code.
335 [Arguments] ${expected_response_code} ${url_path}
336 # Description of arguments:
337 # expected_response_code Expected REST status codes.
338 # url_path URL path.
339 ${resp}= Openbmc Get Request ${url_path}
340 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
341
342Execute Get And Check Data
343 [Documentation] Request "Get" url path and expect non empty data.
344 [Arguments] ${url_path}
345 # Description of arguments:
346 # url_path URL path.
347 ${resp}= Openbmc Get Request ${url_path}
348 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
349 ${jsondata}= To JSON ${resp.content}
350 Should Not Be Empty ${jsondata["data"]}
351
352Execute Get And Verify Data
353 [Documentation] Request "Get" url path and verify data.
354 [Arguments] ${url_path} ${expected_response_code}
355 # Description of arguments:
356 # expected_response_code Expected REST status codes.
357 # url_path URL path.
358 ${resp}= Openbmc Get Request ${url_path}
359 ${jsondata}= To JSON ${resp.content}
360 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
361 ... Should Contain ${jsondata["data"]} ${expected_response_code}
362 ... ELSE
363 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
364
365Execute Put And Check Response
366 [Documentation] Request "Put" url path and expect REST response code.
367 [Arguments] ${expected_response_code} ${url_path}
368 # Description of arguments:
369 # expected_response_code Expected REST status codes.
370 # url_path URL path.
371 ${resp}= Openbmc Put Request ${url_path}
372 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
373
374Execute Put And Expect Success
375 [Documentation] Request "Put" on url path.
376 [Arguments] ${url_path} ${parm}
377 # Description of arguments:
378 # url_path URL path.
379 # parm Value/string to be set.
380 # expected_response_code Expected REST status codes.
381 ${parmDict}= Create Dictionary data=${parm}
382 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
383 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
384
385Execute Post And Check Response
386 [Documentation] Request Post 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 Post Request ${url_path}
392 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
393
394Execute Post And Check Data
395 [Arguments] ${url_path} ${parm}
396 [Documentation] Request Post on url path and expected non empty data.
397 # Description of arguments:
398 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500399 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600400 ${resp}= Openbmc Post Request ${url_path} data=${data}
401 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
402 ${jsondata}= To JSON ${resp.content}
403 Should Not Be Empty ${jsondata["data"]}
404
405Execute Delete And Check Response
406 [Documentation] Request "Delete" url path and expected REST response code.
407 [Arguments] ${expected_response_code} ${url_path}
408 # Description of arguments:
409 # expected_response_code Expected REST status codes.
410 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500411 ${data}= Create Dictionary data=@{EMPTY}
412 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600413 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
George Keishingadefa262017-07-08 12:54:06 -0500414
415Verify JSON Response Content
416 [Documentation] Verify JSON response data is intact.
417 [Arguments] ${url_path} ${data_empty}=${EMPTY}
418
419 # Description of argument(s):
420 # url_path URL path.
421 # data_empty JSON data element.
422
423 ${resp}= OpenBMC Get Request ${url_path}
424 ${jsondata}= To JSON ${resp.content}
425 Run Keyword If '${data_empty}' == '${EMPTY}'
426 ... Should Be Empty ${jsondata["data"]}
427 ... ELSE
428 ... Should Not Be Empty ${jsondata["data"]}
429 Should Be Equal As Strings ${jsondata["message"]} 200 OK
430 Should Be Equal As Strings ${jsondata["status"]} ok