Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | *** Settings *** |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 2 | Documentation Verify REST services Get/Put/Post/Delete. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 3 | |
George Keishing | 97651c7 | 2016-10-04 00:44:15 -0500 | [diff] [blame] | 4 | Resource ../lib/rest_client.robot |
George Keishing | d55a4be | 2016-08-26 03:28:17 -0500 | [diff] [blame] | 5 | Resource ../lib/openbmc_ffdc.robot |
George Keishing | 7230bbc | 2016-12-14 07:02:48 -0600 | [diff] [blame] | 6 | Resource ../lib/resource.txt |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 7 | Library Collections |
Gunnar Mills | eac1af2 | 2016-11-14 15:30:09 -0600 | [diff] [blame] | 8 | Test Teardown FFDC On Test Case Fail |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 9 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 10 | *** Variables *** |
| 11 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 12 | *** Test Cases *** |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 13 | |
George Keishing | 89f7c1f | 2017-05-03 16:08:37 -0500 | [diff] [blame] | 14 | REST 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 | |
| 24 | REST 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 Keishing | 6715f31 | 2017-05-10 03:22:40 -0500 | [diff] [blame] | 35 | REST 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 | |
| 50 | Verify 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 | |
| 73 | Verify 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 Keishing | e6594f2 | 2017-07-06 12:10:52 -0500 | [diff] [blame] | 93 | Check 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 Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 126 | Get 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 Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 136 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 137 | [Tags] Get_Response_Codes |
| 138 | [Template] Execute Get And Check Response |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 139 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 140 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 141 | Get 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 Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 150 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 151 | [Tags] Get_Data |
| 152 | [Template] Execute Get And Check Data |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 153 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 154 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 155 | Get 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 | |
| 168 | Put 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 | |
| 184 | Put 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 | |
| 195 | Post 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 | |
| 210 | Delete 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 Mills | 56b3289 | 2016-11-14 13:56:17 -0600 | [diff] [blame] | 226 | |
Gunnar Mills | 7c8923f | 2016-12-12 21:19:52 -0600 | [diff] [blame] | 227 | *** Keywords *** |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 228 | |
| 229 | Execute 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 | |
| 238 | Execute 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 | |
| 248 | Execute 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 | |
| 261 | Execute 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 | |
| 270 | Execute 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 | |
| 281 | Execute 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 | |
| 290 | Execute 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 Keishing | 4c02e62 | 2017-04-17 07:57:10 -0500 | [diff] [blame] | 295 | ${data}= Create Dictionary data=@{parm} |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 296 | ${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 | |
| 301 | Execute 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 Keishing | 4c02e62 | 2017-04-17 07:57:10 -0500 | [diff] [blame] | 307 | ${data}= Create Dictionary data=@{EMPTY} |
| 308 | ${resp}= Openbmc Delete Request ${url_path} data=${data} |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 309 | Should Be Equal As Strings ${resp.status_code} ${expected_response_code} |