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&{USERS}       Administrator=${ADMIN}  Operator=${OPERATOR}
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_Credentails
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    operator_user        TestPwd123           ${HTTP_CREATED}
37
38
39Verify SessionService Defaults
40    [Documentation]  Verify SessionService default property values.
41    [Tags]  Verify_SessionService_Defaults
42
43    ${session_service}=  Redfish.Get Properties  /redfish/v1/SessionService
44    Rprint Vars  session_service
45
46    Valid Value  session_service['@odata.id']  ['/redfish/v1/SessionService/']
47    Valid Value  session_service['Description']  ['Session Service']
48    Valid Value  session_service['Id']  ['SessionService']
49    Valid Value  session_service['Name']  ['Session Service']
50    Valid Value  session_service['ServiceEnabled']  [True]
51    Valid Value  session_service['SessionTimeout']  [3600]
52    Valid Value  session_service['Sessions']['@odata.id']  ['/redfish/v1/SessionService/Sessions']
53
54
55Verify Sessions Defaults
56    [Documentation]  Verify Sessions default property values.
57    [Tags]  Verify_Sessions_Defaults
58
59    ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions
60    Rprint Vars  sessions
61    ${sessions_count}=  Get length  ${sessions['Members']}
62
63    Valid Value  sessions['@odata.id']  ['/redfish/v1/SessionService/Sessions/']
64    Valid Value  sessions['Description']  ['Session Collection']
65    Valid Value  sessions['Name']  ['Session Collection']
66    Valid Value  sessions['Members@odata.count']  [${sessions_count}]
67
68
69Verify Current Session Defaults
70    [Documentation]  Verify Current session default property values.
71    [Tags]  Verify_Current_Session_Defaults
72
73    ${session_location}=  Redfish.Get Session Location
74    ${session_id}=  Evaluate  os.path.basename($session_location)  modules=os
75    ${session_properties}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_id}
76    Rprint Vars  session_location  session_id  session_properties
77
78    Valid Value  session_properties['@odata.id']  ['/redfish/v1/SessionService/Sessions/${session_id}']
79    Valid Value  session_properties['Description']  ['Manager User Session']
80    Valid Value  session_properties['Name']  ['User Session']
81    Valid Value  session_properties['Id']  ['${session_id}']
82    Valid Value  session_properties['UserName']  ['${OPENBMC_USERNAME}']
83
84
85Verify Managers Defaults
86    [Documentation]  Verify managers defaults.
87    [Tags]  Verify_Managers_Defaults
88
89    ${managers}=  Redfish.Get Properties  /redfish/v1/Managers
90    Rprint Vars  managers
91    ${managers_count}=  Get Length  ${managers['Members']}
92
93    Valid Value  managers['Name']  ['Manager Collection']
94    Valid Value  managers['@odata.id']  ['/redfish/v1/Managers']
95    Valid Value  managers['Members@odata.count']  [${managers_count}]
96
97    # Members can be one or more, hence checking in the list.
98    Valid List  managers['Members']  required_values=[{'@odata.id': '/redfish/v1/Managers/bmc'}]
99
100
101Verify Chassis Defaults
102    [Documentation]  Verify chassis defaults.
103    [Tags]  Verify_Chassis_Defaults
104
105    ${chassis}=  Redfish.Get Properties  /redfish/v1/Chassis
106    Rprint Vars  chassis
107    ${chassis_count}=  Get Length  ${chassis['Members']}
108
109    Valid Value  chassis['Name']  ['Chassis Collection']
110    Valid Value  chassis['@odata.id']  ['/redfish/v1/Chassis']
111    Valid Value  chassis['Members@odata.count']  [${chassis_count}]
112    Valid Value  chassis['Members@odata.count']  [${chassis_count}]
113
114    # Members can be one or more, hence checking in the list.
115    Valid List  chassis['Members']
116    ...  required_values=[{'@odata.id': '/redfish/v1/Chassis/chassis'}]
117
118
119Verify Systems Defaults
120    [Documentation]  Verify systems defaults.
121    [Tags]  Verify_Systems_Defaults
122
123    ${systems}=  Redfish.Get Properties  /redfish/v1/Systems
124    Rprint Vars  systems
125    ${systems_count}=  Get Length  ${systems['Members']}
126    Valid Value  systems['Name']  ['Computer System Collection']
127    Valid Value  systems['@odata.id']  ['/redfish/v1/Systems']
128    Valid Value  systems['Members@odata.count']  [${systems_count}]
129    Valid Value  systems['Members@odata.count']  [${systems_count}]
130    # Members can be one or more, hence checking in the list.
131    Valid List  systems['Members']  required_values=[{'@odata.id': '/redfish/v1/Systems/system'}]
132
133
134Verify Session Persistency After BMC Reboot
135    [Documentation]  Verify session persistency after BMC reboot.
136    [Tags]  Verify_Session_Persistency_After_BMC_Reboot
137
138    # Note the current session location.
139    ${session_location}=  Redfish.Get Session Location
140
141    Redfish OBMC Reboot (off)  stack_mode=normal
142    Redfish.Login
143
144    # Check for session persistency after BMC reboot.
145    # sessions here will have list of all sessions location.
146    ${sessions}=  Redfish.Get Attribute  /redfish/v1/SessionService/Sessions  Members
147    ${payload}=  Create Dictionary  @odata.id=${session_location}
148
149    List Should Contain Value  ${sessions}  ${payload}
150
151
152REST Logging Interface Read Should Be A SUCCESS For Authorized Users
153    [Documentation]  REST logging interface read should be a success for authorized users.
154    [Tags]    REST_Logging_Interface_Read_Should_Be_A_SUCCESS_For_Authorized_Users
155
156    ${resp}=  Redfish.Get  /xyz/openbmc_project/logging
157
158    ${resp_output}=  evaluate  json.loads('''${resp.text}''')  json
159    ${log_count}=  Get Length  ${resp_output["data"]}
160
161    # Max 200 error logs are allowed in OpenBmc.
162    Run Keyword Unless   ${-1} < ${log_count} < ${201}  Fail
163
164
165*** Keywords ***
166
167Create Session And Verify Response Code
168    [Documentation]  Create session and verify response code.
169    [Arguments]  ${username}=${OPENBMC_USERNAME}  ${password}=${OPENBMC_PASSWORD}
170    ...  ${valid_status_code}=${HTTP_CREATED}
171
172    # Description of argument(s):
173    # username            The username to create a session.
174    # password            The password to create a session.
175    # valid_status_code   Expected response code, default is ${HTTP_CREATED}.
176
177    ${resp}=  Redfish.Post  /redfish/v1/SessionService/Sessions
178    ...  body={'UserName':'${username}', 'Password': '${password}'}
179    ...  valid_status_codes=[${valid_status_code}]
180
181
182Suite Setup Execution
183    [Documentation]  Suite Setup Execution.
184
185    Redfish.Login
186    Create Users With Different Roles  users=${USERS}  force=${True}
187
188
189Suite Teardown Execution
190    [Documentation]  Suite teardown execution.
191
192    Delete BMC Users Via Redfish  users=${USERS}
193    Redfish.Logout
194