blob: 3530bee085d8fe179ed2dcb707e68ec1dbae7f35 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Library Collections
3Library String
4Library RequestsLibrary.RequestsKeywords
5Library OperatingSystem
6Resource ../lib/resource.txt
7Library ../lib/disable_warning_urllib.py
8
9*** Variables ***
10# Response codes
11${HTTP_CONTINUE} 100
12${HTTP_SWITCHING_PROTOCOLS} 101
13${HTTP_PROCESSING} 102
14${HTTP_OK} 200
15${HTTP_CREATED} 201
16${HTTP_ACCEPTED} 202
17${HTTP_NON_AUTHORITATIVE_INFORMATION} 203
18${HTTP_NO_CONTENT} 204
19${HTTP_RESET_CONTENT} 205
20${HTTP_PARTIAL_CONTENT} 206
21${HTTP_MULTI_STATUS} 207
22${HTTP_IM_USED} 226
23${HTTP_MULTIPLE_CHOICES} 300
24${HTTP_MOVED_PERMANENTLY} 301
25${HTTP_FOUND} 302
26${HTTP_SEE_OTHER} 303
27${HTTP_NOT_MODIFIED} 304
28${HTTP_USE_PROXY} 305
29${HTTP_TEMPORARY_REDIRECT} 307
30${HTTP_BAD_REQUEST} 400
31${HTTP_UNAUTHORIZED} 401
32${HTTP_PAYMENT_REQUIRED} 402
33${HTTP_FORBIDDEN} 403
34${HTTP_NOT_FOUND} 404
35${HTTP_METHOD_NOT_ALLOWED} 405
36${HTTP_NOT_ACCEPTABLE} 406
37${HTTP_PROXY_AUTHENTICATION_REQUIRED} 407
38${HTTP_REQUEST_TIMEOUT} 408
39${HTTP_CONFLICT} 409
40${HTTP_GONE} 410
41${HTTP_LENGTH_REQUIRED} 411
42${HTTP_PRECONDITION_FAILED} 412
43${HTTP_REQUEST_ENTITY_TOO_LARGE} 413
44${HTTP_REQUEST_URI_TOO_LONG} 414
45${HTTP_UNSUPPORTED_MEDIA_TYPE} 415
46${HTTP_REQUESTED_RANGE_NOT_SATISFIABLE} 416
47${HTTP_EXPECTATION_FAILED} 417
48${HTTP_UNPROCESSABLE_ENTITY} 422
49${HTTP_LOCKED} 423
50${HTTP_FAILED_DEPENDENCY} 424
51${HTTP_UPGRADE_REQUIRED} 426
52${HTTP_INTERNAL_SERVER_ERROR} 500
53${HTTP_NOT_IMPLEMENTED} 501
54${HTTP_BAD_GATEWAY} 502
55${HTTP_SERVICE_UNAVAILABLE} 503
56${HTTP_GATEWAY_TIMEOUT} 504
57${HTTP_HTTP_VERSION_NOT_SUPPORTED} 505
58${HTTP_INSUFFICIENT_STORAGE} 507
59${HTTP_NOT_EXTENDED} 510
Michael Walsha6723f22016-11-22 11:12:01 -060060# Assign default value to QUIET for programs which may not define it.
61${QUIET} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050062
63*** Keywords ***
64OpenBMC Get Request
George Keishing41c44cf2017-11-15 08:02:59 -060065 [Arguments] ${uri} ${timeout}=30 ${quiet}=${QUIET} &{kwargs}
Michael Walshf00edee2016-12-09 14:10:26 -060066
67 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050068 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -060069 Run Keyword If '${quiet}' == '${0}' Log Request method=Get
70 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060071 ${ret}= Get Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
72 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050073 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050074 [Return] ${ret}
75
76OpenBMC Post Request
Michael Walsha6723f22016-11-22 11:12:01 -060077 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
78
Michael Walshf00edee2016-12-09 14:10:26 -060079 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050080 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
81 ${headers}= Create Dictionary Content-Type=application/json
82 set to dictionary ${kwargs} headers ${headers}
Michael Walsha6723f22016-11-22 11:12:01 -060083 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
84 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060085 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
86 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -050087 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -050088 [Return] ${ret}
89
90OpenBMC Put Request
Rahul Maheshwari79c12942016-10-17 09:39:17 -050091 [Arguments] ${uri} ${timeout}=10 &{kwargs}
Michael Walshf00edee2016-12-09 14:10:26 -060092
93 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050094 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
95 ${headers}= Create Dictionary Content-Type=application/json
96 set to dictionary ${kwargs} headers ${headers}
97 Log Request method=Put base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060098 ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050099 Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -0500100 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -0500101 [Return] ${ret}
102
103OpenBMC Delete Request
Rahul Maheshwari79c12942016-10-17 09:39:17 -0500104 [Arguments] ${uri} ${timeout}=10 &{kwargs}
Michael Walshf00edee2016-12-09 14:10:26 -0600105
106 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500107 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
108 Log Request method=Delete base_uri=${base_uri} args=&{kwargs}
George Keishing0e7c3a02017-04-17 05:01:14 -0500109 ${ret}= Delete Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500110 Log Response ${ret}
George Keishing08540c02017-07-19 09:42:50 -0500111 Delete All Sessions
Chris Austenb29d2e82016-06-07 12:25:35 -0500112 [Return] ${ret}
113
114Initialize OpenBMC
George Keishing1cdc6dd2017-04-24 15:31:03 -0500115 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishingf1331672018-01-18 05:19:02 -0600116 ... ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
117 ... ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
Michael Walshf00edee2016-12-09 14:10:26 -0600118
George Keishing1cdc6dd2017-04-24 15:31:03 -0500119 # Description of argument(s):
120 # timeout REST login attempt time out.
Gunnar Mills28e403b2017-10-25 16:16:38 -0500121 # quiet Suppress console log if set.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500122
123 # TODO : Task to revert this changes openbmc/openbmc-test-automation#532
124 # This will retry at 20 second interval.
125 Wait Until Keyword Succeeds 40 sec 20 sec
126 ... Post Login Request ${timeout} ${quiet}
George Keishingf1331672018-01-18 05:19:02 -0600127 ... ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500128
129Post Login Request
130 [Arguments] ${timeout}=20 ${quiet}=${1}
George Keishingf1331672018-01-18 05:19:02 -0600131 ... ${OPENBMC_USERNAME}=${OPENBMC_USERNAME}
132 ... ${OPENBMC_PASSWORD}=${OPENBMC_PASSWORD}
George Keishing1cdc6dd2017-04-24 15:31:03 -0500133
134 # Description of argument(s):
135 # timeout REST login attempt time out.
Gunnar Mills28e403b2017-10-25 16:16:38 -0500136 # quiet Suppress console log if set.
George Keishing1cdc6dd2017-04-24 15:31:03 -0500137
138 Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3
Michael Walsha6723f22016-11-22 11:12:01 -0600139 ${headers}= Create Dictionary Content-Type=application/json
140 @{credentials}= Create List ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
141 ${data}= create dictionary data=@{credentials}
Michael Walshf00edee2016-12-09 14:10:26 -0600142 ${status} ${resp}= Run Keyword And Ignore Error Post Request openbmc
143 ... /login data=${data} headers=${headers}
144
145 Should Be Equal ${status} PASS msg=${resp}
146 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500147
George Keishinge8225522017-03-31 09:21:13 -0500148Log Out OpenBMC
149 [Documentation] Log out REST connection with active session "openbmc".
150
151 ${headers}= Create Dictionary Content-Type=application/json
152 ${data}= Create dictionary data=@{EMPTY}
153
154 # If there is no active sesion it will throw the following exception
155 # "Non-existing index or alias 'openbmc'"
156 ${resp}= Post Request openbmc
157 ... /logout data=${data} headers=${headers}
158
159 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
160 ... msg=${resp}
161
Chris Austenb29d2e82016-06-07 12:25:35 -0500162Log Request
163 [Arguments] &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600164 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
165 ... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500166 Logging ${msg} console=True
167
168Log Response
169 [Arguments] ${resp}
Michael Walsha6723f22016-11-22 11:12:01 -0600170 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
171 ... , Content: ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500172 Logging ${msg} console=True
173
174Logging
175 [Arguments] ${msg} ${console}=default False
176 Log ${msg} console=True
177
178Read Attribute
Gunnar Mills38032802016-12-12 13:43:40 -0600179 [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
Michael Walsha6723f22016-11-22 11:12:01 -0600180 ${resp}= OpenBMC Get Request ${uri}/attr/${attr} timeout=${timeout}
181 ... quiet=${quiet}
Michael Walsh9cd61932017-01-17 16:11:02 -0600182 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500183 ${content}= To Json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600184 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500185
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500186
Chris Austenb29d2e82016-06-07 12:25:35 -0500187Write Attribute
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500188 [Documentation] Write a D-Bus attribute with REST.
189 [Arguments] ${uri} ${attr} ${timeout}=10 ${verify}=${FALSE}
190 ... ${expected_value}=${EMPTY} &{kwargs}
191
192 # Description of argument(s):
193 # uri URI of the object that the attribute lives on
194 # (e.g. '/xyz/openbmc_project/software/').
195 # attr Name of the attribute (e.g. 'FieldModeEnabled').
196 # timeout Timeout for the REST call.
197 # verify If set to ${TRUE}, the attribute will be read back to
198 # ensure that its value is set to ${verify_attr}.
199 # expected_value Only used if verify is set to ${TRUE}. The value that
200 # ${attr} should be set to. This defaults to
201 # ${kwargs['data']. There are cases where the caller
202 # expects some other value in which case this value can
203 # be explicitly specified.
204 # kwargs Arguments passed to the REST call. This should always
205 # contain the value to set the property to at the 'data'
206 # key (e.g. data={"data": 1}).
207
208 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
209 ${resp}= Openbmc Put Request ${base_uri}/attr/${attr}
Michael Walsha6723f22016-11-22 11:12:01 -0600210 ... timeout=${timeout} &{kwargs}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500211 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
212
213 # Verify the attribute was set correctly if the caller requested it.
214 Return From Keyword If ${verify} == ${FALSE}
215
216 ${expected_value}= Set Variable If '${expected_value}' == '${EMPTY}'
Charles Paul Hofer00401e72017-10-31 11:42:30 -0500217 ... ${kwargs['data']['data']} ${expected_value}
Charles Paul Hoferf45e5ee2017-10-04 12:15:48 -0500218 ${value}= Read Attribute ${uri} ${attr}
219 Should Be Equal ${value} ${expected_value}
220
Chris Austenb29d2e82016-06-07 12:25:35 -0500221
222Read Properties
George Keishing335f5362017-06-30 15:11:20 -0500223 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET}
224 ${resp}= OpenBMC Get Request ${uri} timeout=${timeout} quiet=${quiet}
225 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
226 ${content}= To Json ${resp.content}
227 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500228
229Call Method
Gunnar Mills38032802016-12-12 13:43:40 -0600230 [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600231
Chris Austenb29d2e82016-06-07 12:25:35 -0500232 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -0600233 ${resp}= OpenBmc Post Request ${base_uri}/action/${method}
234 ... timeout=${timeout} quiet=${quiet} &{kwargs}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600235 [Return] ${resp}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500236
237Upload Image To BMC
George Keishingad9a8802017-08-08 12:41:48 -0500238 [Arguments] ${uri} ${timeout}=10 ${quiet}=${1} &{kwargs}
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500239
240 # Description of argument(s):
241 # uri URI for uploading image via REST e.g. "/upload/image".
242 # timeout Time allocated for the REST command to return status
243 # (specified in Robot Framework Time Format e.g. "3 mins").
244 # quiet If enabled turns off logging to console.
245 # kwargs A dictionary keys/values to be passed directly to
246 # Post Request.
247
248 Initialize OpenBMC ${timeout} quiet=${quiet}
249 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
250 ${headers}= Create Dictionary Content-Type=application/octet-stream
251 ... Accept=application/octet-stream
252 Set To Dictionary ${kwargs} headers ${headers}
253 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
254 ... base_uri=${base_uri} args=&{kwargs}
255 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
256 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
257 Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
George Keishing08540c02017-07-19 09:42:50 -0500258 Delete All Sessions