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