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