| 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. | 
| Rahul Maheshwari | 79c1294 | 2016-10-17 09:39:17 -0500 | [diff] [blame] | 110 | [Arguments]    ${uri}    ${timeout}=10    &{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. | 
|  | 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} | 
|  | 125 | Log Request  method=Delete  base_uri=${base_uri}  args=&{kwargs} | 
| George Keishing | 0e7c3a0 | 2017-04-17 05:01:14 -0500 | [diff] [blame] | 126 | ${ret}=  Delete Request  openbmc  ${base_uri}  &{kwargs}  timeout=${timeout} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 127 | 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} | 
| Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 134 | ...  ${rest_username}=${REST_USERNAME} | 
|  | 135 | ...  ${rest_password}=${REST_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. | 
|  | 156 | [Arguments]  ${timeout}=20  ${rest_username}=${REST_USERNAME} | 
|  | 157 | ...  ${rest_password}=${REST_PASSWORD} | 
|  | 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} | 
|  | 169 | ${resp}=  Post Request  openbmc  /login  data=${data}  headers=${headers} | 
|  | 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} | 
| Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 185 | ...  ${rest_username}=${REST_USERNAME} | 
|  | 186 | ...  ${rest_password}=${REST_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} | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 198 | ${data}=  create dictionary   data=@{credentials} | 
| Michael Walsh | f00edee | 2016-12-09 14:10:26 -0600 | [diff] [blame] | 199 | ${status}  ${resp}=  Run Keyword And Ignore Error  Post Request  openbmc | 
|  | 200 | ...  /login  data=${data}  headers=${headers} | 
|  | 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 |  | 
|  | 213 | # If there is no active sesion it will throw the following exception | 
|  | 214 | # "Non-existing index or alias 'openbmc'" | 
|  | 215 | ${resp}=  Post Request  openbmc | 
|  | 216 | ...  /logout  data=${data}  headers=${headers} | 
|  | 217 |  | 
|  | 218 | Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK} | 
|  | 219 | ...  msg=${resp} | 
|  | 220 |  | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 221 | Log Request | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 222 | [Documentation]  Log the specific REST URI, method name on the console. | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 223 | [Arguments]    &{kwargs} | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 224 | ${msg}=  Catenate  SEPARATOR=  URI:  ${AUTH_URI}  ${kwargs["base_uri"]} | 
|  | 225 | ...  , method:  ${kwargs["method"]}  , args:  ${kwargs["args"]} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 226 | Logging    ${msg}    console=True | 
|  | 227 |  | 
|  | 228 | Log Response | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 229 | [Documentation]  Log the response code on the console. | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 230 | [Arguments]    ${resp} | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 231 | ${msg}=  Catenate  SEPARATOR=  Response code:  ${resp.status_code} | 
|  | 232 | ...  , Content:  ${resp.content} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 233 | Logging    ${msg}    console=True | 
|  | 234 |  | 
|  | 235 | Logging | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 236 | [Documentation]  Log the specified message on the console. | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 237 | [Arguments]    ${msg}    ${console}=default False | 
|  | 238 | Log    ${msg}    console=True | 
|  | 239 |  | 
|  | 240 | Read Attribute | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 241 | [Documentation]  Retrieve attribute value from URI and return result. | 
|  | 242 | # Example result data for the attribute 'FieldModeEnabled' in | 
|  | 243 | # "/xyz/openbmc_project/software/attr/" : | 
|  | 244 | # 0 | 
| Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 245 | [Arguments]    ${uri}    ${attr}    ${timeout}=10  ${quiet}=${QUIET} | 
| manasarm | c505e38 | 2018-02-05 14:05:48 +0530 | [diff] [blame] | 246 | ...  ${expected_value}=${EMPTY} | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 247 | # Description of argument(s): | 
|  | 248 | # uri               URI of the object that the attribute lives on | 
|  | 249 | #                   (e.g. '/xyz/openbmc_project/software/'). | 
|  | 250 | # attr              Name of the attribute (e.g. 'FieldModeEnabled'). | 
|  | 251 | # timeout           Timeout for the REST call. | 
|  | 252 | # quiet             If enabled, turns off logging to console. | 
| manasarm | c505e38 | 2018-02-05 14:05:48 +0530 | [diff] [blame] | 253 | # expected_value    If this argument is not empty, the retrieved value | 
|  | 254 | #                   must match this value. | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 255 |  | 
| Steven Sombar | b348924 | 2018-12-13 15:59:02 -0600 | [diff] [blame] | 256 | # Make sure uri ends with slash. | 
|  | 257 | ${uri}=  Add Trailing Slash  ${uri} | 
|  | 258 |  | 
|  | 259 | ${resp}=  OpenBMC Get Request  ${uri}attr/${attr}  timeout=${timeout} | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 260 | ...  quiet=${quiet} | 
| Michael Walsh | 9cd6193 | 2017-01-17 16:11:02 -0600 | [diff] [blame] | 261 | Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 262 | ${content}=     To Json    ${resp.content} | 
| manasarm | c505e38 | 2018-02-05 14:05:48 +0530 | [diff] [blame] | 263 | Run Keyword If  '${expected_value}' != '${EMPTY}' | 
|  | 264 | ...  Should Be Equal As Strings  ${expected_value}  ${content["data"]} | 
| Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 265 | [Return]    ${content["data"]} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 266 |  | 
| Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 267 |  | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 268 | Write Attribute | 
| Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 269 | [Documentation]  Write a D-Bus attribute with REST. | 
|  | 270 | [Arguments]  ${uri}  ${attr}  ${timeout}=10  ${verify}=${FALSE} | 
|  | 271 | ...  ${expected_value}=${EMPTY}  &{kwargs} | 
|  | 272 |  | 
|  | 273 | # Description of argument(s): | 
|  | 274 | # uri               URI of the object that the attribute lives on | 
|  | 275 | #                   (e.g. '/xyz/openbmc_project/software/'). | 
|  | 276 | # attr              Name of the attribute (e.g. 'FieldModeEnabled'). | 
|  | 277 | # timeout           Timeout for the REST call. | 
|  | 278 | # verify            If set to ${TRUE}, the attribute will be read back to | 
|  | 279 | #                   ensure that its value is set to ${verify_attr}. | 
|  | 280 | # expected_value    Only used if verify is set to ${TRUE}. The value that | 
|  | 281 | #                   ${attr} should be set to. This defaults to | 
|  | 282 | #                   ${kwargs['data']. There are cases where the caller | 
|  | 283 | #                   expects some other value in which case this value can | 
|  | 284 | #                   be explicitly specified. | 
|  | 285 | # kwargs            Arguments passed to the REST call. This should always | 
|  | 286 | #                   contain the value to set the property to at the 'data' | 
|  | 287 | #                   key (e.g. data={"data": 1}). | 
|  | 288 |  | 
| George Keishing | df3e65f | 2018-12-18 13:06:56 -0600 | [diff] [blame] | 289 | # Make sure uri ends with slash. | 
|  | 290 | ${uri}=  Add Trailing Slash  ${uri} | 
|  | 291 |  | 
| Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 292 | ${base_uri}=  Catenate  SEPARATOR=  ${DBUS_PREFIX}  ${uri} | 
| George Keishing | df3e65f | 2018-12-18 13:06:56 -0600 | [diff] [blame] | 293 | ${resp}=  Openbmc Put Request  ${base_uri}attr/${attr} | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 294 | ...  timeout=${timeout}  &{kwargs} | 
| Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 295 | Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK} | 
|  | 296 |  | 
|  | 297 | # Verify the attribute was set correctly if the caller requested it. | 
|  | 298 | Return From Keyword If  ${verify} == ${FALSE} | 
|  | 299 |  | 
|  | 300 | ${expected_value}=  Set Variable If  '${expected_value}' == '${EMPTY}' | 
| Charles Paul Hofer | 00401e7 | 2017-10-31 11:42:30 -0500 | [diff] [blame] | 301 | ...  ${kwargs['data']['data']}  ${expected_value} | 
| Charles Paul Hofer | f45e5ee | 2017-10-04 12:15:48 -0500 | [diff] [blame] | 302 | ${value}=  Read Attribute  ${uri}  ${attr} | 
|  | 303 | Should Be Equal  ${value}  ${expected_value} | 
|  | 304 |  | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 305 | Read Properties | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 306 | [Documentation]  Read data part of the URI object and return result. | 
|  | 307 | # Example result data: | 
|  | 308 | # [u'/xyz/openbmc_project/software/cf7bf9d5', | 
|  | 309 | #  u'/xyz/openbmc_project/software/5ecb8b2c', | 
|  | 310 | #  u'/xyz/openbmc_project/software/active', | 
|  | 311 | #  u'/xyz/openbmc_project/software/functional'] | 
| George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 312 | [Arguments]  ${uri}  ${timeout}=10  ${quiet}=${QUIET} | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 313 | # Description of argument(s): | 
|  | 314 | # uri               URI of the object | 
|  | 315 | #                   (e.g. '/xyz/openbmc_project/software/'). | 
|  | 316 | # timeout           Timeout for the REST call. | 
|  | 317 | # quiet             If enabled, turns off logging to console. | 
|  | 318 |  | 
| George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 319 | ${resp}=  OpenBMC Get Request  ${uri}  timeout=${timeout}  quiet=${quiet} | 
|  | 320 | Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK} | 
| Michael Walsh | ad66c95 | 2018-10-04 15:12:47 -0500 | [diff] [blame] | 321 | ${content}=  To Json Ordered  ${resp.content} | 
|  | 322 |  | 
| George Keishing | 335f536 | 2017-06-30 15:11:20 -0500 | [diff] [blame] | 323 | [Return]  ${content["data"]} | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 324 |  | 
|  | 325 | Call Method | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 326 | [Documentation]  Invoke the specific REST service method. | 
| Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 327 | [Arguments]  ${uri}  ${method}  ${timeout}=10  ${quiet}=${QUIET}  &{kwargs} | 
| manasarm | 604b8cd | 2018-01-29 12:14:20 +0530 | [diff] [blame] | 328 | # Description of arguments: | 
|  | 329 | # uri      The URI to establish connection with | 
|  | 330 | #          (e.g. '/xyz/openbmc_project/software/'). | 
|  | 331 | # timeout  Timeout in seconds to establish connection with URI. | 
|  | 332 | # quiet    If enabled, turns off logging to console. | 
|  | 333 | # kwargs   Arguments passed to the REST call. | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 334 |  | 
| Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 335 | ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri} | 
| George Keishing | 5c231a8 | 2019-02-05 09:02:04 -0600 | [diff] [blame] | 336 | ${resp}=  OpenBmc Post Request  ${base_uri}action/${method} | 
| Michael Walsh | a6723f2 | 2016-11-22 11:12:01 -0600 | [diff] [blame] | 337 | ...  timeout=${timeout}  quiet=${quiet}  &{kwargs} | 
| Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 338 | [Return]     ${resp} | 
| Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 339 |  | 
| Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 340 |  | 
| Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 341 | Upload Image To BMC | 
| Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 342 | [Documentation]  Upload image to BMC via REST and return status code. | 
|  | 343 | [Arguments]  ${uri}  ${timeout}=10  ${quiet}=${1} | 
| Sushil Singh | c08df05 | 2020-03-30 00:39:22 -0500 | [diff] [blame] | 344 | ...  ${valid_status_codes}=[${HTTP_OK}, ${HTTP_ACCEPTED}]  &{kwargs} | 
| Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 345 |  | 
|  | 346 | # Description of argument(s): | 
| Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 347 | # uri                           URI for uploading image via REST e.g. | 
|  | 348 | #                               "/upload/image". | 
|  | 349 | # timeout                       Time allocated for the REST command to | 
|  | 350 | #                               return status (specified in Robot | 
|  | 351 | #                               Framework Time Format e.g. "3 mins"). | 
|  | 352 | # quiet                         If enabled, turns off logging to console. | 
|  | 353 | # valid_status_codes            A list of status codes that are valid for | 
|  | 354 | #                               the REST post command. This can be | 
|  | 355 | #                               specified as a string the evaluates to a | 
|  | 356 | #                               python object (e.g. [${HTTP_OK}]). | 
|  | 357 | # kwargs                        A dictionary keys/values to be passed | 
|  | 358 | #                               directly to Post Request. | 
| Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 359 |  | 
|  | 360 | Initialize OpenBMC  ${timeout}  quiet=${quiet} | 
|  | 361 | ${base_uri}=  Catenate  SEPARATOR=  ${DBUS_PREFIX}  ${uri} | 
|  | 362 | ${headers}=  Create Dictionary  Content-Type=application/octet-stream | 
| Sridevi Ramesh | eadeef0 | 2019-01-17 08:56:18 -0600 | [diff] [blame] | 363 | ...  X-Auth-Token=${XAUTH_TOKEN}  Accept=application/octet-stream | 
| Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 364 | Set To Dictionary  ${kwargs}  headers  ${headers} | 
|  | 365 | Run Keyword If  '${quiet}' == '${0}'  Log Request  method=Post | 
|  | 366 | ...  base_uri=${base_uri}  args=&{kwargs} | 
|  | 367 | ${ret}=  Post Request  openbmc  ${base_uri}  &{kwargs}  timeout=${timeout} | 
|  | 368 | Run Keyword If  '${quiet}' == '${0}'  Log Response  ${ret} | 
| Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 369 | Valid Value  ret.status_code  ${valid_status_codes} | 
| George Keishing | 08540c0 | 2017-07-19 09:42:50 -0500 | [diff] [blame] | 370 | Delete All Sessions | 
| Sushil Singh | 47f8013 | 2019-08-27 04:53:24 -0500 | [diff] [blame] | 371 |  | 
|  | 372 | [Return]  ${ret.status_code} | 
|  | 373 |  |