blob: 859414c58e9905edab7e700b3a2cd0443ca43e19 [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}
George Keishing7efd7742025-07-03 10:47:13 +053048 IF '${quiet}' == '${0}' Log Request method=Get
49 ... base_uri=${base_uri} args=&{kwargs}
50 END
George Keishingfbd67002022-08-01 11:24:03 -050051 ${resp}= GET On Session openbmc ${base_uri} &{kwargs} timeout=${timeout} expected_status=any
George Keishing7efd7742025-07-03 10:47:13 +053052 IF '${quiet}' == '${0}' Log Response ${resp}
George Keishing08540c02017-07-19 09:42:50 -050053 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +053054 RETURN ${resp}
Chris Austenb29d2e82016-06-07 12:25:35 -050055
56OpenBMC Post Request
manasarm604b8cd2018-01-29 12:14:20 +053057 [Documentation] Do REST POST request and return the result.
58 # Example result data:
59 # <Response [200]>
Michael Walsha6723f22016-11-22 11:12:01 -060060 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053061 # 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 Walsha6723f22016-11-22 11:12:01 -060070
Michael Walshf00edee2016-12-09 14:10:26 -060071 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050072 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Sridevi Ramesheadeef02019-01-17 08:56:18 -060073 ${headers}= Create Dictionary Content-Type=application/json
74 ... X-Auth-Token=${XAUTH_TOKEN}
George Keishingfbd67002022-08-01 11:24:03 -050075 Set To Dictionary ${kwargs} headers ${headers}
George Keishing7efd7742025-07-03 10:47:13 +053076 IF '${quiet}' == '${0}' Log Request method=Post
77 ... base_uri=${base_uri} args=&{kwargs}
78 END
George Keishingfbd67002022-08-01 11:24:03 -050079 ${ret}= POST On Session openbmc ${base_uri} &{kwargs} timeout=${timeout}
George Keishing7efd7742025-07-03 10:47:13 +053080 IF '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050081 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +053082 RETURN ${ret}
Chris Austenb29d2e82016-06-07 12:25:35 -050083
84OpenBMC Put Request
manasarm604b8cd2018-01-29 12:14:20 +053085 [Documentation] Do REST PUT request on the resource identified by the URI.
Rahul Maheshwari79c12942016-10-17 09:39:17 -050086 [Arguments] ${uri} ${timeout}=10 &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053087 # Description of argument(s):
88 # uri The URI to establish connection with
89 # (e.g. '/xyz/openbmc_project/software/').
90 # timeout Timeout in seconds to establish connection with URI.
91 # kwargs Arguments passed to the REST call.
92 # kwargs Any additional arguments to be passed directly to the
93 # Put Request call. For example, the caller might
94 # set kwargs as follows:
95 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -060096
97 Initialize OpenBMC ${timeout}
George Keishingfbd67002022-08-01 11:24:03 -050098 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
99 ${headers}= Create Dictionary Content-Type=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600100 ... X-Auth-Token=${XAUTH_TOKEN}
George Keishingfbd67002022-08-01 11:24:03 -0500101 Log Request method=Put base_uri=${base_uri} args=&{kwargs}
102 ${resp}= PUT On Session openbmc ${base_uri} json=${kwargs["data"]} headers=${headers}
103 Log Response ${resp}
George Keishing08540c02017-07-19 09:42:50 -0500104 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +0530105 RETURN ${resp}
Chris Austenb29d2e82016-06-07 12:25:35 -0500106
107OpenBMC Delete Request
manasarm604b8cd2018-01-29 12:14:20 +0530108 [Documentation] Do REST request to delete the resource identified by the
109 ... URI.
Michael Sheposcc490b42020-08-26 12:53:01 -0500110 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530111 # Description of argument(s):
112 # uri The URI to establish connection with
113 # (e.g. '/xyz/openbmc_project/software/').
114 # timeout Timeout in seconds to establish connection with URI.
Michael Sheposcc490b42020-08-26 12:53:01 -0500115 # quiet If enabled, turns off logging to console.
manasarm604b8cd2018-01-29 12:14:20 +0530116 # kwargs Any additional arguments to be passed directly to the
117 # Delete Request call. For example, the caller might
118 # set kwargs as follows:
119 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -0600120
121 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500122 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600123 ${headers}= Create Dictionary Content-Type=application/json
124 ... X-Auth-Token=${XAUTH_TOKEN}
125 Set To Dictionary ${kwargs} headers ${headers}
George Keishing7efd7742025-07-03 10:47:13 +0530126 IF '${quiet}' == '${0}' Log Request method=Delete
127 ... base_uri=${base_uri} args=&{kwargs}
128 END
George Keishingfbd67002022-08-01 11:24:03 -0500129 ${ret}= DELETE On Session openbmc ${base_uri} &{kwargs} timeout=${timeout}
George Keishing7efd7742025-07-03 10:47:13 +0530130 IF '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -0500131 Delete All Sessions
George Keishing409df052024-01-17 22:36:14 +0530132 RETURN ${ret}
Chris Austenb29d2e82016-06-07 12:25:35 -0500133
134Initialize OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530135 [Documentation] Do a REST login connection within specified time.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500136 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishing7981f432023-11-15 23:49:16 +0530137 ... ${rest_username}=${OPENBMC_USERNAME}
138 ... ${rest_password}=${OPENBMC_PASSWORD}
Michael Walshf00edee2016-12-09 14:10:26 -0600139
George Keishing1cdc6dd2017-04-24 15:31:03 -0500140 # Description of argument(s):
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600141 # timeout REST login attempt time out.
142 # quiet Suppress console log if set.
143 # rest_username The REST username.
144 # rest_password The REST password.
145
146 ${bmcweb_status}= Run Keyword And Return Status BMC Web Login Request
147 ... ${timeout} ${rest_username} ${rest_password}
148
149 Return From Keyword If ${bmcweb_status} == ${True}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500150
George Keishing1cdc6dd2017-04-24 15:31:03 -0500151 # This will retry at 20 second interval.
152 Wait Until Keyword Succeeds 40 sec 20 sec
153 ... Post Login Request ${timeout} ${quiet}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600154 ... ${rest_username} ${rest_password}
155
156
157BMC Web Login Request
158 [Documentation] Do BMC web-based login.
George Keishing7981f432023-11-15 23:49:16 +0530159 [Arguments] ${timeout}=20 ${rest_username}=${OPENBMC_USERNAME}
160 ... ${rest_password}=${OPENBMC_PASSWORD}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600161
162 # Description of argument(s):
163 # timeout REST login attempt time out.
164 # rest_username The REST username.
165 # rest_password The REST password.
166
167 Create Session openbmc ${AUTH_URI} timeout=${timeout}
168
169 ${headers}= Create Dictionary Content-Type=application/json
170 @{credentials}= Create List ${rest_username} ${rest_password}
171 ${data}= Create Dictionary data=@{credentials}
George Keishingfbd67002022-08-01 11:24:03 -0500172 ${resp}= POST On Session openbmc /login json=${data} headers=${headers}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600173 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
174
175 ${processed_token_data}=
176 ... Evaluate re.split(r'[;,]', '${resp.headers["Set-Cookie"]}') modules=re
177 ${result}= Key Value List To Dict ${processed_token_data} delim==
178
179 # Example result data:
180 # 'XSRF-TOKEN=hQuOyDJFEIbrN4aOg2CT; Secure,
Gunnar Millsecad51c2025-03-06 11:02:54 -0600181 # BMCWEB-SESSION=c4wloTiETumSxPI9nLeg; Secure; HttpOnly'
rramyasr-in1963a4b2025-04-16 04:58:05 -0500182
183 # To handle latest bmcweb token exceptions.
184 ${session_token}=
185 ... Get Variable Value ${result['bmcweb-session']} ${result['session']}
186 Set Global Variable ${XAUTH_TOKEN} ${session_token}
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600187
George Keishing1cdc6dd2017-04-24 15:31:03 -0500188
189Post Login Request
manasarm604b8cd2018-01-29 12:14:20 +0530190 [Documentation] Do REST login request.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500191 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishing7981f432023-11-15 23:49:16 +0530192 ... ${rest_username}=${OPENBMC_USERNAME}
193 ... ${rest_password}=${OPENBMC_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500194
195 # Description of argument(s):
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600196 # timeout REST login attempt time out.
197 # quiet Suppress console log if set.
198 # rest_username The REST username.
199 # rest_password The REST password.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500200
201 Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600202
Michael Walsha6723f22016-11-22 11:12:01 -0600203 ${headers}= Create Dictionary Content-Type=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600204 @{credentials}= Create List ${rest_username} ${rest_password}
George Keishing695ffe82022-08-17 22:00:03 -0500205 ${data}= Create Dictionary data=@{credentials}
George Keishingfbd67002022-08-01 11:24:03 -0500206 ${status} ${resp}= Run Keyword And Ignore Error POST On Session openbmc
George Keishing695ffe82022-08-17 22:00:03 -0500207 ... /login json=${data} headers=${headers}
Michael Walshf00edee2016-12-09 14:10:26 -0600208
209 Should Be Equal ${status} PASS msg=${resp}
210 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500211
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600212
George Keishinge8225522017-03-31 09:21:13 -0500213Log Out OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530214 [Documentation] Log out of the openbmc REST session.
George Keishinge8225522017-03-31 09:21:13 -0500215
216 ${headers}= Create Dictionary Content-Type=application/json
Sridevi Ramesheadeef02019-01-17 08:56:18 -0600217 ... X-Auth-Token=${XAUTH_TOKEN}
George Keishinge8225522017-03-31 09:21:13 -0500218 ${data}= Create dictionary data=@{EMPTY}
219
George Keishinge16f1582022-12-15 07:32:21 -0600220 # If there is no active session it will throw the following exception
George Keishinge8225522017-03-31 09:21:13 -0500221 # "Non-existing index or alias 'openbmc'"
George Keishingfbd67002022-08-01 11:24:03 -0500222 ${resp}= POST On Session openbmc
George Keishing695ffe82022-08-17 22:00:03 -0500223 ... /logout json=${data} headers=${headers}
George Keishinge8225522017-03-31 09:21:13 -0500224
225 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
226 ... msg=${resp}
227
George Keishingfbd67002022-08-01 11:24:03 -0500228
Chris Austenb29d2e82016-06-07 12:25:35 -0500229Log Request
manasarm604b8cd2018-01-29 12:14:20 +0530230 [Documentation] Log the specific REST URI, method name on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500231 [Arguments] &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600232 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
233 ... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500234 Logging ${msg} console=True
235
George Keishingfbd67002022-08-01 11:24:03 -0500236
Chris Austenb29d2e82016-06-07 12:25:35 -0500237Log Response
manasarm604b8cd2018-01-29 12:14:20 +0530238 [Documentation] Log the response code on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500239 [Arguments] ${resp}
George Keishingfbd67002022-08-01 11:24:03 -0500240
Michael Walsha6723f22016-11-22 11:12:01 -0600241 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
242 ... , Content: ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500243 Logging ${msg} console=True
244
George Keishingfbd67002022-08-01 11:24:03 -0500245
Chris Austenb29d2e82016-06-07 12:25:35 -0500246Logging
manasarm604b8cd2018-01-29 12:14:20 +0530247 [Documentation] Log the specified message on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500248 [Arguments] ${msg} ${console}=default False
George Keishingfbd67002022-08-01 11:24:03 -0500249 Log ${msg} console=True
250
Chris Austenb29d2e82016-06-07 12:25:35 -0500251
252Read Attribute
manasarm604b8cd2018-01-29 12:14:20 +0530253 [Documentation] Retrieve attribute value from URI and return result.
254 # Example result data for the attribute 'FieldModeEnabled' in
255 # "/xyz/openbmc_project/software/attr/" :
256 # 0
Gunnar Mills38032802016-12-12 13:43:40 -0600257 [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
manasarmc505e382018-02-05 14:05:48 +0530258 ... ${expected_value}=${EMPTY}
manasarm604b8cd2018-01-29 12:14:20 +0530259 # Description of argument(s):
260 # uri URI of the object that the attribute lives on
261 # (e.g. '/xyz/openbmc_project/software/').
262 # attr Name of the attribute (e.g. 'FieldModeEnabled').
263 # timeout Timeout for the REST call.
264 # quiet If enabled, turns off logging to console.
manasarmc505e382018-02-05 14:05:48 +0530265 # expected_value If this argument is not empty, the retrieved value
266 # must match this value.
manasarm604b8cd2018-01-29 12:14:20 +0530267
Steven Sombarb3489242018-12-13 15:59:02 -0600268 # Make sure uri ends with slash.
269 ${uri}= Add Trailing Slash ${uri}
270
271 ${resp}= OpenBMC Get Request ${uri}attr/${attr} timeout=${timeout}
Michael Walsha6723f22016-11-22 11:12:01 -0600272 ... quiet=${quiet}
Michael Walsh9cd61932017-01-17 16:11:02 -0600273 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishing7efd7742025-07-03 10:47:13 +0530274 IF '${expected_value}' != '${EMPTY}'
275 ... Should Be Equal As Strings ${expected_value} ${resp.json()["data"]}
276 END
George Keishing409df052024-01-17 22:36:14 +0530277 RETURN ${resp.json()["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500278
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500279
Chris Austenb29d2e82016-06-07 12:25:35 -0500280Write Attribute
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500281 [Documentation] Write a D-Bus attribute with REST.
282 [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE}
283 ... ${expected_value}=${EMPTY} &{kwargs}
284
285 # Description of argument(s):
286 # uri URI of the object that the attribute lives on
287 # (e.g. '/xyz/openbmc_project/software/').
288 # attr Name of the attribute (e.g. 'FieldModeEnabled').
289 # timeout Timeout for the REST call.
290 # verify If set to ${TRUE}, the attribute will be read back to
291 # ensure that its value is set to ${verify_attr}.
292 # expected_value Only used if verify is set to ${TRUE}. The value that
293 # ${attr} should be set to. This defaults to
294 # ${kwargs['data']. There are cases where the caller
295 # expects some other value in which case this value can
296 # be explicitly specified.
297 # kwargs Arguments passed to the REST call. This should always
298 # contain the value to set the property to at the 'data'
299 # key (e.g. data={"data": 1}).
300
George Keishingdf3e65f2018-12-18 13:06:56 -0600301 # Make sure uri ends with slash.
302 ${uri}= Add Trailing Slash ${uri}
303
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500304 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
George Keishingdf3e65f2018-12-18 13:06:56 -0600305 ${resp}= Openbmc Put Request ${base_uri}attr/${attr}
Michael Walsha6723f22016-11-22 11:12:01 -0600306 ... timeout=${timeout} &{kwargs}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500307 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
308
309 # Verify the attribute was set correctly if the caller requested it.
310 Return From Keyword If ${verify} == ${FALSE}
311
312 ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}'
Charles Paul Hofer00401e72017-10-31 11:42:30 -0500313 ... ${kwargs['data']['data']} ${expected_value}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500314 ${value}= Read Attribute ${uri} ${attr}
315 Should Be Equal ${value} ${expected_value}
316
Chris Austenb29d2e82016-06-07 12:25:35 -0500317Read Properties
manasarm604b8cd2018-01-29 12:14:20 +0530318 [Documentation] Read data part of the URI object and return result.
319 # Example result data:
320 # [u'/xyz/openbmc_project/software/cf7bf9d5',
321 # u'/xyz/openbmc_project/software/5ecb8b2c',
322 # u'/xyz/openbmc_project/software/active',
323 # u'/xyz/openbmc_project/software/functional']
George Keishing335f5362017-06-30 15:11:20 -0500324 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET}
manasarm604b8cd2018-01-29 12:14:20 +0530325 # Description of argument(s):
326 # uri URI of the object
327 # (e.g. '/xyz/openbmc_project/software/').
328 # timeout Timeout for the REST call.
329 # quiet If enabled, turns off logging to console.
330
George Keishing335f5362017-06-30 15:11:20 -0500331 ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet}
332 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Michael Walshad66c952018-10-04 15:12:47 -0500333
George Keishing409df052024-01-17 22:36:14 +0530334 RETURN ${resp.json()["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500335
336Call Method
manasarm604b8cd2018-01-29 12:14:20 +0530337 [Documentation] Invoke the specific REST service method.
Gunnar Mills38032802016-12-12 13:43:40 -0600338 [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530339 # Description of arguments:
340 # uri The URI to establish connection with
341 # (e.g. '/xyz/openbmc_project/software/').
342 # timeout Timeout in seconds to establish connection with URI.
343 # quiet If enabled, turns off logging to console.
344 # kwargs Arguments passed to the REST call.
Michael Walsha6723f22016-11-22 11:12:01 -0600345
Chris Austenb29d2e82016-06-07 12:25:35 -0500346 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
George Keishing5c231a82019-02-05 09:02:04 -0600347 ${resp}= OpenBmc Post Request ${base_uri}action/${method}
Michael Walsha6723f22016-11-22 11:12:01 -0600348 ... timeout=${timeout} quiet=${quiet} &{kwargs}
George Keishing409df052024-01-17 22:36:14 +0530349 RETURN ${resp}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500350
Sushil Singh47f80132019-08-27 04:53:24 -0500351
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500352Upload Image To BMC
Sushil Singh47f80132019-08-27 04:53:24 -0500353 [Documentation] Upload image to BMC via REST and return status code.
354 [Arguments] ${uri} ${timeout}=10 ${quiet}=${1}
Sushil Singhc08df052020-03-30 00:39:22 -0500355 ... ${valid_status_codes}=[${HTTP_OK}, ${HTTP_ACCEPTED}] &{kwargs}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500356
357 # Description of argument(s):
Sushil Singh47f80132019-08-27 04:53:24 -0500358 # uri URI for uploading image via REST e.g.
359 # "/upload/image".
360 # timeout Time allocated for the REST command to
361 # return status (specified in Robot
362 # Framework Time Format e.g. "3 mins").
363 # quiet If enabled, turns off logging to console.
364 # valid_status_codes A list of status codes that are valid for
365 # the REST post command. This can be
366 # specified as a string the evaluates to a
367 # python object (e.g. [${HTTP_OK}]).
368 # kwargs A dictionary keys/values to be passed
369 # directly to Post Request.
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500370
George Keishingbadd1fc2025-02-05 23:00:05 +0530371
372 # If /redfish/v1/SessionService/Sessions POST fails, fallback to
373 # REST /login method.
374 ${passed}= Run Keyword And Return Status Redfish Login
George Keishing7efd7742025-07-03 10:47:13 +0530375 IF ${passed} != True Initialize OpenBMC ${timeout} quiet=${quiet}
George Keishingbadd1fc2025-02-05 23:00:05 +0530376 ${session_object}= Set Variable If ${passed} redfish openbmc
377
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500378 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
379 ${headers}= Create Dictionary Content-Type=application/octet-stream
George Keishing4f76cf62020-12-22 06:42:07 -0600380 ... X-Auth-Token=${XAUTH_TOKEN} Accept=application/json
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500381 Set To Dictionary ${kwargs} headers ${headers}
George Keishing7efd7742025-07-03 10:47:13 +0530382 IF '${quiet}' == '${0}' Log Request method=Post
383 ... base_uri=${base_uri} args=&{kwargs}
384 END
George Keishingbadd1fc2025-02-05 23:00:05 +0530385 ${ret}= POST On Session ${session_object} ${base_uri} &{kwargs} timeout=${timeout}
George Keishing7efd7742025-07-03 10:47:13 +0530386 IF '${quiet}' == '${0}' Log Response ${ret}
Sushil Singh47f80132019-08-27 04:53:24 -0500387 Valid Value ret.status_code ${valid_status_codes}
George Keishing08540c02017-07-19 09:42:50 -0500388 Delete All Sessions
Sushil Singh47f80132019-08-27 04:53:24 -0500389
George Keishing409df052024-01-17 22:36:14 +0530390 RETURN ${ret}
Sushil Singh47f80132019-08-27 04:53:24 -0500391
George Keishingf4a43972020-06-29 03:55:38 -0500392
393Redfish Login
394 [Documentation] Do BMC web-based login.
George Keishing7981f432023-11-15 23:49:16 +0530395 [Arguments] ${timeout}=20 ${rest_username}=${OPENBMC_USERNAME}
396 ... ${rest_password}=${OPENBMC_PASSWORD} ${kwargs}=${EMPTY}
George Keishingf4a43972020-06-29 03:55:38 -0500397
398 # Description of argument(s):
399 # timeout REST login attempt time out.
400 # rest_username The REST username.
401 # rest_password The REST password.
402 # kwargs Any additional arguments to be passed directly to the
403 # Get Request call. For example, the caller might
404 # set kwargs as follows:
405 # ${kwargs}= Create Dictionary allow_redirect=${True}.
406
George Keishing566daaf2020-07-02 06:18:50 -0500407 Create Session redfish ${AUTH_URI} timeout=${timeout}
George Keishingf4a43972020-06-29 03:55:38 -0500408 ${headers}= Create Dictionary Content-Type=application/json
409 ${data}= Set Variable If '${kwargs}' == '${EMPTY}'
410 ... {"UserName":"${rest_username}", "Password":"${rest_password}"}
411 ... {"UserName":"${rest_username}", "Password":"${rest_password}", ${kwargs}}
412
George Keishingfbd67002022-08-01 11:24:03 -0500413 ${resp}= POST On Session redfish /redfish/v1/SessionService/Sessions
George Keishingf4a43972020-06-29 03:55:38 -0500414 ... data=${data} headers=${headers}
415 Should Be Equal As Strings ${resp.status_code} ${HTTP_CREATED}
416
417 Set Global Variable ${XAUTH_TOKEN} ${resp.headers["X-Auth-Token"]}
418
George Keishing409df052024-01-17 22:36:14 +0530419 RETURN ${resp.json()}
George Keishing566daaf2020-07-02 06:18:50 -0500420
421
Sushil Singh4ec68ba2020-09-11 09:16:43 -0500422Redfish Get Request
423 [Documentation] Do REST POST request and return the result.
424 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
425
426 # Description of argument(s):
427 # uri The URI to establish connection with
428 # (e.g. '/xyz/openbmc_project/software/').
429 # timeout Timeout in seconds to establish connection with URI.
430 # quiet If enabled, turns off logging to console.
431 # kwargs Any additional arguments to be passed directly to the
432 # Post Request call. For example, the caller might
433 # set kwargs as follows:
434 # ${kwargs}= Create Dictionary allow_redirect=${True}.
435
436 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
437 ${headers}= Create Dictionary Content-Type=application/json X-Auth-Token=${XAUTH_TOKEN}
438 Set To Dictionary ${kwargs} headers ${headers}
George Keishing7efd7742025-07-03 10:47:13 +0530439 IF '${quiet}' == '${0}' Log Request method=Post
440 ... base_uri=${base_uri} args=&{kwargs}
441 END
George Keishingfbd67002022-08-01 11:24:03 -0500442 ${resp}= GET On Session redfish ${base_uri} &{kwargs} timeout=${timeout}
George Keishing7efd7742025-07-03 10:47:13 +0530443 IF '${quiet}' == '${0}' Log Response ${resp}
Sushil Singh4ec68ba2020-09-11 09:16:43 -0500444
George Keishing409df052024-01-17 22:36:14 +0530445 RETURN ${resp}
Sushil Singh4ec68ba2020-09-11 09:16:43 -0500446
447
George Keishing566daaf2020-07-02 06:18:50 -0500448Redfish Post Request
449 [Documentation] Do REST POST request and return the result.
450 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
451
452 # Description of argument(s):
453 # uri The URI to establish connection with
454 # (e.g. '/xyz/openbmc_project/software/').
455 # timeout Timeout in seconds to establish connection with URI.
456 # quiet If enabled, turns off logging to console.
457 # kwargs Any additional arguments to be passed directly to the
458 # Post Request call. For example, the caller might
459 # set kwargs as follows:
460 # ${kwargs}= Create Dictionary allow_redirect=${True}.
461
462 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
463 ${headers}= Create Dictionary Content-Type=application/json X-Auth-Token=${XAUTH_TOKEN}
464 Set To Dictionary ${kwargs} headers ${headers}
George Keishing7efd7742025-07-03 10:47:13 +0530465 IF '${quiet}' == '${0}' Log Request method=Post
466 ... base_uri=${base_uri} args=&{kwargs}
467 END
George Keishingfbd67002022-08-01 11:24:03 -0500468 ${resp}= POST On Session redfish ${base_uri} &{kwargs} timeout=${timeout} expected_status=any
George Keishing7efd7742025-07-03 10:47:13 +0530469 IF '${quiet}' == '${0}' Log Response ${resp}
George Keishing566daaf2020-07-02 06:18:50 -0500470
George Keishing409df052024-01-17 22:36:14 +0530471 RETURN ${resp}