blob: b8e3aa329fc8dfc995902d81f6963f9d0c7ff932 [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
42 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
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 Keishingeaa73b72018-07-30 09:30:16 -050067 ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix}
68
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
84 ... openbmc ${base_uri} headers=${headers} timeout=${timeout}
85
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
94Redfish Delete Request
95 [Documentation] Delete the resource identified by the URI.
George Keishing138f9d32018-08-08 10:50:05 -050096 [Arguments] ${uri_suffix}
George Keishing9cef1092018-08-06 01:06:24 -050097 ... ${xauth_token}
98 ... ${timeout}=10
George Keishingd61775f2018-08-09 01:02:30 -050099 ... ${resp_check}=${1}
George Keishing9cef1092018-08-06 01:06:24 -0500100
101 # Description of argument(s):
George Keishing138f9d32018-08-08 10:50:05 -0500102 # uri_suffix The URI to establish connection with
103 # (e.g. 'SessionService/Sessions/XIApcw39QU').
George Keishing9cef1092018-08-06 01:06:24 -0500104 # xauth_token Authentication token.
105 # timeout Timeout in seconds to establish connection with URI.
George Keishing884d7d42018-08-09 12:43:13 -0500106 # resp_check By default check the response status.
George Keishing9cef1092018-08-06 01:06:24 -0500107
George Keishing138f9d32018-08-08 10:50:05 -0500108 ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix}
George Keishing9cef1092018-08-06 01:06:24 -0500109
110 # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
111 ${headers} = Create Dictionary Content-Type=application/json
112 ... X-Auth-Token=${xauth_token}
113
114 # Delete server session.
115 ${resp}= Delete Request openbmc
116 ... ${base_uri} headers=${headers} timeout=${timeout}
George Keishingd61775f2018-08-09 01:02:30 -0500117
118 Return From Keyword If ${resp_check} == ${0} ${resp}
119
George Keishing9cef1092018-08-06 01:06:24 -0500120 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
121
122 # Delete client sessions.
123 Delete All Sessions