George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation BMC and PNOR update utilities keywords. |
| 3 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 4 | Library code_update_utils.py |
| 5 | Library OperatingSystem |
| 6 | Library String |
George Keishing | 81ae45b | 2017-09-28 14:05:04 -0500 | [diff] [blame] | 7 | Library utilities.py |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 8 | Variables ../data/variables.py |
Charles Paul Hofer | e0e1780 | 2017-09-21 09:19:33 -0500 | [diff] [blame] | 9 | Resource boot_utils.robot |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 10 | Resource rest_client.robot |
George Keishing | 0071549 | 2017-08-18 11:46:37 -0500 | [diff] [blame] | 11 | Resource openbmc_ffdc.robot |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 12 | |
| 13 | *** Keywords *** |
| 14 | |
| 15 | Get Software Objects |
| 16 | [Documentation] Get the host software objects and return as a list. |
| 17 | [Arguments] ${version_type}=${VERSION_PURPOSE_HOST} |
| 18 | |
| 19 | # Description of argument(s): |
| 20 | # version_type Either BMC or host version purpose. |
| 21 | # By default host version purpose string. |
| 22 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 23 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
| 24 | |
| 25 | # Example: |
| 26 | # "data": [ |
| 27 | # "/xyz/openbmc_project/software/f3b29aa8", |
| 28 | # "/xyz/openbmc_project/software/e49bc78e", |
| 29 | # ], |
| 30 | # Iterate the list and return the host object name path list. |
| 31 | |
| 32 | ${host_list}= Create List |
| 33 | ${sw_list}= Read Properties ${SOFTWARE_VERSION_URI} |
| 34 | |
| 35 | :FOR ${index} IN @{sw_list} |
George Keishing | d62db0f | 2017-09-13 08:50:33 -0500 | [diff] [blame] | 36 | \ ${attr_purpose}= Read Software Attribute ${index} Purpose |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 37 | \ Continue For Loop If '${attr_purpose}' != '${version_type}' |
| 38 | \ Append To List ${host_list} ${index} |
| 39 | |
George Keishing | d62db0f | 2017-09-13 08:50:33 -0500 | [diff] [blame] | 40 | [Return] ${host_list} |
| 41 | |
| 42 | |
| 43 | Read Software Attribute |
| 44 | [Documentation] Return software attribute data. |
| 45 | [Arguments] ${software_object} ${attribute_name} |
| 46 | |
| 47 | # Description of argument(s): |
| 48 | # software_object Software object path. |
| 49 | # (e.g. "/xyz/openbmc_project/software/f3b29aa8"). |
| 50 | # attribute_name Software object attribute name. |
| 51 | |
| 52 | ${resp}= OpenBMC Get Request ${software_object}/attr/${attribute_name} |
| 53 | ... quiet=${1} |
| 54 | Return From Keyword If ${resp.status_code} != ${HTTP_OK} |
| 55 | ${content}= To JSON ${resp.content} |
| 56 | [Return] ${content["data"]} |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 57 | |
| 58 | |
George Keishing | fe4ebd2 | 2017-09-12 06:05:22 -0500 | [diff] [blame] | 59 | Get Software Objects Id |
| 60 | [Documentation] Get the software objects id and return as a list. |
| 61 | [Arguments] ${version_type}=${VERSION_PURPOSE_HOST} |
| 62 | |
| 63 | # Description of argument(s): |
| 64 | # version_type Either BMC or host version purpose. |
| 65 | # By default host version purpose string. |
| 66 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 67 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
| 68 | |
| 69 | ${sw_id_list}= Create List |
| 70 | ${sw_list}= Get Software Objects ${version_type} |
| 71 | |
| 72 | :FOR ${index} IN @{sw_list} |
| 73 | \ Append To List ${sw_id_list} ${index.rsplit('/', 1)[1]} |
| 74 | |
| 75 | [Return] ${sw_id_list} |
| 76 | |
| 77 | |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 78 | Get Host Software Property |
| 79 | [Documentation] Return a dictionary of host software properties. |
| 80 | [Arguments] ${host_object} |
| 81 | |
| 82 | # Description of argument(s): |
| 83 | # host_object Host software object path. |
| 84 | # (e.g. "/xyz/openbmc_project/software/f3b29aa8"). |
| 85 | |
| 86 | ${sw_attributes}= Read Properties ${host_object} |
| 87 | [return] ${sw_attributes} |
| 88 | |
Sweta Potthuri | cd96634 | 2017-09-06 03:41:32 -0500 | [diff] [blame] | 89 | Get Host Software Objects Details |
| 90 | [Documentation] Return software object details as a list of dictionaries. |
| 91 | [Arguments] ${quiet}=${QUIET} |
| 92 | |
| 93 | ${software}= Create List |
| 94 | |
| 95 | ${pnor_details}= Get Software Objects ${VERSION_PURPOSE_HOST} |
| 96 | :FOR ${pnor} IN @{pnor_details} |
| 97 | \ ${resp}= OpenBMC Get Request ${pnor} quiet=${1} |
| 98 | \ ${json}= To JSON ${resp.content} |
| 99 | \ Append To List ${software} ${json["data"]} |
| 100 | |
| 101 | [Return] ${software} |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 102 | |
| 103 | Set Host Software Property |
| 104 | [Documentation] Set the host software properties of a given object. |
| 105 | [Arguments] ${host_object} ${sw_attribute} ${data} |
| 106 | |
| 107 | # Description of argument(s): |
| 108 | # host_object Host software object name. |
| 109 | # sw_attribute Host software attribute name. |
| 110 | # (e.g. "Activation", "Priority", "RequestedActivation" etc). |
| 111 | # data Value to be written. |
| 112 | |
| 113 | ${args}= Create Dictionary data=${data} |
| 114 | Write Attribute ${host_object} ${sw_attribute} data=${args} |
| 115 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 116 | |
| 117 | Set Property To Invalid Value And Verify No Change |
| 118 | [Documentation] Attempt to set a property and check that the value didn't |
| 119 | ... change. |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 120 | [Arguments] ${property} ${version_type} |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 121 | |
| 122 | # Description of argument(s): |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 123 | # property The property to attempt to set. |
| 124 | # version_type Either BMC or host version purpose. |
| 125 | # By default host version purpose string. |
| 126 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 127 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 128 | |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 129 | ${software_objects}= Get Software Objects version_type=${version_type} |
| 130 | ${prev_properties}= Get Host Software Property @{software_objects}[0] |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 131 | Run Keyword And Expect Error 500 != 200 |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 132 | ... Set Host Software Property @{software_objects}[0] ${property} foo |
| 133 | ${cur_properties}= Get Host Software Property @{software_objects}[0] |
| 134 | Should Be Equal As Strings &{prev_properties}[${property}] |
| 135 | ... &{cur_properties}[${property}] |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 136 | |
| 137 | |
Charles Paul Hofer | 42f1746 | 2017-09-12 14:09:32 -0500 | [diff] [blame] | 138 | Set Priority To Invalid Value And Expect Error |
| 139 | [Documentation] Set the priority of an image to an invalid value and |
| 140 | ... check that an error was returned. |
| 141 | [Arguments] ${version_type} ${priority} |
| 142 | |
| 143 | # Description of argument(s): |
| 144 | # version_type Either BMC or host version purpose. |
| 145 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 146 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
| 147 | # priority The priority value to set. Should be an integer outside of |
| 148 | # the range of 0 through 255. |
| 149 | |
| 150 | ${images}= Get Software Objects version_type=${version_type} |
| 151 | ${num_images}= Get Length ${images} |
| 152 | Should Be True 0 < ${num_images} |
| 153 | |
| 154 | Run Keyword And Expect Error 403 != 200 |
| 155 | ... Set Host Software Property @{images}[0] Priority ${priority} |
| 156 | |
| 157 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 158 | Upload And Activate Image |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 159 | [Documentation] Upload an image to the BMC and activate it with REST. |
Charles Paul Hofer | b7842a5 | 2017-09-22 10:11:33 -0500 | [diff] [blame] | 160 | [Arguments] ${image_file_path} ${wait}=${1} ${skip_if_active}=false |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 161 | |
| 162 | # Description of argument(s): |
George Keishing | 71c24ed | 2017-09-25 13:11:10 -0500 | [diff] [blame] | 163 | # image_file_path The path to the image tarball to upload and activate. |
| 164 | # wait Indicates that this keyword should wait for host or |
| 165 | # BMC activation is completed. |
Charles Paul Hofer | b7842a5 | 2017-09-22 10:11:33 -0500 | [diff] [blame] | 166 | # skip_if_active If set to true, will skip the code update if this |
| 167 | # image is already on the BMC. |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 168 | |
| 169 | OperatingSystem.File Should Exist ${image_file_path} |
| 170 | ${image_version}= Get Version Tar ${image_file_path} |
| 171 | |
| 172 | ${image_data}= OperatingSystem.Get Binary File ${image_file_path} |
| 173 | Upload Image To BMC /upload/image data=${image_data} |
| 174 | ${ret} ${version_id}= Verify Image Upload ${image_version} |
| 175 | Should Be True ${ret} |
| 176 | |
Charles Paul Hofer | b7842a5 | 2017-09-22 10:11:33 -0500 | [diff] [blame] | 177 | # Verify the image is 'READY' to be activated or if it's already active, |
| 178 | # set priority to 0 and reboot the BMC. |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 179 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
Charles Paul Hofer | b7842a5 | 2017-09-22 10:11:33 -0500 | [diff] [blame] | 180 | ${activation}= Set Variable &{software_state}[Activation] |
| 181 | Run Keyword If |
| 182 | ... '${skip_if_active}' == 'true' and '${activation}' == '${ACTIVE}' |
| 183 | ... Switch To Active Image And Pass ${SOFTWARE_VERSION_URI}${version_id} |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 184 | Should Be Equal As Strings &{software_state}[Activation] ${READY} |
| 185 | |
| 186 | # Request the image to be activated. |
| 187 | ${args}= Create Dictionary data=${REQUESTED_ACTIVE} |
| 188 | Write Attribute ${SOFTWARE_VERSION_URI}${version_id} |
| 189 | ... RequestedActivation data=${args} |
| 190 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
| 191 | Should Be Equal As Strings &{software_state}[RequestedActivation] |
| 192 | ... ${REQUESTED_ACTIVE} |
| 193 | |
George Keishing | 71c24ed | 2017-09-25 13:11:10 -0500 | [diff] [blame] | 194 | # Does caller want to wait for activation to complete? |
Charles Paul Hofer | e0e1780 | 2017-09-21 09:19:33 -0500 | [diff] [blame] | 195 | Return From Keyword If '${wait}' == '${0}' ${version_id} |
George Keishing | 71c24ed | 2017-09-25 13:11:10 -0500 | [diff] [blame] | 196 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 197 | # Verify code update was successful and Activation state is Active. |
| 198 | Wait For Activation State Change ${version_id} ${ACTIVATING} |
| 199 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
| 200 | Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE} |
| 201 | |
Charles Paul Hofer | e0e1780 | 2017-09-21 09:19:33 -0500 | [diff] [blame] | 202 | [Return] ${version_id} |
| 203 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 204 | |
Charles Paul Hofer | b7842a5 | 2017-09-22 10:11:33 -0500 | [diff] [blame] | 205 | Switch To Active Image And Pass |
| 206 | [Documentation] Make the given active image the image running on the BMC |
| 207 | ... and pass the test. |
| 208 | [Arguments] ${software_object} |
| 209 | |
| 210 | # Description of argument(s): |
| 211 | # software_object Software object path. |
| 212 | # (e.g. "/xyz/openbmc_project/software/f3b29aa8"). |
| 213 | |
| 214 | Set Host Software Property ${software_object} Priority ${0} |
| 215 | OBMC Reboot (off) |
| 216 | Pass Execution ${software_object} was already on the BMC. |
| 217 | |
| 218 | |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 219 | Activate Image And Verify No Duplicate Priorities |
| 220 | [Documentation] Upload an image, and then check that no images have the |
| 221 | ... same priority. |
| 222 | [Arguments] ${image_file_path} ${image_purpose} |
| 223 | |
| 224 | # Description of argument(s): |
| 225 | # image_file_path The path to the image to upload. |
| 226 | # image_purpose The purpose in the image's MANIFEST file. |
| 227 | |
| 228 | Upload And Activate Image ${image_file_path} |
| 229 | Verify No Duplicate Image Priorities ${image_purpose} |
| 230 | |
| 231 | |
Charles Paul Hofer | a567316 | 2017-08-30 09:49:16 -0500 | [diff] [blame] | 232 | Set Same Priority For Multiple Images |
| 233 | [Documentation] Find two images, set the priorities to be the same, and |
| 234 | ... verify that the priorities are not the same. |
| 235 | [Arguments] ${version_purpose} |
| 236 | |
| 237 | # Description of argument(s): |
| 238 | # version_purpose Either BMC or host version purpose. |
| 239 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 240 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
| 241 | |
| 242 | # Make sure we have more than two images. |
| 243 | ${software_objects}= Get Software Objects version_type=${version_purpose} |
| 244 | ${num_images}= Get Length ${software_objects} |
| 245 | Should Be True 1 < ${num_images} |
| 246 | ... msg=Only found one image on the BMC with purpose ${version_purpose}. |
| 247 | |
| 248 | # Set the priority of the second image to the priority of the first. |
| 249 | ${properties}= Get Host Software Property @{software_objects}[0] |
| 250 | Set Host Software Property @{software_objects}[1] Priority |
| 251 | ... &{properties}[Priority] |
| 252 | Verify No Duplicate Image Priorities ${version_purpose} |
| 253 | |
| 254 | # Set the priority of the first image back to what it was before |
| 255 | Set Host Software Property @{software_objects}[0] Priority |
| 256 | ... &{properties}[Priority] |
| 257 | |
| 258 | |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 259 | Delete Software Object |
| 260 | [Documentation] Deletes an image from the BMC. |
| 261 | [Arguments] ${software_object} |
| 262 | |
| 263 | # Description of argument(s): |
| 264 | # software_object The URI to the software image to delete. |
| 265 | |
| 266 | ${arglist}= Create List |
| 267 | ${args}= Create Dictionary data=${arglist} |
| 268 | ${resp}= OpenBMC Post Request ${software_object}/action/delete |
| 269 | ... data=${args} |
| 270 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 271 | |
| 272 | |
| 273 | Delete Image And Verify |
| 274 | [Documentation] Delete an image from the BMC and verify that it was |
| 275 | ... removed from software and the /tmp/images directory. |
| 276 | [Arguments] ${software_object} ${version_type} |
| 277 | |
| 278 | # Description of argument(s): |
| 279 | # software_object The URI of the software object to delete. |
| 280 | # version_type The type of the software object, e.g. |
| 281 | # xyz.openbmc_project.Software.Version.VersionPurpose.Host |
| 282 | # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC. |
| 283 | |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 284 | Log To Console Deleteing ${software_object} |
| 285 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 286 | # Delete the image. |
| 287 | Delete Software Object ${software_object} |
| 288 | # TODO: If/when we don't have to delete twice anymore, take this out |
| 289 | Run Keyword And Ignore Error Delete Software Object ${software_object} |
| 290 | |
| 291 | # Verify that it's gone from software. |
| 292 | ${software_objects}= Get Software Objects version_type=${version_type} |
| 293 | Should Not Contain ${software_objects} ${software_object} |
| 294 | |
| 295 | # Check that there is no file in the /tmp/images directory. |
| 296 | ${image_id}= Fetch From Right ${software_object} / |
| 297 | BMC Execute Command |
| 298 | ... [ ! -d "/tmp/images/${image_id}" ] |
George Keishing | 0071549 | 2017-08-18 11:46:37 -0500 | [diff] [blame] | 299 | |
| 300 | |
| 301 | Check Error And Collect FFDC |
| 302 | [Documentation] Collect FFDC if error log exists. |
| 303 | |
| 304 | ${status}= Run Keyword And Return Status Error Logs Should Not Exist |
| 305 | Run Keyword If '${status}' == 'False' FFDC |
| 306 | Delete Error Logs |
Charles Paul Hofer | e43fb2f | 2017-09-26 15:36:18 -0500 | [diff] [blame] | 307 | |
| 308 | |
| 309 | Verify Running BMC Image |
| 310 | [Documentation] Verify that the version on the BMC is the same as the |
| 311 | ... version in the given image. |
| 312 | [Arguments] ${image_file_path} |
| 313 | |
| 314 | # Description of argument(s): |
| 315 | # image_file_path Path to the BMC image tarball. |
| 316 | |
| 317 | ${tar_version}= Get Version Tar ${image_file_path} |
| 318 | ${bmc_version}= Get BMC Version |
| 319 | ${bmc_version}= Remove String ${bmc_version} " |
| 320 | Should Be Equal ${tar_version} ${bmc_version} |
| 321 | |
| 322 | |
| 323 | Verify Running Host Image |
| 324 | [Documentation] Verify that the version of the PNOR image that is on the |
| 325 | ... BMC is the same as the one in the given image. |
| 326 | [Arguments] ${image_file_path} |
| 327 | |
| 328 | # Description of argument(s): |
| 329 | # image_file_path Path to the PNOR image tarball. |
| 330 | |
| 331 | ${tar_version}= Get Version Tar ${image_file_path} |
| 332 | ${pnor_version}= Get PNOR Version |
| 333 | Should Be Equal ${tar_version} ${pnor_version} |
Charles Paul Hofer | e0e1780 | 2017-09-21 09:19:33 -0500 | [diff] [blame] | 334 | |
Charles Paul Hofer | e0e1780 | 2017-09-21 09:19:33 -0500 | [diff] [blame] | 335 | Reset Network Interface During Code Update |
| 336 | [Documentation] Disable and re-enable the network while doing code update. |
| 337 | [Arguments] ${image_file_path} ${reboot} |
| 338 | |
| 339 | # Reseting the network will be done via the serial console. |
| 340 | # |
| 341 | # Description of argument(s): |
| 342 | # image_file_path Path to the image file to update to. |
| 343 | # reboot If set to true, will reboot the BMC after the code |
| 344 | # update is finished. |
| 345 | |
| 346 | ${version_id}= Upload And Activate Image ${image_file_path} wait=${0} |
| 347 | Reset Network Interface |
| 348 | |
| 349 | # Verify code update was successful and 'Activation' state is 'Active'. |
| 350 | Wait For Activation State Change ${version_id} ${ACTIVATING} |
| 351 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
| 352 | Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE} |
| 353 | |
| 354 | Run Keyword If '${reboot}' OBMC Reboot (off) stack_mode=normal |
| 355 | |
| 356 | |
| 357 | Reset Network Interface |
| 358 | [Documentation] Turn the ethernet network interface off and then on again |
| 359 | ... through the serial console. |
| 360 | |
| 361 | Import Resource ${CURDIR}/oem/ibm/serial_console_client.robot |
| 362 | Set Library Search Order SSHLibrary Telnet |
| 363 | Execute Command On Serial Console ifconfig eth0 down |
| 364 | Sleep 30s |
| 365 | Execute Command On Serial Console ifconfig eth0 up |
George Keishing | 81ae45b | 2017-09-28 14:05:04 -0500 | [diff] [blame] | 366 | |
| 367 | |
| 368 | Get Least Value Priority Image |
| 369 | [Documentation] Find the least value in "Priority" attribute and return. |
| 370 | [Arguments] ${version_type} |
| 371 | |
| 372 | # Description of argument(s): |
| 373 | # version_type Either BMC or host version purpose. |
| 374 | |
| 375 | ${priority_value_list}= Create List |
| 376 | ${sw_list}= Get Software Objects version_type=${version_type} |
| 377 | |
| 378 | :FOR ${index} IN @{sw_list} |
| 379 | \ ${priority_value}= |
| 380 | ... Read Software Attribute ${index} Priority |
| 381 | \ Append To List ${priority_value_list} ${priority_value} |
| 382 | |
| 383 | ${min_value}= Min List Value ${priority_value_list} |
| 384 | |
| 385 | [Return] ${min_value} |