1*** Settings *** 2 3Documentation Test Save Area feature of Management Console on BMC. 4 5Resource ../../lib/rest_client.robot 6Resource ../../lib/openbmc_ffdc.robot 7Resource ../../lib/resource.robot 8Resource ../../lib/bmc_redfish_utils.robot 9Resource ../../lib/utils.robot 10 11Suite Setup Suite Setup Execution 12Test Teardown Test Teardown Execution 13 14 15*** Variables *** 16 17${MAX_SIZE_MSG} File size exceeds 200KB. Maximum allowed size is 200KB 18${UPLOADED_MSG} File Created 19${FORBIDDEN_MSG} Forbidden 20${FILE_CREATE_ERROR_MSG} Error while creating the file 21 22@{ADMIN} admin_user TestPwd123 23@{OPERATOR} operator_user TestPwd123 24&{USERS} Administrator=${ADMIN} Operator=${OPERATOR} 25 26*** Test Cases *** 27 28Verify Small Partition File Upload And Delete 29 [Documentation] Verify small partition file upload and delete. 30 [Tags] Verify_Small_Partition_File_Upload_And_Delete 31 [Template] Upload File To Create Partition Then Delete Partition 32 33 # partition delete 34 # file_name size_kb name expect_resp_code expected_msg partition username 35 201KB_file 201 201KB ${HTTP_BAD_REQUEST} ${MAX_SIZE_MSG} ${True} ${OPENBMC_USERNAME} 36 15KB_file 15 15KB ${HTTP_OK} ${UPLOADED_MSG} ${True} ${OPENBMC_USERNAME} 37 200KB_file 200 200KB ${HTTP_OK} ${UPLOADED_MSG} ${True} ${OPENBMC_USERNAME} 38 39 40Verify Multiple Files Upload 41 [Documentation] Verify multiple files upload. 42 [Tags] Verify_Multiple_Files_Upload 43 [Template] Upload File To Create Partition Then Delete Partition 44 45 # partition delete 46 # file_name size_kb name expect_resp_code expected_msg partition username 47 0KB_file 0 0KB ${HTTP_OK} ${UPLOADED_MSG} ${False} ${OPENBMC_USERNAME} 48 10KB_file 10 10KB ${HTTP_OK} ${UPLOADED_MSG} ${False} ${OPENBMC_USERNAME} 49 50KB_file 50 50KB ${HTTP_OK} ${UPLOADED_MSG} ${False} ${OPENBMC_USERNAME} 50 250KB_file 250 250KB ${HTTP_BAD_REQUEST} ${MAX_SIZE_MSG} ${False} ${OPENBMC_USERNAME} 51 19KB_file 19 19KB ${HTTP_OK} ${UPLOADED_MSG} ${False} ${OPENBMC_USERNAME} 52 199KB_file 199 199KB ${HTTP_OK} ${UPLOADED_MSG} ${False} ${OPENBMC_USERNAME} 53 54 55Verify Read Partition 56 [Documentation] Verify read partition. 57 [Tags] Verify_Read_Partition 58 59 Set Test Variable ${file_name} testfile 60 Set Test Variable ${partition_name} part_read 61 Set Test Variable ${content} Sample Content to test partition file upload 62 63 Run echo "${content}" > ${file_name} 64 OperatingSystem.File Should Exist ${file_name} 65 66 Upload File To Create Partition Then Delete Partition ${file_name} 1 ${partition_name} 67 ... delete_partition=${False} 68 69 Read Partition And Verify Content ${partition_name} ${content} 70 71 72Verify Non-Admin User Is Forbidden To Upload Partition File 73 [Documentation] Verify non-admin user is forbidden to upload partition file. 74 [Tags] Verify_Non-Admin_User_Is_Forbidden_To_Upload_Partition_File 75 [Template] Upload File To Create Partition Then Delete Partition 76 77 # partition delete 78 # file_name size_kb name expect_resp_code expected_msg partition username 79 12KB_file 12 12KB ${HTTP_FORBIDDEN} ${FORBIDDEN_MSG} ${False} operator_user 80 81 82Verify Partition Update On BMC 83 [Documentation] Verify partition update on BMC. 84 [Tags] Verify_Partition_Update_On_BMC 85 86 Set Test Variable ${file_name} testfile 87 Set Test Variable ${partition_name} part_read 88 Set Test Variable ${content1} Sample Content to test partition file upload 89 Set Test Variable ${content2} Sample Content to test partition file update 90 91 Upload Partition File With Some Known Contents ${file_name} ${partition_name} ${content1} 92 Read Partition And Verify Content ${partition_name} ${content1} 93 94 # Upload the same partition with modified contents to verify update partition feature. 95 Upload Partition File With Some Known Contents ${file_name} ${partition_name} ${content2} 96 Read Partition And Verify Content ${partition_name} ${content2} 97 98 99Verify Delete Partition When Partition Does Not Exist 100 [Documentation] Verify delete partition when partition does not exist. 101 [Tags] Verify_Delete_Partition_When_Partition_Does_Not_Exist 102 [Template] Delete Partition And Verify On BMC 103 104 # partition_name expect_resp_code username 105 Does_not_exist ${HTTP_NOT_FOUND} ${OPENBMC_USERNAME} 106 Does_not_exist ${HTTP_FORBIDDEN} operator_user 107 108 109Verify Partition Files Persistency And Re-upload After BMC Reboot 110 [Documentation] Verify partition files persistency and re-upload after BMC reboot. 111 [Tags] Verify_Partition_Files_Persistency_And_Re-upload_After_BMC_Reboot 112 113 Set Test Variable ${file_name} testfile 114 Set Test Variable ${partition_name} part_read 115 Set Test Variable ${content} Sample Content to test partition file upload 116 117 Upload Partition File With Some Known Contents 118 ... ${file_name}_1 ${partition_name}_1 ${content}_${file_name}_1 119 Upload Partition File With Some Known Contents 120 ... ${file_name}_2 ${partition_name}_2 ${content}_${file_name}_2 121 122 OBMC Reboot (off) 123 124 # Get REST session to BMC. 125 Initialize OpenBMC 126 127 # Checking for the content of uploaded partitions after BMC reboot. 128 Read Partition And Verify Content ${partition_name}_1 ${content}_${file_name}_1 129 Read Partition And Verify Content ${partition_name}_2 ${content}_${file_name}_2 130 131 # Upload same partition with different content to test partition update after BMC reboot. 132 Upload Partition File With Some Known Contents 133 ... ${file_name}_1 ${partition_name}_1 ${content}_${file_name}_2 134 135 # Upload different partition. 136 Upload Partition File With Some Known Contents ${file_name} ${partition_name} ${content} 137 138 139Verify One Thousand Partitions File Upload 140 [Documentation] Verify One Thousand Partitions File Upload. 141 [Tags] Verify_One_Thousand_Partitions_File_Upload 142 143 # Note: 1000 Partitions file upload would take 15-20 minutes. 144 FOR ${INDEX} IN RANGE 1 1000 145 ${status}= Run Keyword And Return Status Upload File To Create Partition Then Delete Partition 146 ... 200KB 200 p${INDEX} delete_partition=${False} 147 Run Keyword If ${status} == ${True} Continue For Loop 148 149 # Check if /var is full on BMC. 150 ${status} ${stderr} ${rc}= BMC Execute Command df -k | grep \' /var\' | grep -v /var/ 151 ${var_size}= Set Variable ${status.split('%')[0].split()[1]} 152 153 # Should be a problem if partition file upload request has failed when /var is not full. 154 Exit For Loop If ${var_size} != ${100} 155 156 # Expect HTTP_INTERNAL_SERVER_ERROR and FILE_CREATE_ERROR_MSG when /var is full. 157 Upload File To Create Partition Then Delete Partition 158 ... 200KB 200 p${INDEX} ${HTTP_INTERNAL_SERVER_ERROR} ${FILE_CREATE_ERROR_MSG} ${False} 159 END 160 161 162*** Keywords *** 163 164Create Partition File 165 [Documentation] Create partition file. 166 [Arguments] ${file_name}=dummyfile ${size_kb}=15 167 168 # Description of argument(s): 169 # file_name Name of the test file to be created. Examples: p1.log, part1.txt etc. 170 # size_kb Size of the test file to be created in KB, default is 15KB. 171 # Example : 15, 200 etc. 172 173 ${file_exist}= Run Keyword And Return Status OperatingSystem.File Should Exist ${file_name} 174 Return From Keyword If ${file_exist} ${True} 175 176 # Create a partition file if it does not exist locally. 177 Run dd if=/dev/zero of=${file_name} bs=1 count=0 seek=${size_kb}KB 178 OperatingSystem.File Should Exist ${file_name} 179 180 181Delete All Sessions And Login Using Given User 182 [Documentation] Delete all sessions and login using given user. 183 [Arguments] ${username}=${OPENBMC_USERNAME} 184 185 # Description of argument(s): 186 # username Username to login. Default is OPENBMC_USERNAME. 187 # Ex: root, operator_user, admin_user, readonly_user etc. 188 189 Delete All Sessions 190 ${password}= Set Variable If '${username}' == '${OPENBMC_USERNAME}' ${OPENBMC_PASSWORD} TestPwd123 191 Initialize OpenBMC rest_username=${username} rest_password=${password} 192 193 194Upload File To Create Partition Then Delete Partition 195 [Documentation] Upload file to create partition the delete partition. 196 [Arguments] ${file_name}=dummyfile ${size_kb}=15 ${partition_name}=p1 ${expect_resp_code}=${HTTP_OK} 197 ... ${expected_msg}=File Created ${delete_partition}=${True} ${username}=${OPENBMC_USERNAME} 198 199 # Description of argument(s): 200 # file_name Name of the test file to be created. 201 # partition_name Name of the partition on BMC. 202 # expect_resp_code Expected REST response code, default is ${HTTP_OK}. 203 # expected_msg Expected message from file upload, default is 'File Created'. 204 # delete_partition Partition will be deleted if this is True. 205 # username Login username 206 207 # Create a session with given user to test upload partition file. 208 Run Keyword If '${username}' != '${OPENBMC_USERNAME}' 209 ... Delete All Sessions And Login Using Given User ${username} 210 211 # Create a partition file. 212 Create Partition File ${file_name} ${size_kb} 213 214 # Get the content of the file and upload to BMC. 215 ${image_data}= OperatingSystem.Get Binary File ${file_name} 216 ${data}= Create Dictionary data ${image_data} 217 ${headers}= Create Dictionary X-Auth-Token=${XAUTH_TOKEN} 218 219 Set To Dictionary ${data} headers ${headers} 220 ${resp}= Put Request openbmc /ibm/v1/Host/ConfigFiles/${partition_name} &{data} 221 Should Be Equal As Strings ${resp.status_code} ${expect_resp_code} 222 223 ${description}= Run Keyword If ${expect_resp_code} != ${HTTP_FORBIDDEN} 224 ... Return Description Of REST Response ${resp.text} 225 ... ELSE Set Variable ${FORBIDDEN_MSG} 226 227 Should Be Equal As Strings ${description} ${expected_msg} 228 229 # Cleanup local space after upload attempt. 230 Run Keyword And Ignore Error Delete Local File Created To Upload ${file_name} 231 232 ${upload_success}= Set Variable If ${expect_resp_code} != ${HTTP_OK} ${False} ${True} 233 Verify Partition Available On BMC ${partition_name} ${upload_success} ${username} 234 235 # Delete partition and verify on BMC. 236 ${expect_resp_code}= Set Variable If ${expect_resp_code} != ${HTTP_OK} ${HTTP_NOT_FOUND} ${HTTP_OK} 237 Run Keyword If ${delete_partition} == ${True} Delete Partition And Verify On BMC 238 ... ${partition_name} ${expect_resp_code} ${username} 239 240 241Return Description Of REST Response 242 [Documentation] Return description of REST response. 243 [Arguments] ${resp_text} 244 245 # Description of argument(s): 246 # resp_text REST response body. 247 248 # resp_text after successful partition file upload looks like: 249 # { 250 # "Description": "File Created" 251 # } 252 253 ${message}= Evaluate json.loads('''${resp_text}''') json 254 255 [Return] ${message["Description"]} 256 257 258Delete Partition And Verify On BMC 259 [Documentation] Delete partition and verify on BMC. 260 [Arguments] ${partition_name} ${expect_resp_code}=${HTTP_OK} ${username}=${OPENBMC_USERNAME} 261 262 # Description of argument(s): 263 # partition_name Name of the partition on BMC. 264 # expect_resp_code Expected REST response code from DELETE request, default is ${HTTP_OK}. 265 # username Username to login, if other than OPENBMC_USERNAME user. 266 267 # Create a session with given user to test delete operation. 268 # If user is a non-admin user then DELETE request is forbidden for the user. 269 Run Keyword If '${username}' != '${OPENBMC_USERNAME}' 270 ... Delete All Sessions And Login Using Given User ${username} 271 272 Delete Partition ${partition_name} ${expect_resp_code} 273 Verify Partition Available On BMC ${partition_name} ${False} ${username} 274 275 276Get List Of Partitions 277 [Documentation] Get list of partitions. 278 [Arguments] ${expect_resp_code}=${HTTP_OK} 279 280 # Description of argument(s): 281 # expect_resp_code Expected REST response code, default is ${HTTP_OK}. 282 283 ${resp}= Get Request openbmc /ibm/v1/Host/ConfigFiles 284 Should Be Equal As Strings ${resp.status_code} ${expect_resp_code} 285 Return From Keyword If ${expect_resp_code} != ${HTTP_OK} 286 287 ${resp_json}= To JSON ${resp.content} 288 ${partitions_cnt}= Get Length ${resp_json['Members']} 289 290 [Return] ${resp_json['Members']} ${partitions_cnt} 291 292 293Verify Partition Available On BMC 294 [Documentation] Verify partition available on BMC. 295 [Arguments] ${partition_name}=${EMPTY} ${operation_status}=${True} ${username}=${OPENBMC_USERNAME} 296 297 # Description of argument(s): 298 # partition_name Name of the partition on BMC. 299 # operation_success Status of the previous operation like upload/delete success or failure. 300 # True if operation was a success else False. 301 # username Username used to upload/delete. Default is ${OPENBMC_USERNAME}. 302 303 # Non admin users will not have an access to do GET list 304 Run Keyword If '${username}' != '${OPENBMC_USERNAME}' 305 ... Delete All Sessions And Login Using Given User 306 307 ${partitions} ${partitions_cnt}= Get List Of Partitions 308 ${rest_response}= Run Keyword And Return Status List Should Contain Value ${partitions} 309 ... /ibm/v1/Host/ConfigFiles/${partition_name} 310 311 ${status} ${stderr} ${rc}= BMC Execute Command 312 ... ls -l /var/lib/obmc/bmc-console-mgmt/save-area/${partition_name} | wc -l 313 ${bmc_response}= Run Keyword And Return Status Should Be True ${status} == ${1} 314 315 Run Keyword If '${partition_name}' == '${EMPTY}' Run Keywords 316 ... Should Be Equal ${rest_response} ${False} AND Should Be Equal ${bmc_response} ${False} 317 318 Run Keyword And Return If '${partition_name}' != '${EMPTY}' Run Keywords 319 ... Should Be True ${rest_response} == ${operation_status} AND 320 ... Should Be True ${bmc_response} == ${operation_status} 321 322 323Delete Partition 324 [Documentation] Delete partition. 325 [Arguments] ${partition_name}='${EMPTY}' ${expect_resp_code}=${HTTP_OK} 326 327 # Description of argument(s): 328 # partition_name Name of the partition on BMC. 329 # expect_resp_code Expected REST response code, default is ${HTTP_OK}. 330 331 ${data}= Create Dictionary 332 ${headers}= Create Dictionary X-Auth-Token=${XAUTH_TOKEN} 333 Set To Dictionary ${data} headers ${headers} 334 335 ${resp}= Delete Request openbmc /ibm/v1/Host/ConfigFiles/${partition_name} &{data} 336 ${expect_resp_code}= Set Variable If '${partition_name}' == '${EMPTY}' 337 ... ${HTTP_NOT_FOUND} ${expect_resp_code} 338 Should Be Equal As Strings ${resp.status_code} ${expect_resp_code} 339 340 341Delete And Verify All Partitions on BMC 342 [Documentation] Delete and verify all partitions on BMC. 343 [Arguments] ${expect_resp_code}=${HTTP_OK} 344 345 # Description of argument(s): 346 # expect_resp_code Expected REST response code, default is ${HTTP_OK}. 347 348 ${data}= Create Dictionary 349 ${headers}= Create Dictionary X-Auth-Token=${XAUTH_TOKEN} 350 Set To Dictionary ${data} headers ${headers} 351 352 ${resp}= Post Request openbmc /ibm/v1/Host/ConfigFiles/Actions/FileCollection.DeleteAll &{data} 353 Should Be Equal As Strings ${resp.status_code} ${expect_resp_code} 354 355 Return From Keyword If ${expect_resp_code} != ${HTTP_OK} 356 Verify Partition Available On BMC operation_status=${False} 357 358 359Read Partition And Verify Content 360 [Documentation] Read partition and verify content. 361 [Arguments] ${partition_name}=p1 ${content}=${EMPTY} ${expect_resp_code}=${HTTP_OK} 362 363 # Description of argument(s): 364 # partition_name Name of the partition on BMC. 365 # content Content of the partition file uploaded. 366 # expect_resp_code Expected REST response code, default is ${HTTP_OK}. 367 368 ${resp}= Get Request openbmc /ibm/v1/Host/ConfigFiles/${partition_name} 369 Should Be Equal As Strings ${resp.status_code} ${expect_resp_code} 370 371 ${partition_data}= Remove String ${resp.text} \\n 372 ${partition_data}= Evaluate json.loads('''${partition_data}''') json 373 Should Be Equal As Strings ${partition_data["Data"]} ${content} 374 375 376Delete Local File Created To Upload 377 [Documentation] Delete local file created to upload. 378 [Arguments] ${file_name} 379 380 # Description of argument(s): 381 # file_name Name of the local file to be deleted. 382 383 Run Keyword And Ignore Error Run rm -f ${file_name} 384 385 386Upload Partition File With Some Known Contents 387 [Documentation] Upload partition file with some known contents. 388 [Arguments] ${file_name} ${partition_name} ${content} 389 390 # Description of argument(s): 391 # file_name Name of the partition file to be uploaded. 392 # partition_name Name of the partition on BMC. 393 # content Content of the partition file to be uploaded. 394 395 Run echo "${content}" > ${file_name} 396 OperatingSystem.File Should Exist ${file_name} 397 398 Upload File To Create Partition Then Delete Partition ${file_name} 1 ${partition_name} 399 ... delete_partition=${False} 400 401 402Suite Setup Execution 403 [Documentation] Suite setup execution. 404 405 # Create different user accounts. 406 Redfish.Login 407 Create Users With Different Roles users=${USERS} force=${True} 408 Redfish.Logout 409 410 # Get REST session to BMC. 411 Initialize OpenBMC 412 413 414Test Teardown Execution 415 [Documentation] Test teardown execution. 416 417 Delete And Verify All Partitions on BMC 418 FFDC On Test Case Fail 419 420