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