Rahul Maheshwari | a37963e | 2022-08-29 06:15:47 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Test IPMI and Redfish combinations for user management. |
| 3 | |
srichn28 | e64caee | 2022-09-14 04:56:03 -0500 | [diff] [blame] | 4 | Resource ../../lib/resource.robot |
| 5 | Resource ../../lib/bmc_redfish_resource.robot |
| 6 | Resource ../../lib/openbmc_ffdc.robot |
| 7 | Resource ../../lib/ipmi_client.robot |
| 8 | Library ../../lib/ipmi_utils.py |
| 9 | |
| 10 | Test Setup Test Setup Execution |
| 11 | Test Teardown Test Teardown Execution |
| 12 | |
Matt Fischer | 6fb70d9 | 2023-10-24 19:06:33 -0600 | [diff] [blame] | 13 | Test Tags IPMI_Redfish_User |
srichn28 | e64caee | 2022-09-14 04:56:03 -0500 | [diff] [blame] | 14 | |
| 15 | *** Variables *** |
| 16 | |
| 17 | ${valid_password} 0penBmc1 |
| 18 | ${valid_password2} 0penBmc2 |
Rahul Maheshwari | a37963e | 2022-08-29 06:15:47 -0500 | [diff] [blame] | 19 | |
| 20 | |
| 21 | *** Test Cases *** |
| 22 | |
| 23 | Create IPMI User Without Any Privilege And Verify Via Redfish |
| 24 | [Documentation] Create user using IPMI without privilege and verify user privilege |
| 25 | ... via Redfish. |
| 26 | [Tags] Create_IPMI_User_Without_Any_Privilege_And_Verify_Via_Redfish |
Rahul Maheshwari | a37963e | 2022-08-29 06:15:47 -0500 | [diff] [blame] | 27 | |
| 28 | # Create IPMI user with random id and username. |
| 29 | ${random_userid}= Evaluate random.randint(2, 15) modules=random |
| 30 | ${random_username}= Generate Random String 8 [LETTERS] |
| 31 | Run IPMI Standard Command |
| 32 | ... user set name ${random_userid} ${random_username} |
| 33 | |
| 34 | # Verify new user privilege level via Redfish. |
| 35 | ${privilege}= Redfish_Utils.Get Attribute |
| 36 | ... /redfish/v1/AccountService/Accounts/${random_username} RoleId |
| 37 | Valid Value privilege ['ReadOnly'] |
| 38 | |
srichn28 | e64caee | 2022-09-14 04:56:03 -0500 | [diff] [blame] | 39 | |
| 40 | Create Admin User Via Redfish And Verify Login Via IPMI |
| 41 | [Documentation] Create user via redfish and verify via IPMI. |
| 42 | [Tags] Create_Admin_User_Via_Redfish_And_Verify_Login_Via_IPMI |
| 43 | |
| 44 | ${random_username}= Generate Random String 8 [LETTERS] |
| 45 | Set Test Variable ${random_username} |
| 46 | |
| 47 | ${payload}= Create Dictionary |
| 48 | ... UserName=${random_username} Password=${valid_password} |
| 49 | ... RoleId=Administrator Enabled=${True} |
| 50 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 51 | ... valid_status_codes=[${HTTP_CREATED}] |
| 52 | |
| 53 | # Add delay for a new admin user password to set. |
| 54 | Sleep 5s |
| 55 | |
| 56 | Enable IPMI Access To User Using Redfish ${random_username} |
| 57 | |
| 58 | # Update user password using Redfish. |
| 59 | ${payload}= Create Dictionary Password=${valid_password2} |
| 60 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 61 | |
| 62 | Verify IPMI Username And Password ${random_username} ${valid_password2} |
| 63 | |
| 64 | |
| 65 | Delete User Via Redfish And Verify Using IPMI |
| 66 | [Documentation] Delete user via redfish and verify using IPMI. |
| 67 | [Tags] Delete_User_Via_Redfish_And_Verify_Using_IPMI |
| 68 | |
| 69 | # Create user using Redfish. |
| 70 | ${random_username}= Generate Random String 8 [LETTERS] |
| 71 | Set Test Variable ${random_username} |
| 72 | |
| 73 | ${payload}= Create Dictionary |
| 74 | ... UserName=${random_username} Password=${valid_password} |
| 75 | ... RoleId=Administrator Enabled=${True} |
| 76 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 77 | ... valid_status_codes=[${HTTP_CREATED}] |
| 78 | |
| 79 | Enable IPMI Access To User Using Redfish ${random_username} |
| 80 | |
| 81 | # Update user password using Redfish. |
| 82 | ${payload}= Create Dictionary Password=${valid_password2} |
| 83 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 84 | |
| 85 | # Delete user using Redfish. |
| 86 | Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username} |
| 87 | |
| 88 | # Verify that IPMI command fails with deleted user. |
| 89 | Run Keyword And Expect Error *Error: Unable to establish IPMI* |
| 90 | ... Verify IPMI Username And Password ${random_username} ${valid_password2} |
| 91 | |
| 92 | |
srichn28 | 3d53b0f | 2022-09-22 05:52:49 -0500 | [diff] [blame] | 93 | Update User Password Via Redfish And Verify Using IPMI |
| 94 | [Documentation] Update user password via Redfish and verify using IPMI. |
| 95 | [Tags] Update_User_Password_Via_Redfish_And_Verify_Using_IPMI |
| 96 | |
| 97 | # Create user using Redfish. |
| 98 | ${random_username}= Generate Random String 8 [LETTERS] |
| 99 | Set Test Variable ${random_username} |
| 100 | |
| 101 | ${payload}= Create Dictionary |
| 102 | ... UserName=${random_username} Password=${valid_password} |
| 103 | ... RoleId=Administrator Enabled=${True} |
| 104 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 105 | ... valid_status_codes=[${HTTP_CREATED}] |
| 106 | |
| 107 | Enable IPMI Access To User Using Redfish ${random_username} |
| 108 | |
| 109 | # Update user password using Redfish. |
| 110 | ${payload}= Create Dictionary Password=${valid_password2} |
| 111 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 112 | |
| 113 | # Verify that IPMI command works with new password and fails with older password. |
| 114 | Verify IPMI Username And Password ${random_username} ${valid_password2} |
| 115 | |
| 116 | Run Keyword And Expect Error *Error: Unable to establish IPMI* |
| 117 | ... Verify IPMI Username And Password ${random_username} ${valid_password} |
| 118 | |
| 119 | |
| 120 | Update User Privilege Via Redfish And Verify Using IPMI |
| 121 | [Documentation] Update user privilege via Redfish and verify using IPMI. |
| 122 | [Tags] Update_User_Privilege_Via_Redfish_And_Verify_Using_IPMI |
| 123 | |
| 124 | # Create user using Redfish with admin privilege. |
| 125 | ${random_username}= Generate Random String 8 [LETTERS] |
| 126 | Set Test Variable ${random_username} |
| 127 | |
| 128 | ${payload}= Create Dictionary |
| 129 | ... UserName=${random_username} Password=${valid_password} |
| 130 | ... RoleId=Administrator Enabled=${True} |
| 131 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 132 | ... valid_status_codes=[${HTTP_CREATED}] |
| 133 | |
| 134 | Enable IPMI Access To User Using Redfish ${random_username} |
| 135 | |
| 136 | # Update user password using Redfish. |
| 137 | ${payload}= Create Dictionary Password=${valid_password2} |
| 138 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 139 | |
| 140 | # Update user privilege to readonly using Redfish. |
| 141 | ${payload}= Create Dictionary RoleId=ReadOnly |
| 142 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 143 | |
| 144 | # Verify new user privilege level via IPMI. |
| 145 | ${resp}= Run IPMI Standard Command user list |
| 146 | |
| 147 | # Example of response data: |
| 148 | # ID Name Callin Link Auth IPMI Msg Channel Priv Limit |
| 149 | # 1 ipmi_admin false true true ADMINISTRATOR |
| 150 | # 2 OAvCxjMv false true true USER |
| 151 | # 3 true false false NO ACCESS |
| 152 | # .. |
| 153 | # .. |
| 154 | # 15 true false false NO ACCESS |
| 155 | |
| 156 | ${user_info}= |
| 157 | ... Get Lines Containing String ${resp} ${random_username} |
| 158 | Should Contain ${user_info} USER |
| 159 | |
| 160 | |
srichn28 | e64caee | 2022-09-14 04:56:03 -0500 | [diff] [blame] | 161 | *** Keywords *** |
| 162 | |
| 163 | Create IPMI Random User With Password And Privilege |
| 164 | [Documentation] Create random IPMI user with given password and privilege |
| 165 | ... level. |
| 166 | [Arguments] ${password} ${privilege}=0 |
| 167 | |
| 168 | # Description of argument(s): |
| 169 | # password Password to be assigned for the user. |
| 170 | # privilege Privilege level for the user (e.g. "1", "2", "3", etc.). |
| 171 | |
| 172 | # Create IPMI user. |
| 173 | ${random_username}= Generate Random String 8 [LETTERS] |
| 174 | Set Suite Variable ${random_username} |
| 175 | |
| 176 | ${random_userid}= Find And Return Free User Id |
| 177 | IPMI Create User ${random_userid} ${random_username} |
| 178 | |
| 179 | # Set given password for newly created user. |
| 180 | Run IPMI Standard Command |
| 181 | ... user set password ${random_userid} ${password} |
| 182 | |
| 183 | # Enable IPMI user. |
| 184 | Run IPMI Standard Command user enable ${random_userid} |
| 185 | |
| 186 | # Set given privilege and enable IPMI messaging for newly created user. |
| 187 | Run Keyword If '${privilege}' != '0' |
| 188 | ... Set Channel Access ${random_userid} ipmi=on privilege=${privilege} |
| 189 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 190 | RETURN ${random_username} ${random_userid} |
srichn28 | e64caee | 2022-09-14 04:56:03 -0500 | [diff] [blame] | 191 | |
| 192 | |
| 193 | Delete Users Via Redfish |
| 194 | [Documentation] Delete all the users via redfish from given list. |
| 195 | [Arguments] ${user_list} |
| 196 | |
| 197 | # Description of argument(s): |
| 198 | # user_list List of user which are to be deleted. |
| 199 | |
| 200 | Redfish.Login |
| 201 | |
| 202 | FOR ${user} IN @{user_list} |
| 203 | Redfish.Delete ${user} |
| 204 | END |
| 205 | |
| 206 | Redfish.Logout |
| 207 | |
| 208 | |
| 209 | Enable IPMI Access To User Using Redfish |
| 210 | [Documentation] Add IPMI access to a user through Redfish. |
| 211 | [Arguments] ${user_name} |
| 212 | |
| 213 | # Description of argument(s): |
| 214 | # user_name User name to which IPMI access is to be added. |
| 215 | |
| 216 | # Adding IPMI access to user name. |
| 217 | Redfish.Patch /redfish/v1/AccountService/Accounts/${user_name} |
| 218 | ... body={"AccountTypes": ["Redfish", "HostConsole", "ManagerConsole", "WebUI", "IPMI"]} |
| 219 | |
| 220 | |
| 221 | Test Setup Execution |
| 222 | [Documentation] Do test case setup tasks. |
| 223 | |
| 224 | Redfish.Login |
| 225 | |
| 226 | |
| 227 | Test Teardown Execution |
| 228 | [Documentation] Do the post test teardown. |
| 229 | |
| 230 | FFDC On Test Case Fail |
| 231 | # Delete the test user. |
| 232 | Run Keyword And Ignore Error |
| 233 | ... Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username} |
| 234 | |
| 235 | Redfish.Logout |
| 236 | |
| 237 | |
| 238 | Find And Return Free User Id |
| 239 | [Documentation] Find and return userid that is not being used. |
| 240 | |
| 241 | FOR ${index} IN RANGE 300 |
| 242 | # IPMI maximum users count (i.e. 15 users). |
| 243 | ${random_userid}= Evaluate random.randint(1, ${ipmi_max_num_users}) modules=random |
| 244 | ${access_output}= Run IPMI Standard Command channel getaccess 1 ${random_userid} |
| 245 | |
| 246 | ${name_line}= Get Lines Containing String ${access_output} User Name |
| 247 | Log To Console For ID ${random_userid}: ${name_line} |
| 248 | ${is_empty}= Run Keyword And Return Status |
| 249 | ... Should Match Regexp ${name_line} ${empty_name_pattern} |
| 250 | |
| 251 | Exit For Loop If ${is_empty} == ${True} |
| 252 | END |
| 253 | Run Keyword If '${index}' == '299' Fail msg=A free user ID could not be found. |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 254 | RETURN ${random_userid} |
srichn28 | e64caee | 2022-09-14 04:56:03 -0500 | [diff] [blame] | 255 | |