blob: a015e43b03c01bc8d601cbe6a85e6b263882d0d2 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Library Collections
3Library String
George Keishingfbd67002022-08-01 11:24:03 -05004Library RequestsLibrary
Chris Austenb29d2e82016-06-07 12:25:35 -05005Library OperatingSystem
Sandhya Somashekar839a0c22019-01-31 05:05:43 -06006Resource resource.robot
George Keishingeaa73b72018-07-30 09:30:16 -05007Library disable_warning_urllib.py
Michael Walshad66c952018-10-04 15:12:47 -05008Library utils.py
Steven Sombarb3489242018-12-13 15:59:02 -06009Library gen_misc.py
Sridevi Ramesheadeef02019-01-17 08:56:18 -060010Library var_funcs.py
George Keishingeaa73b72018-07-30 09:30:16 -050011Resource rest_response_code.robot
Chris Austenb29d2e82016-06-07 12:25:35 -050012
13*** Variables ***
Michael Walsha6723f22016-11-22 11:12:01 -060014# Assign default value to QUIET for programs which may not define it.
15${QUIET} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050016
Sridevi Ramesheadeef02019-01-17 08:56:18 -060017${XAUTH_TOKEN} ${EMPTY}
18
Chris Austenb29d2e82016-06-07 12:25:35 -050019*** Keywords ***
20OpenBMC Get Request
manasarm604b8cd2018-01-29 12:14:20 +053021 [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 Keishing41c44cf2017-11-15 08:02:59 -060032 [Arguments] ${uri} ${timeout}=30 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053033 # 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 Walshf00edee2016-12-09 14:10:26 -060042
Sridevi Ramesheadeef02019-01-17 08:56:18 -060043 Initialize OpenBMC ${timeout} quiet=${quiet}
44
Chris Austenb29d2e82016-06-07 12:25:35 -050045 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
George Keishing4f76cf62020-12-22 06:42:07 -060046 ${headers}= Create Dictionary X-Auth-Token=${XAUTH_TOKEN} Accept=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -060047 Set To Dictionary ${kwargs} headers ${headers}
Michael Walsha6723f22016-11-22 11:12:01 -060048 Run Keyword If '${quiet}' == '${0}' Log Request method=Get
49 ... base_uri=${base_uri} args=&{kwargs}
George Keishingfbd67002022-08-01 11:24:03 -050050 ${resp}= GET On Session openbmc ${base_uri} &{kwargs} timeout=${timeout} expected_status=any
51 Run Keyword If '${quiet}' == '${0}' Log Response ${resp}
George Keishing08540c02017-07-19 09:42:50 -050052 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +053053 RETURN ${resp}
Chris Austenb29d2e82016-06-07 12:25:35 -050054
55OpenBMC Post Request
manasarm604b8cd2018-01-29 12:14:20 +053056 [Documentation] Do REST POST request and return the result.
57 # Example result data:
58 # <Response [200]>
Michael Walsha6723f22016-11-22 11:12:01 -060059 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053060 # 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 Walsha6723f22016-11-22 11:12:01 -060069
Michael Walshf00edee2016-12-09 14:10:26 -060070 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050071 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Sridevi Ramesheadeef02019-01-17 08:56:18 -060072 ${headers}= Create Dictionary Content-Type=application/json
73 ... X-Auth-Token=${XAUTH_TOKEN}
George Keishingfbd67002022-08-01 11:24:03 -050074 Set To Dictionary ${kwargs} headers ${headers}
Michael Walsha6723f22016-11-22 11:12:01 -060075 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
76 ... base_uri=${base_uri} args=&{kwargs}
George Keishingfbd67002022-08-01 11:24:03 -050077 ${ret}= POST On Session openbmc ${base_uri} &{kwargs} timeout=${timeout}
Michael Walsha6723f22016-11-22 11:12:01 -060078 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050079 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +053080 RETURN ${ret}
Chris Austenb29d2e82016-06-07 12:25:35 -050081
82OpenBMC Put Request
manasarm604b8cd2018-01-29 12:14:20 +053083 [Documentation] Do REST PUT request on the resource identified by the URI.
Rahul Maheshwari79c12942016-10-17 09:39:17 -050084 [Arguments] ${uri} ${timeout}=10 &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053085 # 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 Walshf00edee2016-12-09 14:10:26 -060094
95 Initialize OpenBMC ${timeout}
George Keishingfbd67002022-08-01 11:24:03 -050096 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
97 ${headers}= Create Dictionary Content-Type=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -060098 ... X-Auth-Token=${XAUTH_TOKEN}
George Keishingfbd67002022-08-01 11:24:03 -050099 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 Keishing08540c02017-07-19 09:42:50 -0500102 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +0530103 RETURN ${resp}
Chris Austenb29d2e82016-06-07 12:25:35 -0500104
105OpenBMC Delete Request
manasarm604b8cd2018-01-29 12:14:20 +0530106 [Documentation] Do REST request to delete the resource identified by the
107 ... URI.
Michael Sheposcc490b42020-08-26 12:53:01 -0500108 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530109 # 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 Sheposcc490b42020-08-26 12:53:01 -0500113 # quiet If enabled, turns off logging to console.
manasarm604b8cd2018-01-29 12:14:20 +0530114 # 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 Walshf00edee2016-12-09 14:10:26 -0600118
119 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500120 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600121 ${headers}= Create Dictionary Content-Type=application/json
122 ... X-Auth-Token=${XAUTH_TOKEN}
123 Set To Dictionary ${kwargs} headers ${headers}
Michael Sheposcc490b42020-08-26 12:53:01 -0500124 Run Keyword If '${quiet}' == '${0}' Log Request method=Delete
125 ... base_uri=${base_uri} args=&{kwargs}
George Keishingfbd67002022-08-01 11:24:03 -0500126 ${ret}= DELETE On Session openbmc ${base_uri} &{kwargs} timeout=${timeout}
Michael Sheposcc490b42020-08-26 12:53:01 -0500127 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -0500128 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +0530129 RETURN ${ret}
Chris Austenb29d2e82016-06-07 12:25:35 -0500130
131Initialize OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530132 [Documentation] Do a REST login connection within specified time.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500133 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishing7981f432023-11-15 23:49:16 +0530134 ... ${rest_username}=${OPENBMC_USERNAME}
135 ... ${rest_password}=${OPENBMC_PASSWORD}
Michael Walshf00edee2016-12-09 14:10:26 -0600136
George Keishing1cdc6dd2017-04-24 15:31:03 -0500137 # Description of argument(s):
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600138 # 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 Keishing1cdc6dd2017-04-24 15:31:03 -0500147
George Keishing1cdc6dd2017-04-24 15:31:03 -0500148 # This will retry at 20 second interval.
149 Wait Until Keyword Succeeds 40 sec 20 sec
150 ... Post Login Request ${timeout} ${quiet}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600151 ... ${rest_username} ${rest_password}
152
153
154BMC Web Login Request
155 [Documentation] Do BMC web-based login.
George Keishing7981f432023-11-15 23:49:16 +0530156 [Arguments] ${timeout}=20 ${rest_username}=${OPENBMC_USERNAME}
157 ... ${rest_password}=${OPENBMC_PASSWORD}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600158
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 Keishingfbd67002022-08-01 11:24:03 -0500169 ${resp}= POST On Session openbmc /login json=${data} headers=${headers}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600170 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,
Gunnar Millsecad51c2025-03-06 11:02:54 -0600178 # BMCWEB-SESSION=c4wloTiETumSxPI9nLeg; Secure; HttpOnly'
rramyasr-in1963a4b2025-04-16 04:58:05 -0500179
180 # To handle latest bmcweb token exceptions.
181 ${session_token}=
182 ... Get Variable Value ${result['bmcweb-session']} ${result['session']}
183 Set Global Variable ${XAUTH_TOKEN} ${session_token}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600184
George Keishing1cdc6dd2017-04-24 15:31:03 -0500185
186Post Login Request
manasarm604b8cd2018-01-29 12:14:20 +0530187 [Documentation] Do REST login request.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500188 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishing7981f432023-11-15 23:49:16 +0530189 ... ${rest_username}=${OPENBMC_USERNAME}
190 ... ${rest_password}=${OPENBMC_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500191
192 # Description of argument(s):
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600193 # timeout REST login attempt time out.
194 # quiet Suppress console log if set.
195 # rest_username The REST username.
196 # rest_password The REST password.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500197
198 Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600199
Michael Walsha6723f22016-11-22 11:12:01 -0600200 ${headers}= Create Dictionary Content-Type=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600201 @{credentials}= Create List ${rest_username} ${rest_password}
George Keishing695ffe82022-08-17 22:00:03 -0500202 ${data}= Create Dictionary data=@{credentials}
George Keishingfbd67002022-08-01 11:24:03 -0500203 ${status} ${resp}= Run Keyword And Ignore Error POST On Session openbmc
George Keishing695ffe82022-08-17 22:00:03 -0500204 ... /login json=${data} headers=${headers}
Michael Walshf00edee2016-12-09 14:10:26 -0600205
206 Should Be Equal ${status} PASS msg=${resp}
207 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500208
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600209
George Keishinge8225522017-03-31 09:21:13 -0500210Log Out OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530211 [Documentation] Log out of the openbmc REST session.
George Keishinge8225522017-03-31 09:21:13 -0500212
213 ${headers}= Create Dictionary Content-Type=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600214 ... X-Auth-Token=${XAUTH_TOKEN}
George Keishinge8225522017-03-31 09:21:13 -0500215 ${data}= Create dictionary data=@{EMPTY}
216
George Keishinge16f1582022-12-15 07:32:21 -0600217 # If there is no active session it will throw the following exception
George Keishinge8225522017-03-31 09:21:13 -0500218 # "Non-existing index or alias 'openbmc'"
George Keishingfbd67002022-08-01 11:24:03 -0500219 ${resp}= POST On Session openbmc
George Keishing695ffe82022-08-17 22:00:03 -0500220 ... /logout json=${data} headers=${headers}
George Keishinge8225522017-03-31 09:21:13 -0500221
222 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
223 ... msg=${resp}
224
George Keishingfbd67002022-08-01 11:24:03 -0500225
Chris Austenb29d2e82016-06-07 12:25:35 -0500226Log Request
manasarm604b8cd2018-01-29 12:14:20 +0530227 [Documentation] Log the specific REST URI, method name on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500228 [Arguments] &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600229 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
230 ... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500231 Logging ${msg} console=True
232
George Keishingfbd67002022-08-01 11:24:03 -0500233
Chris Austenb29d2e82016-06-07 12:25:35 -0500234Log Response
manasarm604b8cd2018-01-29 12:14:20 +0530235 [Documentation] Log the response code on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500236 [Arguments] ${resp}
George Keishingfbd67002022-08-01 11:24:03 -0500237
Michael Walsha6723f22016-11-22 11:12:01 -0600238 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
239 ... , Content: ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500240 Logging ${msg} console=True
241
George Keishingfbd67002022-08-01 11:24:03 -0500242
Chris Austenb29d2e82016-06-07 12:25:35 -0500243Logging
manasarm604b8cd2018-01-29 12:14:20 +0530244 [Documentation] Log the specified message on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500245 [Arguments] ${msg} ${console}=default False
George Keishingfbd67002022-08-01 11:24:03 -0500246 Log ${msg} console=True
247
Chris Austenb29d2e82016-06-07 12:25:35 -0500248
249Read Attribute
manasarm604b8cd2018-01-29 12:14:20 +0530250 [Documentation] Retrieve attribute value from URI and return result.
251 # Example result data for the attribute 'FieldModeEnabled' in
252 # "/xyz/openbmc_project/software/attr/" :
253 # 0
Gunnar Mills38032802016-12-12 13:43:40 -0600254 [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
manasarmc505e382018-02-05 14:05:48 +0530255 ... ${expected_value}=${EMPTY}
manasarm604b8cd2018-01-29 12:14:20 +0530256 # Description of argument(s):
257 # uri URI of the object that the attribute lives on
258 # (e.g. '/xyz/openbmc_project/software/').
259 # attr Name of the attribute (e.g. 'FieldModeEnabled').
260 # timeout Timeout for the REST call.
261 # quiet If enabled, turns off logging to console.
manasarmc505e382018-02-05 14:05:48 +0530262 # expected_value If this argument is not empty, the retrieved value
263 # must match this value.
manasarm604b8cd2018-01-29 12:14:20 +0530264
Steven Sombarb3489242018-12-13 15:59:02 -0600265 # Make sure uri ends with slash.
266 ${uri}= Add Trailing Slash ${uri}
267
268 ${resp}= OpenBMC Get Request ${uri}attr/${attr} timeout=${timeout}
Michael Walsha6723f22016-11-22 11:12:01 -0600269 ... quiet=${quiet}
Michael Walsh9cd61932017-01-17 16:11:02 -0600270 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
manasarmc505e382018-02-05 14:05:48 +0530271 Run Keyword If '${expected_value}' != '${EMPTY}'
George Keishingfbd67002022-08-01 11:24:03 -0500272 ... Should Be Equal As Strings ${expected_value} ${resp.json()["data"]}
George Keishing409df052024-01-17 22:36:14 +0530273 RETURN ${resp.json()["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500274
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500275
Chris Austenb29d2e82016-06-07 12:25:35 -0500276Write Attribute
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500277 [Documentation] Write a D-Bus attribute with REST.
278 [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE}
279 ... ${expected_value}=${EMPTY} &{kwargs}
280
281 # Description of argument(s):
282 # uri URI of the object that the attribute lives on
283 # (e.g. '/xyz/openbmc_project/software/').
284 # attr Name of the attribute (e.g. 'FieldModeEnabled').
285 # timeout Timeout for the REST call.
286 # verify If set to ${TRUE}, the attribute will be read back to
287 # ensure that its value is set to ${verify_attr}.
288 # expected_value Only used if verify is set to ${TRUE}. The value that
289 # ${attr} should be set to. This defaults to
290 # ${kwargs['data']. There are cases where the caller
291 # expects some other value in which case this value can
292 # be explicitly specified.
293 # kwargs Arguments passed to the REST call. This should always
294 # contain the value to set the property to at the 'data'
295 # key (e.g. data={"data": 1}).
296
George Keishingdf3e65f2018-12-18 13:06:56 -0600297 # Make sure uri ends with slash.
298 ${uri}= Add Trailing Slash ${uri}
299
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500300 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
George Keishingdf3e65f2018-12-18 13:06:56 -0600301 ${resp}= Openbmc Put Request ${base_uri}attr/${attr}
Michael Walsha6723f22016-11-22 11:12:01 -0600302 ... timeout=${timeout} &{kwargs}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500303 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
304
305 # Verify the attribute was set correctly if the caller requested it.
306 Return From Keyword If ${verify} == ${FALSE}
307
308 ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}'
Charles Paul Hofer00401e72017-10-31 11:42:30 -0500309 ... ${kwargs['data']['data']} ${expected_value}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500310 ${value}= Read Attribute ${uri} ${attr}
311 Should Be Equal ${value} ${expected_value}
312
Chris Austenb29d2e82016-06-07 12:25:35 -0500313Read Properties
manasarm604b8cd2018-01-29 12:14:20 +0530314 [Documentation] Read data part of the URI object and return result.
315 # Example result data:
316 # [u'/xyz/openbmc_project/software/cf7bf9d5',
317 # u'/xyz/openbmc_project/software/5ecb8b2c',
318 # u'/xyz/openbmc_project/software/active',
319 # u'/xyz/openbmc_project/software/functional']
George Keishing335f5362017-06-30 15:11:20 -0500320 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET}
manasarm604b8cd2018-01-29 12:14:20 +0530321 # Description of argument(s):
322 # uri URI of the object
323 # (e.g. '/xyz/openbmc_project/software/').
324 # timeout Timeout for the REST call.
325 # quiet If enabled, turns off logging to console.
326
George Keishing335f5362017-06-30 15:11:20 -0500327 ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet}
328 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Michael Walshad66c952018-10-04 15:12:47 -0500329
George Keishing409df052024-01-17 22:36:14 +0530330 RETURN ${resp.json()["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500331
332Call Method
manasarm604b8cd2018-01-29 12:14:20 +0530333 [Documentation] Invoke the specific REST service method.
Gunnar Mills38032802016-12-12 13:43:40 -0600334 [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530335 # Description of arguments:
336 # uri The URI to establish connection with
337 # (e.g. '/xyz/openbmc_project/software/').
338 # timeout Timeout in seconds to establish connection with URI.
339 # quiet If enabled, turns off logging to console.
340 # kwargs Arguments passed to the REST call.
Michael Walsha6723f22016-11-22 11:12:01 -0600341
Chris Austenb29d2e82016-06-07 12:25:35 -0500342 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
George Keishing5c231a82019-02-05 09:02:04 -0600343 ${resp}= OpenBmc Post Request ${base_uri}action/${method}
Michael Walsha6723f22016-11-22 11:12:01 -0600344 ... timeout=${timeout} quiet=${quiet} &{kwargs}
George Keishing409df052024-01-17 22:36:14 +0530345 RETURN ${resp}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500346
Sushil Singh47f80132019-08-27 04:53:24 -0500347
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500348Upload Image To BMC
Sushil Singh47f80132019-08-27 04:53:24 -0500349 [Documentation] Upload image to BMC via REST and return status code.
350 [Arguments] ${uri} ${timeout}=10 ${quiet}=${1}
Sushil Singhc08df052020-03-30 00:39:22 -0500351 ... ${valid_status_codes}=[${HTTP_OK}, ${HTTP_ACCEPTED}] &{kwargs}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500352
353 # Description of argument(s):
Sushil Singh47f80132019-08-27 04:53:24 -0500354 # uri URI for uploading image via REST e.g.
355 # "/upload/image".
356 # timeout Time allocated for the REST command to
357 # return status (specified in Robot
358 # Framework Time Format e.g. "3 mins").
359 # quiet If enabled, turns off logging to console.
360 # valid_status_codes A list of status codes that are valid for
361 # the REST post command. This can be
362 # specified as a string the evaluates to a
363 # python object (e.g. [${HTTP_OK}]).
364 # kwargs A dictionary keys/values to be passed
365 # directly to Post Request.
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500366
George Keishingbadd1fc2025-02-05 23:00:05 +0530367
368 # If /redfish/v1/SessionService/Sessions POST fails, fallback to
369 # REST /login method.
370 ${passed}= Run Keyword And Return Status Redfish Login
371 Run Keyword If ${passed} != True Initialize OpenBMC ${timeout} quiet=${quiet}
372 ${session_object}= Set Variable If ${passed} redfish openbmc
373
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500374 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
375 ${headers}= Create Dictionary Content-Type=application/octet-stream
George Keishing4f76cf62020-12-22 06:42:07 -0600376 ... X-Auth-Token=${XAUTH_TOKEN} Accept=application/json
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500377 Set To Dictionary ${kwargs} headers ${headers}
378 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
379 ... base_uri=${base_uri} args=&{kwargs}
George Keishingbadd1fc2025-02-05 23:00:05 +0530380 ${ret}= POST On Session ${session_object} ${base_uri} &{kwargs} timeout=${timeout}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500381 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
Sushil Singh47f80132019-08-27 04:53:24 -0500382 Valid Value ret.status_code ${valid_status_codes}
George Keishing08540c02017-07-19 09:42:50 -0500383 Delete All Sessions
Sushil Singh47f80132019-08-27 04:53:24 -0500384
George Keishing409df052024-01-17 22:36:14 +0530385 RETURN ${ret}
Sushil Singh47f80132019-08-27 04:53:24 -0500386
George Keishingf4a43972020-06-29 03:55:38 -0500387
388Redfish Login
389 [Documentation] Do BMC web-based login.
George Keishing7981f432023-11-15 23:49:16 +0530390 [Arguments] ${timeout}=20 ${rest_username}=${OPENBMC_USERNAME}
391 ... ${rest_password}=${OPENBMC_PASSWORD} ${kwargs}=${EMPTY}
George Keishingf4a43972020-06-29 03:55:38 -0500392
393 # Description of argument(s):
394 # timeout REST login attempt time out.
395 # rest_username The REST username.
396 # rest_password The REST password.
397 # kwargs Any additional arguments to be passed directly to the
398 # Get Request call. For example, the caller might
399 # set kwargs as follows:
400 # ${kwargs}= Create Dictionary allow_redirect=${True}.
401
George Keishing566daaf2020-07-02 06:18:50 -0500402 Create Session redfish ${AUTH_URI} timeout=${timeout}
George Keishingf4a43972020-06-29 03:55:38 -0500403 ${headers}= Create Dictionary Content-Type=application/json
404 ${data}= Set Variable If '${kwargs}' == '${EMPTY}'
405 ... {"UserName":"${rest_username}", "Password":"${rest_password}"}
406 ... {"UserName":"${rest_username}", "Password":"${rest_password}", ${kwargs}}
407
George Keishingfbd67002022-08-01 11:24:03 -0500408 ${resp}= POST On Session redfish /redfish/v1/SessionService/Sessions
George Keishingf4a43972020-06-29 03:55:38 -0500409 ... data=${data} headers=${headers}
410 Should Be Equal As Strings ${resp.status_code} ${HTTP_CREATED}
411
412 Set Global Variable ${XAUTH_TOKEN} ${resp.headers["X-Auth-Token"]}
413
George Keishing409df052024-01-17 22:36:14 +0530414 RETURN ${resp.json()}
George Keishing566daaf2020-07-02 06:18:50 -0500415
416
Sushil Singh4ec68ba2020-09-11 09:16:43 -0500417Redfish Get Request
418 [Documentation] Do REST POST request and return the result.
419 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
420
421 # Description of argument(s):
422 # uri The URI to establish connection with
423 # (e.g. '/xyz/openbmc_project/software/').
424 # timeout Timeout in seconds to establish connection with URI.
425 # quiet If enabled, turns off logging to console.
426 # kwargs Any additional arguments to be passed directly to the
427 # Post Request call. For example, the caller might
428 # set kwargs as follows:
429 # ${kwargs}= Create Dictionary allow_redirect=${True}.
430
431 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
432 ${headers}= Create Dictionary Content-Type=application/json X-Auth-Token=${XAUTH_TOKEN}
433 Set To Dictionary ${kwargs} headers ${headers}
434 Run Keyword If '${quiet}' == '${0}' Log Request method=Post base_uri=${base_uri} args=&{kwargs}
George Keishingfbd67002022-08-01 11:24:03 -0500435 ${resp}= GET On Session redfish ${base_uri} &{kwargs} timeout=${timeout}
Sushil Singh4ec68ba2020-09-11 09:16:43 -0500436 Run Keyword If '${quiet}' == '${0}' Log Response ${resp}
437
George Keishing409df052024-01-17 22:36:14 +0530438 RETURN ${resp}
Sushil Singh4ec68ba2020-09-11 09:16:43 -0500439
440
George Keishing566daaf2020-07-02 06:18:50 -0500441Redfish Post Request
442 [Documentation] Do REST POST request and return the result.
443 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
444
445 # Description of argument(s):
446 # uri The URI to establish connection with
447 # (e.g. '/xyz/openbmc_project/software/').
448 # timeout Timeout in seconds to establish connection with URI.
449 # quiet If enabled, turns off logging to console.
450 # kwargs Any additional arguments to be passed directly to the
451 # Post Request call. For example, the caller might
452 # set kwargs as follows:
453 # ${kwargs}= Create Dictionary allow_redirect=${True}.
454
455 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
456 ${headers}= Create Dictionary Content-Type=application/json X-Auth-Token=${XAUTH_TOKEN}
457 Set To Dictionary ${kwargs} headers ${headers}
458 Run Keyword If '${quiet}' == '${0}' Log Request method=Post base_uri=${base_uri} args=&{kwargs}
George Keishingfbd67002022-08-01 11:24:03 -0500459 ${resp}= POST On Session redfish ${base_uri} &{kwargs} timeout=${timeout} expected_status=any
George Keishing566daaf2020-07-02 06:18:50 -0500460 Run Keyword If '${quiet}' == '${0}' Log Response ${resp}
461
George Keishing409df052024-01-17 22:36:14 +0530462 RETURN ${resp}