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