manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 1 | *** Settings *** |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 2 | |
| 3 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 4 | Documentation Verify Redfish tool functionality. |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 5 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 6 | Library OperatingSystem |
| 7 | Library String |
| 8 | Library Collections |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 9 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 10 | Resource ../../lib/resource.robot |
| 11 | Resource ../../lib/bmc_redfish_resource.robot |
| 12 | Resource ../../lib/openbmc_ffdc.robot |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 13 | Resource ../../lib/certificate_utils.robot |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 14 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 15 | |
| 16 | Suite Setup Suite Setup Execution |
| 17 | |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 18 | |
| 19 | *** Variables *** |
| 20 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 21 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 22 | ${root_cmd_args} = SEPARATOR= |
| 23 | ... redfishtool raw -r ${OPENBMC_HOST} -u ${OPENBMC_USERNAME} -p ${OPENBMC_PASSWORD} -S Always |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 24 | ${min_number_sensors} ${15} |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 25 | ${min_number_roles} ${4} |
| 26 | ${min_number_users} ${1} |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 27 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 28 | |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 29 | *** Test Cases *** |
| 30 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 31 | |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 32 | Verify Redfishtool Sensor Commands |
| 33 | [Documentation] Verify redfishtool's sensor commands. |
| 34 | [Tags] Verify_Redfishtool_Sensor_Commands |
| 35 | |
| 36 | ${sensor_status}= Redfishtool Get /redfish/v1/Chassis/chassis/Sensors |
| 37 | ${json_object}= Evaluate json.loads('''${sensor_status}''') json |
| 38 | Should Be True ${json_object["Members@odata.count"]} > ${min_number_sensors} |
| 39 | ... msg=There should be at least ${min_number_sensors} sensors. |
| 40 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 41 | |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 42 | Verify Redfishtool Health Check Commands |
| 43 | [Documentation] Verify redfishtool's health check command. |
| 44 | [Tags] Verify_Redfishtool_Health_Check_Commands |
| 45 | |
| 46 | ${chassis_data}= Redfishtool Get /redfish/v1/Chassis/chassis/ |
| 47 | ${json_object}= Evaluate json.loads('''${chassis_data}''') json |
| 48 | ${status}= Set Variable ${json_object["Status"]} |
| 49 | Should Be Equal OK ${status["Health"]} |
| 50 | ... msg=Health status should be OK. |
| 51 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 52 | |
| 53 | Verify Redfishtool Create Users |
| 54 | [Documentation] Create user via Redfishtool and verify. |
| 55 | [Tags] Verify_Redfishtool_Create_Users |
| 56 | [Teardown] Redfishtool Delete User "UserT100" |
| 57 | |
| 58 | Redfishtool Create User "UserT100" "TestPwd123" "Operator" true |
| 59 | Redfishtool Verify User "UserT100" "Operator" |
| 60 | |
| 61 | |
| 62 | Verify Redfishtool Modify Users |
| 63 | [Documentation] Modify user via Redfishtool and verify. |
| 64 | [Tags] Verify_Redfishtool_Modify_Users |
| 65 | [Teardown] Redfishtool Delete User "UserT100" |
| 66 | |
| 67 | Redfishtool Create User "UserT100" "TestPwd123" "Operator" true |
| 68 | Redfishtool Update User Role "UserT100" "Administrator" |
| 69 | Redfishtool Verify User "UserT100" "Administrator" |
| 70 | |
| 71 | |
| 72 | Verify Redfishtool Delete Users |
| 73 | [Documentation] Delete user via Redfishtool and verify. |
| 74 | [Tags] Verify_Redfishtool_Delete_Users |
| 75 | |
| 76 | Redfishtool Create User "UserT100" "TestPwd123" "Operator" true |
| 77 | Redfishtool Delete User "UserT100" |
| 78 | ${status}= Redfishtool Verify User Name Exists "UserT100" |
| 79 | Should Be True ${status} == False |
| 80 | |
| 81 | |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 82 | Verify Redfishtool Login With Deleted Redfish Users |
| 83 | [Documentation] Verify login with deleted user via Redfishtool. |
| 84 | [Tags] Verify_Redfishtool_Login_With_Deleted_Redfish_Users |
| 85 | |
| 86 | Redfishtool Create User "UserT100" "TestPwd123" "Operator" true |
| 87 | Redfishtool Delete User "UserT100" |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 88 | Redfishtool Access Resource /redfish/v1/AccountService/Accounts "UserT100" "TestPwd123" |
| 89 | ... ${HTTP_UNAUTHORIZED} |
| 90 | |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 91 | |
| 92 | Verify Redfishtool Error Upon Creating Same Users With Different Privileges |
George Keishing | e20f82c | 2020-05-13 10:51:02 -0500 | [diff] [blame] | 93 | [Documentation] Verify error upon creating same users with different privileges. |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 94 | [Tags] Verify_Redfishtool_Error_Upon_Creating_Same_Users_With_Different_Privileges |
| 95 | [Teardown] Redfishtool Delete User "UserT100" |
| 96 | |
| 97 | Redfishtool Create User "UserT100" "TestPwd123" "Operator" true |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 98 | Redfishtool Create User "UserT100" "TestPwd123" "Administrator" true |
| 99 | ... expected_error=${HTTP_BAD_REQUEST} |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 100 | |
| 101 | |
| 102 | Verify Redfishtool Admin User Privilege |
George Keishing | e20f82c | 2020-05-13 10:51:02 -0500 | [diff] [blame] | 103 | [Documentation] Verify privilege of admin user. |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 104 | [Tags] Verify_Redfishtool_Admin_User_Privilege |
| 105 | [Teardown] Run Keywords Redfishtool Delete User "UserT100" AND |
| 106 | ... Redfishtool Delete User "UserT101" |
| 107 | |
| 108 | Redfishtool Create User "UserT100" "TestPwd123" "Administrator" true |
| 109 | |
| 110 | # Verify if an user can be added by admin |
| 111 | Redfishtool Create User "UserT101" "TestPwd123" "Operator" true "UserT100" "TestPwd123" |
| 112 | |
| 113 | |
| 114 | Verify Redfishtool ReadOnly User Privilege |
| 115 | [Documentation] Verify Redfishtool ReadOnly user privilege works. |
| 116 | [Tags] Verify_Redfishtool_ReadOnly_User_Privilege |
| 117 | [Teardown] Redfishtool Delete User "UserT100" |
| 118 | |
| 119 | Redfishtool Create User "UserT100" "TestPwd123" "ReadOnly" true |
| 120 | Redfishtool Access Resource /redfish/v1/Systems/ "UserT100" "TestPwd123" |
| 121 | |
| 122 | Redfishtool Create User |
| 123 | ... "UserT101" "TestPwd123" "Operator" true "UserT100" "TestPwd123" ${HTTP_FORBIDDEN} |
| 124 | |
| 125 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 126 | Verify Redfishtool Replace Server Certificate Valid CertKey |
| 127 | [Documentation] Verify replace server certificate. |
| 128 | [Tags] Verify_Redfishtool_Replace_Server_Certificate_Valid_CertKey |
| 129 | |
| 130 | Verify Redfishtool Replace Certificate Server Valid Certificate Valid Privatekey ok |
| 131 | |
| 132 | |
| 133 | Verify Redfishtool Replace Client Certificate Valid CertKey |
| 134 | [Documentation] Verify replace client certificate. |
| 135 | [Tags] Verify_Redfishtool_Replace_Client_Certificate_Valid_CertKey |
| 136 | |
| 137 | Verify Redfishtool Replace Certificate Client Valid Certificate Valid Privatekey ok |
| 138 | |
| 139 | |
| 140 | Verify Redfishtool Replace CA Certificate Valid Cert |
| 141 | [Documentation] Verify replace CA certificate. |
| 142 | [Tags] Verify_Redfishtool_Replace_CA_Certificate_Valid_Cert |
| 143 | |
| 144 | Verify Redfishtool Replace Certificate CA Valid Certificate ok |
| 145 | |
| 146 | |
| 147 | Verify Redfishtool Client Certificate Install Valid CertKey |
| 148 | [Documentation] Verify client certificate installation. |
| 149 | [Tags] Verify_Redfishtool_Client_Certificate_Install_Valid_CertKey |
| 150 | |
| 151 | Verify Redfishtool Install Certificate Client Valid Certificate Valid Privatekey ok |
| 152 | |
| 153 | |
| 154 | Verify Redfishtool CA Certificate Install Valid Cert |
| 155 | [Documentation] Verify CA Certificate installation. |
| 156 | [Tags] Verify_Redfishtool_CA_Certificate_Install_Valid_Cert |
| 157 | |
| 158 | Verify Redfishtool Install Certificate CA Valid Certificate ok |
| 159 | |
| 160 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 161 | Verify Redfishtool Replace Server Certificate Errors |
| 162 | [Documentation] Verify error while replacing invalid server certificate. |
| 163 | [Tags] Verify_Redfishtool_Replace_Server_Certificate_Errors |
| 164 | [Template] Verify Redfishtool Replace Certificate |
| 165 | |
| 166 | Server Empty Certificate Empty Privatekey error |
| 167 | Server Empty Certificate Valid Privatekey error |
| 168 | Server Valid Certificate Empty Privatekey error |
| 169 | |
| 170 | |
| 171 | Verify Redfishtool Replace Client Certificate Errors |
| 172 | [Documentation] Verify error while replacing invalid client certificate. |
| 173 | [Tags] Verify_Redfishtool_Replace_Client_Certificate_Errors |
| 174 | [Template] Verify Redfishtool Replace Certificate |
| 175 | |
| 176 | Client Empty Certificate Empty Privatekey error |
| 177 | Client Empty Certificate Valid Privatekey error |
| 178 | Client Valid Certificate Empty Privatekey error |
| 179 | |
| 180 | Verify Redfishtool Replace CA Certificate Errors |
| 181 | [Documentation] Verify error while replacing invalid CA certificate. |
| 182 | [Tags] Verify_Redfishtool_Replace_CA_Certificate_Errors |
| 183 | [Template] Verify Redfishtool Replace Certificate |
| 184 | |
| 185 | CA Empty Certificate error |
| 186 | |
| 187 | Verify Redfishtool Client Certificate Install Errors |
| 188 | [Documentation] Verify error while installing invalid client certificate. |
| 189 | [Tags] Verify_Redfishtool_Client_Certificate_Install_Errors |
| 190 | [Template] Verify Redfishtool Install Certificate |
| 191 | |
| 192 | Client Empty Certificate Empty Privatekey error |
| 193 | Client Empty Certificate Valid Privatekey error |
| 194 | Client Valid Certificate Empty Privatekey error |
| 195 | |
| 196 | |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 197 | *** Keywords *** |
| 198 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 199 | |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 200 | Redfishtool Access Resource |
| 201 | [Documentation] Access resource. |
| 202 | [Arguments] ${uri} ${login_user} ${login_pasword} ${expected_error}="" |
| 203 | |
| 204 | # Description of argument(s): |
| 205 | # uri URI for resource access. |
| 206 | # login_user The login user name used other than default root user. |
| 207 | # login_pasword The login password. |
| 208 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 209 | # authentication error, etc. ) |
| 210 | |
| 211 | ${user_cmd_args}= Set Variable |
| 212 | ... redfishtool raw -r ${OPENBMC_HOST} -u ${login_user} -p ${login_pasword} -S Always |
| 213 | Redfishtool Get ${uri} ${user_cmd_args} ${expected_error} |
| 214 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 215 | |
| 216 | Is HTTP error Expected |
| 217 | [Documentation] Check if the HTTP error is expected. |
| 218 | [Arguments] ${cmd_output} ${error_expected} |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 219 | |
| 220 | # Description of argument(s): |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 221 | # cmd_output Output of an HTTP operation. |
| 222 | # error_expected Expected error. |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 223 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 224 | @{words} = Split String ${error_expected} , |
| 225 | @{errorString}= Split String ${cmd_output} ${SPACE} |
| 226 | Should Contain Any ${errorString} @{words} |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 227 | |
| 228 | |
| 229 | Redfishtool Create User |
| 230 | [Documentation] Create new user. |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 231 | [Arguments] ${user_name} ${password} ${roleID} ${enable} ${login_user}="" ${login_pasword}="" |
| 232 | ... ${expected_error}="" |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 233 | |
| 234 | # Description of argument(s): |
| 235 | # user_name The user name (e.g. "test", "robert", etc.). |
| 236 | # password The user password (e.g. "0penBmc", "0penBmc1", etc.). |
| 237 | # roleID The role of user (e.g. "Administrator", "Operator", etc.). |
| 238 | # enable Enabled attribute of (e.g. true or false). |
| 239 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 240 | # authentication error, etc. ) |
| 241 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 242 | ${user_cmd_args}= Set Variable |
| 243 | ... redfishtool raw -r ${OPENBMC_HOST} -u ${login_user} -p ${login_pasword} -S Always |
| 244 | ${data}= Set Variable |
| 245 | ... '{"UserName":${user_name},"Password":${password},"RoleId":${roleId},"Enabled":${enable}}' |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 246 | Run Keyword If ${login_user} == "" |
| 247 | ... Redfishtool Post ${data} /redfish/v1/AccountService/Accounts ${root_cmd_args} ${expected_error} |
| 248 | ... ELSE |
| 249 | ... Redfishtool Post ${data} /redfish/v1/AccountService/Accounts ${user_cmd_args} ${expected_error} |
| 250 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 251 | |
| 252 | Redfishtool Update User Role |
| 253 | [Documentation] Update user role. |
| 254 | [Arguments] ${user_name} ${newRole} ${login_user}="" ${login_pasword}="" |
| 255 | ... ${expected_error}="" |
| 256 | |
| 257 | # Description of argument(s): |
| 258 | # user_name The user name (e.g. "test", "robert", etc.). |
| 259 | # newRole The new role of user (e.g. "Administrator", "Operator", etc.). |
| 260 | # login_user The login user name used other than default root user. |
| 261 | # login_pasword The login password. |
| 262 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 263 | # authentication error, etc. ) |
| 264 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 265 | ${user_cmd_args}= Set Variable |
| 266 | ... redfishtool raw -r ${OPENBMC_HOST} -u ${login_user} -p ${login_pasword} -S Always |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 267 | Run Keyword If ${login_user} == "" |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 268 | ... Redfishtool Patch '{"RoleId":${newRole}}' |
| 269 | ... /redfish/v1/AccountService/Accounts/${user_name} ${root_cmd_args} ${expected_error} |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 270 | ... ELSE |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 271 | ... Redfishtool Patch '{"RoleId":${newRole}}' |
| 272 | ... /redfish/v1/AccountService/Accounts/${user_name} ${user_cmd_args} ${expected_error} |
manashsarma | ea14dae | 2020-03-26 11:00:27 -0500 | [diff] [blame] | 273 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 274 | |
| 275 | Redfishtool Delete User |
| 276 | [Documentation] Delete an user. |
| 277 | [Arguments] ${user_name} ${expected_error}="" |
| 278 | |
| 279 | # Description of argument(s): |
| 280 | # user_name The user name (e.g. "test", "robert", etc.). |
| 281 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 282 | # authentication error, etc. ). |
| 283 | |
| 284 | Redfishtool Delete /redfish/v1/AccountService/Accounts/${user_name} |
| 285 | ... ${root_cmd_args} ${expected_error} |
| 286 | |
| 287 | |
| 288 | Redfishtool Verify User |
| 289 | [Documentation] Verify role of the user. |
| 290 | [Arguments] ${user_name} ${role} |
| 291 | |
| 292 | # Description of argument(s): |
| 293 | # user_name The user name (e.g. "test", "robert", etc.). |
| 294 | # role The new role of user (e.g. "Administrator", "Operator", etc.). |
| 295 | |
| 296 | ${user_account}= Redfishtool Get /redfish/v1/AccountService/Accounts/${user_name} |
| 297 | ${json_obj}= Evaluate json.loads('''${user_account}''') json |
| 298 | Should Be equal "${json_obj["RoleId"]}" ${role} |
| 299 | |
| 300 | |
| 301 | Redfishtool Verify User Name Exists |
| 302 | [Documentation] Verify user name exists. |
| 303 | [Arguments] ${user_name} |
| 304 | |
| 305 | # Description of argument(s): |
| 306 | # user_name The user name (e.g. "test", "robert", etc.). |
| 307 | |
| 308 | ${status}= Run Keyword And Return Status redfishtool Get |
| 309 | ... /redfish/v1/AccountService/Accounts/${user_name} |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 310 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 311 | [return] ${status} |
| 312 | |
| 313 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 314 | Verify Redfishtool Install Certificate |
| 315 | [Documentation] Install and verify certificate using Redfishtool. |
| 316 | [Arguments] ${cert_type} ${cert_format} ${expected_status} ${delete_cert}=${True} |
| 317 | |
| 318 | # Description of argument(s): |
| 319 | # cert_type Certificate type (e.g. "Client" or "CA"). |
| 320 | # cert_format Certificate file format |
| 321 | # expected_status Expected status of certificate install Redfishtool |
| 322 | # request (i.e. "ok" or "error"). |
| 323 | # delete_cert Certificate will be deleted before installing if this True. |
| 324 | |
| 325 | Run Keyword If '${cert_type}' == 'CA' and '${delete_cert}' == '${True}' |
| 326 | ... Delete All CA Certificate Via Redfisthtool |
| 327 | ... ELSE IF '${cert_type}' == 'Client' and '${delete_cert}' == '${True}' |
| 328 | ... Redfishtool Delete Certificate Via BMC CLI ${cert_type} |
| 329 | |
| 330 | ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} |
| 331 | ${bytes}= OperatingSystem.Get Binary File ${cert_file_path} |
| 332 | ${file_data}= Decode Bytes To String ${bytes} UTF-8 |
| 333 | |
| 334 | ${certificate_uri}= Set Variable If |
| 335 | ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI} |
| 336 | ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI} |
| 337 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 338 | ${cert_id}= Redfishtool Install Certificate File On BMC |
| 339 | ... ${certificate_uri} ${expected_status} data=${file_data} |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 340 | Logging Installed certificate id: ${cert_id} |
| 341 | |
| 342 | # Adding delay after certificate installation. |
| 343 | Sleep 30s |
| 344 | |
| 345 | ${cert_file_content}= OperatingSystem.Get File ${cert_file_path} |
| 346 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 347 | ${bmc_cert_content}= Run Keyword If '${expected_status}' == 'ok' |
| 348 | ... Redfishtool GetAttribute ${certificate_uri}/${cert_id} CertificateString |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 349 | |
| 350 | Run Keyword If '${expected_status}' == 'ok' Should Contain ${cert_file_content} ${bmc_cert_content} |
| 351 | |
| 352 | [Return] ${cert_id} |
| 353 | |
| 354 | |
| 355 | Delete All CA Certificate Via Redfisthtool |
| 356 | [Documentation] Delete all CA certificate via Redfish. |
| 357 | |
| 358 | ${cmd_output}= Redfishtool Get /redfish/v1/Managers/bmc/Truststore/Certificates |
| 359 | ${json_object}= To JSON ${cmd_output} |
| 360 | ${cert_list}= Set Variable ${json_object["Members"]} |
| 361 | FOR ${cert} IN @{cert_list} |
| 362 | Redfishtool Delete ${cert["@odata.id"]} ${root_cmd_args} ${HTTP_NO_CONTENT} |
| 363 | END |
| 364 | |
| 365 | |
| 366 | Redfishtool Delete Certificate Via BMC CLI |
| 367 | [Documentation] Delete certificate via BMC CLI. |
| 368 | [Arguments] ${cert_type} |
| 369 | |
| 370 | # Description of argument(s): |
| 371 | # cert_type Certificate type (e.g. "Client" or "CA"). |
| 372 | |
| 373 | ${certificate_file_path} ${certificate_service} ${certificate_uri}= |
| 374 | ... Run Keyword If '${cert_type}' == 'Client' |
| 375 | ... Set Variable /etc/nslcd/certs/cert.pem phosphor-certificate-manager@nslcd.service |
| 376 | ... ${REDFISH_LDAP_CERTIFICATE_URI} |
| 377 | ... ELSE IF '${cert_type}' == 'CA' |
| 378 | ... Set Variable ${ROOT_CA_FILE_PATH} phosphor-certificate-manager@authority.service |
| 379 | ... ${REDFISH_CA_CERTIFICATE_URI} |
| 380 | |
| 381 | ${file_status} ${stderr} ${rc}= BMC Execute Command |
| 382 | ... [ -f ${certificate_file_path} ] && echo "Found" || echo "Not Found" |
| 383 | |
| 384 | Return From Keyword If "${file_status}" != "Found" |
| 385 | BMC Execute Command rm ${certificate_file_path} |
| 386 | BMC Execute Command systemctl restart ${certificate_service} |
| 387 | BMC Execute Command systemctl daemon-reload |
| 388 | |
| 389 | |
| 390 | Redfishtool Install Certificate File On BMC |
| 391 | [Documentation] Install certificate file in BMC using POST operation. |
| 392 | [Arguments] ${uri} ${status}=ok &{kwargs} |
| 393 | |
| 394 | # Description of argument(s): |
| 395 | # uri URI for installing certificate file via Redfishtool. |
| 396 | # e.g. "/redfish/v1/AccountService/LDAP/Certificates". |
| 397 | # status Expected status of certificate installation via Redfishtool. |
| 398 | # e.g. error, ok. |
| 399 | # kwargs A dictionary of keys/values to be passed directly to |
| 400 | # POST Request. |
| 401 | |
| 402 | Initialize OpenBMC 20 ${quiet}=${1} ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} |
| 403 | |
| 404 | ${headers}= Create Dictionary Content-Type=application/octet-stream |
| 405 | ... X-Auth-Token=${XAUTH_TOKEN} |
| 406 | Set To Dictionary ${kwargs} headers ${headers} |
| 407 | |
| 408 | ${ret}= Post Request openbmc ${uri} &{kwargs} |
| 409 | ${content_json}= To JSON ${ret.content} |
| 410 | ${cert_id}= Set Variable If '${ret.status_code}' == '${HTTP_OK}' ${content_json["Id"]} -1 |
| 411 | |
| 412 | Run Keyword If '${status}' == 'ok' |
| 413 | ... Should Be Equal As Strings ${ret.status_code} ${HTTP_OK} |
| 414 | ... ELSE IF '${status}' == 'error' |
| 415 | ... Should Be Equal As Strings ${ret.status_code} ${HTTP_INTERNAL_SERVER_ERROR} |
| 416 | |
| 417 | Delete All Sessions |
| 418 | |
| 419 | [Return] ${cert_id} |
| 420 | |
| 421 | |
| 422 | Verify Redfishtool Replace Certificate |
| 423 | [Documentation] Verify replace server certificate. |
| 424 | [Arguments] ${cert_type} ${cert_format} ${expected_status} |
| 425 | |
| 426 | # Description of argument(s): |
| 427 | # cert_type Certificate type (e.g. "Client", "Server" or "CA"). |
| 428 | # cert_format Certificate file format |
| 429 | # (e.g. "Valid_Certificate_Valid_Privatekey"). |
| 430 | # expected_status Expected status of certificate replace Redfishtool |
| 431 | # request (i.e. "ok" or "error"). |
| 432 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 433 | # Install certificate before replacing client or CA certificate. |
| 434 | ${cert_id}= Run Keyword If '${cert_type}' == 'Client' |
| 435 | ... Verify Redfishtool Install Certificate ${cert_type} Valid Certificate Valid Privatekey ok |
| 436 | ... ELSE IF '${cert_type}' == 'CA' |
| 437 | ... Verify Redfishtool Install Certificate ${cert_type} Valid Certificate ok |
| 438 | |
| 439 | ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} |
| 440 | ${bytes}= OperatingSystem.Get Binary File ${cert_file_path} |
| 441 | ${file_data}= Decode Bytes To String ${bytes} UTF-8 |
| 442 | |
| 443 | ${certificate_uri}= Set Variable If |
| 444 | ... '${cert_type}' == 'Server' ${REDFISH_HTTPS_CERTIFICATE_URI}/1 |
| 445 | ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}/1 |
| 446 | ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI}/${cert_id} |
| 447 | |
| 448 | ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri} |
| 449 | ${dict_objects}= Create Dictionary CertificateString=${file_data} |
| 450 | ... CertificateType=PEM CertificateUri=${certificate_dict} |
| 451 | ${string}= Convert To String ${dict_objects} |
| 452 | ${string}= Replace String ${string} ' " |
| 453 | ${payload}= Set Variable '${string}' |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 454 | |
| 455 | ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK} |
| 456 | ... '${expected_status}' == 'error' ${HTTP_NOT_FOUND} |
| 457 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 458 | ${response}= Redfishtool Post |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 459 | ... ${payload} /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate expected_error=${expected_resp} |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 460 | |
| 461 | ${cert_file_content}= OperatingSystem.Get File ${cert_file_path} |
| 462 | ${bmc_cert_content}= Redfishtool GetAttribute ${certificate_uri} CertificateString |
| 463 | |
| 464 | Run Keyword If '${expected_status}' == 'ok' |
| 465 | ... Should Contain ${cert_file_content} ${bmc_cert_content} |
| 466 | ... ELSE |
| 467 | ... Should Not Contain ${cert_file_content} ${bmc_cert_content} |
| 468 | |
| 469 | |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 470 | Redfishtool Get |
| 471 | [Documentation] Execute redfishtool for GET operation. |
| 472 | [Arguments] ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}="" |
| 473 | |
| 474 | # Description of argument(s): |
| 475 | # uri URI for GET operation (e.g. /redfish/v1/AccountService/Accounts/). |
| 476 | # cmd_args Commandline arguments. |
| 477 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 478 | # authentication error, etc. ). |
| 479 | |
| 480 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd_args} GET ${uri} |
| 481 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
| 482 | |
| 483 | [Return] ${cmd_output} |
| 484 | |
| 485 | |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 486 | Redfishtool GetAttribute |
| 487 | [Documentation] Execute redfishtool for GET operation. |
| 488 | [Arguments] ${uri} ${Attribute} ${cmd_args}=${root_cmd_args} ${expected_error}="" |
| 489 | |
| 490 | # Description of argument(s): |
| 491 | # uri URI for GET operation (e.g. /redfish/v1/AccountService/Accounts/). |
| 492 | # Attribute The specific attribute to be retrieved with the URI. |
| 493 | # cmd_args Commandline arguments. |
| 494 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 495 | # authentication error, etc. ). |
| 496 | |
| 497 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd_args} GET ${uri} |
| 498 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
| 499 | ${json_object}= To JSON ${cmd_output} |
| 500 | |
| 501 | [Return] ${json_object["CertificateString"]} |
| 502 | |
| 503 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 504 | Redfishtool Post |
| 505 | [Documentation] Execute redfishtool for Post operation. |
| 506 | [Arguments] ${payload} ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}="" |
| 507 | |
| 508 | # Description of argument(s): |
| 509 | # payload Payload with POST operation (e.g. data for user name, password, role, |
| 510 | # enabled attribute) |
| 511 | # uri URI for POST operation (e.g. /redfish/v1/AccountService/Accounts/). |
| 512 | # cmd_args Commandline arguments. |
| 513 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 514 | # authentication error, etc. ). |
| 515 | |
| 516 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd_args} POST ${uri} --data=${payload} |
| 517 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 518 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 519 | [Return] ${cmd_output} |
| 520 | |
| 521 | |
| 522 | Redfishtool Patch |
| 523 | [Documentation] Execute redfishtool for Patch operation. |
| 524 | [Arguments] ${payload} ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}="" |
| 525 | |
| 526 | # Description of argument(s): |
| 527 | # payload Payload with POST operation (e.g. data for user name, role, etc. ). |
| 528 | # uri URI for PATCH operation (e.g. /redfish/v1/AccountService/Accounts/ ). |
| 529 | # cmd_args Commandline arguments. |
| 530 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 531 | # authentication error, etc. ). |
| 532 | |
| 533 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd_args} PATCH ${uri} --data=${payload} |
| 534 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 535 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 536 | [Return] ${cmd_output} |
| 537 | |
| 538 | |
| 539 | Redfishtool Delete |
| 540 | [Documentation] Execute redfishtool for Post operation. |
| 541 | [Arguments] ${uri} ${cmd_args}=${root_cmd_args} ${expected_error}="" |
| 542 | |
| 543 | # Description of argument(s): |
| 544 | # uri URI for DELETE operation. |
| 545 | # cmd_args Commandline arguments. |
| 546 | # expected_error Expected error optionally provided in testcase (e.g. 401 / |
| 547 | # authentication error, etc. ). |
| 548 | |
| 549 | ${rc} ${cmd_output}= Run and Return RC and Output ${cmd_args} DELETE ${uri} |
| 550 | Run Keyword If ${rc} != 0 Is HTTP error Expected ${cmd_output} ${expected_error} |
manashsarma | 40b85d1 | 2020-04-04 21:18:59 -0500 | [diff] [blame] | 551 | |
manashsarma | 91abf37 | 2020-03-17 20:34:02 -0500 | [diff] [blame] | 552 | [Return] ${cmd_output} |
| 553 | |
| 554 | |
manashsarma | 8b5d680 | 2020-03-09 04:09:15 -0500 | [diff] [blame] | 555 | Suite Setup Execution |
| 556 | [Documentation] Do suite setup execution. |
| 557 | |
| 558 | ${tool_exist}= Run which redfishtool |
| 559 | Should Not Be Empty ${tool_exist} |
manashsarma | 0b4b9e5 | 2020-05-19 12:13:38 -0500 | [diff] [blame] | 560 | |
| 561 | # Create certificate sub-directory in current working directory. |
| 562 | Create Directory certificate_dir |