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