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