blob: d471dafea81b17b7be55c6c3360a9f6861e018cb [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
8Resource rest_response_code.robot
Chris Austenb29d2e82016-06-07 12:25:35 -05009
10*** Variables ***
Michael Walsha6723f22016-11-22 11:12:01 -060011# Assign default value to QUIET for programs which may not define it.
12${QUIET} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050013
14*** Keywords ***
15OpenBMC Get Request
manasarm604b8cd2018-01-29 12:14:20 +053016 [Documentation] Do REST GET request and return the result.
17 # Example result data:
18 # Response code:200, Content:{
19 # "data": [
20 # "/xyz/openbmc_project/state/host0",
21 # "/xyz/openbmc_project/state/chassis0",
22 # "/xyz/openbmc_project/state/bmc0"
23 # ],
24 # "message": "200 OK",
25 # "status": "ok"
26 # }
George Keishing41c44cf2017-11-15 08:02:59 -060027 [Arguments] ${uri} ${timeout}=30 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053028 # Description of argument(s):
29 # uri The URI to establish connection with
30 # (e.g. '/xyz/openbmc_project/software/').
31 # timeout Timeout in seconds to establish connection with URI.
32 # quiet If enabled, turns off logging to console.
33 # kwargs Any additional arguments to be passed directly to the
34 # Get Request call. For example, the caller might
35 # set kwargs as follows:
36 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -060037
38 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050039 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -060040 Run Keyword If '${quiet}' == '${0}' Log Request method=Get
41 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060042 ${ret}= Get Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
43 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050044 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050045 [Return] ${ret}
46
47OpenBMC Post Request
manasarm604b8cd2018-01-29 12:14:20 +053048 [Documentation] Do REST POST request and return the result.
49 # Example result data:
50 # <Response [200]>
Michael Walsha6723f22016-11-22 11:12:01 -060051 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053052 # Description of argument(s):
53 # uri The URI to establish connection with
54 # (e.g. '/xyz/openbmc_project/software/').
55 # timeout Timeout in seconds to establish connection with URI.
56 # quiet If enabled, turns off logging to console.
57 # kwargs Any additional arguments to be passed directly to the
58 # Post Request call. For example, the caller might
59 # set kwargs as follows:
60 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walsha6723f22016-11-22 11:12:01 -060061
Michael Walshf00edee2016-12-09 14:10:26 -060062 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050063 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
64 ${headers}= Create Dictionary Content-Type=application/json
65 set to dictionary ${kwargs} headers ${headers}
Michael Walsha6723f22016-11-22 11:12:01 -060066 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
67 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060068 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
69 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050070 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050071 [Return] ${ret}
72
73OpenBMC Put Request
manasarm604b8cd2018-01-29 12:14:20 +053074 [Documentation] Do REST PUT request on the resource identified by the URI.
Rahul Maheshwari79c12942016-10-17 09:39:17 -050075 [Arguments] ${uri} ${timeout}=10 &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +053076 # Description of argument(s):
77 # uri The URI to establish connection with
78 # (e.g. '/xyz/openbmc_project/software/').
79 # timeout Timeout in seconds to establish connection with URI.
80 # kwargs Arguments passed to the REST call.
81 # kwargs Any additional arguments to be passed directly to the
82 # Put Request call. For example, the caller might
83 # set kwargs as follows:
84 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -060085
86 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050087 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
88 ${headers}= Create Dictionary Content-Type=application/json
89 set to dictionary ${kwargs} headers ${headers}
90 Log Request method=Put base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060091 ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050092 Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050093 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050094 [Return] ${ret}
95
96OpenBMC Delete Request
manasarm604b8cd2018-01-29 12:14:20 +053097 [Documentation] Do REST request to delete the resource identified by the
98 ... URI.
Rahul Maheshwari79c12942016-10-17 09:39:17 -050099 [Arguments] ${uri} ${timeout}=10 &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530100 # Description of argument(s):
101 # uri The URI to establish connection with
102 # (e.g. '/xyz/openbmc_project/software/').
103 # timeout Timeout in seconds to establish connection with URI.
104 # kwargs Any additional arguments to be passed directly to the
105 # Delete Request call. For example, the caller might
106 # set kwargs as follows:
107 # ${kwargs}= Create Dictionary allow_redirect=${True}.
Michael Walshf00edee2016-12-09 14:10:26 -0600108
109 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500110 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
111 Log Request method=Delete base_uri=${base_uri} args=&{kwargs}
George Keishing0e7c3a02017-04-17 05:01:14 -0500112 ${ret}= Delete Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500113 Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -0500114 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -0500115 [Return] ${ret}
116
117Initialize OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530118 [Documentation] Do a REST login connection within specified time.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500119 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishingf1331672018-01-18 05:19:02 -0600120 ... ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
121 ... ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
Michael Walshf00edee2016-12-09 14:10:26 -0600122
George Keishing1cdc6dd2017-04-24 15:31:03 -0500123 # Description of argument(s):
124 # timeout REST login attempt time out.
Gunnar Mills28e403b2017-10-25 16:16:38 -0500125 # quiet Suppress console log if set.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500126
127 # TODO : Task to revert this changes openbmc/openbmc-test-automation#532
128 # This will retry at 20 second interval.
129 Wait Until Keyword Succeeds 40 sec 20 sec
130 ... Post Login Request ${timeout} ${quiet}
George Keishingf1331672018-01-18 05:19:02 -0600131 ... ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500132
133Post Login Request
manasarm604b8cd2018-01-29 12:14:20 +0530134 [Documentation] Do REST login request.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500135 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishingf1331672018-01-18 05:19:02 -0600136 ... ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
137 ... ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500138
139 # Description of argument(s):
140 # timeout REST login attempt time out.
Gunnar Mills28e403b2017-10-25 16:16:38 -0500141 # quiet Suppress console log if set.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500142
143 Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3
Michael Walsha6723f22016-11-22 11:12:01 -0600144 ${headers}= Create Dictionary Content-Type=application/json
145 @{credentials}= Create List ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
146 ${data}= create dictionary data=@{credentials}
Michael Walshf00edee2016-12-09 14:10:26 -0600147 ${status} ${resp}= Run Keyword And Ignore Error Post Request openbmc
148 ... /login data=${data} headers=${headers}
149
150 Should Be Equal ${status} PASS msg=${resp}
151 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500152
George Keishinge8225522017-03-31 09:21:13 -0500153Log Out OpenBMC
manasarm604b8cd2018-01-29 12:14:20 +0530154 [Documentation] Log out of the openbmc REST session.
George Keishinge8225522017-03-31 09:21:13 -0500155
156 ${headers}= Create Dictionary Content-Type=application/json
157 ${data}= Create dictionary data=@{EMPTY}
158
159 # If there is no active sesion it will throw the following exception
160 # "Non-existing index or alias 'openbmc'"
161 ${resp}= Post Request openbmc
162 ... /logout data=${data} headers=${headers}
163
164 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
165 ... msg=${resp}
166
Chris Austenb29d2e82016-06-07 12:25:35 -0500167Log Request
manasarm604b8cd2018-01-29 12:14:20 +0530168 [Documentation] Log the specific REST URI, method name on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500169 [Arguments] &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600170 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
171 ... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500172 Logging ${msg} console=True
173
174Log Response
manasarm604b8cd2018-01-29 12:14:20 +0530175 [Documentation] Log the response code on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500176 [Arguments] ${resp}
Michael Walsha6723f22016-11-22 11:12:01 -0600177 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
178 ... , Content: ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500179 Logging ${msg} console=True
180
181Logging
manasarm604b8cd2018-01-29 12:14:20 +0530182 [Documentation] Log the specified message on the console.
Chris Austenb29d2e82016-06-07 12:25:35 -0500183 [Arguments] ${msg} ${console}=default False
184 Log ${msg} console=True
185
186Read Attribute
manasarm604b8cd2018-01-29 12:14:20 +0530187 [Documentation] Retrieve attribute value from URI and return result.
188 # Example result data for the attribute 'FieldModeEnabled' in
189 # "/xyz/openbmc_project/software/attr/" :
190 # 0
Gunnar Mills38032802016-12-12 13:43:40 -0600191 [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
manasarmc505e382018-02-05 14:05:48 +0530192 ... ${expected_value}=${EMPTY}
manasarm604b8cd2018-01-29 12:14:20 +0530193 # Description of argument(s):
194 # uri URI of the object that the attribute lives on
195 # (e.g. '/xyz/openbmc_project/software/').
196 # attr Name of the attribute (e.g. 'FieldModeEnabled').
197 # timeout Timeout for the REST call.
198 # quiet If enabled, turns off logging to console.
manasarmc505e382018-02-05 14:05:48 +0530199 # expected_value If this argument is not empty, the retrieved value
200 # must match this value.
manasarm604b8cd2018-01-29 12:14:20 +0530201
Michael Walsha6723f22016-11-22 11:12:01 -0600202 ${resp}= OpenBMC Get Request ${uri}/attr/${attr} timeout=${timeout}
203 ... quiet=${quiet}
Michael Walsh9cd61932017-01-17 16:11:02 -0600204 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500205 ${content}= To Json ${resp.content}
manasarmc505e382018-02-05 14:05:48 +0530206 Run Keyword If '${expected_value}' != '${EMPTY}'
207 ... Should Be Equal As Strings ${expected_value} ${content["data"]}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600208 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500209
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500210
Chris Austenb29d2e82016-06-07 12:25:35 -0500211Write Attribute
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500212 [Documentation] Write a D-Bus attribute with REST.
213 [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE}
214 ... ${expected_value}=${EMPTY} &{kwargs}
215
216 # Description of argument(s):
217 # uri URI of the object that the attribute lives on
218 # (e.g. '/xyz/openbmc_project/software/').
219 # attr Name of the attribute (e.g. 'FieldModeEnabled').
220 # timeout Timeout for the REST call.
221 # verify If set to ${TRUE}, the attribute will be read back to
222 # ensure that its value is set to ${verify_attr}.
223 # expected_value Only used if verify is set to ${TRUE}. The value that
224 # ${attr} should be set to. This defaults to
225 # ${kwargs['data']. There are cases where the caller
226 # expects some other value in which case this value can
227 # be explicitly specified.
228 # kwargs Arguments passed to the REST call. This should always
229 # contain the value to set the property to at the 'data'
230 # key (e.g. data={"data": 1}).
231
232 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
233 ${resp}= Openbmc Put Request ${base_uri}/attr/${attr}
Michael Walsha6723f22016-11-22 11:12:01 -0600234 ... timeout=${timeout} &{kwargs}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500235 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
236
237 # Verify the attribute was set correctly if the caller requested it.
238 Return From Keyword If ${verify} == ${FALSE}
239
240 ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}'
Charles Paul Hofer00401e72017-10-31 11:42:30 -0500241 ... ${kwargs['data']['data']} ${expected_value}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500242 ${value}= Read Attribute ${uri} ${attr}
243 Should Be Equal ${value} ${expected_value}
244
Chris Austenb29d2e82016-06-07 12:25:35 -0500245Read Properties
manasarm604b8cd2018-01-29 12:14:20 +0530246 [Documentation] Read data part of the URI object and return result.
247 # Example result data:
248 # [u'/xyz/openbmc_project/software/cf7bf9d5',
249 # u'/xyz/openbmc_project/software/5ecb8b2c',
250 # u'/xyz/openbmc_project/software/active',
251 # u'/xyz/openbmc_project/software/functional']
George Keishing335f5362017-06-30 15:11:20 -0500252 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET}
manasarm604b8cd2018-01-29 12:14:20 +0530253 # Description of argument(s):
254 # uri URI of the object
255 # (e.g. '/xyz/openbmc_project/software/').
256 # timeout Timeout for the REST call.
257 # quiet If enabled, turns off logging to console.
258
George Keishing335f5362017-06-30 15:11:20 -0500259 ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet}
260 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
261 ${content}= To Json ${resp.content}
262 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500263
264Call Method
manasarm604b8cd2018-01-29 12:14:20 +0530265 [Documentation] Invoke the specific REST service method.
Gunnar Mills38032802016-12-12 13:43:40 -0600266 [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
manasarm604b8cd2018-01-29 12:14:20 +0530267 # Description of arguments:
268 # uri The URI to establish connection with
269 # (e.g. '/xyz/openbmc_project/software/').
270 # timeout Timeout in seconds to establish connection with URI.
271 # quiet If enabled, turns off logging to console.
272 # kwargs Arguments passed to the REST call.
Michael Walsha6723f22016-11-22 11:12:01 -0600273
Chris Austenb29d2e82016-06-07 12:25:35 -0500274 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -0600275 ${resp}= OpenBmc Post Request ${base_uri}/action/${method}
276 ... timeout=${timeout} quiet=${quiet} &{kwargs}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600277 [Return] ${resp}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500278
279Upload Image To BMC
manasarm604b8cd2018-01-29 12:14:20 +0530280 [Documentation] Upload image to BMC device using REST POST operation.
George Keishingad9a8802017-08-08 12:41:48 -0500281 [Arguments] ${uri} ${timeout}=10 ${quiet}=${1} &{kwargs}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500282
283 # Description of argument(s):
284 # uri URI for uploading image via REST e.g. "/upload/image".
285 # timeout Time allocated for the REST command to return status
286 # (specified in Robot Framework Time Format e.g. "3 mins").
manasarm604b8cd2018-01-29 12:14:20 +0530287 # quiet If enabled, turns off logging to console.
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500288 # kwargs A dictionary keys/values to be passed directly to
289 # Post Request.
290
291 Initialize OpenBMC ${timeout} quiet=${quiet}
292 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
293 ${headers}= Create Dictionary Content-Type=application/octet-stream
294 ... Accept=application/octet-stream
295 Set To Dictionary ${kwargs} headers ${headers}
296 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
297 ... base_uri=${base_uri} args=&{kwargs}
298 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
299 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
300 Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
George Keishing08540c02017-07-19 09:42:50 -0500301 Delete All Sessions