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