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 | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 93 | Get Response Codes |
| 94 | [Documentation] REST "Get" response status test. |
| 95 | #-------------------------------------------------------------------- |
| 96 | # Expect status URL Path |
| 97 | #-------------------------------------------------------------------- |
| 98 | ${HTTP_OK} / |
| 99 | ${HTTP_OK} /xyz/ |
| 100 | ${HTTP_OK} /xyz/openbmc_project/ |
| 101 | ${HTTP_OK} /xyz/openbmc_project/enumerate |
| 102 | ${HTTP_NOT_FOUND} /i/dont/exist/ |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 103 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 104 | [Tags] Get_Response_Codes |
| 105 | [Template] Execute Get And Check Response |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 106 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 107 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 108 | Get Data |
| 109 | [Documentation] REST "Get" request url and expect the |
| 110 | ... response OK and data non empty. |
| 111 | #-------------------------------------------------------------------- |
| 112 | # URL Path |
| 113 | #-------------------------------------------------------------------- |
| 114 | /xyz/openbmc_project/ |
| 115 | /xyz/openbmc_project/list |
| 116 | /xyz/openbmc_project/enumerate |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 117 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 118 | [Tags] Get_Data |
| 119 | [Template] Execute Get And Check Data |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 120 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 121 | |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 122 | Get Data Validation |
| 123 | [Documentation] REST "Get" request url and expect the |
| 124 | ... pre-defined string in response data. |
| 125 | #-------------------------------------------------------------------- |
| 126 | # URL Path Expect Data |
| 127 | #-------------------------------------------------------------------- |
| 128 | /xyz/openbmc_project/ /xyz/openbmc_project/logging |
| 129 | /i/dont/exist/ path or object not found: /i/dont/exist |
| 130 | |
| 131 | [Tags] Get_Data_Validation |
| 132 | [Template] Execute Get And Verify Data |
| 133 | |
| 134 | |
| 135 | Put Response Codes |
| 136 | [Documentation] REST "Put" request url and expect the REST pre-defined |
| 137 | ... codes. |
| 138 | #-------------------------------------------------------------------- |
| 139 | # Expect status URL Path |
| 140 | #-------------------------------------------------------------------- |
| 141 | ${HTTP_METHOD_NOT_ALLOWED} / |
| 142 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/ |
| 143 | ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/ |
| 144 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/list |
| 145 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate |
| 146 | |
| 147 | [Tags] Put_Response_Codes |
| 148 | [Template] Execute Put And Check Response |
| 149 | |
| 150 | |
| 151 | Put Data Validation |
| 152 | [Documentation] REST "Put" request url and expect success. |
| 153 | #-------------------------------------------------------------------- |
| 154 | # URL Path Parm Data |
| 155 | #-------------------------------------------------------------------- |
| 156 | /xyz/openbmc_project/state/host0/attr/RequestedHostTransition xyz.openbmc_project.State.Host.Transition.Off |
| 157 | |
| 158 | [Tags] Put_Data_Validation |
| 159 | [Template] Execute Put And Expect Success |
| 160 | |
| 161 | |
| 162 | Post Response Code |
| 163 | [Documentation] REST Post request url and expect the |
| 164 | ... REST response code pre define. |
| 165 | #-------------------------------------------------------------------- |
| 166 | # Expect status URL Path |
| 167 | #-------------------------------------------------------------------- |
| 168 | ${HTTP_METHOD_NOT_ALLOWED} / |
| 169 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/ |
| 170 | ${HTTP_METHOD_NOT_ALLOWED} /i/dont/exist/ |
| 171 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate |
| 172 | |
| 173 | [Tags] Post_Response_Codes |
| 174 | [Template] Execute Post And Check Response |
| 175 | |
| 176 | |
| 177 | Delete Response Code |
| 178 | [Documentation] REST "Delete" request url and expect the |
| 179 | ... REST response code pre define. |
| 180 | #-------------------------------------------------------------------- |
| 181 | # Expect status URL Path |
| 182 | #-------------------------------------------------------------------- |
| 183 | ${HTTP_METHOD_NOT_ALLOWED} / |
| 184 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/ |
| 185 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/nothere/ |
| 186 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/enumerate |
| 187 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/list |
| 188 | ${HTTP_METHOD_NOT_ALLOWED} /xyz/openbmc_project/enumerate |
| 189 | |
| 190 | [Tags] Delete_Response_Codes |
| 191 | [Template] Execute Delete And Check Response |
| 192 | |
Gunnar Mills | 56b3289 | 2016-11-14 13:56:17 -0600 | [diff] [blame] | 193 | |
Gunnar Mills | 7c8923f | 2016-12-12 21:19:52 -0600 | [diff] [blame] | 194 | *** Keywords *** |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 195 | |
| 196 | Execute Get And Check Response |
| 197 | [Documentation] Request "Get" url path and expect REST response code. |
| 198 | [Arguments] ${expected_response_code} ${url_path} |
| 199 | # Description of arguments: |
| 200 | # expected_response_code Expected REST status codes. |
| 201 | # url_path URL path. |
| 202 | ${resp}= Openbmc Get Request ${url_path} |
| 203 | Should Be Equal As Strings ${resp.status_code} ${expected_response_code} |
| 204 | |
| 205 | Execute Get And Check Data |
| 206 | [Documentation] Request "Get" url path and expect non empty data. |
| 207 | [Arguments] ${url_path} |
| 208 | # Description of arguments: |
| 209 | # url_path URL path. |
| 210 | ${resp}= Openbmc Get Request ${url_path} |
| 211 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 212 | ${jsondata}= To JSON ${resp.content} |
| 213 | Should Not Be Empty ${jsondata["data"]} |
| 214 | |
| 215 | Execute Get And Verify Data |
| 216 | [Documentation] Request "Get" url path and verify data. |
| 217 | [Arguments] ${url_path} ${expected_response_code} |
| 218 | # Description of arguments: |
| 219 | # expected_response_code Expected REST status codes. |
| 220 | # url_path URL path. |
| 221 | ${resp}= Openbmc Get Request ${url_path} |
| 222 | ${jsondata}= To JSON ${resp.content} |
| 223 | Run Keyword If '${resp.status_code}' == '${HTTP_OK}' |
| 224 | ... Should Contain ${jsondata["data"]} ${expected_response_code} |
| 225 | ... ELSE |
| 226 | ... Should Contain ${jsondata["data"]["description"]} ${expected_response_code} |
| 227 | |
| 228 | Execute Put And Check Response |
| 229 | [Documentation] Request "Put" url path and expect REST response code. |
| 230 | [Arguments] ${expected_response_code} ${url_path} |
| 231 | # Description of arguments: |
| 232 | # expected_response_code Expected REST status codes. |
| 233 | # url_path URL path. |
| 234 | ${resp}= Openbmc Put Request ${url_path} |
| 235 | Should Be Equal As Strings ${resp.status_code} ${expected_response_code} |
| 236 | |
| 237 | Execute Put And Expect Success |
| 238 | [Documentation] Request "Put" on url path. |
| 239 | [Arguments] ${url_path} ${parm} |
| 240 | # Description of arguments: |
| 241 | # url_path URL path. |
| 242 | # parm Value/string to be set. |
| 243 | # expected_response_code Expected REST status codes. |
| 244 | ${parmDict}= Create Dictionary data=${parm} |
| 245 | ${resp}= Openbmc Put Request ${url_path} data=${parmDict} |
| 246 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 247 | |
| 248 | Execute Post And Check Response |
| 249 | [Documentation] Request Post url path and expect REST response code. |
| 250 | [Arguments] ${expected_response_code} ${url_path} |
| 251 | # Description of arguments: |
| 252 | # expected_response_code Expected REST status codes. |
| 253 | # url_path URL path. |
| 254 | ${resp}= Openbmc Post Request ${url_path} |
| 255 | Should Be Equal As Strings ${resp.status_code} ${expected_response_code} |
| 256 | |
| 257 | Execute Post And Check Data |
| 258 | [Arguments] ${url_path} ${parm} |
| 259 | [Documentation] Request Post on url path and expected non empty data. |
| 260 | # Description of arguments: |
| 261 | # url_path URL path. |
George Keishing | 4c02e62 | 2017-04-17 07:57:10 -0500 | [diff] [blame] | 262 | ${data}= Create Dictionary data=@{parm} |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 263 | ${resp}= Openbmc Post Request ${url_path} data=${data} |
| 264 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 265 | ${jsondata}= To JSON ${resp.content} |
| 266 | Should Not Be Empty ${jsondata["data"]} |
| 267 | |
| 268 | Execute Delete And Check Response |
| 269 | [Documentation] Request "Delete" url path and expected REST response code. |
| 270 | [Arguments] ${expected_response_code} ${url_path} |
| 271 | # Description of arguments: |
| 272 | # expected_response_code Expected REST status codes. |
| 273 | # url_path URL path. |
George Keishing | 4c02e62 | 2017-04-17 07:57:10 -0500 | [diff] [blame] | 274 | ${data}= Create Dictionary data=@{EMPTY} |
| 275 | ${resp}= Openbmc Delete Request ${url_path} data=${data} |
George Keishing | 8553666 | 2017-03-03 10:49:58 -0600 | [diff] [blame] | 276 | Should Be Equal As Strings ${resp.status_code} ${expected_response_code} |