xref: /openbmc/openbmc-test-automation/ipmi/test_ipmi_user.robot (revision c6e7f937468fda46e766b5eefd7afa7b44cbc362)
1*** Settings ***
2Documentation       Test suite for OpenBMC IPMI user management.
3
4Resource            ../lib/ipmi_client.robot
5Resource            ../lib/openbmc_ffdc.robot
6Resource            ../lib/bmc_network_utils.robot
7Library             ../lib/ipmi_utils.py
8Test Setup          Printn
9
10Suite Setup         Suite Setup Execution
11Test Teardown       Test Teardown Execution
12
13Test Tags          IPMI_User
14
15*** Variables ***
16
17${invalid_username}     user%
18${invalid_password}     abc123
19${new_username}         newuser
20${root_userid}          1
21${operator_level_priv}  0x3
22${user_priv}            2
23${operator_priv}        3
24${admin_level_priv}     4
25${valid_password}       0penBmc1
26${max_password_length}  20
27${ipmi_setaccess_cmd}   channel setaccess
28&{password_values}      16=0penBmc10penBmc2  17=0penBmc10penBmc2B
29              ...       20=0penBmc10penBmc2Bmc3  21=0penBmc10penBmc2Bmc34
30              ...       7=0penBmc  8=0penBmc0
31${expected_max_ids}     15
32${root_pattern}         ^.*\\sroot\\s.*ADMINISTRATOR.*$
33
34# User defined count.
35${USER_LOOP_COUNT}      20
36
37*** Test Cases ***
38
39Verify IPMI User Summary
40    [Documentation]  Verify IPMI maximum supported IPMI user ID and
41    ...  enabled user from user summary.
42    [Tags]  Verify_IPMI_User_Summary
43    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
44    ...  Delete Created User  ${random_userid}
45
46    ${initial_user_count}  ${maximum_ids}=  Get Enabled User Count
47
48    ${random_userid}  ${random_username}=  Create Random IPMI User
49    Set Test Variable  ${random_userid}
50    Run IPMI Standard Command  user enable ${random_userid}
51
52    # Enable IPMI user and verify
53    Enable IPMI User And Verify  ${random_userid}
54
55    # Verify number of currently enabled users.
56    ${current_user_count}  ${maximum_ids}=  Get Enabled User Count
57    ${calculated_count}=  Evaluate  ${initial_user_count} + 1
58    Should Be Equal As Integers  ${current_user_count}   ${calculated_count}
59
60    # Verify maximum user count IPMI local user can have.
61    Should Be Equal As Integers  ${maximum_ids}  ${expected_max_ids}
62
63
64Verify IPMI User List
65    [Documentation]  Verify user list via IPMI.
66    [Tags]  Verify_IPMI_User_List
67    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
68    ...  Delete Created User  ${random_userid}
69
70    ${random_userid}  ${random_username}=  Create Random IPMI User
71    Set Test Variable  ${random_userid}
72
73    Run IPMI Standard Command
74    ...  user set password ${random_userid} ${valid_password}
75    Run IPMI Standard Command  user enable ${random_userid}
76    # Delay added for IPMI user to get enabled.
77    Sleep  5s
78    # Set admin privilege and enable IPMI messaging for newly created user.
79    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
80
81    ${users_access}=  Get User Access Ipmi  ${CHANNEL_NUMBER}
82    Rprint Vars  users_access
83
84    ${index}=  Evaluate  ${random_userid} - 1
85    # Verify the user access of created user.
86    Valid Value  users_access[${index}]['id']  ['${random_userid}']
87    Valid Value  users_access[${index}]['name']  ['${random_username}']
88    Valid Value  users_access[${index}]['callin']  ['true']
89    Valid Value  users_access[${index}]['link']  ['false']
90    Valid Value  users_access[${index}]['auth']  ['true']
91    Valid Value  users_access[${index}]['ipmi']  ['ADMINISTRATOR']
92
93
94Verify IPMI User Creation With Valid Name And ID
95    [Documentation]  Create user via IPMI and verify.
96    [Tags]  Verify_IPMI_User_Creation_With_Valid_Name_And_ID
97    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
98    ...  Delete Created User  ${random_userid}
99
100    ${random_userid}  ${random_username}=  Create Random IPMI User
101    Set Test Variable  ${random_userid}
102
103
104Verify IPMI User Creation With Invalid Name
105    [Documentation]  Verify error while creating IPMI user with invalid
106    ...  name (e.g. user name with special characters).
107    [Tags]  Verify_IPMI_User_Creation_With_Invalid_Name
108
109    ${random_userid}=  Find Free User Id
110    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
111    ...  user set name ${random_userid} ${invalid_username}
112    Should Contain  ${msg}  Invalid data
113
114
115Verify IPMI User Creation With Invalid ID
116    [Documentation]  Verify error while creating IPMI user with invalid
117    ...  ID(i.e. any number greater than 15 or 0).
118    [Tags]  Verify_IPMI_User_Creation_With_Invalid_ID
119
120    @{id_list}=  Create List
121    ${random_invalid_id}=  Evaluate  random.randint(16, 1000)  modules=random
122    Append To List  ${id_list}  ${random_invalid_id}
123    Append To List  ${id_list}  0
124
125    FOR  ${id}  IN  @{id_list}
126      ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
127      ...  user set name ${id} newuser
128      Should Contain Any  ${msg}  User ID is limited to range  Parameter out of range
129    END
130
131
132Verify Setting IPMI User With Invalid Password
133    [Documentation]  Verify error while setting IPMI user with invalid password.
134    [Tags]  Verify_Setting_IPMI_User_With_Invalid_Password
135    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
136    ...  Delete Created User  ${random_userid}
137
138    ${random_userid}  ${random_username}=  Create Random IPMI User
139    Set Test Variable  ${random_userid}
140
141    # Set invalid password for newly created user.
142    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
143    ...  user set password ${random_userid} ${invalid_password}
144
145    # Delay added for user password to get set.
146    Sleep  5s
147
148    Should Contain  ${msg}  Set User Password command failed
149
150
151Verify Setting IPMI Root User With New Name
152    [Documentation]  Verify error while setting IPMI root user with new name.
153    [Tags]  Verify_Setting_IPMI_Root_User_With_New_Name
154
155    # Set invalid password for newly created user.
156    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
157    ...  user set name ${root_userid} abcd
158
159    Should Contain  ${msg}  Set User Name command failed
160
161
162Verify IPMI User Password Via Test Command
163    [Documentation]  Verify IPMI user password using test command.
164    [Tags]  Verify_IPMI_User_Password_Via_Test_Command
165    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
166    ...  Delete Created User  ${random_userid}
167
168    ${random_userid}  ${random_username}=  Create Random IPMI User
169    Set Test Variable  ${random_userid}
170
171    # Set valid password for newly created user.
172    Run IPMI Standard Command
173    ...  user set password ${random_userid} ${valid_password}
174
175    # Verify newly set password using test command.
176    ${msg}=  Run IPMI Standard Command
177    ...  user test ${random_userid} ${max_password_length} ${valid_password}
178
179    Should Contain  ${msg}  Success
180
181
182Verify Setting Valid Password For IPMI User
183    [Documentation]  Set valid password for IPMI user and verify.
184    [Tags]  Verify_Setting_Valid_Password_For_IPMI_User
185    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
186    ...  Delete Created User  ${random_userid}
187
188    ${random_userid}  ${random_username}=  Create Random IPMI User
189    Set Test Variable  ${random_userid}
190
191    # Set valid password for newly created user.
192    Run IPMI Standard Command
193    ...  user set password ${random_userid} ${valid_password}
194
195    Run IPMI Standard Command  user enable ${random_userid}
196
197    # Delay added for IPMI user to get enable
198    Sleep  5s
199
200    # Set admin privilege and enable IPMI messaging for newly created user
201    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
202
203    Verify IPMI Username And Password  ${random_username}  ${valid_password}
204
205
206Verify IPMI User Creation With Same Name
207    [Documentation]  Verify error while creating two IPMI user with same name.
208    [Tags]  Verify_IPMI_User_Creation_With_Same_Name
209    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
210    ...  Delete Created User  ${random_userid}
211
212    ${random_userid}  ${random_username}=  Create Random IPMI User
213
214    # Set same username for another IPMI user.
215    ${rand_userid_two}=  Find Free User Id
216    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
217    ...  user set name ${rand_userid_two} ${random_username}
218    Should Contain  ${msg}  Invalid data field in request
219
220
221Verify Setting IPMI User With Null Password
222    [Documentation]  Verify error while setting IPMI user with null
223    ...  password.
224    [Tags]  Verify_Setting_IPMI_User_With_Null_Password
225    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
226    ...  Delete Created User  ${random_userid}
227
228    ${random_userid}  ${random_username}=  Create Random IPMI User
229    Set Test Variable  ${random_userid}
230
231    # Set null password for newly created user.
232    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
233    ...  user set password ${random_userid} ""
234
235    Should Contain  ${msg}  Invalid data field in request
236
237
238Verify IPMI User Deletion
239    [Documentation]  Delete user via IPMI and verify.
240    [Tags]  Verify_IPMI_User_Deletion
241    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
242    ...  Delete Created User  ${random_userid}
243
244    ${random_userid}  ${random_username}=  Create Random IPMI User
245    Set Test Variable  ${random_userid}
246    # Delete IPMI User and verify
247    Run IPMI Standard Command  user set name ${random_userid} ""
248    ${user_info}=  Get User Info  ${random_userid}  ${CHANNEL_NUMBER}
249    Should Be Equal  ${user_info['user_name']}  ${EMPTY}
250
251
252Test IPMI User Privilege Level
253    [Documentation]  Verify IPMI user with user privilege can only run user level commands.
254    [Tags]  Test_IPMI_User_Privilege_Level
255    [Template]  Test IPMI User Privilege
256    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
257    ...  Delete Created User  ${random_userid}
258
259    #Privilege level     User Cmd Status  Operator Cmd Status  Admin Cmd Status
260    ${user_priv}         Passed           Failed               Failed
261
262
263Test IPMI Operator Privilege Level
264    [Documentation]  Verify IPMI user with operator privilege can only run user and
265    ...   operator level commands.
266    [Tags]  Test_IPMI_Operator_Privilege_Level
267    [Template]  Test IPMI User Privilege
268    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
269    ...  Delete Created User  ${random_userid}
270
271    #Privilege level     User Cmd Status  Operator Cmd Status  Admin Cmd Status
272    ${operator_priv}     Passed           Passed               Failed
273
274
275Test IPMI Administrator Privilege Level
276    [Documentation]  Verify IPMI user with admin privilege can run all levels command.
277    [Tags]  Test_IPMI_Administrator_Privilege_Level
278    [Template]  Test IPMI User Privilege
279    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
280    ...  Delete Created User  ${random_userid}
281
282    #Privilege level     User Cmd Status  Operator Cmd Status  Admin Cmd Status
283    ${admin_level_priv}  Passed           Passed               Passed
284
285
286Enable IPMI User And Verify
287    [Documentation]  Enable IPMI user and verify that the user is able
288    ...  to run IPMI command.
289    [Tags]  Enable_IPMI_User_And_Verify
290    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
291    ...  Delete Created User  ${random_userid}
292
293    ${random_userid}  ${random_username}=  Create Random IPMI User
294    Set Test Variable  ${random_userid}
295    Run IPMI Standard Command
296    ...  user set password ${random_userid} ${valid_password}
297
298    # Set admin privilege and enable IPMI messaging for newly created user.
299    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
300
301    # Delay added for user privilege to get set.
302    Sleep  5s
303
304    Enable IPMI User And Verify  ${random_userid}
305    Wait And Confirm New Username And Password  ${random_username}  ${valid_password}
306
307    # Verify that enabled IPMI  user is able to run IPMI command.
308    Verify IPMI Username And Password  ${random_username}  ${valid_password}
309
310
311Disable IPMI User And Verify
312    [Documentation]  Disable IPMI user and verify that that the user
313    ...  is unable to run IPMI command.
314    [Tags]  Disable_IPMI_User_And_Verify
315    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
316    ...  Delete Created User  ${random_userid}
317
318    ${random_userid}  ${random_username}=  Create Random IPMI User
319    Set Test Variable  ${random_userid}
320    Run IPMI Standard Command
321    ...  user set password ${random_userid} ${valid_password}
322
323    # Set admin privilege and enable IPMI messaging for newly created user.
324    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
325
326    # Disable IPMI user and verify.
327    Run IPMI Standard Command  user disable ${random_userid}
328    ${user_info}=  Get User Info  ${random_userid}  ${CHANNEL_NUMBER}
329    Should Be Equal  ${user_info['enable_status']}  disabled
330
331    # Verify that disabled IPMI  user is unable to run IPMI command.
332    ${msg}=  Run Keyword And Expect Error  *  Verify IPMI Username And Password
333    ...  ${random_username}  ${valid_password}
334    Should Contain  ${msg}  Unable to establish IPMI
335
336
337Verify IPMI Root User Password Change
338    [Documentation]  Change IPMI root user password and verify that
339    ...  root user is able to run IPMI command.
340    [Tags]  Verify_IPMI_Root_User_Password_Change
341    [Setup]  Skip if  len( '${OPENBMC_PASSWORD}' ) < 8
342    ...  msg= Do not run this test if len( OPENBMC_PASSWORD ) < 8
343    # Reason: if OPENBMC_PASSWORD is not at least 8 characters,
344    #         it cannot be restored in the Teardown step.
345    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
346    ...  Run Keyword If  "${TEST STATUS}" != "SKIP"
347    ...  Wait Until Keyword Succeeds  15 sec  5 sec
348    ...  Restore Default Password For IPMI Root User
349
350    # Set new password for root user.
351    Run IPMI Standard Command
352    ...  user set password ${root_userid} ${valid_password}
353
354    # Delay added for user password to get set.
355    Sleep  5s
356
357    # Verify that root user is able to run IPMI command using new password.
358    Wait Until Keyword Succeeds  15 sec  5 sec  Verify IPMI Username And Password
359    ...  root  ${valid_password}
360
361
362Verify Administrator And User Privilege For Different Channels
363    [Documentation]  Set administrator and user privilege for different channels and verify.
364    [Tags]  Verify_Administrator_And_User_Privilege_For_Different_Channels
365    [Setup]  Check Active Ethernet Channels
366    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
367    ...  Delete Created User  ${random_userid}
368
369    ${random_userid}  ${random_username}=  Create Random IPMI User
370    Set Test Variable  ${random_userid}
371    Run IPMI Standard Command
372    ...  user set password ${random_userid} ${valid_password}
373
374    # Set admin privilege for newly created user with channel 1.
375    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}  ${CHANNEL_NUMBER}
376
377    # Set user privilege for newly created user with channel 2.
378    Set Channel Access  ${random_userid}  ipmi=on privilege=${user_priv}  ${secondary_channel_number}
379
380    # Delay added for user privileges to get set.
381    Sleep  5s
382
383    Enable IPMI User And Verify  ${random_userid}
384
385    # Verify that user is able to run administrator level IPMI command with channel 1.
386    Verify IPMI Command  ${random_username}  ${valid_password}  Administrator  ${CHANNEL_NUMBER}
387
388    # Verify that user is unable to run IPMI command with channel 2.
389    Run IPMI Standard Command
390    ...  sel info ${secondary_channel_number}  expected_rc=${1}  U=${random_username}  P=${valid_password}
391
392
393Verify Operator And User Privilege For Different Channels
394    [Documentation]  Set operator and user privilege for different channels and verify.
395    [Tags]  Verify_Operator_And_User_Privilege_For_Different_Channels
396    [Setup]  Check Active Ethernet Channels
397    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
398    ...  Delete Created User  ${random_userid}
399
400    ${random_userid}  ${random_username}=  Create Random IPMI User
401    Set Test Variable  ${random_userid}
402    Run IPMI Standard Command
403    ...  user set password ${random_userid} ${valid_password}
404
405    # Set operator privilege for newly created user with channel 1.
406    Set Channel Access  ${random_userid}  ipmi=on privilege=${operator_priv}  ${CHANNEL_NUMBER}
407
408    # Set user privilege for newly created user with channel 2.
409    Set Channel Access  ${random_userid}  ipmi=on privilege=${user_priv}  ${secondary_channel_number}
410
411    # Delay added for user privileges to get set.
412    Sleep  5s
413
414    Enable IPMI User And Verify  ${random_userid}
415
416    # Verify that user is able to run operator level IPMI command with channel 1.
417    Verify IPMI Command  ${random_username}  ${valid_password}  Operator  ${CHANNEL_NUMBER}
418
419    # Verify that user is able to run user level IPMI command with channel 2.
420    Verify IPMI Command  ${random_username}  ${valid_password}  User  ${secondary_channel_number}
421
422
423Verify Setting IPMI User With Max Password Length
424    [Documentation]  Verify IPMI user creation with password length of 20 characters.
425    [Tags]  Verify_Setting_IPMI_User_With_Max_Password_Length
426    [Template]  Set User Password And Verify
427
428    # password_length  password_option  expected_status
429    20                 20               ${True}
430
431
432Verify Setting IPMI User With Invalid Password Length
433    [Documentation]  Verify that IPMI user cannot be set with 21 character password using 16 char
434    ...  or 20 char password option.
435    [Tags]  Verify_Setting_IPMI_User_With_Invalid_Password_Length
436    [Template]  Set User Password And Verify
437
438    # password_length  password_option  expected_status
439    21                 16               ${False}
440    21                 20               ${False}
441
442
443Verify Setting IPMI User With 16 Character Password
444    [Documentation]  Verify that IPMI user can create a 16 character password using 16 char or 20
445    ...  char password option.
446    [Tags]  Verify_Setting_IPMI_User_With_16_Character_Password
447    [Template]  Set User Password And Verify
448
449    # password_length  password_option  expected_status
450    16                 16               ${True}
451    16                 20               ${True}
452
453
454Verify Default Selection Of 16 Character Password For IPMI User
455    [Documentation]  Verify that ipmitool by default opts for the 16 character option when given a
456    ...  password whose length is in between 17 and 20.
457    [Tags]  Verify_Default_Selection_Of_16_Character_Password_For_IPMI_User
458    [Template]  Set User Password And Verify
459
460    # password_length  password_option  expected_status
461    17                 16               ${True}
462    20                 16               ${True}
463
464
465Verify Minimum Password Length For IPMI User
466    [Documentation]  Verify minimum password length of 8 characters.
467    [Tags]  Verify_Minimum_Password_Length_For_IPMI_User
468    [Template]  Set User Password And Verify
469
470    # password_length  password_option  expected_status
471    7                  16               ${False}
472    8                  16               ${True}
473    7                  20               ${False}
474    8                  20               ${True}
475
476
477Verify Continuous IPMI Command Execution
478    [Documentation]  Verify that continuous IPMI command execution runs fine.
479    [Tags]  Verify_Continuous_IPMI_Command_Execution
480
481    FOR  ${i}  IN RANGE  ${USER_LOOP_COUNT}
482        Run IPMI Standard Command  lan print ${CHANNEL_NUMBER}
483        Run IPMI Standard Command  power status
484        Run IPMI Standard Command  fru list
485        Run IPMI Standard Command  sel list
486    END
487
488
489Modify IPMI User
490    [Documentation]  Verify modified IPMI user is communicating via IPMI.
491    [Tags]  Modify_IPMI_User
492    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
493    ...  Delete Created User  ${random_userid}
494
495    ${random_userid}  ${random_username}=  Create Random IPMI User
496    Set Test Variable  ${random_userid}
497    Run IPMI Standard Command
498    ...  user set password ${random_userid} ${valid_password}
499
500    # Set admin privilege and enable IPMI messaging for newly created user.
501    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
502
503    # Delay added for user privilege to get set.
504    Sleep  5s
505
506    Enable IPMI User And Verify  ${random_userid}
507
508    # Verify that user is able to run administrator level IPMI command.
509    Verify IPMI Command  ${random_username}  ${valid_password}  Administrator  ${CHANNEL_NUMBER}
510
511    # Set different username for same IPMI user.
512    Run IPMI Standard Command
513    ...  user set name ${random_userid} ${new_username}
514    Wait And Confirm New Username And Password  ${new_username}  ${valid_password}
515
516    # Verify that user is able to run administrator level IPMI command.
517    Verify IPMI Command  ${new_username}  ${valid_password}  Administrator  ${CHANNEL_NUMBER}
518
519
520*** Keywords ***
521
522Restore Default Password For IPMI Root User
523    [Documentation]  Restore default password for IPMI root user
524
525    ${result}=  Run External IPMI Standard Command
526    ...  user set password ${root_userid} ${OPENBMC_PASSWORD}
527    ...  P=${valid_password}
528    Should Contain  ${result}  Set User Password command successful
529
530    # Verify that root user is able to run IPMI command using default password.
531    Verify IPMI Username And Password  root  ${OPENBMC_PASSWORD}
532
533
534Test IPMI User Privilege
535    [Documentation]  Test IPMI user privilege by executing IPMI command with different privileges.
536    [Arguments]  ${privilege_level}  ${user_cmd_status}  ${operator_cmd_status}  ${admin_cmd_status}
537
538    # Description of argument(s):
539    # privilege_level     Privilege level of IPMI user (e.g. 4, 3).
540    # user_cmd_status     Expected status of IPMI command run with the "User"
541    #                     privilege (i.e. "Passed" or "Failed").
542    # operator_cmd_status Expected status of IPMI command run with the "Operator"
543    #                     privilege (i.e. "Passed" or "Failed").
544    # admin_cmd_status    Expected status of IPMI command run with the "Administrator"
545    #                     privilege (i.e. "Passed" or "Failed").
546
547    # Create IPMI user and set valid password.
548    ${random_userid}  ${random_username}=  Create Random IPMI User
549    Set Test Variable  ${random_userid}
550    Run IPMI Standard Command
551    ...  user set password ${random_userid} ${valid_password}
552
553    # Set privilege and enable IPMI messaging for newly created user.
554    Set Channel Access  ${random_userid}  ipmi=on privilege=${privilege_level}
555
556    # Delay added for user privilege to get set.
557    Sleep  5s
558
559    Enable IPMI User And Verify  ${random_userid}
560
561    Verify IPMI Command  ${random_username}  ${valid_password}  User
562    ...  expected_status=${user_cmd_status}
563    Verify IPMI Command  ${random_username}  ${valid_password}  Operator
564    ...  expected_status=${operator_cmd_status}
565    Verify IPMI Command  ${random_username}  ${valid_password}  Administrator
566    ...  expected_status=${admin_cmd_status}
567
568
569Verify IPMI Command
570    [Documentation]  Verify IPMI command execution with given username,
571    ...  password, privilege and expected status.
572    [Arguments]  ${username}  ${password}  ${privilege}  ${channel}=${1}  ${expected_status}=Passed
573    # Description of argument(s):
574    # username         The user name (e.g. "root", "robert", etc.).
575    # password         The user password (e.g. "0penBmc", "0penBmc1", etc.).
576    # privilege        The session privilege for IPMI command (e.g. "User", "Operator", etc.).
577    # channel          The user channel number (e.g. "1" or "2").
578    # expected_status  Expected status of IPMI command run with the user
579    #                  of above password and privilege (i.e. "Passed" or "Failed").
580
581    ${expected_rc}=  Set Variable If  '${expected_status}' == 'Passed'  ${0}  ${1}
582    Wait Until Keyword Succeeds  15 sec  5 sec  Run IPMI Standard Command
583    ...  sel info ${channel}  expected_rc=${expected_rc}  U=${username}  P=${password}
584    ...  L=${privilege}
585
586
587Set User Password And Verify
588    [Documentation]  Create a user and set its password with given length and option.
589    [Arguments]  ${password_length}  ${password_option}  ${expected_result}
590    [Teardown]  Run Keyword  Delete Created User  ${random_userid}
591    # Description of argument(s):
592    # password_length  Length of password to be generated and used (e.g. "16").
593    # password_option  Password length option to be given in IPMI command (e.g. "16", "20").
594    # expected_result  Expected result for setting the user's password (e.g. "True", "False").
595
596    Rprint Vars  password_length  password_option  expected_result
597    ${random_userid}  ${random_username}=  Create Random IPMI User
598    Set Test Variable  ${random_userid}
599    ${password}=  Get From Dictionary  ${password_values}  ${password_length}
600    Rprint Vars  random_userid  password
601
602    # Set password for newly created user.
603    ${status}=  Run Keyword And Return Status  Run IPMI Standard Command
604    ...  user set password ${random_userid} ${password} ${password_option}
605    Rprint Vars  status
606    Valid Value  status  [${expected_result}]
607    IF  '${expected_result}' == '${False}'  RETURN
608
609    # Set admin privilege and enable IPMI messaging for newly created user.
610    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
611
612    # Delay added for user privilege to get set.
613    Sleep  5s
614
615    Enable IPMI User And Verify  ${random_userid}
616
617    # For password_option 16, passwords with length between 17 and 20 will be truncated.
618    # For all other cases, passwords will be retained as it is to verify.
619    ${truncated_password}=  Set Variable  ${password[:${password_option}]}
620    Rprint Vars  truncated_password
621    ${status}=  Run Keyword And Return Status  Verify IPMI Username And Password  ${random_username}
622    ...  ${truncated_password}
623    Rprint Vars  status
624    Valid Value  status  [${expected_result}]
625
626
627Test Teardown Execution
628    [Documentation]  Do the test teardown execution.
629
630    FFDC On Test Case Fail
631
632
633Check Active Ethernet Channels
634    [Documentation]  Check active ethernet channels and set suite variables.
635
636    ${channel_number_list}=  Get Active Ethernet Channel List
637    ${channel_length}=  Get Length  ${channel_number_list}
638    Skip If  '${channel_length}' == '1'
639    ...  msg= Skips this test case as only one channel was in active.
640
641    FOR  ${channel_num}  IN  @{channel_number_list}
642        ${secondary_channel_number}=  Set Variable If  ${channel_num} != ${CHANNEL_NUMBER}  ${channel_num}
643    END
644
645    Set Suite Variable  ${secondary_channel_number}
646
647
648Suite Setup Execution
649    [Documentation]  Make sure the enabled user count is below maximum,
650    ...  and prepares administrative user list suite variables.
651
652    Check Enabled User Count
653    # Skip root user checking if user decides not to use root user as default.
654    IF  '${IPMI_USERNAME}' == 'root'  Determine Root User Id
655
656
657Determine Root User Id
658    [Documentation]  Determines the user ID of the root user.
659
660    ${resp}=  Wait Until Keyword Succeeds  15 sec  1 sec  Run IPMI Standard Command
661    ...  user list ${CHANNEL_NUMBER}
662    @{lines}=  Split To Lines  ${resp}
663
664    ${root_userid}=  Set Variable  ${-1}
665    ${line_count}=  Get Length  ${lines}
666    FOR  ${id_index}  IN RANGE  1  ${line_count}
667        ${line}=  Get From List  ${lines}  ${id_index}
668        ${root_found}=  Get Lines Matching Regexp  ${line}  ${root_pattern}
669        IF  '${root_found}' != '${EMPTY}'
670            ${root_userid}=  Set Variable  ${id_index}
671            BREAK
672        END
673    END
674    Set Suite Variable  ${root_userid}
675
676    Log To Console  The root user ID is ${root_userid}.
677    IF  ${root_userid} < ${1}  Fail  msg= Did not identify root user ID.
678
679
680Wait And Confirm New Username And Password
681    [Documentation]  Wait in loop trying to to confirm Username And Password.
682    [Arguments]  ${username}  ${password}
683
684    # Description of argument(s):
685    # username         The user name (e.g. "root", "robert", etc.).
686    # password         The user password (e.g. "0penBmc", "0penBmc1", etc.).
687
688    # Give time for previous command to complete.
689    Sleep  5s
690
691    # Looping verify that root user is able to run IPMI command using new password.
692    Wait Until Keyword Succeeds  15 sec  5 sec  Verify IPMI Username And Password
693    ...  ${username}  ${password}
694
695
696Get Enabled User Count
697    [Documentation]  Return as integers: current number of enabled users and
698    ...  Maximum number of Ids.
699
700    # Isolate 'Enabled User Count' value and convert to integer
701    ${resp}=  Wait Until Keyword Succeeds  15 sec  1 sec  Run IPMI Standard Command
702    ...  user summary ${CHANNEL_NUMBER}
703    ${user_count_line}=  Get Lines Containing String  ${resp}  Enabled User Count
704    ${count}=  Fetch From Right  ${user_count_line}  \:
705    ${user_count}=  Convert To Integer  ${count}
706
707    # Isolate 'Maximum IDs' value and convert to integer
708    ${maximum_ids}=  Get Lines Containing String  ${resp}  Maximum IDs
709    ${max_ids}=  Fetch From Right  ${maximum_ids}  \:
710    ${int_maximum_ids_count}=  Convert To Integer  ${max_ids}
711
712    RETURN  ${user_count}  ${int_maximum_ids_count}
713