Rahul Maheshwari | 51dee26 | 2019-03-06 23:36:21 -0600 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Test IPMI and Redfish combinations for user management. |
| 3 | |
| 4 | Resource ../../lib/resource.robot |
| 5 | Resource ../../lib/bmc_redfish_resource.robot |
| 6 | Resource ../../lib/openbmc_ffdc.robot |
| 7 | Resource ../../lib/ipmi_client.robot |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 8 | Library ../lib/ipmi_utils.py |
Rahul Maheshwari | 51dee26 | 2019-03-06 23:36:21 -0600 | [diff] [blame] | 9 | |
| 10 | Test Setup Test Setup Execution |
| 11 | Test Teardown Test Teardown Execution |
| 12 | |
| 13 | |
| 14 | *** Variables *** |
| 15 | |
| 16 | ${valid_password} 0penBmc1 |
Rahul Maheshwari | cf2336e | 2019-03-15 00:49:13 -0500 | [diff] [blame] | 17 | ${valid_password2} 0penBmc2 |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 18 | ${admin_level_priv} 4 |
| 19 | ${operator_level_priv} 3 |
George Keishing | 48d998e | 2022-07-07 10:10:47 -0500 | [diff] [blame] | 20 | # Refer: #openbmc/phosphor-user-manager/blob/master/user_mgr.cpp |
George Keishing | 6c88252 | 2022-07-07 11:18:50 -0500 | [diff] [blame] | 21 | # ipmiMaxUsers = 15; <-- IPMI |
| 22 | # maxSystemUsers = 30; <-- Max system redfish account users allowed |
George Keishing | dc7d689 | 2022-07-07 14:28:32 -0500 | [diff] [blame] | 23 | ${ipmi_max_num_users} ${15} |
George Keishing | 48d998e | 2022-07-07 10:10:47 -0500 | [diff] [blame] | 24 | ${max_num_users} ${30} |
Gene Ratzlaff | d4cdc11 | 2022-05-06 13:17:35 -0400 | [diff] [blame] | 25 | ${empty_name_pattern} ^User Name\\s.*\\s:\\s$ |
Rahul Maheshwari | 51dee26 | 2019-03-06 23:36:21 -0600 | [diff] [blame] | 26 | |
| 27 | ** Test Cases ** |
| 28 | |
| 29 | Create Admin Redfish User And Verify Login Via IPMI |
| 30 | [Documentation] Create user using redfish and verify via IPMI. |
| 31 | [Tags] Create_Admin_Redfish_User_And_Verify_Login_Via_IPMI |
| 32 | |
| 33 | ${random_username}= Generate Random String 8 [LETTERS] |
| 34 | Set Test Variable ${random_username} |
| 35 | |
| 36 | ${payload}= Create Dictionary |
| 37 | ... UserName=${random_username} Password=${valid_password} |
| 38 | ... RoleId=Administrator Enabled=${True} |
| 39 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 40 | ... valid_status_codes=[${HTTP_CREATED}] |
| 41 | |
Sushma M M | 97fccae | 2020-07-27 14:55:19 -0500 | [diff] [blame] | 42 | # Delay added for created new user password to get set. |
| 43 | Sleep 5s |
| 44 | |
Rahul Maheshwari | 51dee26 | 2019-03-06 23:36:21 -0600 | [diff] [blame] | 45 | Verify IPMI Username And Password ${random_username} ${valid_password} |
| 46 | |
| 47 | |
Rahul Maheshwari | cf2336e | 2019-03-15 00:49:13 -0500 | [diff] [blame] | 48 | Update User Password Via Redfish And Verify Using IPMI |
| 49 | [Documentation] Update user password via Redfish and verify using IPMI. |
| 50 | [Tags] Update_User_Password_Via_Redfish_And_Verify_Using_IPMI |
| 51 | |
| 52 | # Create user using Redfish. |
| 53 | ${random_username}= Generate Random String 8 [LETTERS] |
| 54 | Set Test Variable ${random_username} |
| 55 | |
| 56 | ${payload}= Create Dictionary |
| 57 | ... UserName=${random_username} Password=${valid_password} |
| 58 | ... RoleId=Administrator Enabled=${True} |
| 59 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 60 | ... valid_status_codes=[${HTTP_CREATED}] |
| 61 | |
| 62 | # Update user password using Redfish. |
| 63 | ${payload}= Create Dictionary Password=${valid_password2} |
| 64 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 65 | |
| 66 | # Verify that IPMI command works with new password and fails with older password. |
| 67 | Verify IPMI Username And Password ${random_username} ${valid_password2} |
| 68 | |
Anusha Dathatri | 652fc74 | 2020-02-05 05:14:21 -0600 | [diff] [blame] | 69 | Run Keyword And Expect Error *Error: Unable to establish IPMI* |
Rahul Maheshwari | cf2336e | 2019-03-15 00:49:13 -0500 | [diff] [blame] | 70 | ... Verify IPMI Username And Password ${random_username} ${valid_password} |
| 71 | |
| 72 | |
Rahul Maheshwari | ff63ac0 | 2019-03-29 10:25:21 -0500 | [diff] [blame] | 73 | Update User Privilege Via Redfish And Verify Using IPMI |
| 74 | [Documentation] Update user privilege via Redfish and verify using IPMI. |
| 75 | [Tags] Update_User_Privilege_Via_Redfish_And_Verify_Using_IPMI |
| 76 | |
| 77 | # Create user using Redfish with admin privilege. |
| 78 | ${random_username}= Generate Random String 8 [LETTERS] |
| 79 | Set Test Variable ${random_username} |
| 80 | |
| 81 | ${payload}= Create Dictionary |
| 82 | ... UserName=${random_username} Password=${valid_password} |
| 83 | ... RoleId=Administrator Enabled=${True} |
| 84 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 85 | ... valid_status_codes=[${HTTP_CREATED}] |
| 86 | |
| 87 | # Update user privilege to operator using Redfish. |
| 88 | ${payload}= Create Dictionary RoleId=Operator |
| 89 | Redfish.Patch /redfish/v1/AccountService/Accounts/${random_username} body=&{payload} |
| 90 | |
| 91 | # Verify new user privilege level via IPMI. |
Tony Lee | c317c98 | 2020-05-20 15:46:35 +0800 | [diff] [blame] | 92 | ${resp}= Run IPMI Standard Command user list ${CHANNEL_NUMBER} |
Rahul Maheshwari | ff63ac0 | 2019-03-29 10:25:21 -0500 | [diff] [blame] | 93 | |
| 94 | # Example of response data: |
| 95 | # ID Name Callin Link Auth IPMI Msg Channel Priv Limit |
| 96 | # 1 root false true true ADMINISTRATOR |
| 97 | # 2 OAvCxjMv false true true OPERATOR |
| 98 | # 3 true false false NO ACCESS |
| 99 | # .. |
| 100 | # .. |
| 101 | # 15 true false false NO ACCESS |
| 102 | |
| 103 | ${user_info}= |
| 104 | ... Get Lines Containing String ${resp} ${random_username} |
| 105 | Should Contain ${user_info} OPERATOR |
| 106 | |
| 107 | |
Rahul Maheshwari | cf2336e | 2019-03-15 00:49:13 -0500 | [diff] [blame] | 108 | Delete User Via Redfish And Verify Using IPMI |
| 109 | [Documentation] Delete user via redfish and verify using IPMI. |
| 110 | [Tags] Delete_User_Via_Redfish_And_Verify_Using_IPMI |
| 111 | |
| 112 | # Create user using Redfish. |
| 113 | ${random_username}= Generate Random String 8 [LETTERS] |
| 114 | Set Test Variable ${random_username} |
| 115 | |
| 116 | ${payload}= Create Dictionary |
| 117 | ... UserName=${random_username} Password=${valid_password} |
| 118 | ... RoleId=Administrator Enabled=${True} |
| 119 | Redfish.Post /redfish/v1/AccountService/Accounts body=&{payload} |
| 120 | ... valid_status_codes=[${HTTP_CREATED}] |
| 121 | |
| 122 | # Delete user using Redfish. |
| 123 | Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username} |
| 124 | |
| 125 | # Verify that IPMI command fails with deleted user. |
Anusha Dathatri | 652fc74 | 2020-02-05 05:14:21 -0600 | [diff] [blame] | 126 | Run Keyword And Expect Error *Error: Unable to establish IPMI* |
Rahul Maheshwari | cf2336e | 2019-03-15 00:49:13 -0500 | [diff] [blame] | 127 | ... Verify IPMI Username And Password ${random_username} ${valid_password} |
| 128 | |
| 129 | |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 130 | Create IPMI User And Verify Login Via Redfish |
| 131 | [Documentation] Create user using IPMI and verify user login via Redfish. |
| 132 | [Tags] Create_IPMI_User_And_Verify_Login_Via_Redfish |
| 133 | |
| 134 | ${username} ${userid}= IPMI Create Random User Plus Password And Privilege |
| 135 | ... ${valid_password} ${admin_level_priv} |
| 136 | |
Anusha Dathatri | 4d89465 | 2020-02-12 04:08:10 -0600 | [diff] [blame] | 137 | Redfish.Logout |
| 138 | |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 139 | # Verify user login using Redfish. |
| 140 | Redfish.Login ${username} ${valid_password} |
Anusha Dathatri | 4d89465 | 2020-02-12 04:08:10 -0600 | [diff] [blame] | 141 | Redfish.Logout |
| 142 | |
| 143 | Redfish.Login |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 144 | |
| 145 | |
| 146 | Update User Password Via IPMI And Verify Using Redfish |
| 147 | [Documentation] Update user password using IPMI and verify user |
| 148 | ... login via Redfish. |
| 149 | [Tags] Update_User_Password_Via_IPMI_And_Verify_Using_Redfish |
| 150 | |
| 151 | ${username} ${userid}= IPMI Create Random User Plus Password And Privilege |
| 152 | ... ${valid_password} ${admin_level_priv} |
| 153 | |
| 154 | # Update user password using IPMI. |
| 155 | Run IPMI Standard Command |
| 156 | ... user set password ${userid} ${valid_password2} |
| 157 | |
Anusha Dathatri | 4d89465 | 2020-02-12 04:08:10 -0600 | [diff] [blame] | 158 | Redfish.Logout |
| 159 | |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 160 | # Verify that user login works with new password using Redfish. |
| 161 | Redfish.Login ${username} ${valid_password2} |
Anusha Dathatri | 4d89465 | 2020-02-12 04:08:10 -0600 | [diff] [blame] | 162 | Redfish.Logout |
| 163 | |
| 164 | Redfish.Login |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 165 | |
| 166 | |
| 167 | Update User Privilege Via IPMI And Verify Using Redfish |
| 168 | [Documentation] Update user privilege via IPMI and verify using Redfish. |
| 169 | [Tags] Update_User_Privilege_Via_IPMI_And_Verify_Using_Redfish |
| 170 | |
| 171 | # Create user using IPMI with admin privilege. |
| 172 | ${username} ${userid}= IPMI Create Random User Plus Password And Privilege |
| 173 | ... ${valid_password} ${admin_level_priv} |
| 174 | |
| 175 | # Change user privilege to opetrator using IPMI. |
| 176 | Run IPMI Standard Command |
Tony Lee | 69ed33e | 2020-05-20 17:15:02 +0800 | [diff] [blame] | 177 | ... user priv ${userid} ${operator_level_priv} ${CHANNEL_NUMBER} |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 178 | |
| 179 | # Verify new user privilege level via Redfish. |
| 180 | ${privilege}= Redfish_Utils.Get Attribute |
| 181 | ... /redfish/v1/AccountService/Accounts/${username} RoleId |
| 182 | Should Be Equal ${privilege} Operator |
| 183 | |
| 184 | |
| 185 | Delete User Via IPMI And Verify Using Redfish |
| 186 | [Documentation] Delete user using IPMI and verify error while doing |
| 187 | ... user login with deleted user via Redfish. |
| 188 | [Tags] Delete_User_Via_IPMI_And_Verify_Using_Redfish |
| 189 | |
| 190 | ${username} ${userid}= IPMI Create Random User Plus Password And Privilege |
| 191 | ... ${valid_password} ${admin_level_priv} |
| 192 | |
| 193 | # Delete IPMI User. |
| 194 | Run IPMI Standard Command user set name ${userid} "" |
| 195 | |
| 196 | # Verify that Redfish login fails with deleted user. |
| 197 | Run Keyword And Expect Error *InvalidCredentialsError* |
| 198 | ... Redfish.Login ${username} ${valid_password} |
| 199 | |
| 200 | |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 201 | Verify Failure To Exceed Max Number Of Users |
| 202 | [Documentation] Verify failure attempting to exceed the max number of user accounts. |
| 203 | [Tags] Verify_Failure_To_Exceed_Max_Number_Of_Users |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 204 | |
| 205 | # Get existing user count. |
| 206 | ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/ |
| 207 | ${current_user_count}= Get From Dictionary ${resp.dict} Members@odata.count |
| 208 | |
| 209 | ${payload}= Create Dictionary Password=${valid_password} |
| 210 | ... RoleId=Administrator Enabled=${True} |
| 211 | |
Ashwini Chandrappa | dfd4801 | 2022-04-06 06:33:37 -0500 | [diff] [blame] | 212 | @{username_list}= Create List |
| 213 | |
George Keishing | dc7d689 | 2022-07-07 14:28:32 -0500 | [diff] [blame] | 214 | # Create users to reach maximum users count (i.e. 30 users). |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 215 | FOR ${INDEX} IN RANGE ${current_user_count} ${max_num_users} |
| 216 | ${random_username}= Generate Random String 8 [LETTERS] |
| 217 | Set To Dictionary ${payload} UserName ${random_username} |
| 218 | Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload} |
| 219 | ... valid_status_codes=[${HTTP_CREATED}] |
Ashwini Chandrappa | dfd4801 | 2022-04-06 06:33:37 -0500 | [diff] [blame] | 220 | Append To List ${username_list} /redfish/v1/AccountService/Accounts/${random_username} |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 221 | END |
| 222 | |
Ashwini Chandrappa | dfd4801 | 2022-04-06 06:33:37 -0500 | [diff] [blame] | 223 | # Verify error while creating 16th user. |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 224 | ${random_username}= Generate Random String 8 [LETTERS] |
| 225 | Set To Dictionary ${payload} UserName ${random_username} |
| 226 | Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload} |
| 227 | ... valid_status_codes=[${HTTP_BAD_REQUEST}] |
| 228 | |
Ashwini Chandrappa | dfd4801 | 2022-04-06 06:33:37 -0500 | [diff] [blame] | 229 | FOR ${saved_user_list} IN @{username_list} |
| 230 | Redfish.Delete ${saved_user_list} |
| 231 | END |
| 232 | |
Rahul Maheshwari | 3e61ce6 | 2019-06-18 02:09:01 -0500 | [diff] [blame] | 233 | |
Anusha Dathatri | 9ecaaf4 | 2020-01-20 04:50:13 -0600 | [diff] [blame] | 234 | Create IPMI User Without Any Privilege And Verify Via Redfish |
| 235 | [Documentation] Create user using IPMI without privilege and verify via redfish. |
| 236 | [Tags] Create_IPMI_User_Without_Any_Privilege_And_Verify_Via_Redfish |
| 237 | |
| 238 | ${username} ${userid}= IPMI Create Random User Plus Password And Privilege |
| 239 | ... ${valid_password} |
| 240 | |
| 241 | # Verify new user privilege level via Redfish. |
| 242 | ${privilege}= Redfish_Utils.Get Attribute |
| 243 | ... /redfish/v1/AccountService/Accounts/${username} RoleId |
| 244 | Valid Value privilege ['NoAccess'] |
| 245 | |
Rahul Maheshwari | 51dee26 | 2019-03-06 23:36:21 -0600 | [diff] [blame] | 246 | *** Keywords *** |
| 247 | |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 248 | IPMI Create Random User Plus Password And Privilege |
| 249 | [Documentation] Create random IPMI user with given password and privilege |
| 250 | ... level. |
Anusha Dathatri | 9ecaaf4 | 2020-01-20 04:50:13 -0600 | [diff] [blame] | 251 | [Arguments] ${password} ${privilege}=0 |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 252 | |
| 253 | # Description of argument(s): |
| 254 | # password Password to be assigned for the user. |
| 255 | # privilege Privilege level for the user (e.g. "1", "2", "3", etc.). |
| 256 | |
| 257 | # Create IPMI user. |
| 258 | ${random_username}= Generate Random String 8 [LETTERS] |
| 259 | Set Suite Variable ${random_username} |
| 260 | |
Gene Ratzlaff | d4cdc11 | 2022-05-06 13:17:35 -0400 | [diff] [blame] | 261 | ${random_userid}= Find Free User Id |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 262 | IPMI Create User ${random_userid} ${random_username} |
| 263 | |
| 264 | # Set given password for newly created user. |
| 265 | Run IPMI Standard Command |
| 266 | ... user set password ${random_userid} ${password} |
| 267 | |
| 268 | # Enable IPMI user. |
| 269 | Run IPMI Standard Command user enable ${random_userid} |
| 270 | |
| 271 | # Set given privilege and enable IPMI messaging for newly created user. |
Anusha Dathatri | 9ecaaf4 | 2020-01-20 04:50:13 -0600 | [diff] [blame] | 272 | Run Keyword If '${privilege}' != '0' |
| 273 | ... Set Channel Access ${random_userid} ipmi=on privilege=${privilege} |
Rahul Maheshwari | 75e91fe | 2019-03-29 05:32:28 -0500 | [diff] [blame] | 274 | |
| 275 | [Return] ${random_username} ${random_userid} |
| 276 | |
| 277 | |
Rahul Maheshwari | 51dee26 | 2019-03-06 23:36:21 -0600 | [diff] [blame] | 278 | Test Setup Execution |
| 279 | [Documentation] Do test case setup tasks. |
| 280 | |
| 281 | Redfish.Login |
| 282 | |
| 283 | |
| 284 | Test Teardown Execution |
| 285 | [Documentation] Do the post test teardown. |
| 286 | |
| 287 | FFDC On Test Case Fail |
| 288 | # Delete the test user. |
| 289 | Run Keyword And Ignore Error |
| 290 | ... Redfish.Delete /redfish/v1/AccountService/Accounts/${random_username} |
| 291 | |
| 292 | Redfish.Logout |
Gene Ratzlaff | d4cdc11 | 2022-05-06 13:17:35 -0400 | [diff] [blame] | 293 | |
| 294 | |
| 295 | Find Free User Id |
| 296 | [Documentation] Find a userid that is not being used. |
| 297 | FOR ${jj} IN RANGE 300 |
George Keishing | dc7d689 | 2022-07-07 14:28:32 -0500 | [diff] [blame] | 298 | # IPMI maximum users count (i.e. 15 users). |
| 299 | ${random_userid}= Evaluate random.randint(1, ${ipmi_max_num_users}) modules=random |
Gene Ratzlaff | d4cdc11 | 2022-05-06 13:17:35 -0400 | [diff] [blame] | 300 | ${access}= Run IPMI Standard Command channel getaccess 1 ${random_userid} |
| 301 | |
| 302 | ${name_line}= Get Lines Containing String ${access} User Name |
| 303 | Log To Console For ID ${random_userid}: ${name_line} |
| 304 | ${is_empty}= Run Keyword And Return Status |
| 305 | ... Should Match Regexp ${name_line} ${empty_name_pattern} |
| 306 | |
| 307 | Exit For Loop If ${is_empty} == ${True} |
| 308 | END |
| 309 | Run Keyword If '${jj}' == '299' Fail msg=A free user ID could not be found. |
| 310 | [Return] ${random_userid} |