1*** Settings ***
2
3Documentation    Test Redfish SessionService.
4
5Resource         ../../lib/resource.robot
6Resource         ../../lib/bmc_redfish_resource.robot
7Resource         ../../lib/bmc_redfish_utils.robot
8Resource         ../../lib/openbmc_ffdc.robot
9
10Suite Setup      Suite Setup Execution
11Suite Teardown   Suite Teardown Execution
12Test Setup       Printn
13Test Teardown    FFDC On Test Case Fail
14
15
16*** Variables ***
17
18@{ADMIN}       admin_user  TestPwd123
19@{OPERATOR}    operator_user  TestPwd123
20# User-driven input parameter to skip operator user.
21# -v SKIP_OPERATOR_USER:1  to skip from CLI.
22${SKIP_OPERATOR_USER}    ${0}
23
24
25*** Test Cases ***
26
27Create Session And Verify Response Code Using Different Credentials
28    [Documentation]  Create session and verify response code using different credentials.
29    [Tags]  Create_Session_And_Verify_Response_Code_Using_Different_Credentials
30    [Template]  Create Session And Verify Response Code
31
32    # username           password             valid_status_code
33    ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  ${HTTP_CREATED}
34    r00t                 ${OPENBMC_PASSWORD}  ${HTTP_UNAUTHORIZED}
35    ${OPENBMC_USERNAME}  password             ${HTTP_UNAUTHORIZED}
36    r00t                 password             ${HTTP_UNAUTHORIZED}
37    admin_user           TestPwd123           ${HTTP_CREATED}
38    operator_user        TestPwd123           ${HTTP_CREATED}
39
40
41Set Session Timeout And Verify Response Code
42    [Documentation]  Set Session Timeout And Verify Response Code.
43    [Tags]  Set_Session_Timeout_And_Verify_Response_Code
44    [Template]  Set Session Timeout And Verify
45    [Teardown]  Set Session Timeout And Verify  ${Default_Timeout_Value}  ${HTTP_OK}
46
47    # The minimum & maximum allowed values for session timeout are 30
48    # seconds and 86400 seconds respectively as per the session service
49    # schema mentioned at
50    # https://redfish.dmtf.org/schemas/v1/SessionService.v1_1_7.json
51
52    # value             valid_status_code
53    ${25}               ${HTTP_BAD_REQUEST}
54    ${30}               ${HTTP_OK}
55    ${3600}             ${HTTP_OK}
56    ${86400}            ${HTTP_OK}
57    ${86500}            ${HTTP_BAD_REQUEST}
58
59
60Set Session Timeout And Verify Session After Timeout
61    [Documentation]  Set timeout for session service and verify session is deleted after timeout.
62    [Tags]  Set_Session_Timeout_And_Verify_Session_After_Timeout
63    [Teardown]  Set Session Timeout And Verify   ${Default_Timeout_Value}  ${HTTP_OK}
64    [Template]  Set Session Timeout And Verify Session Deleted After Timeout
65
66    #timeout Value
67    ${30}
68    ${300}
69
70
71Verify Session Login And Logout For Newly Created User
72    [Documentation]  Verify able to login and logout using the session created for new user.
73    [Tags]  Verify_Session_Login_And_Logout_For_Newly_Created_User
74    [Teardown]  Redfish.Login
75
76    # Logout already created redfish session.
77    Redfish.Logout
78    Redfish.Login  ${ADMIN}[0]  ${ADMIN}[1]
79    ${systems}=  Redfish.Get Properties  /redfish/v1/Systems
80    Rprint Vars  systems
81    Redfish.Logout
82    ${systems}=  Redfish.Get  /redfish/v1/Systems
83    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}]
84
85
86Verify SessionService Defaults
87    [Documentation]  Verify SessionService default property values.
88    [Tags]  Verify_SessionService_Defaults
89
90    ${session_service}=  Redfish.Get Properties  /redfish/v1/SessionService
91    Rprint Vars  session_service
92
93    Valid Value  session_service['@odata.id']  ['/redfish/v1/SessionService/']
94    Valid Value  session_service['Description']  ['Session Service']
95    Valid Value  session_service['Id']  ['SessionService']
96    Valid Value  session_service['Name']  ['Session Service']
97    Valid Value  session_service['ServiceEnabled']  [True]
98    Valid Value  session_service['SessionTimeout']  [${Default_Timeout_Value}]
99    Valid Value  session_service['Sessions']['@odata.id']  ['/redfish/v1/SessionService/Sessions']
100
101
102Verify Sessions Defaults
103    [Documentation]  Verify Sessions default property values.
104    [Tags]  Verify_Sessions_Defaults
105
106    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions
107    Rprint Vars  sessions
108    ${sessions_count}=  Get length  ${sessions['Members']}
109
110    Valid Value  sessions['@odata.id']  ['/redfish/v1/SessionService/Sessions/']
111    Valid Value  sessions['Description']  ['Session Collection']
112    Valid Value  sessions['Name']  ['Session Collection']
113    Valid Value  sessions['Members@odata.count']  [${sessions_count}]
114
115
116Verify Current Session Defaults
117    [Documentation]  Verify Current session default property values.
118    [Tags]  Verify_Current_Session_Defaults
119
120    ${session_location}=  Redfish.Get Session Location
121    ${session_id}=  Evaluate  os.path.basename($session_location)  modules=os
122    ${session_properties}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_id}
123    Rprint Vars  session_location  session_id  session_properties
124
125    Valid Value  session_properties['@odata.id']  ['/redfish/v1/SessionService/Sessions/${session_id}']
126    Valid Value  session_properties['Description']  ['Manager User Session']
127    Valid Value  session_properties['Name']  ['User Session']
128    Valid Value  session_properties['Id']  ['${session_id}']
129    Valid Value  session_properties['UserName']  ['${OPENBMC_USERNAME}']
130
131
132Verify Managers Defaults
133    [Documentation]  Verify managers defaults.
134    [Tags]  Verify_Managers_Defaults
135
136    ${managers}=  Redfish.Get Properties  /redfish/v1/Managers
137    Rprint Vars  managers
138    ${managers_count}=  Get Length  ${managers['Members']}
139
140    Valid Value  managers['Name']  ['Manager Collection']
141    Valid Value  managers['@odata.id']  ['/redfish/v1/Managers']
142    Valid Value  managers['Members@odata.count']  [${managers_count}]
143
144    # Members can be one or more, hence checking in the list.
145    Valid List  managers['Members']  required_values=[{'@odata.id': '/redfish/v1/Managers/bmc'}]
146
147
148Verify Chassis Defaults
149    [Documentation]  Verify chassis defaults.
150    [Tags]  Verify_Chassis_Defaults
151
152    ${chassis}=  Redfish.Get Properties  /redfish/v1/Chassis
153    Rprint Vars  chassis
154    ${chassis_count}=  Get Length  ${chassis['Members']}
155
156    Valid Value  chassis['Name']  ['Chassis Collection']
157    Valid Value  chassis['@odata.id']  ['/redfish/v1/Chassis']
158    Valid Value  chassis['Members@odata.count']  [${chassis_count}]
159    Valid Value  chassis['Members@odata.count']  [${chassis_count}]
160
161    # Members can be one or more, hence checking in the list.
162    Valid List  chassis['Members']
163    ...  required_values=[{'@odata.id': '/redfish/v1/Chassis/${CHASSIS_ID}'}]
164
165
166Verify Systems Defaults
167    [Documentation]  Verify systems defaults.
168    [Tags]  Verify_Systems_Defaults
169
170    ${systems}=  Redfish.Get Properties  /redfish/v1/Systems
171    Rprint Vars  systems
172    ${systems_count}=  Get Length  ${systems['Members']}
173    Valid Value  systems['Name']  ['Computer System Collection']
174    Valid Value  systems['@odata.id']  ['/redfish/v1/Systems']
175    Valid Value  systems['Members@odata.count']  [${systems_count}]
176    Valid Value  systems['Members@odata.count']  [${systems_count}]
177    # Members can be one or more, hence checking in the list.
178    Valid List  systems['Members']  required_values=[{'@odata.id': '/redfish/v1/Systems/system'}]
179
180
181Verify Session Persistency After BMC Reboot
182    [Documentation]  Verify session persistency after BMC reboot.
183    [Tags]  Verify_Session_Persistency_After_BMC_Reboot
184
185    # Note the current session location.
186    ${session_location}=  Redfish.Get Session Location
187
188    Redfish OBMC Reboot (off)  stack_mode=normal
189
190    # Check for session persistency after BMC reboot.
191    # sessions here will have list of all sessions location.
192    ${sessions}=  Redfish.Get Attribute  /redfish/v1/SessionService/Sessions  Members
193    ${payload}=  Create Dictionary  @odata.id=${session_location}
194
195    List Should Contain Value  ${sessions}  ${payload}
196
197*** Keywords ***
198
199Create Session And Verify Response Code
200    [Documentation]  Create session and verify response code.
201    [Arguments]  ${username}=${OPENBMC_USERNAME}  ${password}=${OPENBMC_PASSWORD}
202    ...  ${valid_status_code}=${HTTP_CREATED}
203
204    # Description of argument(s):
205    # username            The username to create a session.
206    # password            The password to create a session.
207    # valid_status_code   Expected response code, default is ${HTTP_CREATED}.
208
209    ${resp}=  Redfish.Post  /redfish/v1/SessionService/Sessions
210    ...  body={'UserName':'${username}', 'Password': '${password}'}
211    ...  valid_status_codes=[${valid_status_code}]
212
213
214Set Session Timeout And Verify
215    [Documentation]  Set Session Timeout And Verify.
216    [Arguments]  ${value}=3600  ${valid_status_code}=${HTTP_OK}
217
218    # Description of argument(s):
219    # value               The value to patch session timeout.
220    # valid_status_code   Expected response code, default is ${HTTP_OK}.
221
222    Redfish.Login
223    ${data}=  Create Dictionary  SessionTimeout=${value}
224    Redfish.Patch  ${REDFISH_BASE_URI}SessionService
225    ...  body=&{data}
226    ...  valid_status_codes=[${valid_status_code}]
227
228    ${session_timeout}=  Redfish.Get Attribute
229    ...  ${REDFISH_BASE_URI}SessionService  SessionTimeout
230
231    Run Keyword If  ${valid_status_code}==${HTTP_OK}
232    ...  Valid Value  session_timeout  [${value}]
233
234
235Create Session And Check Session Timeout
236    [Documentation]  Create session and check session timeout.
237    [Arguments]  ${value}
238
239    # Description of argument(s):
240    # value   timeout value in integer to be configured.
241
242    ${resp}=  Redfish.Post  /redfish/v1/SessionService/Sessions
243    ...  body={'UserName':'${OPENBMC_USERNAME}', 'Password': '${OPENBMC_PASSWORD}'}
244    ...  valid_status_codes=[${HTTP_CREATED}]
245    ${session_id}=  Set Variable  ${resp.dict['@odata.id']}
246    Sleep  ${value}s
247
248    Redfish.Get  ${REDFISH_SESSION}  valid_status_codes=[${HTTP_UNAUTHORIZED}]
249    # Since sessions will deleted so logging again.
250    Redfish.login
251    ${session_list}=  Redfish.Get Members List  /redfish/v1/SessionService/Sessions
252
253    List Should Not Contain Value  ${session_list}  ${session_id}
254
255
256Set Session Timeout And Verify Session Deleted After Timeout
257    [Documentation]  Set timeout for session service and verify session is deleted after timeout.
258    [Arguments]  ${timeout_value}
259
260    # Description of argument(s):
261    # timeout_value   timeout value in integer to be configured.
262
263    ${data}=  Create Dictionary  SessionTimeout=${timeout_value}
264    ${resp_patch}=  Redfish.Patch  /redfish/v1/SessionService
265    ...  body=&{data}  valid_status_codes=[${HTTP_OK}]
266    Create Session And Check Session Timeout  ${timeout_value}
267
268
269Get Default Timeout Value
270    [Documentation]  Get default session timeout value and set as a suite variable.
271
272    ${Default_Timeout_Value}=  Redfish.Get Attribute  /redfish/v1/SessionService  SessionTimeout
273    Set Suite Variable   ${Default_Timeout_Value}
274
275
276Suite Setup Execution
277    [Documentation]  Suite Setup Execution.
278
279    Redfish.Login
280
281    # Skip operator user if SKIP_OPERATOR_USER is 1.
282    Run Keyword If
283    ...  ${SKIP_OPERATOR_USER} == ${1}
284    ...  Set Suite Variable  &{USERS}  Administrator=${ADMIN}
285    ...  ELSE
286    ...  Set Suite Variable  &{USERS}  Administrator=${ADMIN}  Operator=${OPERATOR}
287
288    Create Users With Different Roles  users=${USERS}  force=${True}
289    Get Default Timeout Value
290
291
292Suite Teardown Execution
293    [Documentation]  Suite teardown execution.
294
295    Delete BMC Users Via Redfish  users=${USERS}
296    Run Keyword And Ignore Error  Delete All Redfish Sessions
297    Redfish.Logout
298