blob: 3969ea7aecfdbb7af16c0c159c29cdda9be58bdb [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Library Collections
3Library String
4Library RequestsLibrary.RequestsKeywords
5Library OperatingSystem
George Keishingeaa73b72018-07-30 09:30:16 -05006Resource resource.txt
7Library 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
George Keishingeaa73b72018-07-30 09:30:16 -050010Resource rest_response_code.robot
Chris Austenb29d2e82016-06-07 12:25:35 -050011
12*** Variables ***
Michael Walsha6723f22016-11-22 11:12:01 -060013# Assign default value to QUIET for programs which may not define it.
14${QUIET} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050015
16*** Keywords ***
17OpenBMC Get Request
manasarm604b8cd2018-01-29 12:14:20 +053018 [Documentation] Do REST GET request and return the result.
19 # Example result data:
20 # Response code:200, Content:{
21 # "data": [
22 # "/xyz/openbmc_project/state/host0",
23 # "/xyz/openbmc_project/state/chassis0",
24 # "/xyz/openbmc_project/state/bmc0"
25 # ],
26 # "message": "200 OK",
27 # "status": "ok"
28 # }
George Keishing41c44cf2017-11-15 08:02:59 -060029 [Arguments] ${uri} ${timeout}=30 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053030 # Description of argument(s):
31 # uri The URI to establish connection with
32 # (e.g. '/xyz/openbmc_project/software/').
33 # timeout Timeout in seconds to establish connection with URI.
34 # quiet If enabled, turns off logging to console.
35 # kwargs Any additional arguments to be passed directly to the
36 # Get Request call. For example, the caller might
37 # set kwargs as follows:
38 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -060039
40 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050041 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -060042 Run Keyword If '${quiet}' == '${0}' Log Request method=Get
43 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060044 ${ret}= Get Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
45 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050046 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050047 [Return] ${ret}
48
49OpenBMC Post Request
manasarm604b8cd2018-01-29 12:14:20 +053050 [Documentation] Do REST POST request and return the result.
51 # Example result data:
52 # <Response [200]>
Michael Walsha6723f22016-11-22 11:12:01 -060053 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053054 # Description of argument(s):
55 # uri The URI to establish connection with
56 # (e.g. '/xyz/openbmc_project/software/').
57 # timeout Timeout in seconds to establish connection with URI.
58 # quiet If enabled, turns off logging to console.
59 # kwargs Any additional arguments to be passed directly to the
60 # Post Request call. For example, the caller might
61 # set kwargs as follows:
62 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walsha6723f22016-11-22 11:12:01 -060063
Michael Walshf00edee2016-12-09 14:10:26 -060064 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050065 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
66 ${headers}= Create Dictionary Content-Type=application/json
67 set to dictionary ${kwargs} headers ${headers}
Michael Walsha6723f22016-11-22 11:12:01 -060068 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
69 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060070 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
71 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050072 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050073 [Return] ${ret}
74
75OpenBMC Put Request
manasarm604b8cd2018-01-29 12:14:20 +053076 [Documentation] Do REST PUT request on the resource identified by the URI.
Rahul Maheshwari79c12942016-10-17 09:39:17 -050077 [Arguments] ${uri} ${timeout}=10 &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053078 # Description of argument(s):
79 # uri The URI to establish connection with
80 # (e.g. '/xyz/openbmc_project/software/').
81 # timeout Timeout in seconds to establish connection with URI.
82 # kwargs Arguments passed to the REST call.
83 # kwargs Any additional arguments to be passed directly to the
84 # Put Request call. For example, the caller might
85 # set kwargs as follows:
86 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -060087
88 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050089 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
90 ${headers}= Create Dictionary Content-Type=application/json
91 set to dictionary ${kwargs} headers ${headers}
92 Log Request method=Put base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060093 ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050094 Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050095 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050096 [Return] ${ret}
97
98OpenBMC Delete Request
manasarm604b8cd2018-01-29 12:14:20 +053099 [Documentation] Do REST request to delete the resource identified by the
100 ... URI.
Rahul Maheshwari79c12942016-10-17 09:39:17 -0500101 [Arguments] ${uri} ${timeout}=10 &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530102 # Description of argument(s):
103 # uri The URI to establish connection with
104 # (e.g. '/xyz/openbmc_project/software/').
105 # timeout Timeout in seconds to establish connection with URI.
106 # kwargs Any additional arguments to be passed directly to the
107 # Delete Request call. For example, the caller might
108 # set kwargs as follows:
109 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -0600110
111 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500112 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
113 Log Request method=Delete base_uri=${base_uri} args=&{kwargs}
George Keishing0e7c3a02017-04-17 05:01:14 -0500114 ${ret}= Delete Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500115 Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -0500116 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -0500117 [Return] ${ret}
118
119Initialize OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530120 [Documentation] Do a REST login connection within specified time.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500121 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishingaf4ab322018-10-17 12:42:52 -0500122 ... ${REST_USERNAME}=${REST_USERNAME}
123 ... ${REST_PASSWORD}=${REST_PASSWORD}
Michael Walshf00edee2016-12-09 14:10:26 -0600124
George Keishing1cdc6dd2017-04-24 15:31:03 -0500125 # Description of argument(s):
126 # timeout REST login attempt time out.
Gunnar Mills28e403b2017-10-25 16:16:38 -0500127 # quiet Suppress console log if set.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500128
129 # TODO : Task to revert this changes openbmc/openbmc-test-automation#532
130 # This will retry at 20 second interval.
131 Wait Until Keyword Succeeds 40 sec 20 sec
132 ... Post Login Request ${timeout} ${quiet}
George Keishingaf4ab322018-10-17 12:42:52 -0500133 ... ${REST_USERNAME} ${REST_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500134
135Post Login Request
manasarm604b8cd2018-01-29 12:14:20 +0530136 [Documentation] Do REST login request.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500137 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishingaf4ab322018-10-17 12:42:52 -0500138 ... ${REST_USERNAME}=${REST_USERNAME}
139 ... ${REST_PASSWORD}=${REST_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500140
141 # Description of argument(s):
142 # timeout REST login attempt time out.
Gunnar Mills28e403b2017-10-25 16:16:38 -0500143 # quiet Suppress console log if set.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500144
145 Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3
Michael Walsha6723f22016-11-22 11:12:01 -0600146 ${headers}= Create Dictionary Content-Type=application/json
George Keishingaf4ab322018-10-17 12:42:52 -0500147 @{credentials}= Create List ${REST_USERNAME} ${REST_PASSWORD}
Michael Walsha6723f22016-11-22 11:12:01 -0600148 ${data}= create dictionary data=@{credentials}
Michael Walshf00edee2016-12-09 14:10:26 -0600149 ${status} ${resp}= Run Keyword And Ignore Error Post Request openbmc
150 ... /login data=${data} headers=${headers}
151
152 Should Be Equal ${status} PASS msg=${resp}
153 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500154
George Keishinge8225522017-03-31 09:21:13 -0500155Log Out OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530156 [Documentation] Log out of the openbmc REST session.
George Keishinge8225522017-03-31 09:21:13 -0500157
158 ${headers}= Create Dictionary Content-Type=application/json
159 ${data}= Create dictionary data=@{EMPTY}
160
161 # If there is no active sesion it will throw the following exception
162 # "Non-existing index or alias 'openbmc'"
163 ${resp}= Post Request openbmc
164 ... /logout data=${data} headers=${headers}
165
166 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
167 ... msg=${resp}
168
Chris Austenb29d2e82016-06-07 12:25:35 -0500169Log Request
manasarm604b8cd2018-01-29 12:14:20 +0530170 [Documentation] Log the specific REST URI, method name on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500171 [Arguments] &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600172 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
173 ... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500174 Logging ${msg} console=True
175
176Log Response
manasarm604b8cd2018-01-29 12:14:20 +0530177 [Documentation] Log the response code on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500178 [Arguments] ${resp}
Michael Walsha6723f22016-11-22 11:12:01 -0600179 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
180 ... , Content: ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500181 Logging ${msg} console=True
182
183Logging
manasarm604b8cd2018-01-29 12:14:20 +0530184 [Documentation] Log the specified message on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500185 [Arguments] ${msg} ${console}=default False
186 Log ${msg} console=True
187
188Read Attribute
manasarm604b8cd2018-01-29 12:14:20 +0530189 [Documentation] Retrieve attribute value from URI and return result.
190 # Example result data for the attribute 'FieldModeEnabled' in
191 # "/xyz/openbmc_project/software/attr/" :
192 # 0
Gunnar Mills38032802016-12-12 13:43:40 -0600193 [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
manasarmc505e382018-02-05 14:05:48 +0530194 ... ${expected_value}=${EMPTY}
manasarm604b8cd2018-01-29 12:14:20 +0530195 # Description of argument(s):
196 # uri URI of the object that the attribute lives on
197 # (e.g. '/xyz/openbmc_project/software/').
198 # attr Name of the attribute (e.g. 'FieldModeEnabled').
199 # timeout Timeout for the REST call.
200 # quiet If enabled, turns off logging to console.
manasarmc505e382018-02-05 14:05:48 +0530201 # expected_value If this argument is not empty, the retrieved value
202 # must match this value.
manasarm604b8cd2018-01-29 12:14:20 +0530203
Steven Sombarb3489242018-12-13 15:59:02 -0600204 # Make sure uri ends with slash.
205 ${uri}= Add Trailing Slash ${uri}
206
207 ${resp}= OpenBMC Get Request ${uri}attr/${attr} timeout=${timeout}
Michael Walsha6723f22016-11-22 11:12:01 -0600208 ... quiet=${quiet}
Michael Walsh9cd61932017-01-17 16:11:02 -0600209 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500210 ${content}= To Json ${resp.content}
manasarmc505e382018-02-05 14:05:48 +0530211 Run Keyword If '${expected_value}' != '${EMPTY}'
212 ... Should Be Equal As Strings ${expected_value} ${content["data"]}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600213 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500214
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500215
Chris Austenb29d2e82016-06-07 12:25:35 -0500216Write Attribute
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500217 [Documentation] Write a D-Bus attribute with REST.
218 [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE}
219 ... ${expected_value}=${EMPTY} &{kwargs}
220
221 # Description of argument(s):
222 # uri URI of the object that the attribute lives on
223 # (e.g. '/xyz/openbmc_project/software/').
224 # attr Name of the attribute (e.g. 'FieldModeEnabled').
225 # timeout Timeout for the REST call.
226 # verify If set to ${TRUE}, the attribute will be read back to
227 # ensure that its value is set to ${verify_attr}.
228 # expected_value Only used if verify is set to ${TRUE}. The value that
229 # ${attr} should be set to. This defaults to
230 # ${kwargs['data']. There are cases where the caller
231 # expects some other value in which case this value can
232 # be explicitly specified.
233 # kwargs Arguments passed to the REST call. This should always
234 # contain the value to set the property to at the 'data'
235 # key (e.g. data={"data": 1}).
236
George Keishingdf3e65f2018-12-18 13:06:56 -0600237 # Make sure uri ends with slash.
238 ${uri}= Add Trailing Slash ${uri}
239
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500240 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
George Keishingdf3e65f2018-12-18 13:06:56 -0600241 ${resp}= Openbmc Put Request ${base_uri}attr/${attr}
Michael Walsha6723f22016-11-22 11:12:01 -0600242 ... timeout=${timeout} &{kwargs}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500243 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
244
245 # Verify the attribute was set correctly if the caller requested it.
246 Return From Keyword If ${verify} == ${FALSE}
247
248 ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}'
Charles Paul Hofer00401e72017-10-31 11:42:30 -0500249 ... ${kwargs['data']['data']} ${expected_value}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500250 ${value}= Read Attribute ${uri} ${attr}
251 Should Be Equal ${value} ${expected_value}
252
Chris Austenb29d2e82016-06-07 12:25:35 -0500253Read Properties
manasarm604b8cd2018-01-29 12:14:20 +0530254 [Documentation] Read data part of the URI object and return result.
255 # Example result data:
256 # [u'/xyz/openbmc_project/software/cf7bf9d5',
257 # u'/xyz/openbmc_project/software/5ecb8b2c',
258 # u'/xyz/openbmc_project/software/active',
259 # u'/xyz/openbmc_project/software/functional']
George Keishing335f5362017-06-30 15:11:20 -0500260 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET}
manasarm604b8cd2018-01-29 12:14:20 +0530261 # Description of argument(s):
262 # uri URI of the object
263 # (e.g. '/xyz/openbmc_project/software/').
264 # timeout Timeout for the REST call.
265 # quiet If enabled, turns off logging to console.
266
George Keishing335f5362017-06-30 15:11:20 -0500267 ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet}
268 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Michael Walshad66c952018-10-04 15:12:47 -0500269 ${content}= To Json Ordered ${resp.content}
270
George Keishing335f5362017-06-30 15:11:20 -0500271 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500272
273Call Method
manasarm604b8cd2018-01-29 12:14:20 +0530274 [Documentation] Invoke the specific REST service method.
Gunnar Mills38032802016-12-12 13:43:40 -0600275 [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530276 # Description of arguments:
277 # uri The URI to establish connection with
278 # (e.g. '/xyz/openbmc_project/software/').
279 # timeout Timeout in seconds to establish connection with URI.
280 # quiet If enabled, turns off logging to console.
281 # kwargs Arguments passed to the REST call.
Michael Walsha6723f22016-11-22 11:12:01 -0600282
Chris Austenb29d2e82016-06-07 12:25:35 -0500283 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -0600284 ${resp}= OpenBmc Post Request ${base_uri}/action/${method}
285 ... timeout=${timeout} quiet=${quiet} &{kwargs}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600286 [Return] ${resp}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500287
288Upload Image To BMC
manasarm604b8cd2018-01-29 12:14:20 +0530289 [Documentation] Upload image to BMC device using REST POST operation.
George Keishingad9a8802017-08-08 12:41:48 -0500290 [Arguments] ${uri} ${timeout}=10 ${quiet}=${1} &{kwargs}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500291
292 # Description of argument(s):
293 # uri URI for uploading image via REST e.g. "/upload/image".
294 # timeout Time allocated for the REST command to return status
295 # (specified in Robot Framework Time Format e.g. "3 mins").
manasarm604b8cd2018-01-29 12:14:20 +0530296 # quiet If enabled, turns off logging to console.
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500297 # kwargs A dictionary keys/values to be passed directly to
298 # Post Request.
299
300 Initialize OpenBMC ${timeout} quiet=${quiet}
301 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
302 ${headers}= Create Dictionary Content-Type=application/octet-stream
303 ... Accept=application/octet-stream
304 Set To Dictionary ${kwargs} headers ${headers}
305 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
306 ... base_uri=${base_uri} args=&{kwargs}
307 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
308 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
309 Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
George Keishing08540c02017-07-19 09:42:50 -0500310 Delete All Sessions