blob: ea750638f1f081cb2b009cbd4ff7e28cbdf2418b [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
Michael Walsha6723f22016-11-22 11:12:01 -060065 [Arguments] ${uri} ${timeout}=10 ${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}
Chris Austenb29d2e82016-06-07 12:25:35 -050073 [Return] ${ret}
74
75OpenBMC Post Request
Michael Walsha6723f22016-11-22 11:12:01 -060076 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
77
Michael Walshf00edee2016-12-09 14:10:26 -060078 Initialize OpenBMC ${timeout} quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050079 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
80 ${headers}= Create Dictionary Content-Type=application/json
81 set to dictionary ${kwargs} headers ${headers}
Michael Walsha6723f22016-11-22 11:12:01 -060082 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
83 ... base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060084 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
85 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
Chris Austenb29d2e82016-06-07 12:25:35 -050086 [Return] ${ret}
87
88OpenBMC Put Request
Rahul Maheshwari79c12942016-10-17 09:39:17 -050089 [Arguments] ${uri} ${timeout}=10 &{kwargs}
Michael Walshf00edee2016-12-09 14:10:26 -060090
91 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050092 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
93 ${headers}= Create Dictionary Content-Type=application/json
94 set to dictionary ${kwargs} headers ${headers}
95 Log Request method=Put base_uri=${base_uri} args=&{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -060096 ${ret}= Put Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -050097 Log Response ${ret}
98 [Return] ${ret}
99
100OpenBMC Delete Request
Rahul Maheshwari79c12942016-10-17 09:39:17 -0500101 [Arguments] ${uri} ${timeout}=10 &{kwargs}
Michael Walshf00edee2016-12-09 14:10:26 -0600102
103 Initialize OpenBMC ${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500104 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
105 Log Request method=Delete base_uri=${base_uri} args=&{kwargs}
George Keishing0e7c3a02017-04-17 05:01:14 -0500106 ${ret}= Delete Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500107 Log Response ${ret}
108 [Return] ${ret}
109
110Initialize OpenBMC
George Keishing59fa0482017-03-02 10:01:09 -0600111 [Arguments] ${timeout}=20 ${quiet}=${1}
Michael Walshf00edee2016-12-09 14:10:26 -0600112
Michael Walsha6723f22016-11-22 11:12:01 -0600113 Create Session openbmc ${AUTH_URI} timeout=${timeout} max_retries=3
114 ${headers}= Create Dictionary Content-Type=application/json
115 @{credentials}= Create List ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
116 ${data}= create dictionary data=@{credentials}
Michael Walshf00edee2016-12-09 14:10:26 -0600117
118 ${status} ${resp}= Run Keyword And Ignore Error Post Request openbmc
119 ... /login data=${data} headers=${headers}
120
121 Should Be Equal ${status} PASS msg=${resp}
122 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500123
George Keishinge8225522017-03-31 09:21:13 -0500124Log Out OpenBMC
125 [Documentation] Log out REST connection with active session "openbmc".
126
127 ${headers}= Create Dictionary Content-Type=application/json
128 ${data}= Create dictionary data=@{EMPTY}
129
130 # If there is no active sesion it will throw the following exception
131 # "Non-existing index or alias 'openbmc'"
132 ${resp}= Post Request openbmc
133 ... /logout data=${data} headers=${headers}
134
135 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
136 ... msg=${resp}
137
Chris Austenb29d2e82016-06-07 12:25:35 -0500138Log Request
139 [Arguments] &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600140 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]}
141 ... , method: ${kwargs["method"]} , args: ${kwargs["args"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500142 Logging ${msg} console=True
143
144Log Response
145 [Arguments] ${resp}
Michael Walsha6723f22016-11-22 11:12:01 -0600146 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code}
147 ... , Content: ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500148 Logging ${msg} console=True
149
150Logging
151 [Arguments] ${msg} ${console}=default False
152 Log ${msg} console=True
153
154Read Attribute
Gunnar Mills38032802016-12-12 13:43:40 -0600155 [Arguments] ${uri} ${attr} ${timeout}=10 ${quiet}=${QUIET}
Michael Walsha6723f22016-11-22 11:12:01 -0600156 ${resp}= OpenBMC Get Request ${uri}/attr/${attr} timeout=${timeout}
157 ... quiet=${quiet}
Michael Walsh9cd61932017-01-17 16:11:02 -0600158 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -0500159 ${content}= To Json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600160 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500161
162Write Attribute
Rahul Maheshwari79c12942016-10-17 09:39:17 -0500163 [Arguments] ${uri} ${attr} ${timeout}=10 &{kwargs}
Chris Austenb29d2e82016-06-07 12:25:35 -0500164 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -0600165 ${resp}= openbmc put request ${base_uri}/attr/${attr}
166 ... timeout=${timeout} &{kwargs}
George Keishing06ae4aa2016-08-30 01:41:28 -0500167 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -0600168 ${json}= to json ${resp.content}
Chris Austenb29d2e82016-06-07 12:25:35 -0500169
170Read Properties
Gunnar Mills38032802016-12-12 13:43:40 -0600171 [Arguments] ${uri} ${timeout}=10
Michael Walsha6723f22016-11-22 11:12:01 -0600172 ${resp}= OpenBMC Get Request ${uri} timeout=${timeout}
Chris Austenb29d2e82016-06-07 12:25:35 -0500173 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
174 ${content}= To Json ${resp.content}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600175 [Return] ${content["data"]}
Chris Austenb29d2e82016-06-07 12:25:35 -0500176
177Call Method
Gunnar Mills38032802016-12-12 13:43:40 -0600178 [Arguments] ${uri} ${method} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
Michael Walsha6723f22016-11-22 11:12:01 -0600179
Chris Austenb29d2e82016-06-07 12:25:35 -0500180 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
Michael Walsha6723f22016-11-22 11:12:01 -0600181 ${resp}= OpenBmc Post Request ${base_uri}/action/${method}
182 ... timeout=${timeout} quiet=${quiet} &{kwargs}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600183 [Return] ${resp}