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} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 66 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 67 | Run Keyword If '${quiet}' == '${0}' Log Request method=Get |
| 68 | ... base_uri=${base_uri} args=&{kwargs} |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 69 | Initialize OpenBMC ${timeout} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 70 | ${ret}= Get Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 71 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 72 | [Return] ${ret} |
| 73 | |
| 74 | OpenBMC Post Request |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 75 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
| 76 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 77 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 78 | ${headers}= Create Dictionary Content-Type=application/json |
| 79 | set to dictionary ${kwargs} headers ${headers} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 80 | Run Keyword If '${quiet}' == '${0}' Log Request method=Post |
| 81 | ... base_uri=${base_uri} args=&{kwargs} |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 82 | Initialize OpenBMC ${timeout} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 83 | ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 84 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 85 | [Return] ${ret} |
| 86 | |
| 87 | OpenBMC Put Request |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 88 | [Arguments] ${uri} ${timeout}=10 &{kwargs} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 89 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 90 | ${headers}= Create Dictionary Content-Type=application/json |
| 91 | set to dictionary ${kwargs} headers ${headers} |
| 92 | Log Request method=Put base_uri=${base_uri} args=&{kwargs} |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 93 | Initialize OpenBMC ${timeout} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 94 | ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 95 | Log Response ${ret} |
| 96 | [Return] ${ret} |
| 97 | |
| 98 | OpenBMC Delete Request |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 99 | [Arguments] ${uri} ${timeout}=10 &{kwargs} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 100 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 101 | Log Request method=Delete base_uri=${base_uri} args=&{kwargs} |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 102 | Initialize OpenBMC ${timeout} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 103 | ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 104 | Log Response ${ret} |
| 105 | [Return] ${ret} |
| 106 | |
| 107 | Initialize OpenBMC |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 108 | [Arguments] ${timeout}=10 |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 109 | Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3 |
| 110 | ${headers}= Create Dictionary Content-Type=application/json |
| 111 | @{credentials}= Create List ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} |
| 112 | ${data}= create dictionary data=@{credentials} |
| 113 | ${resp}= Post Request openbmc /login data=${data} headers=${headers} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 114 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 115 | |
| 116 | Log Request |
| 117 | [Arguments] &{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 118 | ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]} |
| 119 | ... , method: ${kwargs["method"]} , args: ${kwargs["args"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 120 | Logging ${msg} console=True |
| 121 | |
| 122 | Log Response |
| 123 | [Arguments] ${resp} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 124 | ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code} |
| 125 | ... , Content: ${resp.content} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 126 | Logging ${msg} console=True |
| 127 | |
| 128 | Logging |
| 129 | [Arguments] ${msg} ${console}=default False |
| 130 | Log ${msg} console=True |
| 131 | |
| 132 | Read Attribute |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 133 | [arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET} |
| 134 | ${resp}= OpenBMC Get Request ${uri}/attr/${attr} timeout=${timeout} |
| 135 | ... quiet=${quiet} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 136 | ${content}= To Json ${resp.content} |
| 137 | [return] ${content["data"]} |
| 138 | |
| 139 | Write Attribute |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 140 | [Arguments] ${uri} ${attr} ${timeout}=10 &{kwargs} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 141 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 142 | ${resp}= openbmc put request ${base_uri}/attr/${attr} |
| 143 | ... timeout=${timeout} &{kwargs} |
George Keishing | 06ae4aa | 2016-08-30 01:41:28 -0500 | [diff] [blame] | 144 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 145 | ${json}= to json ${resp.content} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 146 | |
| 147 | Read Properties |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 148 | [arguments] ${uri} ${timeout}=10 |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 149 | ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 150 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 151 | ${content}= To Json ${resp.content} |
| 152 | [return] ${content["data"]} |
| 153 | |
| 154 | Call Method |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 155 | [arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
| 156 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 157 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 158 | ${resp}= OpenBmc Post Request ${base_uri}/action/${method} |
| 159 | ... timeout=${timeout} quiet=${quiet} &{kwargs} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 160 | [return] ${resp} |