George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 4 | This module provides utilities for code updates. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 5 | """ |
| 6 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 7 | import collections |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 8 | import os |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 9 | import re |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 10 | import sys |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 11 | import tarfile |
| 12 | import time |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 13 | |
George Keishing | 37c58c8 | 2022-12-08 07:42:54 -0600 | [diff] [blame] | 14 | from robot.libraries.BuiltIn import BuiltIn |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 15 | |
| 16 | robot_pgm_dir_path = os.path.dirname(__file__) + os.sep |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 17 | repo_data_path = re.sub("/lib", "/data", robot_pgm_dir_path) |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 18 | sys.path.append(repo_data_path) |
| 19 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 20 | import bmc_ssh_utils as bsu # NOQA |
| 21 | import gen_print as gp # NOQA |
| 22 | import gen_robot_keyword as keyword # NOQA |
| 23 | import variables as var # NOQA |
George Keishing | 37c58c8 | 2022-12-08 07:42:54 -0600 | [diff] [blame] | 24 | |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 25 | |
Sushil Singh | 8469a48 | 2020-07-30 04:19:10 -0500 | [diff] [blame] | 26 | def get_bmc_firmware(image_type, sw_dict): |
| 27 | r""" |
| 28 | Get the dictionary of image based on image type like either BMC or Host. |
| 29 | |
| 30 | Description of argument(s): |
| 31 | image_type This value is either BMC update or Host update type. |
George Keishing | 16b3c7b | 2021-01-28 09:23:37 -0600 | [diff] [blame] | 32 | sw_dict This contain dictionary of firmware inventory properties. |
Sushil Singh | 8469a48 | 2020-07-30 04:19:10 -0500 | [diff] [blame] | 33 | """ |
| 34 | |
| 35 | temp_dict = collections.OrderedDict() |
| 36 | for key, value in sw_dict.items(): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 37 | if value["image_type"] == image_type: |
Sushil Singh | 8469a48 | 2020-07-30 04:19:10 -0500 | [diff] [blame] | 38 | temp_dict[key] = value |
| 39 | else: |
| 40 | pass |
| 41 | return temp_dict |
| 42 | |
| 43 | |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 44 | def verify_no_duplicate_image_priorities(image_purpose): |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 45 | r""" |
| 46 | Check that there are no active images with the same purpose and priority. |
| 47 | |
| 48 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 49 | image_purpose The purpose that images must have to be |
| 50 | checked for priority duplicates. |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 51 | """ |
| 52 | |
| 53 | taken_priorities = {} |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 54 | _, image_names = keyword.run_key( |
| 55 | "Get Software Objects " + "version_type=" + image_purpose |
| 56 | ) |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 57 | |
| 58 | for image_name in image_names: |
| 59 | _, image = keyword.run_key("Get Host Software Property " + image_name) |
| 60 | if image["Activation"] != var.ACTIVE: |
| 61 | continue |
| 62 | image_priority = image["Priority"] |
| 63 | if image_priority in taken_priorities: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 64 | BuiltIn().fail( |
| 65 | "Found active images with the same priority.\n" |
| 66 | + gp.sprint_vars(image, taken_priorities[image_priority]) |
| 67 | ) |
Charles Paul Hofer | a567316 | 2017-08-30 09:49:16 -0500 | [diff] [blame] | 68 | taken_priorities[image_priority] = image |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 69 | |
Charles Paul Hofer | c1fa2bc | 2017-08-18 16:44:03 -0500 | [diff] [blame] | 70 | |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 71 | def get_non_running_bmc_software_object(): |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 72 | r""" |
| 73 | Get the URI to a BMC image from software that is not running on the BMC. |
| 74 | """ |
| 75 | |
| 76 | # Get the version of the image currently running on the BMC. |
| 77 | _, cur_img_version = keyword.run_key("Get BMC Version") |
| 78 | # Remove the surrounding double quotes from the version. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 79 | cur_img_version = cur_img_version.replace('"', "") |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 80 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 81 | _, images = keyword.run_key( |
| 82 | "Read Properties " + var.SOFTWARE_VERSION_URI + "enumerate" |
| 83 | ) |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 84 | |
| 85 | for image_name in images: |
| 86 | _, image_properties = keyword.run_key( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 87 | "Get Host Software Property " + image_name |
| 88 | ) |
| 89 | if ( |
| 90 | "Purpose" in image_properties |
| 91 | and "Version" in image_properties |
| 92 | and image_properties["Purpose"] != var.VERSION_PURPOSE_HOST |
| 93 | and image_properties["Version"] != cur_img_version |
| 94 | ): |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 95 | return image_name |
| 96 | BuiltIn().fail("Did not find any non-running BMC images.") |
| 97 | |
Charles Paul Hofer | da24d0a | 2017-08-09 15:03:40 -0500 | [diff] [blame] | 98 | |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 99 | def delete_all_pnor_images(): |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 100 | r""" |
| 101 | Delete all PNOR images from the BMC. |
| 102 | """ |
| 103 | |
Adriana Kobylak | 7eedb1d | 2019-08-12 15:24:23 -0500 | [diff] [blame] | 104 | keyword.run_key("Initiate Host PowerOff") |
| 105 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 106 | status, images = keyword.run_key( |
| 107 | "Get Software Objects " + var.VERSION_PURPOSE_HOST |
| 108 | ) |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 109 | for image_name in images: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 110 | keyword.run_key( |
| 111 | "Delete Image And Verify " |
| 112 | + image_name |
| 113 | + " " |
| 114 | + var.VERSION_PURPOSE_HOST |
| 115 | ) |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 116 | |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 117 | |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 118 | def wait_for_activation_state_change(version_id, initial_state): |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 119 | r""" |
| 120 | Wait for the current activation state of ${version_id} to |
| 121 | change from the state provided by the calling function. |
| 122 | |
| 123 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 124 | version_id The version ID whose state change we are |
| 125 | waiting for. |
| 126 | initial_state The activation state we want to wait for. |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 127 | """ |
| 128 | |
| 129 | keyword.run_key_u("Open Connection And Log In") |
| 130 | retry = 0 |
Charles Paul Hofer | 290b8bd | 2017-09-26 10:02:22 -0500 | [diff] [blame] | 131 | num_read_errors = 0 |
| 132 | read_fail_threshold = 1 |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 133 | while retry < 60: |
| 134 | status, software_state = keyword.run_key( |
| 135 | "Read Properties " + var.SOFTWARE_VERSION_URI + str(version_id), |
| 136 | ignore=1, |
| 137 | ) |
| 138 | if status == "FAIL": |
Charles Paul Hofer | 290b8bd | 2017-09-26 10:02:22 -0500 | [diff] [blame] | 139 | num_read_errors += 1 |
| 140 | if num_read_errors > read_fail_threshold: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 141 | message = "Read errors exceeds threshold:\n " + gp.sprint_vars( |
| 142 | num_read_errors, read_fail_threshold |
| 143 | ) |
Charles Paul Hofer | 290b8bd | 2017-09-26 10:02:22 -0500 | [diff] [blame] | 144 | BuiltIn().fail(message) |
Charles Paul Hofer | 4d26c00 | 2017-09-27 08:39:29 -0500 | [diff] [blame] | 145 | time.sleep(10) |
Charles Paul Hofer | 290b8bd | 2017-09-26 10:02:22 -0500 | [diff] [blame] | 146 | continue |
| 147 | |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 148 | current_state = (software_state)["Activation"] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 149 | if initial_state == current_state: |
Charles Paul Hofer | 4d26c00 | 2017-09-27 08:39:29 -0500 | [diff] [blame] | 150 | time.sleep(10) |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 151 | retry += 1 |
Charles Paul Hofer | 290b8bd | 2017-09-26 10:02:22 -0500 | [diff] [blame] | 152 | num_read_errors = 0 |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 153 | else: |
| 154 | return |
| 155 | return |
| 156 | |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 157 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 158 | def get_latest_file(dir_path): |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 159 | r""" |
| 160 | Get the path to the latest uploaded file. |
| 161 | |
| 162 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 163 | dir_path Path to the dir from which the name of the |
| 164 | last updated file or folder will be |
| 165 | returned to the calling function. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 166 | """ |
| 167 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 168 | stdout, stderr, rc = bsu.bmc_execute_command( |
| 169 | "cd " |
| 170 | + dir_path |
| 171 | + "; stat -c '%Y %n' * |" |
| 172 | + " sort -k1,1nr | head -n 1" |
| 173 | ) |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 174 | return stdout.split(" ")[-1] |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 175 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 176 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 177 | def get_version_tar(tar_file_path): |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 178 | r""" |
| 179 | Read the image version from the MANIFEST inside the tarball. |
| 180 | |
| 181 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 182 | tar_file_path The path to a tar file that holds the image |
| 183 | version inside the MANIFEST. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 184 | """ |
| 185 | |
Sushil Singh | 3c77d78 | 2019-10-14 05:29:42 -0500 | [diff] [blame] | 186 | version = "" |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 187 | tar = tarfile.open(tar_file_path) |
| 188 | for member in tar.getmembers(): |
George Keishing | 42ade54 | 2020-07-22 09:51:46 -0500 | [diff] [blame] | 189 | BuiltIn().log_to_console(member.name) |
| 190 | if member.name != "MANIFEST": |
| 191 | continue |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 192 | f = tar.extractfile(member) |
| 193 | content = f.read() |
George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 194 | if content.find(b"version=") == -1: |
| 195 | # This tar member does not contain the version. |
| 196 | continue |
George Keishing | 42ade54 | 2020-07-22 09:51:46 -0500 | [diff] [blame] | 197 | content = content.decode("utf-8", "ignore").split("\n") |
George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 198 | content = [x for x in content if "version=" in x] |
| 199 | version = content[0].split("=")[-1] |
| 200 | break |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 201 | tar.close() |
| 202 | return version |
| 203 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 204 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 205 | def get_image_version(file_path): |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 206 | r""" |
| 207 | Read the file for a version object. |
| 208 | |
| 209 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 210 | file_path The path to a file that holds the image |
| 211 | version. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 212 | """ |
| 213 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 214 | stdout, stderr, rc = bsu.bmc_execute_command( |
| 215 | "cat " + file_path + ' | grep "version="', ignore_err=1 |
| 216 | ) |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 217 | return (stdout.split("\n")[0]).split("=")[-1] |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 218 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 219 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 220 | def get_image_purpose(file_path): |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 221 | r""" |
| 222 | Read the file for a purpose object. |
| 223 | |
| 224 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 225 | file_path The path to a file that holds the image |
| 226 | purpose. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 227 | """ |
| 228 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 229 | stdout, stderr, rc = bsu.bmc_execute_command( |
| 230 | "cat " + file_path + ' | grep "purpose="', ignore_err=1 |
| 231 | ) |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 232 | return stdout.split("=")[-1] |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 233 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 234 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 235 | def get_image_path(image_version): |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 236 | r""" |
| 237 | Query the upload image dir for the presence of image matching |
| 238 | the version that was read from the MANIFEST before uploading |
| 239 | the image. Based on the purpose verify the activation object |
| 240 | exists and is either READY or INVALID. |
| 241 | |
| 242 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 243 | image_version The version of the image that should match |
| 244 | one of the images in the upload dir. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 245 | """ |
| 246 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 247 | stdout, stderr, rc = bsu.bmc_execute_command( |
| 248 | "ls -d " + var.IMAGE_UPLOAD_DIR_PATH + "*/" |
| 249 | ) |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 250 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 251 | image_list = stdout.split("\n") |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 252 | retry = 0 |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 253 | while retry < 10: |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 254 | for i in range(0, len(image_list)): |
| 255 | version = get_image_version(image_list[i] + "MANIFEST") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 256 | if version == image_version: |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 257 | return image_list[i] |
| 258 | time.sleep(10) |
| 259 | retry += 1 |
| 260 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 261 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 262 | def verify_image_upload(image_version, timeout=3): |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 263 | r""" |
| 264 | Verify the image was uploaded correctly and that it created |
Charles Paul Hofer | 6b97268 | 2017-07-20 11:36:56 -0500 | [diff] [blame] | 265 | a valid d-bus object. If the first check for the image |
| 266 | fails, try again until we reach the timeout. |
| 267 | |
| 268 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 269 | image_version The version from the image's manifest file |
| 270 | (e.g. "v2.2-253-g00050f1"). |
| 271 | timeout How long, in minutes, to keep trying to |
| 272 | find the image on the BMC. Default is 3 minutes. |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 273 | """ |
| 274 | |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 275 | image_path = get_image_path(image_version) |
| 276 | image_version_id = image_path.split("/")[-2] |
| 277 | |
Charles Paul Hofer | de7d408 | 2017-08-08 14:41:01 -0500 | [diff] [blame] | 278 | keyword.run_key_u("Open Connection And Log In") |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 279 | image_purpose = get_image_purpose(image_path + "MANIFEST") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 280 | if ( |
| 281 | image_purpose == var.VERSION_PURPOSE_BMC |
| 282 | or image_purpose == var.VERSION_PURPOSE_HOST |
| 283 | ): |
George Keishing | ff1e3ec | 2017-07-20 01:58:21 -0500 | [diff] [blame] | 284 | uri = var.SOFTWARE_VERSION_URI + image_version_id |
Charles Paul Hofer | 6b97268 | 2017-07-20 11:36:56 -0500 | [diff] [blame] | 285 | ret_values = "" |
| 286 | for itr in range(timeout * 2): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 287 | status, ret_values = keyword.run_key( |
| 288 | "Read Attribute " + uri + " Activation" |
| 289 | ) |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 290 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 291 | if ( |
| 292 | (ret_values == var.READY) |
| 293 | or (ret_values == var.INVALID) |
| 294 | or (ret_values == var.ACTIVE) |
| 295 | ): |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 296 | return True, image_version_id |
Charles Paul Hofer | 6b97268 | 2017-07-20 11:36:56 -0500 | [diff] [blame] | 297 | else: |
| 298 | time.sleep(30) |
| 299 | |
| 300 | # If we exit the for loop, the timeout has been reached |
| 301 | gp.print_var(ret_values) |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 302 | return False, None |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 303 | else: |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 304 | gp.print_var(image_purpose) |
Charles Paul Hofer | cef6199 | 2017-08-18 10:14:18 -0500 | [diff] [blame] | 305 | return False, None |
Saqib Khan | fb1f6ae | 2017-04-26 13:24:41 -0500 | [diff] [blame] | 306 | |
Charles P. Hofer | 1d20acd | 2017-07-05 15:24:40 -0500 | [diff] [blame] | 307 | |
Charles Paul Hofer | 6b97268 | 2017-07-20 11:36:56 -0500 | [diff] [blame] | 308 | def verify_image_not_in_bmc_uploads_dir(image_version, timeout=3): |
Charles P. Hofer | 1d20acd | 2017-07-05 15:24:40 -0500 | [diff] [blame] | 309 | r""" |
| 310 | Check that an image with the given version is not unpacked inside of the |
| 311 | BMCs image uploads directory. If no image is found, retry every 30 seconds |
Charles Paul Hofer | 6b97268 | 2017-07-20 11:36:56 -0500 | [diff] [blame] | 312 | until the given timeout is hit, in case the BMC takes time |
| 313 | unpacking the image. |
Charles P. Hofer | 1d20acd | 2017-07-05 15:24:40 -0500 | [diff] [blame] | 314 | |
| 315 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 316 | image_version The version of the image to look for on |
| 317 | the BMC. |
| 318 | timeout How long, in minutes, to try to find an |
| 319 | image on the BMC. Default is 3 minutes. |
Charles P. Hofer | 1d20acd | 2017-07-05 15:24:40 -0500 | [diff] [blame] | 320 | """ |
| 321 | |
Charles Paul Hofer | 6b97268 | 2017-07-20 11:36:56 -0500 | [diff] [blame] | 322 | for i in range(timeout * 2): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 323 | stdout, stderr, rc = bsu.bmc_execute_command( |
| 324 | "ls " |
| 325 | + var.IMAGE_UPLOAD_DIR_PATH |
| 326 | + "*/MANIFEST 2>/dev/null " |
| 327 | + '| xargs grep -rl "version=' |
| 328 | + image_version |
| 329 | + '"' |
| 330 | ) |
| 331 | image_dir = os.path.dirname(stdout.split("\n")[0]) |
| 332 | if "" != image_dir: |
| 333 | bsu.bmc_execute_command("rm -rf " + image_dir) |
| 334 | BuiltIn().fail("Found invalid BMC Image: " + image_dir) |
Charles P. Hofer | 1d20acd | 2017-07-05 15:24:40 -0500 | [diff] [blame] | 335 | time.sleep(30) |