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