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