blob: e548b220c5af6efa687ce088991595b2820c9231 [file] [log] [blame]
George Keishingeaa73b72018-07-30 09:30:16 -05001*** Settings ***
2Library Collections
3Library String
4Library RequestsLibrary.RequestsKeywords
5Library OperatingSystem
6Resource resource.txt
7Library disable_warning_urllib.py
8Resource rest_response_code.robot
9
10*** Variables ***
11
12# Assign default value to QUIET for programs which may not define it.
13${QUIET} ${0}
14
15*** Keywords ***
16
17Redfish Login Request
18 [Documentation] Do REST login and return authorization token.
19 [Arguments] ${openbmc_username}=${OPENBMC_USERNAME}
20 ... ${openbmc_password}=${OPENBMC_PASSWORD}
21 ... ${alias_session}=openbmc
22 ... ${timeout}=20
23
24 # Description of argument(s):
25 # openbmc_username The username to be used to login to the BMC.
26 # This defaults to global ${OPENBMC_USERNAME}.
27 # openbmc_password The password to be used to login to the BMC.
28 # This defaults to global ${OPENBMC_PASSWORD}.
29 # alias_session Session object name.
30 # This defaults to "openbmc"
31 # timeout REST login attempt time out.
32
33 Create Session openbmc ${AUTH_URI} timeout=${timeout}
34 ${headers}= Create Dictionary Content-Type=application/json
35
36 ${data}= Create Dictionary
37 ... UserName=${openbmc_username} Password=${openbmc_password}
38
39 ${resp}= Post Request openbmc
40 ... ${REDFISH_SESSION} data=${data} headers=${headers}
41
George Keishingef7a30d2018-10-30 12:34:56 -050042 Should Be Equal As Strings ${resp.status_code} ${HTTP_CREATED}
George Keishing9cef1092018-08-06 01:06:24 -050043 ${content} = To JSON ${resp.content}
44
45 Log ${content["Id"]}
George Keishingeaa73b72018-07-30 09:30:16 -050046 Log ${resp.headers["X-Auth-Token"]}
47
George Keishing9cef1092018-08-06 01:06:24 -050048 [Return] ${content["Id"]} ${resp.headers["X-Auth-Token"]}
George Keishingeaa73b72018-07-30 09:30:16 -050049
50
51Redfish Get Request
52 [Documentation] Do REST GET request and return the result.
George Keishing9cef1092018-08-06 01:06:24 -050053 [Arguments] ${uri_suffix}
54 ... ${session_id}=${None}
55 ... ${xauth_token}=${None}
George Keishing884d7d42018-08-09 12:43:13 -050056 ... ${resp_check}=${1}
George Keishing9cef1092018-08-06 01:06:24 -050057 ... ${timeout}=30
George Keishingeaa73b72018-07-30 09:30:16 -050058
59 # Description of argument(s):
60 # uri_suffix The URI to establish connection with
61 # (e.g. 'Systems').
George Keishing9cef1092018-08-06 01:06:24 -050062 # session_id Session id.
George Keishingeaa73b72018-07-30 09:30:16 -050063 # xauth_token Authentication token.
George Keishing884d7d42018-08-09 12:43:13 -050064 # resp_check By default check the response status and return JSON.
George Keishingeaa73b72018-07-30 09:30:16 -050065 # timeout Timeout in seconds to establish connection with URI.
66
George Keishinge7a3a3b2018-11-27 09:31:03 -060067 ${uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix}
George Keishingeaa73b72018-07-30 09:30:16 -050068
George Keishing9cef1092018-08-06 01:06:24 -050069 # Create session, token list [vIP8IxCQlQ, Nq9l7fgP8FFeFg3QgCpr].
70 ${id_auth_list} = Create List ${session_id} ${xauth_token}
71
72 # Set session and auth token variable.
73 ${session_id} ${xauth_token} =
74 ... Run Keyword If "${xauth_token}" == "${None}"
75 ... Redfish Login Request
76 ... ELSE
77 ... Set Variable ${id_auth_list}
78
George Keishingeaa73b72018-07-30 09:30:16 -050079 # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
80 ${headers} = Create Dictionary Content-Type=application/json
81 ... X-Auth-Token=${xauth_token}
George Keishing9cef1092018-08-06 01:06:24 -050082
George Keishingeaa73b72018-07-30 09:30:16 -050083 ${resp}= Get Request
George Keishinge7a3a3b2018-11-27 09:31:03 -060084 ... openbmc ${uri} headers=${headers} timeout=${timeout}
George Keishingeaa73b72018-07-30 09:30:16 -050085
George Keishing884d7d42018-08-09 12:43:13 -050086 Return From Keyword If ${resp_check} == ${0} ${resp}
George Keishingeaa73b72018-07-30 09:30:16 -050087
88 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
89
90 ${content} = To JSON ${resp.content}
91 [Return] ${content}
92
George Keishing9cef1092018-08-06 01:06:24 -050093
George Keishinge7a3a3b2018-11-27 09:31:03 -060094Redfish Post Request
95 [Documentation] Do redfish POST request.
96 [Arguments] ${uri_suffix}
George Keishinge7a3a3b2018-11-27 09:31:03 -060097 ... ${timeout}=30
George Keishing713dd5e2018-11-29 01:16:19 -060098 ... &{kwargs}
George Keishinge7a3a3b2018-11-27 09:31:03 -060099
100 # Description of argument(s):
101 # uri_suffix The URI to establish connection with
102 # (e.g. '/Systems/1/Actions/ComputerSystem.Reset').
103 # kwargs Any additional arguments to be passed directly to the
104 # Post Request. For example, the caller might
105 # set kwargs as follows:
106 # ${kwargs}= Create Dictionary allow_redirect=${True}.
107 # timeout Timeout in seconds to establish connection with URI.
108
109 ${uri}= Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix}
110 # Set session and auth token variable.
111 ${session_id} ${xauth_token}= Redfish Login Request
112
113 # Set session URI path.
114 ${session_uri}=
115 ... Catenate SEPARATOR= ${REDFISH_SESSION_URI} ${session_id}
116
117 # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
118 ${headers}= Create Dictionary Content-Type=application/json
119 ... X-Auth-Token=${xauth_token}
120
121 ${resp}= Post Request
122 ... openbmc ${uri} &{kwargs} headers=${headers} timeout=${timeout}
123
124 Redfish Delete Request ${session_uri} ${xauth_token}
125
126 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
127
128
George Keishing9cef1092018-08-06 01:06:24 -0500129Redfish Delete Request
130 [Documentation] Delete the resource identified by the URI.
George Keishing138f9d32018-08-08 10:50:05 -0500131 [Arguments] ${uri_suffix}
George Keishing9cef1092018-08-06 01:06:24 -0500132 ... ${xauth_token}
133 ... ${timeout}=10
George Keishingd61775f2018-08-09 01:02:30 -0500134 ... ${resp_check}=${1}
George Keishing9cef1092018-08-06 01:06:24 -0500135
136 # Description of argument(s):
George Keishing138f9d32018-08-08 10:50:05 -0500137 # uri_suffix The URI to establish connection with
138 # (e.g. 'SessionService/Sessions/XIApcw39QU').
George Keishing9cef1092018-08-06 01:06:24 -0500139 # xauth_token Authentication token.
140 # timeout Timeout in seconds to establish connection with URI.
George Keishing884d7d42018-08-09 12:43:13 -0500141 # resp_check By default check the response status.
George Keishing9cef1092018-08-06 01:06:24 -0500142
George Keishinge7a3a3b2018-11-27 09:31:03 -0600143 ${uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix}
George Keishing9cef1092018-08-06 01:06:24 -0500144
145 # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
146 ${headers} = Create Dictionary Content-Type=application/json
147 ... X-Auth-Token=${xauth_token}
148
149 # Delete server session.
150 ${resp}= Delete Request openbmc
George Keishinge7a3a3b2018-11-27 09:31:03 -0600151 ... ${uri} headers=${headers} timeout=${timeout}
George Keishingd61775f2018-08-09 01:02:30 -0500152
153 Return From Keyword If ${resp_check} == ${0} ${resp}
154
George Keishing9cef1092018-08-06 01:06:24 -0500155 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
156
157 # Delete client sessions.
158 Delete All Sessions