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 |
Sandhya Somashekar | 839a0c2 | 2019-01-31 05:05:43 -0600 | [diff] [blame] | 6 | Resource resource.robot |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 7 | Library disable_warning_urllib.py |
Michael Walsh | ad66c95 | 2018-10-04 15:12:47 -0500 | [diff] [blame] | 8 | Library utils.py |
Steven Sombar | b348924 | 2018-12-13 15:59:02 -0600 | [diff] [blame] | 9 | Library gen_misc.py |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 10 | Library var_funcs.py |
George Keishing | eaa73b7 | 2018-07-30 09:30:16 -0500 | [diff] [blame] | 11 | Resource rest_response_code.robot |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 12 | |
| 13 | *** Variables *** |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 14 | # Assign default value to QUIET for programs which may not define it. |
| 15 | ${QUIET} ${0} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 16 | |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 17 | ${XAUTH_TOKEN} ${EMPTY} |
| 18 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 19 | *** Keywords *** |
| 20 | OpenBMC Get Request |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 21 | [Documentation] Do REST GET request and return the result. |
| 22 | # Example result data: |
| 23 | # Response code:200, Content:{ |
| 24 | # "data": [ |
| 25 | # "/xyz/openbmc_project/state/host0", |
| 26 | # "/xyz/openbmc_project/state/chassis0", |
| 27 | # "/xyz/openbmc_project/state/bmc0" |
| 28 | # ], |
| 29 | # "message": "200 OK", |
| 30 | # "status": "ok" |
| 31 | # } |
George Keishing | 41c44cf | 2017-11-15 08:02:59 -0600 | [diff] [blame] | 32 | [Arguments] ${uri} ${timeout}=30 ${quiet}=${QUIET} &{kwargs} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 33 | # Description of argument(s): |
| 34 | # uri The URI to establish connection with |
| 35 | # (e.g. '/xyz/openbmc_project/software/'). |
| 36 | # timeout Timeout in seconds to establish connection with URI. |
| 37 | # quiet If enabled, turns off logging to console. |
| 38 | # kwargs Any additional arguments to be passed directly to the |
| 39 | # Get Request call. For example, the caller might |
| 40 | # set kwargs as follows: |
| 41 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 42 | |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 43 | Initialize OpenBMC ${timeout} quiet=${quiet} |
| 44 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 45 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 46 | ${headers}= Create Dictionary Content-Type=application/octet-stream |
| 47 | ... X-Auth-Token=${XAUTH_TOKEN} Accept=application/octet-stream |
| 48 | Set To Dictionary ${kwargs} headers ${headers} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 49 | Run Keyword If '${quiet}' == '${0}' Log Request method=Get |
| 50 | ... base_uri=${base_uri} args=&{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 51 | ${ret}= Get Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 52 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 53 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 54 | [Return] ${ret} |
| 55 | |
| 56 | OpenBMC Post Request |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 57 | [Documentation] Do REST POST request and return the result. |
| 58 | # Example result data: |
| 59 | # <Response [200]> |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 60 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 61 | # Description of argument(s): |
| 62 | # uri The URI to establish connection with |
| 63 | # (e.g. '/xyz/openbmc_project/software/'). |
| 64 | # timeout Timeout in seconds to establish connection with URI. |
| 65 | # quiet If enabled, turns off logging to console. |
| 66 | # kwargs Any additional arguments to be passed directly to the |
| 67 | # Post Request call. For example, the caller might |
| 68 | # set kwargs as follows: |
| 69 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 70 | |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 71 | Initialize OpenBMC ${timeout} quiet=${quiet} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 72 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 73 | ${headers}= Create Dictionary Content-Type=application/json |
| 74 | ... X-Auth-Token=${XAUTH_TOKEN} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 75 | set to dictionary ${kwargs} headers ${headers} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 76 | Run Keyword If '${quiet}' == '${0}' Log Request method=Post |
| 77 | ... base_uri=${base_uri} args=&{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 78 | ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 79 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 80 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 81 | [Return] ${ret} |
| 82 | |
| 83 | OpenBMC Put Request |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 84 | [Documentation] Do REST PUT request on the resource identified by the URI. |
Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 85 | [Arguments] ${uri} ${timeout}=10 &{kwargs} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 86 | # Description of argument(s): |
| 87 | # uri The URI to establish connection with |
| 88 | # (e.g. '/xyz/openbmc_project/software/'). |
| 89 | # timeout Timeout in seconds to establish connection with URI. |
| 90 | # kwargs Arguments passed to the REST call. |
| 91 | # kwargs Any additional arguments to be passed directly to the |
| 92 | # Put Request call. For example, the caller might |
| 93 | # set kwargs as follows: |
| 94 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 95 | |
| 96 | Initialize OpenBMC ${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 97 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 98 | ${headers}= Create Dictionary Content-Type=application/json |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 99 | ... X-Auth-Token=${XAUTH_TOKEN} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 100 | set to dictionary ${kwargs} headers ${headers} |
| 101 | Log Request method=Put base_uri=${base_uri} args=&{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 102 | ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 103 | Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 104 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 105 | [Return] ${ret} |
| 106 | |
| 107 | OpenBMC Delete Request |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 108 | [Documentation] Do REST request to delete the resource identified by the |
| 109 | ... URI. |
Michael Shepos | cc490b4 | 2020-08-26 12:53:01 -0500 | [diff] [blame] | 110 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 111 | # Description of argument(s): |
| 112 | # uri The URI to establish connection with |
| 113 | # (e.g. '/xyz/openbmc_project/software/'). |
| 114 | # timeout Timeout in seconds to establish connection with URI. |
Michael Shepos | cc490b4 | 2020-08-26 12:53:01 -0500 | [diff] [blame] | 115 | # quiet If enabled, turns off logging to console. |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 116 | # kwargs Any additional arguments to be passed directly to the |
| 117 | # Delete Request call. For example, the caller might |
| 118 | # set kwargs as follows: |
| 119 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 120 | |
| 121 | Initialize OpenBMC ${timeout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 122 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 123 | ${headers}= Create Dictionary Content-Type=application/json |
| 124 | ... X-Auth-Token=${XAUTH_TOKEN} |
| 125 | Set To Dictionary ${kwargs} headers ${headers} |
Michael Shepos | cc490b4 | 2020-08-26 12:53:01 -0500 | [diff] [blame] | 126 | Run Keyword If '${quiet}' == '${0}' Log Request method=Delete |
| 127 | ... base_uri=${base_uri} args=&{kwargs} |
George Keishing | 0e7c3a0 | 2017-04-17 05:01:14 -0500 | [diff] [blame] | 128 | ${ret}= Delete Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
Michael Shepos | cc490b4 | 2020-08-26 12:53:01 -0500 | [diff] [blame] | 129 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 130 | Delete All Sessions |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 131 | [Return] ${ret} |
| 132 | |
| 133 | Initialize OpenBMC |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 134 | [Documentation] Do a REST login connection within specified time. |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 135 | [Arguments] ${timeout}=20 ${quiet}=${1} |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 136 | ... ${rest_username}=${REST_USERNAME} |
| 137 | ... ${rest_password}=${REST_PASSWORD} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 138 | |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 139 | # Description of argument(s): |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 140 | # timeout REST login attempt time out. |
| 141 | # quiet Suppress console log if set. |
| 142 | # rest_username The REST username. |
| 143 | # rest_password The REST password. |
| 144 | |
| 145 | ${bmcweb_status}= Run Keyword And Return Status BMC Web Login Request |
| 146 | ... ${timeout} ${rest_username} ${rest_password} |
| 147 | |
| 148 | Return From Keyword If ${bmcweb_status} == ${True} |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 149 | |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 150 | # This will retry at 20 second interval. |
| 151 | Wait Until Keyword Succeeds 40 sec 20 sec |
| 152 | ... Post Login Request ${timeout} ${quiet} |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 153 | ... ${rest_username} ${rest_password} |
| 154 | |
| 155 | |
| 156 | BMC Web Login Request |
| 157 | [Documentation] Do BMC web-based login. |
| 158 | [Arguments] ${timeout}=20 ${rest_username}=${REST_USERNAME} |
| 159 | ... ${rest_password}=${REST_PASSWORD} |
| 160 | |
| 161 | # Description of argument(s): |
| 162 | # timeout REST login attempt time out. |
| 163 | # rest_username The REST username. |
| 164 | # rest_password The REST password. |
| 165 | |
| 166 | Create Session openbmc ${AUTH_URI} timeout=${timeout} |
| 167 | |
| 168 | ${headers}= Create Dictionary Content-Type=application/json |
| 169 | @{credentials}= Create List ${rest_username} ${rest_password} |
| 170 | ${data}= Create Dictionary data=@{credentials} |
| 171 | ${resp}= Post Request openbmc /login data=${data} headers=${headers} |
| 172 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 173 | |
| 174 | ${processed_token_data}= |
| 175 | ... Evaluate re.split(r'[;,]', '${resp.headers["Set-Cookie"]}') modules=re |
| 176 | ${result}= Key Value List To Dict ${processed_token_data} delim== |
| 177 | |
| 178 | # Example result data: |
| 179 | # 'XSRF-TOKEN=hQuOyDJFEIbrN4aOg2CT; Secure, |
| 180 | # SESSION=c4wloTiETumSxPI9nLeg; Secure; HttpOnly' |
| 181 | Set Global Variable ${XAUTH_TOKEN} ${result['session']} |
| 182 | |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 183 | |
| 184 | Post Login Request |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 185 | [Documentation] Do REST login request. |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 186 | [Arguments] ${timeout}=20 ${quiet}=${1} |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 187 | ... ${rest_username}=${REST_USERNAME} |
| 188 | ... ${rest_password}=${REST_PASSWORD} |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 189 | |
| 190 | # Description of argument(s): |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 191 | # timeout REST login attempt time out. |
| 192 | # quiet Suppress console log if set. |
| 193 | # rest_username The REST username. |
| 194 | # rest_password The REST password. |
George Keishing | 1cdc6dd | 2017-04-24 15:31:03 -0500 | [diff] [blame] | 195 | |
| 196 | Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3 |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 197 | |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 198 | ${headers}= Create Dictionary Content-Type=application/json |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 199 | @{credentials}= Create List ${rest_username} ${rest_password} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 200 | ${data}= create dictionary data=@{credentials} |
Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 201 | ${status} ${resp}= Run Keyword And Ignore Error Post Request openbmc |
| 202 | ... /login data=${data} headers=${headers} |
| 203 | |
| 204 | Should Be Equal ${status} PASS msg=${resp} |
| 205 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 206 | |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 207 | |
George Keishing | e822552 | 2017-03-31 09:21:13 -0500 | [diff] [blame] | 208 | Log Out OpenBMC |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 209 | [Documentation] Log out of the openbmc REST session. |
George Keishing | e822552 | 2017-03-31 09:21:13 -0500 | [diff] [blame] | 210 | |
| 211 | ${headers}= Create Dictionary Content-Type=application/json |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 212 | ... X-Auth-Token=${XAUTH_TOKEN} |
George Keishing | e822552 | 2017-03-31 09:21:13 -0500 | [diff] [blame] | 213 | ${data}= Create dictionary data=@{EMPTY} |
| 214 | |
| 215 | # If there is no active sesion it will throw the following exception |
| 216 | # "Non-existing index or alias 'openbmc'" |
| 217 | ${resp}= Post Request openbmc |
| 218 | ... /logout data=${data} headers=${headers} |
| 219 | |
| 220 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 221 | ... msg=${resp} |
| 222 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 223 | Log Request |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 224 | [Documentation] Log the specific REST URI, method name on the console. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 225 | [Arguments] &{kwargs} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 226 | ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]} |
| 227 | ... , method: ${kwargs["method"]} , args: ${kwargs["args"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 228 | Logging ${msg} console=True |
| 229 | |
| 230 | Log Response |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 231 | [Documentation] Log the response code on the console. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 232 | [Arguments] ${resp} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 233 | ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code} |
| 234 | ... , Content: ${resp.content} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 235 | Logging ${msg} console=True |
| 236 | |
| 237 | Logging |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 238 | [Documentation] Log the specified message on the console. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 239 | [Arguments] ${msg} ${console}=default False |
| 240 | Log ${msg} console=True |
| 241 | |
| 242 | Read Attribute |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 243 | [Documentation] Retrieve attribute value from URI and return result. |
| 244 | # Example result data for the attribute 'FieldModeEnabled' in |
| 245 | # "/xyz/openbmc_project/software/attr/" : |
| 246 | # 0 |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 247 | [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET} |
manasarm | c505e38 | 2018-02-05 14:05:48 +0530 | [diff] [blame] | 248 | ... ${expected_value}=${EMPTY} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 249 | # Description of argument(s): |
| 250 | # uri URI of the object that the attribute lives on |
| 251 | # (e.g. '/xyz/openbmc_project/software/'). |
| 252 | # attr Name of the attribute (e.g. 'FieldModeEnabled'). |
| 253 | # timeout Timeout for the REST call. |
| 254 | # quiet If enabled, turns off logging to console. |
manasarm | c505e38 | 2018-02-05 14:05:48 +0530 | [diff] [blame] | 255 | # expected_value If this argument is not empty, the retrieved value |
| 256 | # must match this value. |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 257 | |
Steven Sombar | b348924 | 2018-12-13 15:59:02 -0600 | [diff] [blame] | 258 | # Make sure uri ends with slash. |
| 259 | ${uri}= Add Trailing Slash ${uri} |
| 260 | |
| 261 | ${resp}= OpenBMC Get Request ${uri}attr/${attr} timeout=${timeout} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 262 | ... quiet=${quiet} |
Michael Walsh | 9cd6193 | 2017-01-17 16:11:02 -0600 | [diff] [blame] | 263 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 264 | ${content}= To Json ${resp.content} |
manasarm | c505e38 | 2018-02-05 14:05:48 +0530 | [diff] [blame] | 265 | Run Keyword If '${expected_value}' != '${EMPTY}' |
| 266 | ... Should Be Equal As Strings ${expected_value} ${content["data"]} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 267 | [Return] ${content["data"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 268 | |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 269 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 270 | Write Attribute |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 271 | [Documentation] Write a D-Bus attribute with REST. |
| 272 | [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE} |
| 273 | ... ${expected_value}=${EMPTY} &{kwargs} |
| 274 | |
| 275 | # Description of argument(s): |
| 276 | # uri URI of the object that the attribute lives on |
| 277 | # (e.g. '/xyz/openbmc_project/software/'). |
| 278 | # attr Name of the attribute (e.g. 'FieldModeEnabled'). |
| 279 | # timeout Timeout for the REST call. |
| 280 | # verify If set to ${TRUE}, the attribute will be read back to |
| 281 | # ensure that its value is set to ${verify_attr}. |
| 282 | # expected_value Only used if verify is set to ${TRUE}. The value that |
| 283 | # ${attr} should be set to. This defaults to |
| 284 | # ${kwargs['data']. There are cases where the caller |
| 285 | # expects some other value in which case this value can |
| 286 | # be explicitly specified. |
| 287 | # kwargs Arguments passed to the REST call. This should always |
| 288 | # contain the value to set the property to at the 'data' |
| 289 | # key (e.g. data={"data": 1}). |
| 290 | |
George Keishing | df3e65f | 2018-12-18 13:06:56 -0600 | [diff] [blame] | 291 | # Make sure uri ends with slash. |
| 292 | ${uri}= Add Trailing Slash ${uri} |
| 293 | |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 294 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
George Keishing | df3e65f | 2018-12-18 13:06:56 -0600 | [diff] [blame] | 295 | ${resp}= Openbmc Put Request ${base_uri}attr/${attr} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 296 | ... timeout=${timeout} &{kwargs} |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 297 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 298 | |
| 299 | # Verify the attribute was set correctly if the caller requested it. |
| 300 | Return From Keyword If ${verify} == ${FALSE} |
| 301 | |
| 302 | ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}' |
Charles Paul Hofer | 00401e7 | 2017-10-31 11:42:30 -0500 | [diff] [blame] | 303 | ... ${kwargs['data']['data']} ${expected_value} |
Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 304 | ${value}= Read Attribute ${uri} ${attr} |
| 305 | Should Be Equal ${value} ${expected_value} |
| 306 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 307 | Read Properties |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 308 | [Documentation] Read data part of the URI object and return result. |
| 309 | # Example result data: |
| 310 | # [u'/xyz/openbmc_project/software/cf7bf9d5', |
| 311 | # u'/xyz/openbmc_project/software/5ecb8b2c', |
| 312 | # u'/xyz/openbmc_project/software/active', |
| 313 | # u'/xyz/openbmc_project/software/functional'] |
George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 314 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 315 | # Description of argument(s): |
| 316 | # uri URI of the object |
| 317 | # (e.g. '/xyz/openbmc_project/software/'). |
| 318 | # timeout Timeout for the REST call. |
| 319 | # quiet If enabled, turns off logging to console. |
| 320 | |
George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 321 | ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet} |
| 322 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Michael Walsh | ad66c95 | 2018-10-04 15:12:47 -0500 | [diff] [blame] | 323 | ${content}= To Json Ordered ${resp.content} |
| 324 | |
George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 325 | [Return] ${content["data"]} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 326 | |
| 327 | Call Method |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 328 | [Documentation] Invoke the specific REST service method. |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 329 | [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 330 | # Description of arguments: |
| 331 | # uri The URI to establish connection with |
| 332 | # (e.g. '/xyz/openbmc_project/software/'). |
| 333 | # timeout Timeout in seconds to establish connection with URI. |
| 334 | # quiet If enabled, turns off logging to console. |
| 335 | # kwargs Arguments passed to the REST call. |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 336 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 337 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
George Keishing | 5c231a8 | 2019-02-05 09:02:04 -0600 | [diff] [blame] | 338 | ${resp}= OpenBmc Post Request ${base_uri}action/${method} |
Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 339 | ... timeout=${timeout} quiet=${quiet} &{kwargs} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 340 | [Return] ${resp} |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 341 | |
Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 342 | |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 343 | Upload Image To BMC |
Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 344 | [Documentation] Upload image to BMC via REST and return status code. |
| 345 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${1} |
Sushil Singh | c08df05 | 2020-03-30 00:39:22 -0500 | [diff] [blame] | 346 | ... ${valid_status_codes}=[${HTTP_OK}, ${HTTP_ACCEPTED}] &{kwargs} |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 347 | |
| 348 | # Description of argument(s): |
Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 349 | # uri URI for uploading image via REST e.g. |
| 350 | # "/upload/image". |
| 351 | # timeout Time allocated for the REST command to |
| 352 | # return status (specified in Robot |
| 353 | # Framework Time Format e.g. "3 mins"). |
| 354 | # quiet If enabled, turns off logging to console. |
| 355 | # valid_status_codes A list of status codes that are valid for |
| 356 | # the REST post command. This can be |
| 357 | # specified as a string the evaluates to a |
| 358 | # python object (e.g. [${HTTP_OK}]). |
| 359 | # kwargs A dictionary keys/values to be passed |
| 360 | # directly to Post Request. |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 361 | |
| 362 | Initialize OpenBMC ${timeout} quiet=${quiet} |
| 363 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 364 | ${headers}= Create Dictionary Content-Type=application/octet-stream |
Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 365 | ... X-Auth-Token=${XAUTH_TOKEN} Accept=application/octet-stream |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 366 | Set To Dictionary ${kwargs} headers ${headers} |
| 367 | Run Keyword If '${quiet}' == '${0}' Log Request method=Post |
| 368 | ... base_uri=${base_uri} args=&{kwargs} |
| 369 | ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout} |
| 370 | Run Keyword If '${quiet}' == '${0}' Log Response ${ret} |
Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 371 | Valid Value ret.status_code ${valid_status_codes} |
George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 372 | Delete All Sessions |
Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 373 | |
| 374 | [Return] ${ret.status_code} |
| 375 | |
George Keishing | f4a4397 | 2020-06-29 03:55:38 -0500 | [diff] [blame] | 376 | |
| 377 | Redfish Login |
| 378 | [Documentation] Do BMC web-based login. |
| 379 | [Arguments] ${timeout}=20 ${rest_username}=${REST_USERNAME} |
| 380 | ... ${rest_password}=${REST_PASSWORD} ${kwargs}=${EMPTY} |
| 381 | |
| 382 | # Description of argument(s): |
| 383 | # timeout REST login attempt time out. |
| 384 | # rest_username The REST username. |
| 385 | # rest_password The REST password. |
| 386 | # kwargs Any additional arguments to be passed directly to the |
| 387 | # Get Request call. For example, the caller might |
| 388 | # set kwargs as follows: |
| 389 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
| 390 | |
George Keishing | 566daaf | 2020-07-02 06:18:50 -0500 | [diff] [blame] | 391 | Create Session redfish ${AUTH_URI} timeout=${timeout} |
George Keishing | f4a4397 | 2020-06-29 03:55:38 -0500 | [diff] [blame] | 392 | ${headers}= Create Dictionary Content-Type=application/json |
| 393 | ${data}= Set Variable If '${kwargs}' == '${EMPTY}' |
| 394 | ... {"UserName":"${rest_username}", "Password":"${rest_password}"} |
| 395 | ... {"UserName":"${rest_username}", "Password":"${rest_password}", ${kwargs}} |
| 396 | |
George Keishing | 566daaf | 2020-07-02 06:18:50 -0500 | [diff] [blame] | 397 | ${resp}= Post Request redfish /redfish/v1/SessionService/Sessions |
George Keishing | f4a4397 | 2020-06-29 03:55:38 -0500 | [diff] [blame] | 398 | ... data=${data} headers=${headers} |
| 399 | Should Be Equal As Strings ${resp.status_code} ${HTTP_CREATED} |
| 400 | |
George Keishing | 0f94f6f | 2020-06-30 08:02:43 -0500 | [diff] [blame] | 401 | ${content}= To JSON ${resp.content} |
| 402 | |
George Keishing | f4a4397 | 2020-06-29 03:55:38 -0500 | [diff] [blame] | 403 | Set Global Variable ${XAUTH_TOKEN} ${resp.headers["X-Auth-Token"]} |
| 404 | |
George Keishing | 0f94f6f | 2020-06-30 08:02:43 -0500 | [diff] [blame] | 405 | [Return] ${content} |
George Keishing | 566daaf | 2020-07-02 06:18:50 -0500 | [diff] [blame] | 406 | |
| 407 | |
| 408 | Redfish Post Request |
| 409 | [Documentation] Do REST POST request and return the result. |
| 410 | [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs} |
| 411 | |
| 412 | # Description of argument(s): |
| 413 | # uri The URI to establish connection with |
| 414 | # (e.g. '/xyz/openbmc_project/software/'). |
| 415 | # timeout Timeout in seconds to establish connection with URI. |
| 416 | # quiet If enabled, turns off logging to console. |
| 417 | # kwargs Any additional arguments to be passed directly to the |
| 418 | # Post Request call. For example, the caller might |
| 419 | # set kwargs as follows: |
| 420 | # ${kwargs}= Create Dictionary allow_redirect=${True}. |
| 421 | |
| 422 | ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri} |
| 423 | ${headers}= Create Dictionary Content-Type=application/json X-Auth-Token=${XAUTH_TOKEN} |
| 424 | Set To Dictionary ${kwargs} headers ${headers} |
| 425 | Run Keyword If '${quiet}' == '${0}' Log Request method=Post base_uri=${base_uri} args=&{kwargs} |
| 426 | ${resp}= Post Request redfish ${base_uri} &{kwargs} timeout=${timeout} |
| 427 | Run Keyword If '${quiet}' == '${0}' Log Response ${resp} |
| 428 | |
| 429 | [Return] ${resp} |