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