blob: 2b9301e8cf6a540c2fb550921e099eb71d471658 [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 Keishinge6594f22017-07-06 12:10:52 -050093Check Response Codes HTTP_UNSUPPORTED_MEDIA_TYPE
94 [Documentation] REST "Post" response status test for
95 ... HTTP_UNSUPPORTED_MEDIA_TYPE.
96 [Tags] Check_Response_Codes_415
97
98 # Example:
99 # Response code:415, Content:{
100 # "data": {
101 # "description": "Expecting content type 'application/octet-stream', got 'application/json'"
102 # },
103 # "message": "415 Unsupported Media Type",
104 # "status": "error"
105 # }
106
107 Initialize OpenBMC
108
109 # Create the REST payload headers and EMPTY data
110 ${data}= Create Dictionary data ${EMPTY}
111 ${headers}= Create Dictionary Content-Type=application/json
112 Set To Dictionary ${data} headers ${headers}
113
114 ${resp}= Post Request openbmc /upload/image &{data}
115 Should Be Equal As Strings
116 ... ${resp.status_code} ${HTTP_UNSUPPORTED_MEDIA_TYPE}
117
118 ${jsondata}= To JSON ${resp.content}
119 Should Be Equal As Strings ${jsondata["data"]["description"]}
120 ... Expecting content type 'application/octet-stream', got 'application/json'
121 Should Be Equal As Strings
122 ... ${jsondata["message"]} 415 Unsupported Media Type
123 Should Be Equal As Strings ${jsondata["status"]} error
124
125
George Keishing85536662017-03-03 10:49:58 -0600126Get Response Codes
127 [Documentation] REST "Get" response status test.
128 #--------------------------------------------------------------------
129 # Expect status URL Path
130 #--------------------------------------------------------------------
131 ${HTTP_OK} /
132 ${HTTP_OK} /xyz/
133 ${HTTP_OK} /xyz/openbmc_project/
134 ${HTTP_OK} /xyz/openbmc_project/enumerate
135 ${HTTP_NOT_FOUND} /i/dont/exist/
Chris Austenb29d2e82016-06-07 12:25:35 -0500136
George Keishing85536662017-03-03 10:49:58 -0600137 [Tags] Get_Response_Codes
138 [Template] Execute Get And Check Response
Chris Austenb29d2e82016-06-07 12:25:35 -0500139
Chris Austenb29d2e82016-06-07 12:25:35 -0500140
George Keishing85536662017-03-03 10:49:58 -0600141Get Data
142 [Documentation] REST "Get" request url and expect the
143 ... response OK and data non empty.
144 #--------------------------------------------------------------------
145 # URL Path
146 #--------------------------------------------------------------------
147 /xyz/openbmc_project/
148 /xyz/openbmc_project/list
149 /xyz/openbmc_project/enumerate
Chris Austenb29d2e82016-06-07 12:25:35 -0500150
George Keishing85536662017-03-03 10:49:58 -0600151 [Tags] Get_Data
152 [Template] Execute Get And Check Data
Chris Austenb29d2e82016-06-07 12:25:35 -0500153
Chris Austenb29d2e82016-06-07 12:25:35 -0500154
George Keishing85536662017-03-03 10:49:58 -0600155Get Data Validation
156 [Documentation] REST "Get" request url and expect the
157 ... pre-defined string in response data.
158 #--------------------------------------------------------------------
159 # URL Path Expect Data
160 #--------------------------------------------------------------------
161 /xyz/openbmc_project/ /xyz/openbmc_project/logging
162 /i/dont/exist/ path or object not found: /i/dont/exist
163
164 [Tags] Get_Data_Validation
165 [Template] Execute Get And Verify Data
166
167
168Put Response Codes
169 [Documentation] REST "Put" request url and expect the REST pre-defined
170 ... codes.
171 #--------------------------------------------------------------------
172 # Expect status URL Path
173 #--------------------------------------------------------------------
174 ${HTTP_METHOD_NOT_ALLOWED} /
175 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
176 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
177 ${HTTP_METHOD_NOT_ALLOWED} /xyz/list
178 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
179
180 [Tags] Put_Response_Codes
181 [Template] Execute Put And Check Response
182
183
184Put Data Validation
185 [Documentation] REST "Put" request url and expect success.
186 #--------------------------------------------------------------------
187 # URL Path Parm Data
188 #--------------------------------------------------------------------
189 /xyz/openbmc_project/state/host0/attr/RequestedHostTransition xyz.openbmc_project.State.Host.Transition.Off
190
191 [Tags] Put_Data_Validation
192 [Template] Execute Put And Expect Success
193
194
195Post Response Code
196 [Documentation] REST Post request url and expect the
197 ... REST response code pre define.
198 #--------------------------------------------------------------------
199 # Expect status URL Path
200 #--------------------------------------------------------------------
201 ${HTTP_METHOD_NOT_ALLOWED} /
202 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
203 ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/
204 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
205
206 [Tags] Post_Response_Codes
207 [Template] Execute Post And Check Response
208
209
210Delete Response Code
211 [Documentation] REST "Delete" request url and expect the
212 ... REST response code pre define.
213 #--------------------------------------------------------------------
214 # Expect status URL Path
215 #--------------------------------------------------------------------
216 ${HTTP_METHOD_NOT_ALLOWED} /
217 ${HTTP_METHOD_NOT_ALLOWED} /xyz/
218 ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/
219 ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate
220 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/list
221 ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/enumerate
222
223 [Tags] Delete_Response_Codes
224 [Template] Execute Delete And Check Response
225
Gunnar Mills56b32892016-11-14 13:56:17 -0600226
Gunnar Mills7c8923f2016-12-12 21:19:52 -0600227*** Keywords ***
George Keishing85536662017-03-03 10:49:58 -0600228
229Execute Get And Check Response
230 [Documentation] Request "Get" url path and expect REST response code.
231 [Arguments] ${expected_response_code} ${url_path}
232 # Description of arguments:
233 # expected_response_code Expected REST status codes.
234 # url_path URL path.
235 ${resp}= Openbmc Get Request ${url_path}
236 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
237
238Execute Get And Check Data
239 [Documentation] Request "Get" url path and expect non empty data.
240 [Arguments] ${url_path}
241 # Description of arguments:
242 # url_path URL path.
243 ${resp}= Openbmc Get Request ${url_path}
244 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
245 ${jsondata}= To JSON ${resp.content}
246 Should Not Be Empty ${jsondata["data"]}
247
248Execute Get And Verify Data
249 [Documentation] Request "Get" url path and verify data.
250 [Arguments] ${url_path} ${expected_response_code}
251 # Description of arguments:
252 # expected_response_code Expected REST status codes.
253 # url_path URL path.
254 ${resp}= Openbmc Get Request ${url_path}
255 ${jsondata}= To JSON ${resp.content}
256 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
257 ... Should Contain ${jsondata["data"]} ${expected_response_code}
258 ... ELSE
259 ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code}
260
261Execute Put And Check Response
262 [Documentation] Request "Put" url path and expect REST response code.
263 [Arguments] ${expected_response_code} ${url_path}
264 # Description of arguments:
265 # expected_response_code Expected REST status codes.
266 # url_path URL path.
267 ${resp}= Openbmc Put Request ${url_path}
268 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
269
270Execute Put And Expect Success
271 [Documentation] Request "Put" on url path.
272 [Arguments] ${url_path} ${parm}
273 # Description of arguments:
274 # url_path URL path.
275 # parm Value/string to be set.
276 # expected_response_code Expected REST status codes.
277 ${parmDict}= Create Dictionary data=${parm}
278 ${resp}= Openbmc Put Request ${url_path} data=${parmDict}
279 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
280
281Execute Post And Check Response
282 [Documentation] Request Post url path and expect REST response code.
283 [Arguments] ${expected_response_code} ${url_path}
284 # Description of arguments:
285 # expected_response_code Expected REST status codes.
286 # url_path URL path.
287 ${resp}= Openbmc Post Request ${url_path}
288 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}
289
290Execute Post And Check Data
291 [Arguments] ${url_path} ${parm}
292 [Documentation] Request Post on url path and expected non empty data.
293 # Description of arguments:
294 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500295 ${data}= Create Dictionary data=@{parm}
George Keishing85536662017-03-03 10:49:58 -0600296 ${resp}= Openbmc Post Request ${url_path} data=${data}
297 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
298 ${jsondata}= To JSON ${resp.content}
299 Should Not Be Empty ${jsondata["data"]}
300
301Execute Delete And Check Response
302 [Documentation] Request "Delete" url path and expected REST response code.
303 [Arguments] ${expected_response_code} ${url_path}
304 # Description of arguments:
305 # expected_response_code Expected REST status codes.
306 # url_path URL path.
George Keishing4c02e622017-04-17 07:57:10 -0500307 ${data}= Create Dictionary data=@{EMPTY}
308 ${resp}= Openbmc Delete Request ${url_path} data=${data}
George Keishing85536662017-03-03 10:49:58 -0600309 Should Be Equal As Strings ${resp.status_code} ${expected_response_code}