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