Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | This module is the python counterpart to obmc_boot_test. |
| 5 | """ |
| 6 | |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 7 | import os |
| 8 | import imp |
| 9 | import time |
| 10 | import glob |
| 11 | import random |
| 12 | import cPickle as pickle |
| 13 | |
| 14 | from robot.utils import DotDict |
| 15 | from robot.libraries.BuiltIn import BuiltIn |
| 16 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 17 | from boot_data import * |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 18 | import gen_print as gp |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 19 | import gen_robot_print as grp |
Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 20 | import gen_robot_plug_in as grpi |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 21 | import gen_robot_valid as grv |
| 22 | import gen_misc as gm |
| 23 | import gen_cmd as gc |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 24 | import gen_robot_keyword as grk |
Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 25 | import state as st |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 26 | |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 27 | base_path = os.path.dirname(os.path.dirname( |
| 28 | imp.find_module("gen_robot_print")[1])) +\ |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 29 | os.sep |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 30 | sys.path.append(base_path + "extended/") |
| 31 | import run_keyword as rk |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 32 | |
Michael Walsh | e1e2644 | 2017-03-06 17:50:07 -0600 | [diff] [blame] | 33 | # Setting master_pid correctly influences the behavior of plug-ins like |
| 34 | # DB_Logging |
| 35 | program_pid = os.getpid() |
| 36 | master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid) |
| 37 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 38 | # Set up boot data structures. |
| 39 | boot_table = create_boot_table() |
| 40 | valid_boot_types = create_valid_boot_list(boot_table) |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 41 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 42 | boot_lists = read_boot_lists() |
| 43 | last_ten = [] |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 44 | |
| 45 | state = st.return_default_state() |
| 46 | cp_setup_called = 0 |
| 47 | next_boot = "" |
| 48 | base_tool_dir_path = os.path.normpath(os.environ.get( |
| 49 | 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 50 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 51 | ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 52 | boot_success = 0 |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 53 | status_dir_path = os.environ.get('STATUS_DIR_PATH', "") |
| 54 | if status_dir_path != "": |
| 55 | status_dir_path = os.path.normpath(status_dir_path) + os.sep |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 56 | default_power_on = "REST Power On" |
| 57 | default_power_off = "REST Power Off" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 58 | boot_count = 0 |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 59 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 60 | LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}") |
| 61 | |
| 62 | |
| 63 | ############################################################################### |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 64 | def process_pgm_parms(): |
| 65 | |
| 66 | r""" |
| 67 | Process the program parameters by assigning them all to corresponding |
| 68 | globals. Also, set some global values that depend on program parameters. |
| 69 | """ |
| 70 | |
| 71 | # Program parameter processing. |
| 72 | # Assign all program parms to python variables which are global to this |
| 73 | # module. |
| 74 | |
| 75 | global parm_list |
| 76 | parm_list = BuiltIn().get_variable_value("${parm_list}") |
| 77 | # The following subset of parms should be processed as integers. |
| 78 | int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only', |
| 79 | 'boot_fail_threshold', 'quiet', 'test_mode', 'debug'] |
| 80 | for parm in parm_list: |
| 81 | if parm in int_list: |
| 82 | sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\ |
| 83 | "}\", \"0\"))" |
| 84 | else: |
| 85 | sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")" |
| 86 | cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd |
| 87 | exec(cmd_buf) |
| 88 | |
| 89 | global ffdc_dir_path_style |
| 90 | global boot_list |
| 91 | global boot_stack |
| 92 | global boot_results_file_path |
| 93 | global boot_results |
| 94 | global ffdc_list_file_path |
| 95 | |
| 96 | if ffdc_dir_path_style == "": |
| 97 | ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0')) |
| 98 | |
| 99 | # Convert these program parms to lists for easier processing.. |
| 100 | boot_list = filter(None, boot_list.split(":")) |
| 101 | boot_stack = filter(None, boot_stack.split(":")) |
| 102 | |
| 103 | boot_results_file_path = "/tmp/" + openbmc_nickname + ":pid_" +\ |
| 104 | str(master_pid) + ":boot_results" |
| 105 | |
| 106 | if os.path.isfile(boot_results_file_path): |
| 107 | # We've been called before in this run so we'll load the saved |
| 108 | # boot_results object. |
| 109 | boot_results = pickle.load(open(boot_results_file_path, 'rb')) |
| 110 | else: |
| 111 | boot_results = boot_results(boot_table, boot_pass, boot_fail) |
| 112 | |
| 113 | ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\ |
| 114 | "/FFDC_FILE_LIST" |
| 115 | |
| 116 | ############################################################################### |
| 117 | |
| 118 | |
| 119 | ############################################################################### |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 120 | def initial_plug_in_setup(): |
| 121 | |
| 122 | r""" |
| 123 | Initialize all plug-in environment variables which do not change for the |
| 124 | duration of the program. |
| 125 | |
| 126 | """ |
| 127 | |
| 128 | global LOG_LEVEL |
| 129 | BuiltIn().set_log_level("NONE") |
| 130 | |
| 131 | BuiltIn().set_global_variable("${master_pid}", master_pid) |
| 132 | BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path) |
| 133 | BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path) |
| 134 | BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path) |
| 135 | BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}", |
| 136 | ffdc_list_file_path) |
| 137 | |
| 138 | BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}", |
| 139 | ffdc_dir_path_style) |
| 140 | BuiltIn().set_global_variable("${FFDC_CHECK}", |
| 141 | ffdc_check) |
| 142 | |
| 143 | # For each program parameter, set the corresponding AUTOBOOT_ environment |
| 144 | # variable value. Also, set an AUTOBOOT_ environment variable for every |
| 145 | # element in additional_values. |
| 146 | additional_values = ["program_pid", "master_pid", "ffdc_dir_path", |
| 147 | "status_dir_path", "base_tool_dir_path", |
| 148 | "ffdc_list_file_path"] |
| 149 | |
| 150 | plug_in_vars = parm_list + additional_values |
| 151 | |
| 152 | for var_name in plug_in_vars: |
| 153 | var_value = BuiltIn().get_variable_value("${" + var_name + "}") |
| 154 | var_name = var_name.upper() |
| 155 | if var_value is None: |
| 156 | var_value = "" |
| 157 | os.environ["AUTOBOOT_" + var_name] = str(var_value) |
| 158 | |
| 159 | BuiltIn().set_log_level(LOG_LEVEL) |
| 160 | |
| 161 | |
| 162 | ############################################################################### |
| 163 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 164 | |
| 165 | ############################################################################### |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 166 | def plug_in_setup(): |
| 167 | |
| 168 | r""" |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 169 | Initialize all changing plug-in environment variables for use by the |
| 170 | plug-in programs. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 171 | """ |
| 172 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 173 | global LOG_LEVEL |
| 174 | global test_really_running |
| 175 | |
| 176 | BuiltIn().set_log_level("NONE") |
| 177 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 178 | boot_pass, boot_fail = boot_results.return_total_pass_fail() |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 179 | if boot_pass > 1: |
| 180 | test_really_running = 1 |
| 181 | else: |
| 182 | test_really_running = 0 |
| 183 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 184 | seconds = time.time() |
| 185 | loc_time = time.localtime(seconds) |
| 186 | time_string = time.strftime("%y%m%d.%H%M%S.", loc_time) |
| 187 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 188 | ffdc_prefix = openbmc_nickname + "." + time_string |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 189 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 190 | BuiltIn().set_global_variable("${test_really_running}", |
| 191 | test_really_running) |
| 192 | BuiltIn().set_global_variable("${boot_type_desc}", next_boot) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 193 | BuiltIn().set_global_variable("${boot_pass}", boot_pass) |
| 194 | BuiltIn().set_global_variable("${boot_fail}", boot_fail) |
| 195 | BuiltIn().set_global_variable("${boot_success}", boot_success) |
| 196 | BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix) |
Michael Walsh | 4c9a645 | 2016-12-13 16:03:11 -0600 | [diff] [blame] | 197 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 198 | # For each program parameter, set the corresponding AUTOBOOT_ environment |
| 199 | # variable value. Also, set an AUTOBOOT_ environment variable for every |
| 200 | # element in additional_values. |
| 201 | additional_values = ["boot_type_desc", "boot_success", "boot_pass", |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 202 | "boot_fail", "test_really_running", "ffdc_prefix"] |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 203 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 204 | plug_in_vars = additional_values |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 205 | |
| 206 | for var_name in plug_in_vars: |
| 207 | var_value = BuiltIn().get_variable_value("${" + var_name + "}") |
| 208 | var_name = var_name.upper() |
| 209 | if var_value is None: |
| 210 | var_value = "" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 211 | os.environ["AUTOBOOT_" + var_name] = str(var_value) |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 212 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 213 | if debug: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 214 | shell_rc, out_buf = \ |
| 215 | gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u") |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 216 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 217 | BuiltIn().set_log_level(LOG_LEVEL) |
| 218 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 219 | ############################################################################### |
| 220 | |
| 221 | |
| 222 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 223 | def setup(): |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 224 | |
| 225 | r""" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 226 | Do general program setup tasks. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 227 | """ |
| 228 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 229 | global cp_setup_called |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 230 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 231 | gp.qprintn() |
| 232 | |
| 233 | shell_rc, out_buf = gc.cmd_fnc_u("which ssh_pw", quiet=1, print_output=0, |
| 234 | show_err=0) |
| 235 | if shell_rc != 0: |
| 236 | robot_pgm_dir_path = os.path.dirname(__file__) + os.sep |
| 237 | os.environ['PATH'] = robot_pgm_dir_path +\ |
| 238 | "../bin:" + os.environ.get('PATH', "") |
| 239 | os.environ['PYTHONPATH'] = robot_pgm_dir_path +\ |
| 240 | os.environ.get('PYTHONPATH', "") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 241 | |
| 242 | validate_parms() |
| 243 | |
| 244 | grp.rqprint_pgm_header() |
| 245 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 246 | grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE") |
Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 247 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 248 | initial_plug_in_setup() |
| 249 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 250 | plug_in_setup() |
| 251 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 252 | call_point='setup') |
| 253 | if rc != 0: |
| 254 | error_message = "Plug-in setup failed.\n" |
| 255 | grp.rprint_error_report(error_message) |
| 256 | BuiltIn().fail(error_message) |
| 257 | # Setting cp_setup_called lets our Teardown know that it needs to call |
| 258 | # the cleanup plug-in call point. |
| 259 | cp_setup_called = 1 |
| 260 | |
| 261 | # Keyword "FFDC" will fail if TEST_MESSAGE is not set. |
| 262 | BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}") |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 263 | # FFDC_LOG_PATH is used by "FFDC" keyword. |
| 264 | BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 265 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 266 | gp.dprint_var(boot_table, 1) |
| 267 | gp.dprint_var(boot_lists) |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 268 | |
| 269 | ############################################################################### |
| 270 | |
| 271 | |
| 272 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 273 | def validate_parms(): |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 274 | |
| 275 | r""" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 276 | Validate all program parameters. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 277 | """ |
| 278 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 279 | process_pgm_parms() |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 280 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 281 | gp.qprintn() |
| 282 | |
| 283 | global openbmc_model |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 284 | grv.rvalid_value("openbmc_host") |
| 285 | grv.rvalid_value("openbmc_username") |
| 286 | grv.rvalid_value("openbmc_password") |
| 287 | if os_host != "": |
| 288 | grv.rvalid_value("os_username") |
| 289 | grv.rvalid_value("os_password") |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 290 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 291 | if pdu_host != "": |
| 292 | grv.rvalid_value("pdu_username") |
| 293 | grv.rvalid_value("pdu_password") |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 294 | grv.rvalid_integer("pdu_slot_no") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 295 | if openbmc_serial_host != "": |
| 296 | grv.rvalid_integer("openbmc_serial_port") |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 297 | if openbmc_model == "": |
| 298 | status, ret_values =\ |
| 299 | grk.run_key_u("Get BMC System Model") |
| 300 | openbmc_model = ret_values |
| 301 | BuiltIn().set_global_variable("${openbmc_model}", openbmc_model) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 302 | grv.rvalid_value("openbmc_model") |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 303 | grv.rvalid_integer("max_num_tests") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 304 | grv.rvalid_integer("boot_pass") |
| 305 | grv.rvalid_integer("boot_fail") |
| 306 | |
| 307 | plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths) |
| 308 | BuiltIn().set_global_variable("${plug_in_packages_list}", |
| 309 | plug_in_packages_list) |
| 310 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 311 | grv.rvalid_value("stack_mode", valid_values=['normal', 'skip']) |
Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 312 | if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 313 | error_message = "You must provide either a value for either the" +\ |
| 314 | " boot_list or the boot_stack parm.\n" |
| 315 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 316 | |
| 317 | valid_boot_list(boot_list, valid_boot_types) |
| 318 | valid_boot_list(boot_stack, valid_boot_types) |
| 319 | |
Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 320 | selected_PDU_boots = list(set(boot_list + boot_stack) & |
| 321 | set(boot_lists['PDU_reboot'])) |
| 322 | |
| 323 | if len(selected_PDU_boots) > 0 and pdu_host == "": |
| 324 | error_message = "You have selected the following boots which" +\ |
| 325 | " require a PDU host but no value for pdu_host:\n" |
| 326 | error_message += gp.sprint_var(selected_PDU_boots) |
| 327 | error_message += gp.sprint_var(pdu_host, 2) |
| 328 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 329 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 330 | return |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 331 | |
| 332 | ############################################################################### |
| 333 | |
| 334 | |
| 335 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 336 | def my_get_state(): |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 337 | |
| 338 | r""" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 339 | Get the system state plus a little bit of wrapping. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 340 | """ |
| 341 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 342 | global state |
| 343 | |
| 344 | req_states = ['epoch_seconds'] + st.default_req_states |
| 345 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 346 | gp.qprint_timen("Getting system state.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 347 | if test_mode: |
| 348 | state['epoch_seconds'] = int(time.time()) |
| 349 | else: |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 350 | state = st.get_state(req_states=req_states, quiet=quiet) |
| 351 | gp.qprint_var(state) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 352 | |
| 353 | ############################################################################### |
| 354 | |
| 355 | |
| 356 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 357 | def select_boot(): |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 358 | |
| 359 | r""" |
| 360 | Select a boot test to be run based on our current state and return the |
| 361 | chosen boot type. |
| 362 | |
| 363 | Description of arguments: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 364 | state The state of the machine. |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 365 | """ |
| 366 | |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 367 | global boot_stack |
| 368 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 369 | gp.qprint_timen("Selecting a boot test.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 370 | |
| 371 | my_get_state() |
| 372 | |
| 373 | stack_popped = 0 |
| 374 | if len(boot_stack) > 0: |
| 375 | stack_popped = 1 |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 376 | gp.qprint_dashes() |
| 377 | gp.qprint_var(boot_stack) |
| 378 | gp.qprint_dashes() |
| 379 | skip_boot_printed = 0 |
| 380 | while len(boot_stack) > 0: |
| 381 | boot_candidate = boot_stack.pop() |
| 382 | if stack_mode == 'normal': |
| 383 | break |
| 384 | else: |
| 385 | if st.compare_states(state, boot_table[boot_candidate]['end']): |
| 386 | if not skip_boot_printed: |
| 387 | gp.print_var(stack_mode) |
| 388 | gp.printn() |
| 389 | gp.print_timen("Skipping the following boot tests" + |
| 390 | " which are unnecessary since their" + |
| 391 | " required end states match the" + |
| 392 | " current machine state:") |
| 393 | skip_boot_printed = 1 |
| 394 | gp.print_var(boot_candidate) |
| 395 | boot_candidate = "" |
| 396 | if boot_candidate == "": |
| 397 | gp.qprint_dashes() |
| 398 | gp.qprint_var(boot_stack) |
| 399 | gp.qprint_dashes() |
| 400 | return boot_candidate |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 401 | if st.compare_states(state, boot_table[boot_candidate]['start']): |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 402 | gp.qprint_timen("The machine state is valid for a '" + |
| 403 | boot_candidate + "' boot test.") |
| 404 | gp.qprint_dashes() |
| 405 | gp.qprint_var(boot_stack) |
| 406 | gp.qprint_dashes() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 407 | return boot_candidate |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 408 | else: |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 409 | gp.qprint_timen("The machine state does not match the required" + |
| 410 | " starting state for a '" + boot_candidate + |
| 411 | "' boot test:") |
| 412 | gp.print_varx("boot_table[" + boot_candidate + "][start]", |
| 413 | boot_table[boot_candidate]['start'], 1) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 414 | boot_stack.append(boot_candidate) |
| 415 | popped_boot = boot_candidate |
| 416 | |
| 417 | # Loop through your list selecting a boot_candidates |
| 418 | boot_candidates = [] |
| 419 | for boot_candidate in boot_list: |
| 420 | if st.compare_states(state, boot_table[boot_candidate]['start']): |
| 421 | if stack_popped: |
| 422 | if st.compare_states(boot_table[boot_candidate]['end'], |
| 423 | boot_table[popped_boot]['start']): |
| 424 | boot_candidates.append(boot_candidate) |
| 425 | else: |
| 426 | boot_candidates.append(boot_candidate) |
| 427 | |
| 428 | if len(boot_candidates) == 0: |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 429 | gp.qprint_timen("The user's boot list contained no boot tests" + |
| 430 | " which are valid for the current machine state.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 431 | boot_candidate = default_power_on |
| 432 | if not st.compare_states(state, boot_table[default_power_on]['start']): |
| 433 | boot_candidate = default_power_off |
| 434 | boot_candidates.append(boot_candidate) |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 435 | gp.qprint_timen("Using default '" + boot_candidate + |
| 436 | "' boot type to transition to valid state.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 437 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 438 | gp.dprint_var(boot_candidates) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 439 | |
| 440 | # Randomly select a boot from the candidate list. |
| 441 | boot = random.choice(boot_candidates) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 442 | |
| 443 | return boot |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 444 | |
| 445 | ############################################################################### |
Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 446 | |
| 447 | |
| 448 | ############################################################################### |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 449 | def print_last_boots(): |
| 450 | |
| 451 | r""" |
| 452 | Print the last ten boots done with their time stamps. |
| 453 | """ |
| 454 | |
| 455 | # indent 0, 90 chars wide, linefeed, char is "=" |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 456 | gp.qprint_dashes(0, 90) |
| 457 | gp.qprintn("Last 10 boots:\n") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 458 | |
| 459 | for boot_entry in last_ten: |
| 460 | grp.rqprint(boot_entry) |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 461 | gp.qprint_dashes(0, 90) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 462 | |
| 463 | ############################################################################### |
| 464 | |
| 465 | |
| 466 | ############################################################################### |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 467 | def print_defect_report(): |
| 468 | |
| 469 | r""" |
| 470 | Print a defect report. |
| 471 | """ |
| 472 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 473 | gp.qprintn() |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 474 | # indent=0, width=90, linefeed=1, char="=" |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 475 | gp.qprint_dashes(0, 90, 1, "=") |
| 476 | gp.qprintn("Copy this data to the defect:\n") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 477 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 478 | grp.rqpvars(*parm_list) |
| 479 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 480 | gp.qprintn() |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 481 | |
| 482 | print_last_boots() |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 483 | gp.qprintn() |
| 484 | gp.qprint_var(state) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 485 | |
| 486 | # At some point I'd like to have the 'Call FFDC Methods' return a list |
| 487 | # of files it has collected. In that case, the following "ls" command |
| 488 | # would no longer be needed. For now, however, glob shows the files |
| 489 | # named in FFDC_LIST_FILE_PATH so I will refrain from printing those |
| 490 | # out (so we don't see duplicates in the list). |
| 491 | |
| 492 | LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}") |
| 493 | |
| 494 | output = '\n'.join(glob.glob(LOG_PREFIX + '*')) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 495 | try: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 496 | ffdc_list = open(ffdc_list_file_path, 'r') |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 497 | except IOError: |
| 498 | ffdc_list = "" |
| 499 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 500 | gp.qprintn() |
| 501 | gp.qprintn("FFDC data files:") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 502 | if status_file_path != "": |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 503 | gp.qprintn(status_file_path) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 504 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 505 | gp.qprintn(output) |
| 506 | # gp.qprintn(ffdc_list) |
| 507 | gp.qprintn() |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 508 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 509 | gp.qprint_dashes(0, 90, 1, "=") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 510 | |
| 511 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 512 | |
| 513 | |
| 514 | ############################################################################### |
| 515 | def my_ffdc(): |
| 516 | |
| 517 | r""" |
| 518 | Collect FFDC data. |
| 519 | """ |
| 520 | |
| 521 | global state |
| 522 | |
| 523 | plug_in_setup() |
| 524 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 525 | call_point='ffdc', stop_on_plug_in_failure=1) |
| 526 | |
| 527 | AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX'] |
| 528 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 529 | cmd_buf = ["FFDC", "ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX] |
| 530 | grp.rpissuing_keyword(cmd_buf) |
Michael Walsh | 3328caf | 2017-03-21 17:04:08 -0500 | [diff] [blame] | 531 | try: |
| 532 | BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf) |
| 533 | except: |
| 534 | gp.print_error("Call to ffdc failed.\n") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 535 | |
| 536 | my_get_state() |
| 537 | |
| 538 | print_defect_report() |
| 539 | |
| 540 | ############################################################################### |
| 541 | |
| 542 | |
| 543 | ############################################################################### |
| 544 | def print_test_start_message(boot_keyword): |
| 545 | |
| 546 | r""" |
| 547 | Print a message indicating what boot test is about to run. |
| 548 | |
| 549 | Description of arguments: |
| 550 | boot_keyword The name of the boot which is to be run |
| 551 | (e.g. "BMC Power On"). |
| 552 | """ |
| 553 | |
| 554 | global last_ten |
| 555 | |
| 556 | doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".") |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 557 | gp.qprint(doing_msg) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 558 | |
| 559 | last_ten.append(doing_msg) |
| 560 | |
| 561 | if len(last_ten) > 10: |
| 562 | del last_ten[0] |
| 563 | |
| 564 | ############################################################################### |
| 565 | |
| 566 | |
| 567 | ############################################################################### |
| 568 | def run_boot(boot): |
| 569 | |
| 570 | r""" |
| 571 | Run the specified boot. |
| 572 | |
| 573 | Description of arguments: |
| 574 | boot The name of the boot test to be performed. |
| 575 | """ |
| 576 | |
| 577 | global state |
| 578 | |
| 579 | print_test_start_message(boot) |
| 580 | |
| 581 | plug_in_setup() |
| 582 | rc, shell_rc, failed_plug_in_name = \ |
| 583 | grpi.rprocess_plug_in_packages(call_point="pre_boot") |
| 584 | if rc != 0: |
| 585 | error_message = "Plug-in failed with non-zero return code.\n" +\ |
| 586 | gp.sprint_var(rc, 1) |
| 587 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 588 | |
| 589 | if test_mode: |
| 590 | # In test mode, we'll pretend the boot worked by assigning its |
| 591 | # required end state to the default state value. |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 592 | state = st.strip_anchor_state(boot_table[boot]['end']) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 593 | else: |
| 594 | # Assertion: We trust that the state data was made fresh by the |
| 595 | # caller. |
| 596 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 597 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 598 | |
| 599 | if boot_table[boot]['method_type'] == "keyword": |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 600 | rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''), |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 601 | boot_table[boot]['method'], |
| 602 | quiet=quiet) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 603 | |
| 604 | if boot_table[boot]['bmc_reboot']: |
| 605 | st.wait_for_comm_cycle(int(state['epoch_seconds'])) |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 606 | plug_in_setup() |
| 607 | rc, shell_rc, failed_plug_in_name = \ |
| 608 | grpi.rprocess_plug_in_packages(call_point="post_reboot") |
| 609 | if rc != 0: |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 610 | error_message = "Plug-in failed with non-zero return code.\n" |
| 611 | error_message += gp.sprint_var(rc, 1) |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 612 | BuiltIn().fail(gp.sprint_error(error_message)) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 613 | else: |
| 614 | match_state = st.anchor_state(state) |
| 615 | del match_state['epoch_seconds'] |
| 616 | # Wait for the state to change in any way. |
| 617 | st.wait_state(match_state, wait_time=state_change_timeout, |
| 618 | interval="3 seconds", invert=1) |
| 619 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 620 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 621 | if boot_table[boot]['end']['chassis'] == "Off": |
| 622 | boot_timeout = power_off_timeout |
| 623 | else: |
| 624 | boot_timeout = power_on_timeout |
| 625 | st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout, |
| 626 | interval="3 seconds") |
| 627 | |
| 628 | plug_in_setup() |
| 629 | rc, shell_rc, failed_plug_in_name = \ |
| 630 | grpi.rprocess_plug_in_packages(call_point="post_boot") |
| 631 | if rc != 0: |
| 632 | error_message = "Plug-in failed with non-zero return code.\n" +\ |
| 633 | gp.sprint_var(rc, 1) |
| 634 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 635 | |
| 636 | ############################################################################### |
| 637 | |
| 638 | |
| 639 | ############################################################################### |
| 640 | def test_loop_body(): |
| 641 | |
| 642 | r""" |
| 643 | The main loop body for the loop in main_py. |
| 644 | |
| 645 | Description of arguments: |
| 646 | boot_count The iteration number (starts at 1). |
| 647 | """ |
| 648 | |
| 649 | global boot_count |
| 650 | global state |
| 651 | global next_boot |
| 652 | global boot_success |
| 653 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 654 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 655 | |
| 656 | next_boot = select_boot() |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 657 | if next_boot == "": |
| 658 | return True |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 659 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 660 | boot_count += 1 |
| 661 | gp.qprint_timen("Starting boot " + str(boot_count) + ".") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 662 | |
| 663 | # Clear the ffdc_list_file_path file. Plug-ins may now write to it. |
| 664 | try: |
| 665 | os.remove(ffdc_list_file_path) |
| 666 | except OSError: |
| 667 | pass |
| 668 | |
| 669 | cmd_buf = ["run_boot", next_boot] |
| 670 | boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) |
| 671 | if boot_status == "FAIL": |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 672 | gp.qprint(msg) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 673 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 674 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 675 | if boot_status == "PASS": |
| 676 | boot_success = 1 |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 677 | gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 678 | else: |
| 679 | boot_success = 0 |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 680 | gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 681 | |
| 682 | boot_results.update(next_boot, boot_status) |
| 683 | |
| 684 | plug_in_setup() |
| 685 | # NOTE: A post_test_case call point failure is NOT counted as a boot |
| 686 | # failure. |
| 687 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 688 | call_point='post_test_case', stop_on_plug_in_failure=1) |
| 689 | |
| 690 | plug_in_setup() |
| 691 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 692 | call_point='ffdc_check', shell_rc=0x00000200, |
| 693 | stop_on_plug_in_failure=1, stop_on_non_zero_rc=1) |
| 694 | if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200: |
| 695 | cmd_buf = ["my_ffdc"] |
| 696 | grp.rpissuing_keyword(cmd_buf) |
Michael Walsh | 3328caf | 2017-03-21 17:04:08 -0500 | [diff] [blame] | 697 | try: |
| 698 | BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf) |
| 699 | except: |
| 700 | gp.print_error("Call to my_ffdc failed.\n") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 701 | |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 702 | # We need to purge error logs between boots or they build up. |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 703 | grk.run_key("Delete Error logs", ignore=1) |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 704 | |
Michael Walsh | 952f9b0 | 2017-03-09 13:11:14 -0600 | [diff] [blame] | 705 | boot_results.print_report() |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 706 | gp.qprint_timen("Finished boot " + str(boot_count) + ".") |
Michael Walsh | 952f9b0 | 2017-03-09 13:11:14 -0600 | [diff] [blame] | 707 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 708 | plug_in_setup() |
| 709 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 710 | call_point='stop_check') |
| 711 | if rc != 0: |
| 712 | error_message = "Stopping as requested by user.\n" |
| 713 | grp.rprint_error_report(error_message) |
| 714 | BuiltIn().fail(error_message) |
| 715 | |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 716 | # This should help prevent ConnectionErrors. |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 717 | grk.run_key_u("Delete All Sessions") |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 718 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 719 | return True |
| 720 | |
| 721 | ############################################################################### |
| 722 | |
| 723 | |
| 724 | ############################################################################### |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 725 | def main_keyword_teardown(): |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 726 | |
| 727 | r""" |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 728 | Clean up after the Main keyword. |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 729 | """ |
| 730 | |
| 731 | if cp_setup_called: |
| 732 | plug_in_setup() |
| 733 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 734 | call_point='cleanup', stop_on_plug_in_failure=1) |
| 735 | |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 736 | # Save boot_results object to a file in case it is needed again. |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 737 | gp.qprint_timen("Saving boot_results to the following path.") |
| 738 | gp.qprint_var(boot_results_file_path) |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 739 | pickle.dump(boot_results, open(boot_results_file_path, 'wb'), |
| 740 | pickle.HIGHEST_PROTOCOL) |
| 741 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 742 | ############################################################################### |
| 743 | |
| 744 | |
| 745 | ############################################################################### |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 746 | def test_teardown(): |
| 747 | |
| 748 | r""" |
| 749 | Clean up after this test case. |
| 750 | """ |
| 751 | |
| 752 | gp.qprintn() |
| 753 | cmd_buf = ["Print Error", |
| 754 | "A keyword timeout occurred ending this program.\n"] |
| 755 | BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf) |
| 756 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 757 | grp.rqprint_pgm_footer() |
| 758 | |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 759 | ############################################################################### |
| 760 | |
| 761 | |
| 762 | ############################################################################### |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 763 | def obmc_boot_test(alt_boot_stack=None): |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 764 | |
| 765 | r""" |
| 766 | Do main program processing. |
| 767 | """ |
| 768 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 769 | if alt_boot_stack is not None: |
| 770 | BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack) |
| 771 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 772 | setup() |
| 773 | |
Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 774 | if ffdc_only: |
| 775 | gp.qprint_timen("Caller requested ffdc_only.") |
| 776 | cmd_buf = ["my_ffdc"] |
| 777 | grp.rpissuing_keyword(cmd_buf) |
| 778 | try: |
| 779 | BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf) |
| 780 | except: |
| 781 | gp.print_error("Call to my_ffdc failed.\n") |
| 782 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 783 | # Process caller's boot_stack. |
| 784 | while (len(boot_stack) > 0): |
| 785 | test_loop_body() |
| 786 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 787 | gp.qprint_timen("Finished processing stack.") |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 788 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 789 | # Process caller's boot_list. |
| 790 | if len(boot_list) > 0: |
| 791 | for ix in range(1, max_num_tests + 1): |
| 792 | test_loop_body() |
| 793 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 794 | gp.qprint_timen("Completed all requested boot tests.") |
| 795 | |
| 796 | boot_pass, boot_fail = boot_results.return_total_pass_fail() |
| 797 | if boot_fail > boot_fail_threshold: |
| 798 | error_message = "Boot failures exceed the boot failure" +\ |
| 799 | " threshold:\n" +\ |
| 800 | gp.sprint_var(boot_fail) +\ |
| 801 | gp.sprint_var(boot_fail_threshold) |
| 802 | BuiltIn().fail(gp.sprint_error(error_message)) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 803 | |
| 804 | ############################################################################### |