blob: 8dcab88c437c3fcdf0dc546ce0e829f6ae564076 [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}
56 ... ${response_format}="json"
57 ... ${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.
64 # response_format The format desired for data returned by this keyword
65 # (json/HTTPS response).
66 # timeout Timeout in seconds to establish connection with URI.
67
George Keishingeaa73b72018-07-30 09:30:16 -050068 ${base_uri} = Catenate SEPARATOR= ${REDFISH_BASE_URI} ${uri_suffix}
69
George Keishing9cef1092018-08-06 01:06:24 -050070 # Create session, token list [vIP8IxCQlQ, Nq9l7fgP8FFeFg3QgCpr].
71 ${id_auth_list} = Create List ${session_id} ${xauth_token}
72
73 # Set session and auth token variable.
74 ${session_id} ${xauth_token} =
75 ... Run Keyword If "${xauth_token}" == "${None}"
76 ... Redfish Login Request
77 ... ELSE
78 ... Set Variable ${id_auth_list}
79
George Keishingeaa73b72018-07-30 09:30:16 -050080 # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
81 ${headers} = Create Dictionary Content-Type=application/json
82 ... X-Auth-Token=${xauth_token}
George Keishing9cef1092018-08-06 01:06:24 -050083
George Keishingeaa73b72018-07-30 09:30:16 -050084 ${resp}= Get Request
85 ... openbmc ${base_uri} headers=${headers} timeout=${timeout}
86
87 Return From Keyword If ${response_format} != "json" ${resp}
88
89 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
90
91 ${content} = To JSON ${resp.content}
92 [Return] ${content}
93
George Keishing9cef1092018-08-06 01:06:24 -050094
95Redfish Delete Request
96 [Documentation] Delete the resource identified by the URI.
97 [Arguments] ${session_id}
98 ... ${xauth_token}
99 ... ${timeout}=10
100
101 # Description of argument(s):
102 # session_id Session id.
103 # xauth_token Authentication token.
104 # timeout Timeout in seconds to establish connection with URI.
105
106 ${base_uri} = Catenate SEPARATOR= ${REDFISH_SESSION}${/} ${session_id}
107
108 # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
109 ${headers} = Create Dictionary Content-Type=application/json
110 ... X-Auth-Token=${xauth_token}
111
112 # Delete server session.
113 ${resp}= Delete Request openbmc
114 ... ${base_uri} headers=${headers} timeout=${timeout}
115 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
116
117 # Delete client sessions.
118 Delete All Sessions