blob: bd2db37eed7ae41d0c14c93cea7f1bf9f924956a [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
60
61*** Keywords ***
62OpenBMC Get Request
63 [Arguments] ${uri} &{kwargs}
64 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
65 Log Request method=Get base_uri=${base_uri} args=&{kwargs}
66 Initialize OpenBMC
67 ${ret}= Get Request openbmc ${base_uri} &{kwargs}
68 Log Response ${ret}
69 [Return] ${ret}
70
71OpenBMC Post Request
72 [Arguments] ${uri} &{kwargs}
73 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
74 ${headers}= Create Dictionary Content-Type=application/json
75 set to dictionary ${kwargs} headers ${headers}
76 Log Request method=Post base_uri=${base_uri} args=&{kwargs}
77 Initialize OpenBMC
78 ${ret}= Post Request openbmc ${base_uri} &{kwargs}
79 Log Response ${ret}
80 [Return] ${ret}
81
82OpenBMC Put Request
83 [Arguments] ${uri} &{kwargs}
84 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
85 ${headers}= Create Dictionary Content-Type=application/json
86 set to dictionary ${kwargs} headers ${headers}
87 Log Request method=Put base_uri=${base_uri} args=&{kwargs}
88 Initialize OpenBMC
89 ${ret}= Put Request openbmc ${base_uri} &{kwargs}
90 Log Response ${ret}
91 [Return] ${ret}
92
93OpenBMC Delete Request
94 [Arguments] ${uri} &{kwargs}
95 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
96 Log Request method=Delete base_uri=${base_uri} args=&{kwargs}
97 Initialize OpenBMC
98 ${ret}= Put Request openbmc ${base_uri} &{kwargs}
99 Log Response ${ret}
100 [Return] ${ret}
101
102Initialize OpenBMC
103 Create Session openbmc ${AUTH_URI} timeout=5 max_retries=1
104 ${headers}= Create Dictionary Content-Type=application/json
105 @{credentials} = Create List ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
106 ${data} = create dictionary data=@{credentials}
107 ${resp} = Post Request openbmc /login data=${data} headers=${headers}
108 should be equal as strings ${resp.status_code} ${HTTP_OK}
109
110Log Request
111 [Arguments] &{kwargs}
112 ${msg}= Catenate SEPARATOR= URI: ${AUTH_URI} ${kwargs["base_uri"]} , method:
113 ... ${kwargs["method"]} , args: ${kwargs["args"]}
114 Logging ${msg} console=True
115
116Log Response
117 [Arguments] ${resp}
118 ${msg}= Catenate SEPARATOR= Response code: ${resp.status_code} , Content: ${resp.content}
119 Logging ${msg} console=True
120
121Logging
122 [Arguments] ${msg} ${console}=default False
123 Log ${msg} console=True
124
125Read Attribute
126 [arguments] ${uri} ${attr}
127 ${resp} = OpenBMC Get Request ${uri}/attr/${attr}
128 ${content}= To Json ${resp.content}
129 [return] ${content["data"]}
130
131Write Attribute
132 [Arguments] ${uri} ${attr} &{kwargs}
133 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
134 ${resp} = openbmc put request ${base_uri}/attr/${attr} &{kwargs}
135 should be equal as strings ${resp.status_code} ${HTTP_OK}
136 ${json} = to json ${resp.content}
137
138Read Properties
139 [arguments] ${uri}
140 ${resp} = OpenBMC Get Request ${uri} timeout=10
141 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
142 ${content}= To Json ${resp.content}
143 [return] ${content["data"]}
144
145Call Method
146 [arguments] ${uri} ${method} &{kwargs}
147 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
148 ${resp} = openbmc post request ${base_uri}/action/${method} &{kwargs}
149 [return] ${resp}