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