Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | This module is the python counterpart to code_update.robot. |
| 5 | """ |
| 6 | |
| 7 | import os |
| 8 | import sys |
| 9 | import re |
| 10 | import string |
| 11 | import tarfile |
| 12 | import time |
| 13 | |
| 14 | robot_pgm_dir_path = os.path.dirname(__file__) + os.sep |
| 15 | repo_lib_path = re.sub('/extended/code_update/', '/lib', robot_pgm_dir_path) |
| 16 | repo_data_path = re.sub('/extended/code_update/', '/data', robot_pgm_dir_path) |
| 17 | sys.path.append(repo_lib_path) |
| 18 | sys.path.append(repo_data_path) |
| 19 | |
| 20 | import gen_robot_keyword as keyword |
| 21 | import gen_print as gp |
| 22 | import gen_valid as gv |
| 23 | import variables as var |
| 24 | from robot.libraries.BuiltIn import BuiltIn |
| 25 | |
| 26 | |
| 27 | ############################################################################### |
Charles Paul Hofer | 2c73164 | 2017-08-03 18:13:27 -0500 | [diff] [blame] | 28 | def delete_all_pnor_images(): |
| 29 | |
| 30 | r""" |
| 31 | Delete all PNOR images from the BMC. |
| 32 | """ |
| 33 | |
| 34 | status, images = keyword.run_key("Read Properties " |
| 35 | + var.SOFTWARE_VERSION_URI + "enumerate") |
| 36 | for image_name in images: |
| 37 | image_id = image_name.split('/')[-1] |
| 38 | image_purpose = images[image_name]["Purpose"] |
| 39 | if var.VERSION_PURPOSE_HOST == image_purpose: |
| 40 | # Delete twice, in case the image is in the /tmp/images directory |
| 41 | keyword.run_key("Call Method " + var.SOFTWARE_VERSION_URI |
| 42 | + image_id + " delete data={\"data\":[]}") |
| 43 | keyword.run_key("Call Method " + var.SOFTWARE_VERSION_URI |
| 44 | + image_id + " delete data={\"data\":[]}") |
| 45 | |
| 46 | ############################################################################### |
| 47 | |
| 48 | |
| 49 | ############################################################################### |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 50 | def wait_for_activation_state_change(version_id, initial_state): |
| 51 | |
| 52 | r""" |
| 53 | Wait for the current activation state of ${version_id} to |
| 54 | change from the state provided by the calling function. |
| 55 | |
| 56 | Description of argument(s): |
| 57 | version_id The version ID whose state change we are waiting for. |
| 58 | initial_state The activation state we want to wait for. |
| 59 | """ |
| 60 | |
| 61 | keyword.run_key_u("Open Connection And Log In") |
| 62 | retry = 0 |
| 63 | while (retry < 20): |
| 64 | status, software_state = keyword.run_key("Read Properties " + |
George Keishing | ff1e3ec | 2017-07-20 01:58:21 -0500 | [diff] [blame] | 65 | var.SOFTWARE_VERSION_URI + str(version_id)) |
Saqib Khan | bb8b63f | 2017-05-24 10:58:01 -0500 | [diff] [blame] | 66 | current_state = (software_state)["Activation"] |
| 67 | if (initial_state == current_state): |
| 68 | time.sleep(60) |
| 69 | retry += 1 |
| 70 | else: |
| 71 | return |
| 72 | return |
| 73 | |
| 74 | ############################################################################### |