blob: 7f90dcb61b7d3aeb26132f56e31cb96d305d860e [file] [log] [blame]
Rahul Maheshwari51dee262019-03-06 23:36:21 -06001*** Settings ***
2Documentation Test IPMI and Redfish combinations for user management.
3
4Resource ../../lib/resource.robot
5Resource ../../lib/bmc_redfish_resource.robot
6Resource ../../lib/openbmc_ffdc.robot
7Resource ../../lib/ipmi_client.robot
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -05008Library ../lib/ipmi_utils.py
Rahul Maheshwari51dee262019-03-06 23:36:21 -06009
10Test Setup Test Setup Execution
11Test Teardown Test Teardown Execution
12
13
14*** Variables ***
15
16${valid_password} 0penBmc1
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -050017${valid_password2} 0penBmc2
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -050018${admin_level_priv} 4
19${operator_level_priv} 3
Rahul Maheshwari7b7ba222022-08-21 23:29:43 -050020${readonly_level_priv} 2
George Keishingdc7d6892022-07-07 14:28:32 -050021${ipmi_max_num_users} ${15}
ganesanb45102292023-03-28 11:13:29 +000022${max_num_users} ${15}
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -040023${empty_name_pattern} ^User Name\\s.*\\s:\\s$
Rahul Maheshwari51dee262019-03-06 23:36:21 -060024
25** Test Cases **
26
27Create Admin Redfish User And Verify Login Via IPMI
28 [Documentation] Create user using redfish and verify via IPMI.
29 [Tags] Create_Admin_Redfish_User_And_Verify_Login_Via_IPMI
30
31 ${random_username}= Generate Random String 8 [LETTERS]
32 Set Test Variable ${random_username}
33
34 ${payload}= Create Dictionary
35 ... UserName=${random_username} Password=${valid_password}
36 ... RoleId=Administrator Enabled=${True}
37 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
38 ... valid_status_codes=[${HTTP_CREATED}]
39
Sushma M M97fccae2020-07-27 14:55:19 -050040 # Delay added for created new user password to get set.
41 Sleep 5s
42
Rahul Maheshwari51dee262019-03-06 23:36:21 -060043 Verify IPMI Username And Password ${random_username} ${valid_password}
44
45
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -050046Update User Password Via Redfish And Verify Using IPMI
47 [Documentation] Update user password via Redfish and verify using IPMI.
48 [Tags] Update_User_Password_Via_Redfish_And_Verify_Using_IPMI
49
50 # Create user using Redfish.
51 ${random_username}= Generate Random String 8 [LETTERS]
52 Set Test Variable ${random_username}
53
54 ${payload}= Create Dictionary
55 ... UserName=${random_username} Password=${valid_password}
56 ... RoleId=Administrator Enabled=${True}
57 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
58 ... valid_status_codes=[${HTTP_CREATED}]
59
60 # Update user password using Redfish.
61 ${payload}= Create Dictionary Password=${valid_password2}
62 Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload}
63
64 # Verify that IPMI command works with new password and fails with older password.
65 Verify IPMI Username And Password ${random_username} ${valid_password2}
66
Anusha Dathatri652fc742020-02-05 05:14:21 -060067 Run Keyword And Expect Error *Error: Unable to establish IPMI*
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -050068 ... Verify IPMI Username And Password ${random_username} ${valid_password}
69
70
Rahul Maheshwariff63ac02019-03-29 10:25:21 -050071Update User Privilege Via Redfish And Verify Using IPMI
72 [Documentation] Update user privilege via Redfish and verify using IPMI.
73 [Tags] Update_User_Privilege_Via_Redfish_And_Verify_Using_IPMI
74
75 # Create user using Redfish with admin privilege.
76 ${random_username}= Generate Random String 8 [LETTERS]
77 Set Test Variable ${random_username}
78
79 ${payload}= Create Dictionary
80 ... UserName=${random_username} Password=${valid_password}
81 ... RoleId=Administrator Enabled=${True}
82 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
83 ... valid_status_codes=[${HTTP_CREATED}]
84
85 # Update user privilege to operator using Redfish.
86 ${payload}= Create Dictionary RoleId=Operator
87 Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload}
88
89 # Verify new user privilege level via IPMI.
Tony Leec317c982020-05-20 15:46:35 +080090 ${resp}= Run IPMI Standard Command user list ${CHANNEL_NUMBER}
Rahul Maheshwariff63ac02019-03-29 10:25:21 -050091
92 # Example of response data:
93 # ID Name Callin Link Auth IPMI Msg Channel Priv Limit
94 # 1 root false true true ADMINISTRATOR
95 # 2 OAvCxjMv false true true OPERATOR
96 # 3 true false false NO ACCESS
97 # ..
98 # ..
99 # 15 true false false NO ACCESS
100
101 ${user_info}=
102 ... Get Lines Containing String ${resp} ${random_username}
103 Should Contain ${user_info} OPERATOR
104
105
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -0500106Delete User Via Redfish And Verify Using IPMI
107 [Documentation] Delete user via redfish and verify using IPMI.
108 [Tags] Delete_User_Via_Redfish_And_Verify_Using_IPMI
109
110 # Create user using Redfish.
111 ${random_username}= Generate Random String 8 [LETTERS]
112 Set Test Variable ${random_username}
113
114 ${payload}= Create Dictionary
115 ... UserName=${random_username} Password=${valid_password}
116 ... RoleId=Administrator Enabled=${True}
117 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
118 ... valid_status_codes=[${HTTP_CREATED}]
119
120 # Delete user using Redfish.
121 Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username}
122
123 # Verify that IPMI command fails with deleted user.
Anusha Dathatri652fc742020-02-05 05:14:21 -0600124 Run Keyword And Expect Error *Error: Unable to establish IPMI*
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -0500125 ... Verify IPMI Username And Password ${random_username} ${valid_password}
126
127
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500128Create IPMI User And Verify Login Via Redfish
129 [Documentation] Create user using IPMI and verify user login via Redfish.
130 [Tags] Create_IPMI_User_And_Verify_Login_Via_Redfish
131
132 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
133 ... ${valid_password} ${admin_level_priv}
134
Anusha Dathatri4d894652020-02-12 04:08:10 -0600135 Redfish.Logout
136
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500137 # Verify user login using Redfish.
138 Redfish.Login ${username} ${valid_password}
Anusha Dathatri4d894652020-02-12 04:08:10 -0600139 Redfish.Logout
140
141 Redfish.Login
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500142
143
144Update User Password Via IPMI And Verify Using Redfish
145 [Documentation] Update user password using IPMI and verify user
146 ... login via Redfish.
147 [Tags] Update_User_Password_Via_IPMI_And_Verify_Using_Redfish
148
149 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
150 ... ${valid_password} ${admin_level_priv}
151
152 # Update user password using IPMI.
153 Run IPMI Standard Command
154 ... user set password ${userid} ${valid_password2}
155
Anusha Dathatri4d894652020-02-12 04:08:10 -0600156 Redfish.Logout
157
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500158 # Verify that user login works with new password using Redfish.
159 Redfish.Login ${username} ${valid_password2}
Anusha Dathatri4d894652020-02-12 04:08:10 -0600160 Redfish.Logout
161
162 Redfish.Login
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500163
164
Rahul Maheshwari7b7ba222022-08-21 23:29:43 -0500165Update User Privilege To Operator Via IPMI And Verify Using Redfish
166 [Documentation] Update user privilege to operator via IPMI and verify using Redfish.
167 [Tags] Update_User_Privilege_To_Operator_Via_IPMI_And_Verify_Using_Redfish
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500168 # Create user using IPMI with admin privilege.
169 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
170 ... ${valid_password} ${admin_level_priv}
171
172 # Change user privilege to opetrator using IPMI.
173 Run IPMI Standard Command
Tony Lee69ed33e2020-05-20 17:15:02 +0800174 ... user priv ${userid} ${operator_level_priv} ${CHANNEL_NUMBER}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500175
176 # Verify new user privilege level via Redfish.
177 ${privilege}= Redfish_Utils.Get Attribute
178 ... /redfish/v1/AccountService/Accounts/${username} RoleId
179 Should Be Equal ${privilege} Operator
180
181
Rahul Maheshwari7b7ba222022-08-21 23:29:43 -0500182Update User Privilege To Readonly Via IPMI And Verify Using Redfish
183 [Documentation] Update user privilege to readonly via IPMI and verify using Redfish.
184 [Tags] Update_User_Privilege_To_Readonly_Via_IPMI_And_Verify_Using_Redfish
185
186 # Create user using IPMI with admin privilege.
187 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
188 ... ${valid_password} ${admin_level_priv}
189
190 # Change user privilege to readonly using IPMI.
191 Run IPMI Standard Command
192 ... user priv ${userid} ${readonly_level_priv} ${CHANNEL_NUMBER}
193
194 # Verify new user privilege level via Redfish.
195 ${privilege}= Redfish_Utils.Get Attribute
196 ... /redfish/v1/AccountService/Accounts/${username} RoleId
197 Should Be Equal ${privilege} ReadOnly
198
199
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500200Delete User Via IPMI And Verify Using Redfish
201 [Documentation] Delete user using IPMI and verify error while doing
202 ... user login with deleted user via Redfish.
203 [Tags] Delete_User_Via_IPMI_And_Verify_Using_Redfish
204
205 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
206 ... ${valid_password} ${admin_level_priv}
207
208 # Delete IPMI User.
209 Run IPMI Standard Command user set name ${userid} ""
210
211 # Verify that Redfish login fails with deleted user.
212 Run Keyword And Expect Error *InvalidCredentialsError*
213 ... Redfish.Login ${username} ${valid_password}
214
215
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500216Verify Failure To Exceed Max Number Of Users
217 [Documentation] Verify failure attempting to exceed the max number of user accounts.
218 [Tags] Verify_Failure_To_Exceed_Max_Number_Of_Users
nagarjunb132d29a2022-07-29 09:02:47 +0000219 [Teardown] Run Keywords Test Teardown Execution
220 ... AND Delete Users Via Redfish ${username_list}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500221
222 # Get existing user count.
223 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/
224 ${current_user_count}= Get From Dictionary ${resp.dict} Members@odata.count
225
226 ${payload}= Create Dictionary Password=${valid_password}
227 ... RoleId=Administrator Enabled=${True}
228
Ashwini Chandrappadfd48012022-04-06 06:33:37 -0500229 @{username_list}= Create List
230
ganesanb45102292023-03-28 11:13:29 +0000231 # Create users to reach maximum users count (i.e. 15 users).
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500232 FOR ${INDEX} IN RANGE ${current_user_count} ${max_num_users}
233 ${random_username}= Generate Random String 8 [LETTERS]
234 Set To Dictionary ${payload} UserName ${random_username}
235 Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
236 ... valid_status_codes=[${HTTP_CREATED}]
Ashwini Chandrappadfd48012022-04-06 06:33:37 -0500237 Append To List ${username_list} /redfish/v1/AccountService/Accounts/${random_username}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500238 END
239
Ashwini Chandrappadfd48012022-04-06 06:33:37 -0500240 # Verify error while creating 16th user.
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500241 ${random_username}= Generate Random String 8 [LETTERS]
242 Set To Dictionary ${payload} UserName ${random_username}
243 Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
244 ... valid_status_codes=[${HTTP_BAD_REQUEST}]
245
246
Anusha Dathatri9ecaaf42020-01-20 04:50:13 -0600247Create IPMI User Without Any Privilege And Verify Via Redfish
248 [Documentation] Create user using IPMI without privilege and verify via redfish.
249 [Tags] Create_IPMI_User_Without_Any_Privilege_And_Verify_Via_Redfish
250
251 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
252 ... ${valid_password}
253
254 # Verify new user privilege level via Redfish.
255 ${privilege}= Redfish_Utils.Get Attribute
256 ... /redfish/v1/AccountService/Accounts/${username} RoleId
257 Valid Value privilege ['NoAccess']
258
Rahul Maheshwari51dee262019-03-06 23:36:21 -0600259*** Keywords ***
260
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500261IPMI Create Random User Plus Password And Privilege
262 [Documentation] Create random IPMI user with given password and privilege
263 ... level.
Anusha Dathatri9ecaaf42020-01-20 04:50:13 -0600264 [Arguments] ${password} ${privilege}=0
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500265
266 # Description of argument(s):
267 # password Password to be assigned for the user.
268 # privilege Privilege level for the user (e.g. "1", "2", "3", etc.).
269
270 # Create IPMI user.
271 ${random_username}= Generate Random String 8 [LETTERS]
272 Set Suite Variable ${random_username}
273
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400274 ${random_userid}= Find Free User Id
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500275 IPMI Create User ${random_userid} ${random_username}
276
277 # Set given password for newly created user.
278 Run IPMI Standard Command
279 ... user set password ${random_userid} ${password}
280
281 # Enable IPMI user.
282 Run IPMI Standard Command user enable ${random_userid}
283
284 # Set given privilege and enable IPMI messaging for newly created user.
Anusha Dathatri9ecaaf42020-01-20 04:50:13 -0600285 Run Keyword If '${privilege}' != '0'
286 ... Set Channel Access ${random_userid} ipmi=on privilege=${privilege}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500287
288 [Return] ${random_username} ${random_userid}
289
290
nagarjunb132d29a2022-07-29 09:02:47 +0000291Delete Users Via Redfish
292 [Documentation] Delete all the users via redfish from given list.
293 [Arguments] ${user_list}
294
295 # Description of argument(s):
296 # user_list List of user which are to be deleted.
297
298 Redfish.Login
299
300 FOR ${user} IN @{user_list}
301 Redfish.Delete ${user}
302 END
303
304 Redfish.Logout
305
306
Rahul Maheshwari51dee262019-03-06 23:36:21 -0600307Test Setup Execution
308 [Documentation] Do test case setup tasks.
309
310 Redfish.Login
311
312
313Test Teardown Execution
314 [Documentation] Do the post test teardown.
315
316 FFDC On Test Case Fail
317 # Delete the test user.
318 Run Keyword And Ignore Error
319 ... Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username}
320
321 Redfish.Logout
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400322
323
324Find Free User Id
325 [Documentation] Find a userid that is not being used.
326 FOR ${jj} IN RANGE 300
George Keishingdc7d6892022-07-07 14:28:32 -0500327 # IPMI maximum users count (i.e. 15 users).
328 ${random_userid}= Evaluate random.randint(1, ${ipmi_max_num_users}) modules=random
Nagarjun B26499142023-02-16 15:20:14 +0530329 ${access}= Run IPMI Standard Command channel getaccess ${CHANNEL_NUMBER} ${random_userid}
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400330
331 ${name_line}= Get Lines Containing String ${access} User Name
332 Log To Console For ID ${random_userid}: ${name_line}
333 ${is_empty}= Run Keyword And Return Status
334 ... Should Match Regexp ${name_line} ${empty_name_pattern}
335
336 Exit For Loop If ${is_empty} == ${True}
337 END
338 Run Keyword If '${jj}' == '299' Fail msg=A free user ID could not be found.
339 [Return] ${random_userid}