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