blob: 0e959218eac8ef686f7b4b405d1060f455209e9d [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
Sridevi Ramesh5f352dc2025-06-26 10:13:19 -050021${user_count} 0
George Keishingdc7d6892022-07-07 14:28:32 -050022${ipmi_max_num_users} ${15}
ganesanb45102292023-03-28 11:13:29 +000023${max_num_users} ${15}
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -040024${empty_name_pattern} ^User Name\\s.*\\s:\\s$
Rahul Maheshwari51dee262019-03-06 23:36:21 -060025
Sridevi Ramesh5f352dc2025-06-26 10:13:19 -050026*** Test Cases ***
Rahul Maheshwari51dee262019-03-06 23:36:21 -060027
28Create Admin Redfish User And Verify Login Via IPMI
29 [Documentation] Create user using redfish and verify via IPMI.
30 [Tags] Create_Admin_Redfish_User_And_Verify_Login_Via_IPMI
31
32 ${random_username}= Generate Random String 8 [LETTERS]
33 Set Test Variable ${random_username}
34
35 ${payload}= Create Dictionary
36 ... UserName=${random_username} Password=${valid_password}
37 ... RoleId=Administrator Enabled=${True}
38 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
39 ... valid_status_codes=[${HTTP_CREATED}]
40
Sushma M M97fccae2020-07-27 14:55:19 -050041 # Delay added for created new user password to get set.
42 Sleep 5s
43
Rahul Maheshwari51dee262019-03-06 23:36:21 -060044 Verify IPMI Username And Password ${random_username} ${valid_password}
45
46
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -050047Update User Password Via Redfish And Verify Using IPMI
48 [Documentation] Update user password via Redfish and verify using IPMI.
49 [Tags] Update_User_Password_Via_Redfish_And_Verify_Using_IPMI
50
51 # Create user using Redfish.
52 ${random_username}= Generate Random String 8 [LETTERS]
53 Set Test Variable ${random_username}
54
55 ${payload}= Create Dictionary
56 ... UserName=${random_username} Password=${valid_password}
57 ... RoleId=Administrator Enabled=${True}
58 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
59 ... valid_status_codes=[${HTTP_CREATED}]
60
61 # Update user password using Redfish.
62 ${payload}= Create Dictionary Password=${valid_password2}
63 Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload}
64
65 # Verify that IPMI command works with new password and fails with older password.
66 Verify IPMI Username And Password ${random_username} ${valid_password2}
67
Anusha Dathatri652fc742020-02-05 05:14:21 -060068 Run Keyword And Expect Error *Error: Unable to establish IPMI*
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -050069 ... Verify IPMI Username And Password ${random_username} ${valid_password}
70
71
Rahul Maheshwariff63ac02019-03-29 10:25:21 -050072Update User Privilege Via Redfish And Verify Using IPMI
73 [Documentation] Update user privilege via Redfish and verify using IPMI.
74 [Tags] Update_User_Privilege_Via_Redfish_And_Verify_Using_IPMI
75
76 # Create user using Redfish with admin privilege.
77 ${random_username}= Generate Random String 8 [LETTERS]
78 Set Test Variable ${random_username}
79
80 ${payload}= Create Dictionary
81 ... UserName=${random_username} Password=${valid_password}
82 ... RoleId=Administrator Enabled=${True}
83 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
84 ... valid_status_codes=[${HTTP_CREATED}]
85
86 # Update user privilege to operator using Redfish.
87 ${payload}= Create Dictionary RoleId=Operator
88 Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload}
89
90 # Verify new user privilege level via IPMI.
Tony Leec317c982020-05-20 15:46:35 +080091 ${resp}= Run IPMI Standard Command user list ${CHANNEL_NUMBER}
Rahul Maheshwariff63ac02019-03-29 10:25:21 -050092
93 # Example of response data:
94 # ID Name Callin Link Auth IPMI Msg Channel Priv Limit
95 # 1 root false true true ADMINISTRATOR
96 # 2 OAvCxjMv false true true OPERATOR
97 # 3 true false false NO ACCESS
98 # ..
99 # ..
100 # 15 true false false NO ACCESS
101
102 ${user_info}=
103 ... Get Lines Containing String ${resp} ${random_username}
104 Should Contain ${user_info} OPERATOR
105
106
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -0500107Delete User Via Redfish And Verify Using IPMI
108 [Documentation] Delete user via redfish and verify using IPMI.
109 [Tags] Delete_User_Via_Redfish_And_Verify_Using_IPMI
110
111 # Create user using Redfish.
112 ${random_username}= Generate Random String 8 [LETTERS]
113 Set Test Variable ${random_username}
114
115 ${payload}= Create Dictionary
116 ... UserName=${random_username} Password=${valid_password}
117 ... RoleId=Administrator Enabled=${True}
118 Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload}
119 ... valid_status_codes=[${HTTP_CREATED}]
120
121 # Delete user using Redfish.
122 Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username}
123
124 # Verify that IPMI command fails with deleted user.
Anusha Dathatri652fc742020-02-05 05:14:21 -0600125 Run Keyword And Expect Error *Error: Unable to establish IPMI*
Rahul Maheshwaricf2336e2019-03-15 00:49:13 -0500126 ... Verify IPMI Username And Password ${random_username} ${valid_password}
127
128
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500129Create IPMI User And Verify Login Via Redfish
130 [Documentation] Create user using IPMI and verify user login via Redfish.
131 [Tags] Create_IPMI_User_And_Verify_Login_Via_Redfish
132
133 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
134 ... ${valid_password} ${admin_level_priv}
135
Anusha Dathatri4d894652020-02-12 04:08:10 -0600136 Redfish.Logout
137
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500138 # Verify user login using Redfish.
139 Redfish.Login ${username} ${valid_password}
Anusha Dathatri4d894652020-02-12 04:08:10 -0600140 Redfish.Logout
141
142 Redfish.Login
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500143
144
145Update User Password Via IPMI And Verify Using Redfish
146 [Documentation] Update user password using IPMI and verify user
147 ... login via Redfish.
148 [Tags] Update_User_Password_Via_IPMI_And_Verify_Using_Redfish
149
150 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
151 ... ${valid_password} ${admin_level_priv}
152
153 # Update user password using IPMI.
154 Run IPMI Standard Command
155 ... user set password ${userid} ${valid_password2}
156
Anusha Dathatri4d894652020-02-12 04:08:10 -0600157 Redfish.Logout
158
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500159 # Verify that user login works with new password using Redfish.
160 Redfish.Login ${username} ${valid_password2}
Anusha Dathatri4d894652020-02-12 04:08:10 -0600161 Redfish.Logout
162
163 Redfish.Login
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500164
165
Rahul Maheshwari7b7ba222022-08-21 23:29:43 -0500166Update User Privilege To Operator Via IPMI And Verify Using Redfish
167 [Documentation] Update user privilege to operator via IPMI and verify using Redfish.
168 [Tags] Update_User_Privilege_To_Operator_Via_IPMI_And_Verify_Using_Redfish
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500169 # Create user using IPMI with admin privilege.
170 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
171 ... ${valid_password} ${admin_level_priv}
172
173 # Change user privilege to opetrator using IPMI.
174 Run IPMI Standard Command
Tony Lee69ed33e2020-05-20 17:15:02 +0800175 ... user priv ${userid} ${operator_level_priv} ${CHANNEL_NUMBER}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500176
177 # Verify new user privilege level via Redfish.
178 ${privilege}= Redfish_Utils.Get Attribute
179 ... /redfish/v1/AccountService/Accounts/${username} RoleId
180 Should Be Equal ${privilege} Operator
181
182
Rahul Maheshwari7b7ba222022-08-21 23:29:43 -0500183Update User Privilege To Readonly Via IPMI And Verify Using Redfish
184 [Documentation] Update user privilege to readonly via IPMI and verify using Redfish.
185 [Tags] Update_User_Privilege_To_Readonly_Via_IPMI_And_Verify_Using_Redfish
186
187 # Create user using IPMI with admin privilege.
188 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
189 ... ${valid_password} ${admin_level_priv}
190
191 # Change user privilege to readonly using IPMI.
192 Run IPMI Standard Command
193 ... user priv ${userid} ${readonly_level_priv} ${CHANNEL_NUMBER}
194
195 # Verify new user privilege level via Redfish.
196 ${privilege}= Redfish_Utils.Get Attribute
197 ... /redfish/v1/AccountService/Accounts/${username} RoleId
198 Should Be Equal ${privilege} ReadOnly
199
200
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500201Delete User Via IPMI And Verify Using Redfish
202 [Documentation] Delete user using IPMI and verify error while doing
203 ... user login with deleted user via Redfish.
204 [Tags] Delete_User_Via_IPMI_And_Verify_Using_Redfish
205
206 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
207 ... ${valid_password} ${admin_level_priv}
208
209 # Delete IPMI User.
210 Run IPMI Standard Command user set name ${userid} ""
211
212 # Verify that Redfish login fails with deleted user.
213 Run Keyword And Expect Error *InvalidCredentialsError*
214 ... Redfish.Login ${username} ${valid_password}
215
216
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500217Verify Failure To Exceed Max Number Of Users
Sridevi Ramesh5f352dc2025-06-26 10:13:19 -0500218 [Documentation] Verify failure attempting to exceed the max number of
219 ... user accounts.
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500220 [Tags] Verify_Failure_To_Exceed_Max_Number_Of_Users
nagarjunb132d29a2022-07-29 09:02:47 +0000221 [Teardown] Run Keywords Test Teardown Execution
222 ... AND Delete Users Via Redfish ${username_list}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500223
224 # Get existing user count.
Sridevi Ramesh5f352dc2025-06-26 10:13:19 -0500225 ${existing_user_count}= Get User Count Of Not IPMI Account Type
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500226
227 ${payload}= Create Dictionary Password=${valid_password}
228 ... RoleId=Administrator Enabled=${True}
229
Ashwini Chandrappadfd48012022-04-06 06:33:37 -0500230 @{username_list}= Create List
231
ganesanb45102292023-03-28 11:13:29 +0000232 # Create users to reach maximum users count (i.e. 15 users).
Sridevi Ramesh5f352dc2025-06-26 10:13:19 -0500233 FOR ${INDEX} IN RANGE ${existing_user_count} ${max_num_users}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500234 ${random_username}= Generate Random String 8 [LETTERS]
235 Set To Dictionary ${payload} UserName ${random_username}
236 Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
237 ... valid_status_codes=[${HTTP_CREATED}]
Ashwini Chandrappadfd48012022-04-06 06:33:37 -0500238 Append To List ${username_list} /redfish/v1/AccountService/Accounts/${random_username}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500239 END
240
Ashwini Chandrappadfd48012022-04-06 06:33:37 -0500241 # Verify error while creating 16th user.
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500242 ${random_username}= Generate Random String 8 [LETTERS]
243 Set To Dictionary ${payload} UserName ${random_username}
244 Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
245 ... valid_status_codes=[${HTTP_BAD_REQUEST}]
246
247
Anusha Dathatri9ecaaf42020-01-20 04:50:13 -0600248Create IPMI User Without Any Privilege And Verify Via Redfish
249 [Documentation] Create user using IPMI without privilege and verify via redfish.
250 [Tags] Create_IPMI_User_Without_Any_Privilege_And_Verify_Via_Redfish
251
252 ${username} ${userid}= IPMI Create Random User Plus Password And Privilege
253 ... ${valid_password}
254
255 # Verify new user privilege level via Redfish.
256 ${privilege}= Redfish_Utils.Get Attribute
257 ... /redfish/v1/AccountService/Accounts/${username} RoleId
kothais42b2e302023-11-03 06:56:08 +0000258 Valid Value privilege ['ReadOnly']
Anusha Dathatri9ecaaf42020-01-20 04:50:13 -0600259
Rahul Maheshwari51dee262019-03-06 23:36:21 -0600260*** Keywords ***
261
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500262IPMI Create Random User Plus Password And Privilege
263 [Documentation] Create random IPMI user with given password and privilege
264 ... level.
Anusha Dathatri9ecaaf42020-01-20 04:50:13 -0600265 [Arguments] ${password} ${privilege}=0
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500266
267 # Description of argument(s):
268 # password Password to be assigned for the user.
269 # privilege Privilege level for the user (e.g. "1", "2", "3", etc.).
270
271 # Create IPMI user.
272 ${random_username}= Generate Random String 8 [LETTERS]
273 Set Suite Variable ${random_username}
274
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400275 ${random_userid}= Find Free User Id
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500276 IPMI Create User ${random_userid} ${random_username}
277
278 # Set given password for newly created user.
279 Run IPMI Standard Command
280 ... user set password ${random_userid} ${password}
281
282 # Enable IPMI user.
283 Run IPMI Standard Command user enable ${random_userid}
284
285 # Set given privilege and enable IPMI messaging for newly created user.
George Keishing79fc7f02025-05-02 00:37:49 +0530286 IF '${privilege}' != '0'
287 Set Channel Access ${random_userid} ipmi=on privilege=${privilege}
288 END
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500289
George Keishing409df052024-01-17 22:36:14 +0530290 RETURN ${random_username} ${random_userid}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500291
292
nagarjunb132d29a2022-07-29 09:02:47 +0000293Delete Users Via Redfish
294 [Documentation] Delete all the users via redfish from given list.
295 [Arguments] ${user_list}
296
297 # Description of argument(s):
298 # user_list List of user which are to be deleted.
299
300 Redfish.Login
301
302 FOR ${user} IN @{user_list}
303 Redfish.Delete ${user}
304 END
305
306 Redfish.Logout
307
308
Rahul Maheshwari51dee262019-03-06 23:36:21 -0600309Test Setup Execution
310 [Documentation] Do test case setup tasks.
311
312 Redfish.Login
313
314
315Test Teardown Execution
316 [Documentation] Do the post test teardown.
317
318 FFDC On Test Case Fail
319 # Delete the test user.
320 Run Keyword And Ignore Error
321 ... Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username}
322
323 Redfish.Logout
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400324
325
326Find Free User Id
327 [Documentation] Find a userid that is not being used.
328 FOR ${jj} IN RANGE 300
George Keishingdc7d6892022-07-07 14:28:32 -0500329 # IPMI maximum users count (i.e. 15 users).
330 ${random_userid}= Evaluate random.randint(1, ${ipmi_max_num_users}) modules=random
Nagarjun B26499142023-02-16 15:20:14 +0530331 ${access}= Run IPMI Standard Command channel getaccess ${CHANNEL_NUMBER} ${random_userid}
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400332
333 ${name_line}= Get Lines Containing String ${access} User Name
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400334 ${is_empty}= Run Keyword And Return Status
335 ... Should Match Regexp ${name_line} ${empty_name_pattern}
336
Sridevi Rameshb0a5a6d2025-04-30 07:14:07 -0500337 IF ${is_empty} == ${True} BREAK
Gene Ratzlaffd4cdc112022-05-06 13:17:35 -0400338 END
George Keishing79fc7f02025-05-02 00:37:49 +0530339 IF '${jj}' == '299' Fail msg=A free user ID could not be found.
George Keishing409df052024-01-17 22:36:14 +0530340 RETURN ${random_userid}
Sridevi Ramesh5f352dc2025-06-26 10:13:19 -0500341
342
343Get All User Account Names
344 [Documentation] Get all user account names in list format.
345
346 @{username_list}= Create List
347 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/
348 ${current_users}= Get From Dictionary ${resp.dict} Members
349 FOR ${user} IN @{current_users}
350 ${output}= Split String ${user["@odata.id"]} /redfish/v1/AccountService/Accounts/
351 Append To List ${username_list} ${output[1]}
352 END
353 RETURN ${username_list}
354
355
356Get User Count Of Not IPMI Account Type
357 [Documentation] Get user count of not IPMI account type.
358
359 ${username_list}= Get All User Account Names
360 FOR ${user} IN @{username_list}
361 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/${user}
362 @{account_type}= Get From Dictionary ${resp.dict} AccountTypes
363 IF "IPMI" not in ${account_type}
364 ${user_count}= Evaluate ${user_count} + 1
365 END
366 END
367 RETURN ${user_count}