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