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