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
10Test Teardown       Test Teardown Execution
11
12*** Variables ***
13
14${invalid_username}     user%
15${invalid_password}     abc123
16${new_username}         newuser
17${root_userid}          1
18${operator_level_priv}  0x3
19${user_priv}            2
20${operator_priv}        3
21${admin_level_priv}     4
22${no_access_priv}       15
23${valid_password}       0penBmc1
24${max_password_length}  20
25${ipmi_setaccess_cmd}   channel setaccess
26&{password_values}      16=0penBmc10penBmc2  17=0penBmc10penBmc2B
27              ...       20=0penBmc10penBmc2Bmc3  21=0penBmc10penBmc2Bmc34
28              ...       7=0penBmc  8=0penBmc0
29
30# User defined count.
31${USER_LOOP_COUNT}      20
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    [Setup]  Check Active Ethernet Channels
368    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
369    ...  Delete Created User  ${random_userid}
370
371    ${random_userid}  ${random_username}=  Create Random IPMI User
372    Set Test Variable  ${random_userid}
373    Run IPMI Standard Command
374    ...  user set password ${random_userid} ${valid_password}
375
376    # Set admin privilege for newly created user with channel 1.
377    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}  ${CHANNEL_NUMBER}
378
379    # Set no access privilege for newly created user with channel 2.
380    Set Channel Access  ${random_userid}  ipmi=on privilege=${no_access_priv}  ${secondary_channel_number}
381
382    Enable IPMI User And Verify  ${random_userid}
383
384    # Verify that user is able to run administrator level IPMI command with channel 1.
385    Verify IPMI Command  ${random_username}  ${valid_password}  Administrator  ${CHANNEL_NUMBER}
386
387    # Verify that user is unable to run IPMI command with channel 2.
388    Run IPMI Standard Command  sel info ${secondary_channel_number}  expected_rc=${1}  U=${random_username}  P=${valid_password}
389
390
391Verify Operator And User Privilege For Different Channels
392    [Documentation]  Set operator and user privilege for different channels and verify.
393    [Tags]  Verify_Operator_And_User_Privilege_For_Different_Channels
394    [Setup]  Check Active Ethernet Channels
395    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
396    ...  Delete Created User  ${random_userid}
397
398    ${random_userid}  ${random_username}=  Create Random IPMI User
399    Set Test Variable  ${random_userid}
400    Run IPMI Standard Command
401    ...  user set password ${random_userid} ${valid_password}
402
403    # Set operator privilege for newly created user with channel 1.
404    Set Channel Access  ${random_userid}  ipmi=on privilege=${operator_priv}  ${CHANNEL_NUMBER}
405
406    # Set user privilege for newly created user with channel 2.
407    Set Channel Access  ${random_userid}  ipmi=on privilege=${user_priv}  ${secondary_channel_number}
408
409    Enable IPMI User And Verify  ${random_userid}
410
411    # Verify that user is able to run operator level IPMI command with channel 1.
412    Verify IPMI Command  ${random_username}  ${valid_password}  Operator  ${CHANNEL_NUMBER}
413
414    # Verify that user is able to run user level IPMI command with channel 2.
415    Verify IPMI Command  ${random_username}  ${valid_password}  User  ${secondary_channel_number}
416
417
418Verify Setting IPMI User With Max Password Length
419    [Documentation]  Verify IPMI user creation with password length of 20 characters.
420    [Tags]  Verify_Setting_IPMI_User_With_Max_Password_Length
421    [Template]  Set User Password And Verify
422
423    # password_length  password_option  expected_status
424    20                 20               ${True}
425
426
427Verify Setting IPMI User With Invalid Password Length
428    [Documentation]  Verify that IPMI user cannot be set with 21 character password using 16 char
429    ...  or 20 char password option.
430    [Tags]  Verify_Setting_IPMI_User_With_Invalid_Password_Length
431    [Template]  Set User Password And Verify
432
433    # password_length  password_option  expected_status
434    21                 16               ${False}
435    21                 20               ${False}
436
437
438Verify Setting IPMI User With 16 Character Password
439    [Documentation]  Verify that IPMI user can create a 16 character password using 16 char or 20
440    ...  char password option.
441    [Tags]  Verify_Setting_IPMI_User_With_16_Character_Password
442    [Template]  Set User Password And Verify
443
444    # password_length  password_option  expected_status
445    16                 16               ${True}
446    16                 20               ${True}
447
448
449Verify Default Selection Of 16 Character Password For IPMI User
450    [Documentation]  Verify that ipmitool by default opts for the 16 character option when given a
451    ...  password whose length is in between 17 and 20.
452    [Tags]  Verify_Default_Selection_Of_16_Character_Password_For_IPMI_User
453    [Template]  Set User Password And Verify
454
455    # password_length  password_option  expected_status
456    17                 16               ${True}
457    20                 16               ${True}
458
459
460Verify Minimum Password Length For IPMI User
461    [Documentation]  Verify minimum password length of 8 characters.
462    [Tags]  Verify_Minimum_Password_Length_For_IPMI_User
463    [Template]  Set User Password And Verify
464
465    # password_length  password_option  expected_status
466    7                  16               ${False}
467    8                  16               ${True}
468    7                  20               ${False}
469    8                  20               ${True}
470
471
472Verify Continuous IPMI Command Execution
473    [Documentation]  Verify that continuous IPMI command execution runs fine.
474    [Tags]  Verify_Continuous_IPMI_Command_Execution
475
476    FOR  ${i}  IN RANGE  ${USER_LOOP_COUNT}
477        Run IPMI Standard Command  lan print
478        Run IPMI Standard Command  power status
479        Run IPMI Standard Command  fru list
480        Run IPMI Standard Command  sel list
481    END
482
483
484Modify IPMI User
485    [Documentation]  Verify modified IPMI user is communicating via IPMI.
486    [Tags]  Modify_IPMI_User
487    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
488    ...  Delete Created User  ${random_userid}
489
490    ${random_userid}  ${random_username}=  Create Random IPMI User
491    Set Test Variable  ${random_userid}
492    Run IPMI Standard Command
493    ...  user set password ${random_userid} ${valid_password}
494
495    # Set admin privilege and enable IPMI messaging for newly created user.
496    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
497
498    # Delay added for user privilege to get set.
499    Sleep  5s
500
501    Enable IPMI User And Verify  ${random_userid}
502
503    # Verify that user is able to run administrator level IPMI command.
504    Verify IPMI Command  ${random_username}  ${valid_password}  Administrator  ${CHANNEL_NUMBER}
505
506    # Set different username for same IPMI user.
507    Run IPMI Standard Command
508    ...  user set name ${random_userid} ${new_username}
509
510    # Verify that user is able to run administrator level IPMI command.
511    Verify IPMI Command  ${new_username}  ${valid_password}  Administrator  ${CHANNEL_NUMBER}
512
513
514*** Keywords ***
515
516Create Random IPMI User
517    [Documentation]  Create IPMI user with random username and userid and return those fields.
518
519    ${random_username}=  Generate Random String  8  [LETTERS]
520    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
521    IPMI Create User  ${random_userid}  ${random_username}
522    [Return]  ${random_userid}  ${random_username}
523
524
525Enable IPMI User And Verify
526    [Documentation]  Enable the userid and verify that it has been enabled.
527    [Arguments]  ${userid}
528
529    # Description of argument(s):
530    # userid   A numeric userid (e.g. "4").
531
532    Run IPMI Standard Command  user enable ${userid}
533    ${user_info}=  Get User Info  ${userid}
534    Valid Value  user_info['enable_status']  ['enabled']
535
536
537Set Default Password For IPMI Root User
538    [Documentation]  Set default password for IPMI root user (i.e. 0penBmc).
539    # Set default password for root user.
540    ${result}=  Run External IPMI Standard Command
541    ...  user set password ${root_userid} ${OPENBMC_PASSWORD}
542    ...  P=${valid_password}
543    Should Contain  ${result}  Set User Password command successful
544
545    # Verify that root user is able to run IPMI command using default password.
546    Verify IPMI Username And Password  root  ${OPENBMC_PASSWORD}
547
548
549Test IPMI User Privilege
550    [Documentation]  Test IPMI user privilege by executing IPMI command with different privileges.
551    [Arguments]  ${privilege_level}  ${user_cmd_status}  ${operator_cmd_status}  ${admin_cmd_status}
552
553    # Description of argument(s):
554    # privilege_level     Privilege level of IPMI user (e.g. 4, 3).
555    # user_cmd_status     Expected status of IPMI command run with the "User"
556    #                     privilege (i.e. "Passed" or "Failed").
557    # operator_cmd_status Expected status of IPMI command run with the "Operator"
558    #                     privilege (i.e. "Passed" or "Failed").
559    # admin_cmd_status    Expected status of IPMI command run with the "Administrator"
560    #                     privilege (i.e. "Passed" or "Failed").
561
562    # Create IPMI user and set valid password.
563    ${random_username}=  Generate Random String  8  [LETTERS]
564    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
565    IPMI Create User  ${random_userid}  ${random_username}
566    Set Test Variable  ${random_userid}
567    Run IPMI Standard Command
568    ...  user set password ${random_userid} ${valid_password}
569
570    # Set privilege and enable IPMI messaging for newly created user.
571    Set Channel Access  ${random_userid}  ipmi=on privilege=${privilege_level}
572
573    # Delay added for user privilege to get set.
574    Sleep  5s
575
576    Enable IPMI User And Verify  ${random_userid}
577
578    Verify IPMI Command  ${random_username}  ${valid_password}  User
579    ...  expected_status=${user_cmd_status}
580    Verify IPMI Command  ${random_username}  ${valid_password}  Operator
581    ...  expected_status=${operator_cmd_status}
582    Verify IPMI Command  ${random_username}  ${valid_password}  Administrator
583    ...  expected_status=${admin_cmd_status}
584
585
586Verify IPMI Command
587    [Documentation]  Verify IPMI command execution with given username,
588    ...  password, privilege and expected status.
589    [Arguments]  ${username}  ${password}  ${privilege}  ${channel}=${1}  ${expected_status}=Passed
590    # Description of argument(s):
591    # username         The user name (e.g. "root", "robert", etc.).
592    # password         The user password (e.g. "0penBmc", "0penBmc1", etc.).
593    # privilege        The session privilege for IPMI command (e.g. "User", "Operator", etc.).
594    # channel          The user channel number (e.g. "1" or "2").
595    # expected_status  Expected status of IPMI command run with the user
596    #                  of above password and privilege (i.e. "Passed" or "Failed").
597
598    ${expected_rc}=  Set Variable If  '${expected_status}' == 'Passed'  ${0}  ${1}
599    Wait Until Keyword Succeeds  15 sec  5 sec  Run IPMI Standard Command
600    ...  sel info ${channel}  expected_rc=${expected_rc}  U=${username}  P=${password}
601    ...  L=${privilege}
602
603
604Set User Password And Verify
605    [Documentation]  Create a user and set its password with given length and option.
606    [Arguments]  ${password_length}  ${password_option}  ${expected_result}
607    [Teardown]  Run Keyword  Delete Created User  ${random_userid}
608    # Description of argument(s):
609    # password_length  Length of password to be generated and used (e.g. "16").
610    # password_option  Password length option to be given in IPMI command (e.g. "16", "20").
611    # expected_result  Expected result for setting the user's password (e.g. "True", "False").
612
613    Rprint Vars  password_length  password_option  expected_result
614    ${random_userid}  ${random_username}=  Create Random IPMI User
615    Set Test Variable  ${random_userid}
616    ${password}=  Get From Dictionary  ${password_values}  ${password_length}
617    Rprint Vars  random_userid  password
618
619    # Set password for newly created user.
620    ${status}=  Run Keyword And Return Status  Run IPMI Standard Command
621    ...  user set password ${random_userid} ${password} ${password_option}
622    Rprint Vars  status
623    Valid Value  status  [${expected_result}]
624    Return From Keyword If  '${expected_result}' == '${False}'
625
626    # Set admin privilege and enable IPMI messaging for newly created user.
627    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
628
629    # Delay added for user privilege to get set.
630    Sleep  5s
631
632    Enable IPMI User And Verify  ${random_userid}
633
634    # For password_option 16, passwords with length between 17 and 20 will be truncated.
635    # For all other cases, passwords will be retained as it is to verify.
636    ${truncated_password}=  Set Variable  ${password[:${password_option}]}
637    Rprint Vars  truncated_password
638    ${status}=  Run Keyword And Return Status  Verify IPMI Username And Password  ${random_username}
639    ...  ${truncated_password}
640    Rprint Vars  status
641    Valid Value  status  [${expected_result}]
642
643
644Test Teardown Execution
645    [Documentation]  Do the test teardown execution.
646
647    FFDC On Test Case Fail
648
649
650Delete Created User
651    [Documentation]  Delete created IPMI user.
652    [Arguments]  ${userid}
653    # Description of argument(s):
654    # userid  The user ID (e.g. "1", "2", etc.).
655
656    Run IPMI Standard Command  user set name ${userid} ""
657    Sleep  5s
658
659
660Check Active Ethernet Channels
661    [Documentation]  Check active ethernet channels and set suite variables.
662
663    ${channel_number_list}=  Get Active Ethernet Channel List
664    ${channel_length}=  Get Length  ${channel_number_list}
665    Skip If  '${channel_length}' == '1'
666    ...  msg= Skips this test case as only one channel was in active.
667
668    FOR  ${channel_num}  IN  @{channel_number_list}
669        ${secondary_channel_number}=  Set Variable If  ${channel_num} != ${CHANNEL_NUMBER}  ${channel_num}
670    END
671
672    Set Suite Variable  ${secondary_channel_number}
673