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 |
| 7 | Variables ../data/variables.py |
| 8 | Resource rest_client.robot |
George Keishing | 0071549 | 2017-08-18 11:46:37 -0500 | [diff] [blame] | 9 | Resource openbmc_ffdc.robot |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 10 | |
| 11 | *** Keywords *** |
| 12 | |
| 13 | Get Software Objects |
| 14 | [Documentation] Get the host software objects and return as a list. |
| 15 | [Arguments] ${version_type}=${VERSION_PURPOSE_HOST} |
| 16 | |
| 17 | # Description of argument(s): |
| 18 | # version_type Either BMC or host version purpose. |
| 19 | # By default host version purpose string. |
| 20 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 21 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
| 22 | |
| 23 | # Example: |
| 24 | # "data": [ |
| 25 | # "/xyz/openbmc_project/software/f3b29aa8", |
| 26 | # "/xyz/openbmc_project/software/e49bc78e", |
| 27 | # ], |
| 28 | # Iterate the list and return the host object name path list. |
| 29 | |
| 30 | ${host_list}= Create List |
| 31 | ${sw_list}= Read Properties ${SOFTWARE_VERSION_URI} |
| 32 | |
| 33 | :FOR ${index} IN @{sw_list} |
George Keishing | d62db0f | 2017-09-13 08:50:33 -0500 | [diff] [blame] | 34 | \ ${attr_purpose}= Read Software Attribute ${index} Purpose |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 35 | \ Continue For Loop If '${attr_purpose}' != '${version_type}' |
| 36 | \ Append To List ${host_list} ${index} |
| 37 | |
George Keishing | d62db0f | 2017-09-13 08:50:33 -0500 | [diff] [blame] | 38 | [Return] ${host_list} |
| 39 | |
| 40 | |
| 41 | Read Software Attribute |
| 42 | [Documentation] Return software attribute data. |
| 43 | [Arguments] ${software_object} ${attribute_name} |
| 44 | |
| 45 | # Description of argument(s): |
| 46 | # software_object Software object path. |
| 47 | # (e.g. "/xyz/openbmc_project/software/f3b29aa8"). |
| 48 | # attribute_name Software object attribute name. |
| 49 | |
| 50 | ${resp}= OpenBMC Get Request ${software_object}/attr/${attribute_name} |
| 51 | ... quiet=${1} |
| 52 | Return From Keyword If ${resp.status_code} != ${HTTP_OK} |
| 53 | ${content}= To JSON ${resp.content} |
| 54 | [Return] ${content["data"]} |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 55 | |
| 56 | |
| 57 | Get Host Software Property |
| 58 | [Documentation] Return a dictionary of host software properties. |
| 59 | [Arguments] ${host_object} |
| 60 | |
| 61 | # Description of argument(s): |
| 62 | # host_object Host software object path. |
| 63 | # (e.g. "/xyz/openbmc_project/software/f3b29aa8"). |
| 64 | |
| 65 | ${sw_attributes}= Read Properties ${host_object} |
| 66 | [return] ${sw_attributes} |
| 67 | |
Sweta Potthuri | cd96634 | 2017-09-06 03:41:32 -0500 | [diff] [blame] | 68 | Get Host Software Objects Details |
| 69 | [Documentation] Return software object details as a list of dictionaries. |
| 70 | [Arguments] ${quiet}=${QUIET} |
| 71 | |
| 72 | ${software}= Create List |
| 73 | |
| 74 | ${pnor_details}= Get Software Objects ${VERSION_PURPOSE_HOST} |
| 75 | :FOR ${pnor} IN @{pnor_details} |
| 76 | \ ${resp}= OpenBMC Get Request ${pnor} quiet=${1} |
| 77 | \ ${json}= To JSON ${resp.content} |
| 78 | \ Append To List ${software} ${json["data"]} |
| 79 | |
| 80 | [Return] ${software} |
George Keishing | 27bf693 | 2017-08-07 14:30:40 -0500 | [diff] [blame] | 81 | |
| 82 | Set Host Software Property |
| 83 | [Documentation] Set the host software properties of a given object. |
| 84 | [Arguments] ${host_object} ${sw_attribute} ${data} |
| 85 | |
| 86 | # Description of argument(s): |
| 87 | # host_object Host software object name. |
| 88 | # sw_attribute Host software attribute name. |
| 89 | # (e.g. "Activation", "Priority", "RequestedActivation" etc). |
| 90 | # data Value to be written. |
| 91 | |
| 92 | ${args}= Create Dictionary data=${data} |
| 93 | Write Attribute ${host_object} ${sw_attribute} data=${args} |
| 94 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 95 | |
| 96 | Set Property To Invalid Value And Verify No Change |
| 97 | [Documentation] Attempt to set a property and check that the value didn't |
| 98 | ... change. |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 99 | [Arguments] ${property} ${version_type} |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 100 | |
| 101 | # Description of argument(s): |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 102 | # property The property to attempt to set. |
| 103 | # version_type Either BMC or host version purpose. |
| 104 | # By default host version purpose string. |
| 105 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 106 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 107 | |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 108 | ${software_objects}= Get Software Objects version_type=${version_type} |
| 109 | ${prev_properties}= Get Host Software Property @{software_objects}[0] |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 110 | Run Keyword And Expect Error 500 != 200 |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 111 | ... Set Host Software Property @{software_objects}[0] ${property} foo |
| 112 | ${cur_properties}= Get Host Software Property @{software_objects}[0] |
| 113 | Should Be Equal As Strings &{prev_properties}[${property}] |
| 114 | ... &{cur_properties}[${property}] |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 115 | |
| 116 | |
| 117 | Upload And Activate Image |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 118 | [Documentation] Upload an image to the BMC and activate it with REST. |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 119 | [Arguments] ${image_file_path} |
| 120 | |
| 121 | # Description of argument(s): |
| 122 | # image_file_path The path to the image tarball to upload and activate. |
| 123 | |
| 124 | OperatingSystem.File Should Exist ${image_file_path} |
| 125 | ${image_version}= Get Version Tar ${image_file_path} |
| 126 | |
| 127 | ${image_data}= OperatingSystem.Get Binary File ${image_file_path} |
| 128 | Upload Image To BMC /upload/image data=${image_data} |
| 129 | ${ret} ${version_id}= Verify Image Upload ${image_version} |
| 130 | Should Be True ${ret} |
| 131 | |
| 132 | # Verify the image is 'READY' to be activated. |
| 133 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
| 134 | Should Be Equal As Strings &{software_state}[Activation] ${READY} |
| 135 | |
| 136 | # Request the image to be activated. |
| 137 | ${args}= Create Dictionary data=${REQUESTED_ACTIVE} |
| 138 | Write Attribute ${SOFTWARE_VERSION_URI}${version_id} |
| 139 | ... RequestedActivation data=${args} |
| 140 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
| 141 | Should Be Equal As Strings &{software_state}[RequestedActivation] |
| 142 | ... ${REQUESTED_ACTIVE} |
| 143 | |
| 144 | # Verify code update was successful and Activation state is Active. |
| 145 | Wait For Activation State Change ${version_id} ${ACTIVATING} |
| 146 | ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id} |
| 147 | Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE} |
| 148 | |
| 149 | |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 150 | Activate Image And Verify No Duplicate Priorities |
| 151 | [Documentation] Upload an image, and then check that no images have the |
| 152 | ... same priority. |
| 153 | [Arguments] ${image_file_path} ${image_purpose} |
| 154 | |
| 155 | # Description of argument(s): |
| 156 | # image_file_path The path to the image to upload. |
| 157 | # image_purpose The purpose in the image's MANIFEST file. |
| 158 | |
| 159 | Upload And Activate Image ${image_file_path} |
| 160 | Verify No Duplicate Image Priorities ${image_purpose} |
| 161 | |
| 162 | |
Charles Paul Hofer | a567316 | 2017-08-30 09:49:16 -0500 | [diff] [blame] | 163 | Set Same Priority For Multiple Images |
| 164 | [Documentation] Find two images, set the priorities to be the same, and |
| 165 | ... verify that the priorities are not the same. |
| 166 | [Arguments] ${version_purpose} |
| 167 | |
| 168 | # Description of argument(s): |
| 169 | # version_purpose Either BMC or host version purpose. |
| 170 | # (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 171 | # "xyz.openbmc_project.Software.Version.VersionPurpose.Host"). |
| 172 | |
| 173 | # Make sure we have more than two images. |
| 174 | ${software_objects}= Get Software Objects version_type=${version_purpose} |
| 175 | ${num_images}= Get Length ${software_objects} |
| 176 | Should Be True 1 < ${num_images} |
| 177 | ... msg=Only found one image on the BMC with purpose ${version_purpose}. |
| 178 | |
| 179 | # Set the priority of the second image to the priority of the first. |
| 180 | ${properties}= Get Host Software Property @{software_objects}[0] |
| 181 | Set Host Software Property @{software_objects}[1] Priority |
| 182 | ... &{properties}[Priority] |
| 183 | Verify No Duplicate Image Priorities ${version_purpose} |
| 184 | |
| 185 | # Set the priority of the first image back to what it was before |
| 186 | Set Host Software Property @{software_objects}[0] Priority |
| 187 | ... &{properties}[Priority] |
| 188 | |
| 189 | |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 190 | Delete Software Object |
| 191 | [Documentation] Deletes an image from the BMC. |
| 192 | [Arguments] ${software_object} |
| 193 | |
| 194 | # Description of argument(s): |
| 195 | # software_object The URI to the software image to delete. |
| 196 | |
| 197 | ${arglist}= Create List |
| 198 | ${args}= Create Dictionary data=${arglist} |
| 199 | ${resp}= OpenBMC Post Request ${software_object}/action/delete |
| 200 | ... data=${args} |
| 201 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 202 | |
| 203 | |
| 204 | Delete Image And Verify |
| 205 | [Documentation] Delete an image from the BMC and verify that it was |
| 206 | ... removed from software and the /tmp/images directory. |
| 207 | [Arguments] ${software_object} ${version_type} |
| 208 | |
| 209 | # Description of argument(s): |
| 210 | # software_object The URI of the software object to delete. |
| 211 | # version_type The type of the software object, e.g. |
| 212 | # xyz.openbmc_project.Software.Version.VersionPurpose.Host |
| 213 | # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC. |
| 214 | |
Charles Paul Hofer | 9f74d3a | 2017-08-18 09:54:28 -0500 | [diff] [blame] | 215 | Log To Console Deleteing ${software_object} |
| 216 | |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 217 | # Delete the image. |
| 218 | Delete Software Object ${software_object} |
| 219 | # TODO: If/when we don't have to delete twice anymore, take this out |
| 220 | Run Keyword And Ignore Error Delete Software Object ${software_object} |
| 221 | |
| 222 | # Verify that it's gone from software. |
| 223 | ${software_objects}= Get Software Objects version_type=${version_type} |
| 224 | Should Not Contain ${software_objects} ${software_object} |
| 225 | |
| 226 | # Check that there is no file in the /tmp/images directory. |
| 227 | ${image_id}= Fetch From Right ${software_object} / |
| 228 | BMC Execute Command |
| 229 | ... [ ! -d "/tmp/images/${image_id}" ] |
George Keishing | 0071549 | 2017-08-18 11:46:37 -0500 | [diff] [blame] | 230 | |
| 231 | |
| 232 | Check Error And Collect FFDC |
| 233 | [Documentation] Collect FFDC if error log exists. |
| 234 | |
| 235 | ${status}= Run Keyword And Return Status Error Logs Should Not Exist |
| 236 | Run Keyword If '${status}' == 'False' FFDC |
| 237 | Delete Error Logs |