Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Library Collections |
| 3 | Library String |
| 4 | Library RequestsLibrary.RequestsKeywords |
| 5 | Library OperatingSystem |
| 6 | Resource ../lib/resource.txt |
| 7 | Library ../lib/disable_warning_urllib.py |
| 8 | |
| 9 | *** Variables *** |
| 10 | # Response codes |
| 11 | ${HTTP_CONTINUE} 100 |
| 12 | ${HTTP_SWITCHING_PROTOCOLS} 101 |
| 13 | ${HTTP_PROCESSING} 102 |
| 14 | ${HTTP_OK} 200 |
| 15 | ${HTTP_CREATED} 201 |
| 16 | ${HTTP_ACCEPTED} 202 |
| 17 | ${HTTP_NON_AUTHORITATIVE_INFORMATION} 203 |
| 18 | ${HTTP_NO_CONTENT} 204 |
| 19 | ${HTTP_RESET_CONTENT} 205 |
| 20 | ${HTTP_PARTIAL_CONTENT} 206 |
| 21 | ${HTTP_MULTI_STATUS} 207 |
| 22 | ${HTTP_IM_USED} 226 |
| 23 | ${HTTP_MULTIPLE_CHOICES} 300 |
| 24 | ${HTTP_MOVED_PERMANENTLY} 301 |
| 25 | ${HTTP_FOUND} 302 |
| 26 | ${HTTP_SEE_OTHER} 303 |
| 27 | ${HTTP_NOT_MODIFIED} 304 |
| 28 | ${HTTP_USE_PROXY} 305 |
| 29 | ${HTTP_TEMPORARY_REDIRECT} 307 |
| 30 | ${HTTP_BAD_REQUEST} 400 |
| 31 | ${HTTP_UNAUTHORIZED} 401 |
| 32 | ${HTTP_PAYMENT_REQUIRED} 402 |
| 33 | ${HTTP_FORBIDDEN} 403 |
| 34 | ${HTTP_NOT_FOUND} 404 |
| 35 | ${HTTP_METHOD_NOT_ALLOWED} 405 |
| 36 | ${HTTP_NOT_ACCEPTABLE} 406 |
| 37 | ${HTTP_PROXY_AUTHENTICATION_REQUIRED} 407 |
| 38 | ${HTTP_REQUEST_TIMEOUT} 408 |
| 39 | ${HTTP_CONFLICT} 409 |
| 40 | ${HTTP_GONE} 410 |
| 41 | ${HTTP_LENGTH_REQUIRED} 411 |
| 42 | ${HTTP_PRECONDITION_FAILED} 412 |
| 43 | ${HTTP_REQUEST_ENTITY_TOO_LARGE} 413 |
| 44 | ${HTTP_REQUEST_URI_TOO_LONG} 414 |
| 45 | ${HTTP_UNSUPPORTED_MEDIA_TYPE} 415 |
| 46 | ${HTTP_REQUESTED_RANGE_NOT_SATISFIABLE} 416 |
| 47 | ${HTTP_EXPECTATION_FAILED} 417 |
| 48 | ${HTTP_UNPROCESSABLE_ENTITY} 422 |
| 49 | ${HTTP_LOCKED} 423 |
| 50 | ${HTTP_FAILED_DEPENDENCY} 424 |
| 51 | ${HTTP_UPGRADE_REQUIRED} 426 |
| 52 | ${HTTP_INTERNAL_SERVER_ERROR} 500 |
| 53 | ${HTTP_NOT_IMPLEMENTED} 501 |
| 54 | ${HTTP_BAD_GATEWAY} 502 |
| 55 | ${HTTP_SERVICE_UNAVAILABLE} 503 |
| 56 | ${HTTP_GATEWAY_TIMEOUT} 504 |
| 57 | ${HTTP_HTTP_VERSION_NOT_SUPPORTED} 505 |
| 58 | ${HTTP_INSUFFICIENT_STORAGE} 507 |
| 59 | ${HTTP_NOT_EXTENDED} 510 |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 60 | # Assign default value to QUIET for programs which may not define it. |
| 61 | ${QUIET} ${0} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 62 | |
| 63 | *** Keywords *** |
| 64 | OpenBMC Get Request |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 65 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 66 | |
| 67 | Initialize OpenBMC ${timeout} quiet=${quiet} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 68 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 69 | Run Keyword If '${quiet}' == '${0}' Log Request method=Get |
| 70 | ... base_uri=${base_uri} args=&{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 71 | ${ret}= Get Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 72 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 73 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 74 | [Return] ${ret} |
| 75 | |
| 76 | OpenBMC Post Request |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 77 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
| 78 | |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 79 | Initialize OpenBMC ${timeout} quiet=${quiet} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 80 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 81 | ${headers}= Create Dictionary Content-Type=application/json |
| 82 | set to dictionary ${kwargs} headers ${headers} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 83 | Run Keyword If '${quiet}' == '${0}' Log Request method=Post |
| 84 | ... base_uri=${base_uri} args=&{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 85 | ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 86 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 87 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 88 | [Return] ${ret} |
| 89 | |
| 90 | OpenBMC Put Request |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 91 | [Arguments] ${uri} ${timeout}=10 &{kwargs} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 92 | |
| 93 | Initialize OpenBMC ${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 94 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 95 | ${headers}= Create Dictionary Content-Type=application/json |
| 96 | set to dictionary ${kwargs} headers ${headers} |
| 97 | Log Request method=Put base_uri=${base_uri} args=&{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 98 | ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 99 | Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 100 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 101 | [Return] ${ret} |
| 102 | |
| 103 | OpenBMC Delete Request |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 104 | [Arguments] ${uri} ${timeout}=10 &{kwargs} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 105 | |
| 106 | Initialize OpenBMC ${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 107 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 108 | Log Request method=Delete base_uri=${base_uri} args=&{kwargs} |
George Keishing | 0e7c3a0 | 2017-04-17 05:01:14 -0500 | [diff] [blame] | 109 | ${ret}= Delete Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 110 | Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 111 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 112 | [Return] ${ret} |
| 113 | |
| 114 | Initialize OpenBMC |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 115 | [Arguments] ${timeout}=20 ${quiet}=${1} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 116 | |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 117 | # Description of argument(s): |
| 118 | # timeout REST login attempt time out. |
Gunnar Mills | 28e403b | 2017-10-25 16:16:38 -0500 | [diff] [blame] | 119 | # quiet Suppress console log if set. |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 120 | |
| 121 | # TODO : Task to revert this changes openbmc/openbmc-test-automation#532 |
| 122 | # This will retry at 20 second interval. |
| 123 | Wait Until Keyword Succeeds 40 sec 20 sec |
| 124 | ... Post Login Request ${timeout} ${quiet} |
| 125 | |
| 126 | Post Login Request |
| 127 | [Arguments] ${timeout}=20 ${quiet}=${1} |
| 128 | |
| 129 | # Description of argument(s): |
| 130 | # timeout REST login attempt time out. |
Gunnar Mills | 28e403b | 2017-10-25 16:16:38 -0500 | [diff] [blame] | 131 | # quiet Suppress console log if set. |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 132 | |
| 133 | Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3 |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 134 | ${headers}= Create Dictionary Content-Type=application/json |
| 135 | @{credentials}= Create List ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} |
| 136 | ${data}= create dictionary data=@{credentials} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 137 | ${status} ${resp}= Run Keyword And Ignore Error Post Request openbmc |
| 138 | ... /login data=${data} headers=${headers} |
| 139 | |
| 140 | Should Be Equal ${status} PASS msg=${resp} |
| 141 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 142 | |
George Keishing | e822552 | 2017-03-31 09:21:13 -0500 | [diff] [blame] | 143 | Log Out OpenBMC |
| 144 | [Documentation] Log out REST connection with active session "openbmc". |
| 145 | |
| 146 | ${headers}= Create Dictionary Content-Type=application/json |
| 147 | ${data}= Create dictionary data=@{EMPTY} |
| 148 | |
| 149 | # If there is no active sesion it will throw the following exception |
| 150 | # "Non-existing index or alias 'openbmc'" |
| 151 | ${resp}= Post Request openbmc |
| 152 | ... /logout data=${data} headers=${headers} |
| 153 | |
| 154 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 155 | ... msg=${resp} |
| 156 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 157 | Log Request |
| 158 | [Arguments] &{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 159 | ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]} |
| 160 | ... , method: ${kwargs["method"]} , args: ${kwargs["args"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 161 | Logging ${msg} console=True |
| 162 | |
| 163 | Log Response |
| 164 | [Arguments] ${resp} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 165 | ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code} |
| 166 | ... , Content: ${resp.content} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 167 | Logging ${msg} console=True |
| 168 | |
| 169 | Logging |
| 170 | [Arguments] ${msg} ${console}=default False |
| 171 | Log ${msg} console=True |
| 172 | |
| 173 | Read Attribute |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 174 | [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 175 | ${resp}= OpenBMC Get Request ${uri}/attr/${attr} timeout=${timeout} |
| 176 | ... quiet=${quiet} |
Michael Walsh | 9cd6193 | 2017-01-17 16:11:02 -0600 | [diff] [blame] | 177 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 178 | ${content}= To Json ${resp.content} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 179 | [Return] ${content["data"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 180 | |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 181 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 182 | Write Attribute |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 183 | [Documentation] Write a D-Bus attribute with REST. |
| 184 | [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE} |
| 185 | ... ${expected_value}=${EMPTY} &{kwargs} |
| 186 | |
| 187 | # Description of argument(s): |
| 188 | # uri URI of the object that the attribute lives on |
| 189 | # (e.g. '/xyz/openbmc_project/software/'). |
| 190 | # attr Name of the attribute (e.g. 'FieldModeEnabled'). |
| 191 | # timeout Timeout for the REST call. |
| 192 | # verify If set to ${TRUE}, the attribute will be read back to |
| 193 | # ensure that its value is set to ${verify_attr}. |
| 194 | # expected_value Only used if verify is set to ${TRUE}. The value that |
| 195 | # ${attr} should be set to. This defaults to |
| 196 | # ${kwargs['data']. There are cases where the caller |
| 197 | # expects some other value in which case this value can |
| 198 | # be explicitly specified. |
| 199 | # kwargs Arguments passed to the REST call. This should always |
| 200 | # contain the value to set the property to at the 'data' |
| 201 | # key (e.g. data={"data": 1}). |
| 202 | |
| 203 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 204 | ${resp}= Openbmc Put Request ${base_uri}/attr/${attr} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 205 | ... timeout=${timeout} &{kwargs} |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 206 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 207 | |
| 208 | # Verify the attribute was set correctly if the caller requested it. |
| 209 | Return From Keyword If ${verify} == ${FALSE} |
| 210 | |
| 211 | ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}' |
| 212 | ... ${kwargs['data']['data']} |
| 213 | ${value}= Read Attribute ${uri} ${attr} |
| 214 | Should Be Equal ${value} ${expected_value} |
| 215 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 216 | |
| 217 | Read Properties |
George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 218 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} |
| 219 | ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet} |
| 220 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 221 | ${content}= To Json ${resp.content} |
| 222 | [Return] ${content["data"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 223 | |
| 224 | Call Method |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 225 | [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 226 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 227 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 228 | ${resp}= OpenBmc Post Request ${base_uri}/action/${method} |
| 229 | ... timeout=${timeout} quiet=${quiet} &{kwargs} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 230 | [Return] ${resp} |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 231 | |
| 232 | Upload Image To BMC |
George Keishing | ad9a880 | 2017-08-08 12:41:48 -0500 | [diff] [blame] | 233 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${1} &{kwargs} |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 234 | |
| 235 | # Description of argument(s): |
| 236 | # uri URI for uploading image via REST e.g. "/upload/image". |
| 237 | # timeout Time allocated for the REST command to return status |
| 238 | # (specified in Robot Framework Time Format e.g. "3 mins"). |
| 239 | # quiet If enabled turns off logging to console. |
| 240 | # kwargs A dictionary keys/values to be passed directly to |
| 241 | # Post Request. |
| 242 | |
| 243 | Initialize OpenBMC ${timeout} quiet=${quiet} |
| 244 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 245 | ${headers}= Create Dictionary Content-Type=application/octet-stream |
| 246 | ... Accept=application/octet-stream |
| 247 | Set To Dictionary ${kwargs} headers ${headers} |
| 248 | Run Keyword If '${quiet}' == '${0}' Log Request method=Post |
| 249 | ... base_uri=${base_uri} args=&{kwargs} |
| 250 | ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 251 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
| 252 | Should Be Equal As Strings ${ret.status_code} ${HTTP_OK} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 253 | Delete All Sessions |