xref: /openbmc/openbmc-test-automation/redfish/account_service/test_ipmi_redfish_user.robot (revision 79fc7f0883398ca6695e2d6e5a200da8d8658289)
151dee266SRahul Maheshwari*** Settings ***
251dee266SRahul MaheshwariDocumentation    Test IPMI and Redfish combinations for user management.
351dee266SRahul Maheshwari
451dee266SRahul MaheshwariResource         ../../lib/resource.robot
551dee266SRahul MaheshwariResource         ../../lib/bmc_redfish_resource.robot
651dee266SRahul MaheshwariResource         ../../lib/openbmc_ffdc.robot
751dee266SRahul MaheshwariResource         ../../lib/ipmi_client.robot
875e91feaSRahul MaheshwariLibrary          ../lib/ipmi_utils.py
951dee266SRahul Maheshwari
1051dee266SRahul MaheshwariTest Setup       Test Setup Execution
1151dee266SRahul MaheshwariTest Teardown    Test Teardown Execution
1251dee266SRahul Maheshwari
1351dee266SRahul Maheshwari
1451dee266SRahul Maheshwari*** Variables ***
1551dee266SRahul Maheshwari
1651dee266SRahul Maheshwari${valid_password}       0penBmc1
17cf2336e0SRahul Maheshwari${valid_password2}      0penBmc2
1875e91feaSRahul Maheshwari${admin_level_priv}     4
1975e91feaSRahul Maheshwari${operator_level_priv}  3
207b7ba223SRahul Maheshwari${readonly_level_priv}  2
21dc7d6893SGeorge Keishing${ipmi_max_num_users}   ${15}
2245102295Sganesanb${max_num_users}        ${15}
23d4cdc11fSGene Ratzlaff${empty_name_pattern}   ^User Name\\s.*\\s:\\s$
2451dee266SRahul Maheshwari
2551dee266SRahul Maheshwari** Test Cases **
2651dee266SRahul Maheshwari
2751dee266SRahul MaheshwariCreate Admin Redfish User And Verify Login Via IPMI
2851dee266SRahul Maheshwari    [Documentation]  Create user using redfish and verify via IPMI.
2951dee266SRahul Maheshwari    [Tags]  Create_Admin_Redfish_User_And_Verify_Login_Via_IPMI
3051dee266SRahul Maheshwari
3151dee266SRahul Maheshwari    ${random_username}=  Generate Random String  8  [LETTERS]
3251dee266SRahul Maheshwari    Set Test Variable  ${random_username}
3351dee266SRahul Maheshwari
3451dee266SRahul Maheshwari    ${payload}=  Create Dictionary
3551dee266SRahul Maheshwari    ...  UserName=${random_username}  Password=${valid_password}
3651dee266SRahul Maheshwari    ...  RoleId=Administrator  Enabled=${True}
3751dee266SRahul Maheshwari    Redfish.Post  /redfish/v1/AccountService/Accounts  body=&{payload}
3851dee266SRahul Maheshwari    ...  valid_status_codes=[${HTTP_CREATED}]
3951dee266SRahul Maheshwari
4097fccae8SSushma M M    # Delay added for created new user password to get set.
4197fccae8SSushma M M    Sleep  5s
4297fccae8SSushma M M
4351dee266SRahul Maheshwari    Verify IPMI Username And Password  ${random_username}  ${valid_password}
4451dee266SRahul Maheshwari
4551dee266SRahul Maheshwari
46cf2336e0SRahul MaheshwariUpdate User Password Via Redfish And Verify Using IPMI
47cf2336e0SRahul Maheshwari    [Documentation]  Update user password via Redfish and verify using IPMI.
48cf2336e0SRahul Maheshwari    [Tags]  Update_User_Password_Via_Redfish_And_Verify_Using_IPMI
49cf2336e0SRahul Maheshwari
50cf2336e0SRahul Maheshwari    # Create user using Redfish.
51cf2336e0SRahul Maheshwari    ${random_username}=  Generate Random String  8  [LETTERS]
52cf2336e0SRahul Maheshwari    Set Test Variable  ${random_username}
53cf2336e0SRahul Maheshwari
54cf2336e0SRahul Maheshwari    ${payload}=  Create Dictionary
55cf2336e0SRahul Maheshwari    ...  UserName=${random_username}  Password=${valid_password}
56cf2336e0SRahul Maheshwari    ...  RoleId=Administrator  Enabled=${True}
57cf2336e0SRahul Maheshwari    Redfish.Post  /redfish/v1/AccountService/Accounts  body=&{payload}
58cf2336e0SRahul Maheshwari    ...  valid_status_codes=[${HTTP_CREATED}]
59cf2336e0SRahul Maheshwari
60cf2336e0SRahul Maheshwari    # Update user password using Redfish.
61cf2336e0SRahul Maheshwari    ${payload}=  Create Dictionary  Password=${valid_password2}
62cf2336e0SRahul Maheshwari    Redfish.Patch  /redfish/v1/AccountService/Accounts/${random_username}  body=&{payload}
63cf2336e0SRahul Maheshwari
64cf2336e0SRahul Maheshwari    # Verify that IPMI command works with new password and fails with older password.
65cf2336e0SRahul Maheshwari    Verify IPMI Username And Password  ${random_username}  ${valid_password2}
66cf2336e0SRahul Maheshwari
67652fc742SAnusha Dathatri    Run Keyword And Expect Error  *Error: Unable to establish IPMI*
68cf2336e0SRahul Maheshwari    ...  Verify IPMI Username And Password  ${random_username}  ${valid_password}
69cf2336e0SRahul Maheshwari
70cf2336e0SRahul Maheshwari
71ff63ac02SRahul MaheshwariUpdate User Privilege Via Redfish And Verify Using IPMI
72ff63ac02SRahul Maheshwari    [Documentation]  Update user privilege via Redfish and verify using IPMI.
73ff63ac02SRahul Maheshwari    [Tags]  Update_User_Privilege_Via_Redfish_And_Verify_Using_IPMI
74ff63ac02SRahul Maheshwari
75ff63ac02SRahul Maheshwari    # Create user using Redfish with admin privilege.
76ff63ac02SRahul Maheshwari    ${random_username}=  Generate Random String  8  [LETTERS]
77ff63ac02SRahul Maheshwari    Set Test Variable  ${random_username}
78ff63ac02SRahul Maheshwari
79ff63ac02SRahul Maheshwari    ${payload}=  Create Dictionary
80ff63ac02SRahul Maheshwari    ...  UserName=${random_username}  Password=${valid_password}
81ff63ac02SRahul Maheshwari    ...  RoleId=Administrator  Enabled=${True}
82ff63ac02SRahul Maheshwari    Redfish.Post  /redfish/v1/AccountService/Accounts  body=&{payload}
83ff63ac02SRahul Maheshwari    ...  valid_status_codes=[${HTTP_CREATED}]
84ff63ac02SRahul Maheshwari
85ff63ac02SRahul Maheshwari    # Update user privilege to operator using Redfish.
86ff63ac02SRahul Maheshwari    ${payload}=  Create Dictionary  RoleId=Operator
87ff63ac02SRahul Maheshwari    Redfish.Patch  /redfish/v1/AccountService/Accounts/${random_username}  body=&{payload}
88ff63ac02SRahul Maheshwari
89ff63ac02SRahul Maheshwari    # Verify new user privilege level via IPMI.
90c317c984STony Lee    ${resp}=  Run IPMI Standard Command  user list ${CHANNEL_NUMBER}
91ff63ac02SRahul Maheshwari
92ff63ac02SRahul Maheshwari    # Example of response data:
93ff63ac02SRahul Maheshwari    # ID  Name             Callin  Link Auth  IPMI Msg   Channel Priv Limit
94ff63ac02SRahul Maheshwari    # 1   root             false   true       true       ADMINISTRATOR
95ff63ac02SRahul Maheshwari    # 2   OAvCxjMv         false   true       true       OPERATOR
96ff63ac02SRahul Maheshwari    # 3                    true    false      false      NO ACCESS
97ff63ac02SRahul Maheshwari    # ..
98ff63ac02SRahul Maheshwari    # ..
99ff63ac02SRahul Maheshwari    # 15                   true    false      false      NO ACCESS
100ff63ac02SRahul Maheshwari
101ff63ac02SRahul Maheshwari    ${user_info}=
102ff63ac02SRahul Maheshwari    ...  Get Lines Containing String  ${resp}  ${random_username}
103ff63ac02SRahul Maheshwari    Should Contain  ${user_info}  OPERATOR
104ff63ac02SRahul Maheshwari
105ff63ac02SRahul Maheshwari
106cf2336e0SRahul MaheshwariDelete User Via Redfish And Verify Using IPMI
107cf2336e0SRahul Maheshwari    [Documentation]  Delete user via redfish and verify using IPMI.
108cf2336e0SRahul Maheshwari    [Tags]  Delete_User_Via_Redfish_And_Verify_Using_IPMI
109cf2336e0SRahul Maheshwari
110cf2336e0SRahul Maheshwari    # Create user using Redfish.
111cf2336e0SRahul Maheshwari    ${random_username}=  Generate Random String  8  [LETTERS]
112cf2336e0SRahul Maheshwari    Set Test Variable  ${random_username}
113cf2336e0SRahul Maheshwari
114cf2336e0SRahul Maheshwari    ${payload}=  Create Dictionary
115cf2336e0SRahul Maheshwari    ...  UserName=${random_username}  Password=${valid_password}
116cf2336e0SRahul Maheshwari    ...  RoleId=Administrator  Enabled=${True}
117cf2336e0SRahul Maheshwari    Redfish.Post  /redfish/v1/AccountService/Accounts  body=&{payload}
118cf2336e0SRahul Maheshwari    ...  valid_status_codes=[${HTTP_CREATED}]
119cf2336e0SRahul Maheshwari
120cf2336e0SRahul Maheshwari    # Delete user using Redfish.
121cf2336e0SRahul Maheshwari    Redfish.Delete  /redfish/v1/AccountService/Accounts/${random_username}
122cf2336e0SRahul Maheshwari
123cf2336e0SRahul Maheshwari    # Verify that IPMI command fails with deleted user.
124652fc742SAnusha Dathatri    Run Keyword And Expect Error  *Error: Unable to establish IPMI*
125cf2336e0SRahul Maheshwari    ...  Verify IPMI Username And Password  ${random_username}  ${valid_password}
126cf2336e0SRahul Maheshwari
127cf2336e0SRahul Maheshwari
12875e91feaSRahul MaheshwariCreate IPMI User And Verify Login Via Redfish
12975e91feaSRahul Maheshwari    [Documentation]  Create user using IPMI and verify user login via Redfish.
13075e91feaSRahul Maheshwari    [Tags]  Create_IPMI_User_And_Verify_Login_Via_Redfish
13175e91feaSRahul Maheshwari
13275e91feaSRahul Maheshwari    ${username}  ${userid}=  IPMI Create Random User Plus Password And Privilege
13375e91feaSRahul Maheshwari    ...  ${valid_password}  ${admin_level_priv}
13475e91feaSRahul Maheshwari
1354d89465fSAnusha Dathatri    Redfish.Logout
1364d89465fSAnusha Dathatri
13775e91feaSRahul Maheshwari    # Verify user login using Redfish.
13875e91feaSRahul Maheshwari    Redfish.Login  ${username}  ${valid_password}
1394d89465fSAnusha Dathatri    Redfish.Logout
1404d89465fSAnusha Dathatri
1414d89465fSAnusha Dathatri    Redfish.Login
14275e91feaSRahul Maheshwari
14375e91feaSRahul Maheshwari
14475e91feaSRahul MaheshwariUpdate User Password Via IPMI And Verify Using Redfish
14575e91feaSRahul Maheshwari    [Documentation]  Update user password using IPMI and verify user
14675e91feaSRahul Maheshwari    ...  login via Redfish.
14775e91feaSRahul Maheshwari    [Tags]  Update_User_Password_Via_IPMI_And_Verify_Using_Redfish
14875e91feaSRahul Maheshwari
14975e91feaSRahul Maheshwari    ${username}  ${userid}=  IPMI Create Random User Plus Password And Privilege
15075e91feaSRahul Maheshwari    ...  ${valid_password}  ${admin_level_priv}
15175e91feaSRahul Maheshwari
15275e91feaSRahul Maheshwari    # Update user password using IPMI.
15375e91feaSRahul Maheshwari    Run IPMI Standard Command
15475e91feaSRahul Maheshwari    ...  user set password ${userid} ${valid_password2}
15575e91feaSRahul Maheshwari
1564d89465fSAnusha Dathatri    Redfish.Logout
1574d89465fSAnusha Dathatri
15875e91feaSRahul Maheshwari    # Verify that user login works with new password using Redfish.
15975e91feaSRahul Maheshwari    Redfish.Login  ${username}  ${valid_password2}
1604d89465fSAnusha Dathatri    Redfish.Logout
1614d89465fSAnusha Dathatri
1624d89465fSAnusha Dathatri    Redfish.Login
16375e91feaSRahul Maheshwari
16475e91feaSRahul Maheshwari
1657b7ba223SRahul MaheshwariUpdate User Privilege To Operator Via IPMI And Verify Using Redfish
1667b7ba223SRahul Maheshwari    [Documentation]  Update user privilege to operator via IPMI and verify using Redfish.
1677b7ba223SRahul Maheshwari    [Tags]  Update_User_Privilege_To_Operator_Via_IPMI_And_Verify_Using_Redfish
16875e91feaSRahul Maheshwari    # Create user using IPMI with admin privilege.
16975e91feaSRahul Maheshwari    ${username}  ${userid}=  IPMI Create Random User Plus Password And Privilege
17075e91feaSRahul Maheshwari    ...  ${valid_password}  ${admin_level_priv}
17175e91feaSRahul Maheshwari
17275e91feaSRahul Maheshwari    # Change user privilege to opetrator using IPMI.
17375e91feaSRahul Maheshwari    Run IPMI Standard Command
17469ed33e2STony Lee    ...  user priv ${userid} ${operator_level_priv} ${CHANNEL_NUMBER}
17575e91feaSRahul Maheshwari
17675e91feaSRahul Maheshwari    # Verify new user privilege level via Redfish.
17775e91feaSRahul Maheshwari    ${privilege}=  Redfish_Utils.Get Attribute
17875e91feaSRahul Maheshwari    ...  /redfish/v1/AccountService/Accounts/${username}  RoleId
17975e91feaSRahul Maheshwari    Should Be Equal  ${privilege}  Operator
18075e91feaSRahul Maheshwari
18175e91feaSRahul Maheshwari
1827b7ba223SRahul MaheshwariUpdate User Privilege To Readonly Via IPMI And Verify Using Redfish
1837b7ba223SRahul Maheshwari    [Documentation]  Update user privilege to readonly via IPMI and verify using Redfish.
1847b7ba223SRahul Maheshwari    [Tags]  Update_User_Privilege_To_Readonly_Via_IPMI_And_Verify_Using_Redfish
1857b7ba223SRahul Maheshwari
1867b7ba223SRahul Maheshwari    # Create user using IPMI with admin privilege.
1877b7ba223SRahul Maheshwari    ${username}  ${userid}=  IPMI Create Random User Plus Password And Privilege
1887b7ba223SRahul Maheshwari    ...  ${valid_password}  ${admin_level_priv}
1897b7ba223SRahul Maheshwari
1907b7ba223SRahul Maheshwari    # Change user privilege to readonly using IPMI.
1917b7ba223SRahul Maheshwari    Run IPMI Standard Command
1927b7ba223SRahul Maheshwari    ...  user priv ${userid} ${readonly_level_priv} ${CHANNEL_NUMBER}
1937b7ba223SRahul Maheshwari
1947b7ba223SRahul Maheshwari    # Verify new user privilege level via Redfish.
1957b7ba223SRahul Maheshwari    ${privilege}=  Redfish_Utils.Get Attribute
1967b7ba223SRahul Maheshwari    ...  /redfish/v1/AccountService/Accounts/${username}  RoleId
1977b7ba223SRahul Maheshwari    Should Be Equal  ${privilege}  ReadOnly
1987b7ba223SRahul Maheshwari
1997b7ba223SRahul Maheshwari
20075e91feaSRahul MaheshwariDelete User Via IPMI And Verify Using Redfish
20175e91feaSRahul Maheshwari    [Documentation]  Delete user using IPMI and verify error while doing
20275e91feaSRahul Maheshwari    ...  user login with deleted user via Redfish.
20375e91feaSRahul Maheshwari    [Tags]  Delete_User_Via_IPMI_And_Verify_Using_Redfish
20475e91feaSRahul Maheshwari
20575e91feaSRahul Maheshwari    ${username}  ${userid}=  IPMI Create Random User Plus Password And Privilege
20675e91feaSRahul Maheshwari    ...  ${valid_password}  ${admin_level_priv}
20775e91feaSRahul Maheshwari
20875e91feaSRahul Maheshwari    # Delete IPMI User.
20975e91feaSRahul Maheshwari    Run IPMI Standard Command  user set name ${userid} ""
21075e91feaSRahul Maheshwari
21175e91feaSRahul Maheshwari    # Verify that Redfish login fails with deleted user.
21275e91feaSRahul Maheshwari    Run Keyword And Expect Error  *InvalidCredentialsError*
21375e91feaSRahul Maheshwari    ...  Redfish.Login  ${username}  ${valid_password}
21475e91feaSRahul Maheshwari
21575e91feaSRahul Maheshwari
2163e61ce66SRahul MaheshwariVerify Failure To Exceed Max Number Of Users
2173e61ce66SRahul Maheshwari    [Documentation]  Verify failure attempting to exceed the max number of user accounts.
2183e61ce66SRahul Maheshwari    [Tags]  Verify_Failure_To_Exceed_Max_Number_Of_Users
219132d29a6Snagarjunb    [Teardown]  Run Keywords  Test Teardown Execution
220132d29a6Snagarjunb    ...         AND  Delete Users Via Redfish  ${username_list}
2213e61ce66SRahul Maheshwari
2223e61ce66SRahul Maheshwari    # Get existing user count.
2233e61ce66SRahul Maheshwari    ${resp}=  Redfish.Get  /redfish/v1/AccountService/Accounts/
2243e61ce66SRahul Maheshwari    ${current_user_count}=  Get From Dictionary  ${resp.dict}  Members@odata.count
2253e61ce66SRahul Maheshwari
2263e61ce66SRahul Maheshwari    ${payload}=  Create Dictionary  Password=${valid_password}
2273e61ce66SRahul Maheshwari    ...  RoleId=Administrator  Enabled=${True}
2283e61ce66SRahul Maheshwari
229dfd48019SAshwini Chandrappa    @{username_list}=  Create List
230dfd48019SAshwini Chandrappa
23145102295Sganesanb    # Create users to reach maximum users count (i.e. 15 users).
2323e61ce66SRahul Maheshwari    FOR  ${INDEX}  IN RANGE  ${current_user_count}  ${max_num_users}
2333e61ce66SRahul Maheshwari      ${random_username}=  Generate Random String  8  [LETTERS]
2343e61ce66SRahul Maheshwari      Set To Dictionary  ${payload}  UserName  ${random_username}
2353e61ce66SRahul Maheshwari      Redfish.Post  ${REDFISH_ACCOUNTS_URI}  body=&{payload}
2363e61ce66SRahul Maheshwari      ...  valid_status_codes=[${HTTP_CREATED}]
237dfd48019SAshwini Chandrappa      Append To List  ${username_list}  /redfish/v1/AccountService/Accounts/${random_username}
2383e61ce66SRahul Maheshwari    END
2393e61ce66SRahul Maheshwari
240dfd48019SAshwini Chandrappa    # Verify error while creating 16th user.
2413e61ce66SRahul Maheshwari    ${random_username}=  Generate Random String  8  [LETTERS]
2423e61ce66SRahul Maheshwari    Set To Dictionary  ${payload}  UserName  ${random_username}
2433e61ce66SRahul Maheshwari    Redfish.Post  ${REDFISH_ACCOUNTS_URI}  body=&{payload}
2443e61ce66SRahul Maheshwari    ...  valid_status_codes=[${HTTP_BAD_REQUEST}]
2453e61ce66SRahul Maheshwari
2463e61ce66SRahul Maheshwari
2479ecaaf42SAnusha DathatriCreate IPMI User Without Any Privilege And Verify Via Redfish
2489ecaaf42SAnusha Dathatri    [Documentation]  Create user using IPMI without privilege and verify via redfish.
2499ecaaf42SAnusha Dathatri    [Tags]  Create_IPMI_User_Without_Any_Privilege_And_Verify_Via_Redfish
2509ecaaf42SAnusha Dathatri
2519ecaaf42SAnusha Dathatri    ${username}  ${userid}=  IPMI Create Random User Plus Password And Privilege
2529ecaaf42SAnusha Dathatri    ...  ${valid_password}
2539ecaaf42SAnusha Dathatri
2549ecaaf42SAnusha Dathatri    # Verify new user privilege level via Redfish.
2559ecaaf42SAnusha Dathatri    ${privilege}=  Redfish_Utils.Get Attribute
2569ecaaf42SAnusha Dathatri    ...  /redfish/v1/AccountService/Accounts/${username}  RoleId
25742b2e303Skothais    Valid Value  privilege  ['ReadOnly']
2589ecaaf42SAnusha Dathatri
25951dee266SRahul Maheshwari*** Keywords ***
26051dee266SRahul Maheshwari
26175e91feaSRahul MaheshwariIPMI Create Random User Plus Password And Privilege
26275e91feaSRahul Maheshwari    [Documentation]  Create random IPMI user with given password and privilege
26375e91feaSRahul Maheshwari    ...  level.
2649ecaaf42SAnusha Dathatri    [Arguments]  ${password}  ${privilege}=0
26575e91feaSRahul Maheshwari
26675e91feaSRahul Maheshwari    # Description of argument(s):
26775e91feaSRahul Maheshwari    # password      Password to be assigned for the user.
26875e91feaSRahul Maheshwari    # privilege     Privilege level for the user (e.g. "1", "2", "3", etc.).
26975e91feaSRahul Maheshwari
27075e91feaSRahul Maheshwari    # Create IPMI user.
27175e91feaSRahul Maheshwari    ${random_username}=  Generate Random String  8  [LETTERS]
27275e91feaSRahul Maheshwari    Set Suite Variable  ${random_username}
27375e91feaSRahul Maheshwari
274d4cdc11fSGene Ratzlaff    ${random_userid}=  Find Free User Id
27575e91feaSRahul Maheshwari    IPMI Create User  ${random_userid}  ${random_username}
27675e91feaSRahul Maheshwari
27775e91feaSRahul Maheshwari    # Set given password for newly created user.
27875e91feaSRahul Maheshwari    Run IPMI Standard Command
27975e91feaSRahul Maheshwari    ...  user set password ${random_userid} ${password}
28075e91feaSRahul Maheshwari
28175e91feaSRahul Maheshwari    # Enable IPMI user.
28275e91feaSRahul Maheshwari    Run IPMI Standard Command  user enable ${random_userid}
28375e91feaSRahul Maheshwari
28475e91feaSRahul Maheshwari    # Set given privilege and enable IPMI messaging for newly created user.
285*79fc7f08SGeorge Keishing    IF  '${privilege}' != '0'
286*79fc7f08SGeorge Keishing        Set Channel Access  ${random_userid}  ipmi=on privilege=${privilege}
287*79fc7f08SGeorge Keishing    END
28875e91feaSRahul Maheshwari
289409df05dSGeorge Keishing    RETURN  ${random_username}  ${random_userid}
29075e91feaSRahul Maheshwari
29175e91feaSRahul Maheshwari
292132d29a6SnagarjunbDelete Users Via Redfish
293132d29a6Snagarjunb    [Documentation]  Delete all the users via redfish from given list.
294132d29a6Snagarjunb    [Arguments]  ${user_list}
295132d29a6Snagarjunb
296132d29a6Snagarjunb    # Description of argument(s):
297132d29a6Snagarjunb    # user_list    List of user which are to be deleted.
298132d29a6Snagarjunb
299132d29a6Snagarjunb    Redfish.Login
300132d29a6Snagarjunb
301132d29a6Snagarjunb    FOR  ${user}  IN  @{user_list}
302132d29a6Snagarjunb      Redfish.Delete  ${user}
303132d29a6Snagarjunb    END
304132d29a6Snagarjunb
305132d29a6Snagarjunb    Redfish.Logout
306132d29a6Snagarjunb
307132d29a6Snagarjunb
30851dee266SRahul MaheshwariTest Setup Execution
30951dee266SRahul Maheshwari    [Documentation]  Do test case setup tasks.
31051dee266SRahul Maheshwari
31151dee266SRahul Maheshwari    Redfish.Login
31251dee266SRahul Maheshwari
31351dee266SRahul Maheshwari
31451dee266SRahul MaheshwariTest Teardown Execution
31551dee266SRahul Maheshwari    [Documentation]  Do the post test teardown.
31651dee266SRahul Maheshwari
31751dee266SRahul Maheshwari    FFDC On Test Case Fail
31851dee266SRahul Maheshwari    # Delete the test user.
31951dee266SRahul Maheshwari    Run Keyword And Ignore Error
32051dee266SRahul Maheshwari    ...  Redfish.Delete  /redfish/v1/AccountService/Accounts/${random_username}
32151dee266SRahul Maheshwari
32251dee266SRahul Maheshwari    Redfish.Logout
323d4cdc11fSGene Ratzlaff
324d4cdc11fSGene Ratzlaff
325d4cdc11fSGene RatzlaffFind Free User Id
326d4cdc11fSGene Ratzlaff    [Documentation]  Find a userid that is not being used.
327d4cdc11fSGene Ratzlaff    FOR    ${jj}    IN RANGE    300
328dc7d6893SGeorge Keishing        # IPMI maximum users count (i.e. 15 users).
329dc7d6893SGeorge Keishing        ${random_userid}=  Evaluate  random.randint(1, ${ipmi_max_num_users})  modules=random
33026499145SNagarjun B        ${access}=  Run IPMI Standard Command  channel getaccess ${CHANNEL_NUMBER} ${random_userid}
331d4cdc11fSGene Ratzlaff
332d4cdc11fSGene Ratzlaff        ${name_line}=  Get Lines Containing String  ${access}  User Name
333d4cdc11fSGene Ratzlaff        Log To Console  For ID ${random_userid}: ${name_line}
334d4cdc11fSGene Ratzlaff        ${is_empty}=  Run Keyword And Return Status
335d4cdc11fSGene Ratzlaff        ...  Should Match Regexp  ${name_line}  ${empty_name_pattern}
336d4cdc11fSGene Ratzlaff
337b0a5a6dbSSridevi Ramesh        IF  ${is_empty} == ${True}  BREAK
338d4cdc11fSGene Ratzlaff    END
339*79fc7f08SGeorge Keishing    IF  '${jj}' == '299'  Fail  msg=A free user ID could not be found.
340409df05dSGeorge Keishing    RETURN  ${random_userid}
341