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 |
Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 12 | import re |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 13 | import cPickle as pickle |
Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 14 | import socket |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 15 | |
| 16 | from robot.utils import DotDict |
| 17 | from robot.libraries.BuiltIn import BuiltIn |
| 18 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 19 | from boot_data import * |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 20 | import gen_print as gp |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 21 | import gen_robot_print as grp |
Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 22 | import gen_robot_plug_in as grpi |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 23 | import gen_robot_valid as grv |
| 24 | import gen_misc as gm |
| 25 | import gen_cmd as gc |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 26 | import gen_robot_keyword as grk |
Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 27 | import state as st |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 28 | |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 29 | base_path = os.path.dirname(os.path.dirname( |
| 30 | imp.find_module("gen_robot_print")[1])) +\ |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 31 | os.sep |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 32 | sys.path.append(base_path + "extended/") |
| 33 | import run_keyword as rk |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 34 | |
Michael Walsh | e1e2644 | 2017-03-06 17:50:07 -0600 | [diff] [blame] | 35 | # Setting master_pid correctly influences the behavior of plug-ins like |
| 36 | # DB_Logging |
| 37 | program_pid = os.getpid() |
| 38 | master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid) |
| 39 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 40 | # Set up boot data structures. |
| 41 | boot_table = create_boot_table() |
| 42 | valid_boot_types = create_valid_boot_list(boot_table) |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 43 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 44 | boot_lists = read_boot_lists() |
| 45 | last_ten = [] |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 46 | |
| 47 | state = st.return_default_state() |
| 48 | cp_setup_called = 0 |
| 49 | next_boot = "" |
| 50 | base_tool_dir_path = os.path.normpath(os.environ.get( |
| 51 | 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 52 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 53 | ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 54 | boot_success = 0 |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 55 | status_dir_path = os.environ.get('STATUS_DIR_PATH', "") |
| 56 | if status_dir_path != "": |
| 57 | status_dir_path = os.path.normpath(status_dir_path) + os.sep |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 58 | default_power_on = "REST Power On" |
| 59 | default_power_off = "REST Power Off" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 60 | boot_count = 0 |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 61 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 62 | LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}") |
| 63 | |
| 64 | |
| 65 | ############################################################################### |
Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 66 | def process_host(host, |
| 67 | host_var_name=""): |
| 68 | |
| 69 | r""" |
| 70 | Process a host by getting the associated host name and IP address and |
| 71 | setting them in global variables. |
| 72 | |
| 73 | If the caller does not pass the host_var_name, this function will try to |
| 74 | figure out the name of the variable used by the caller for the host parm. |
| 75 | Callers are advised to explicitly specify the host_var_name when calling |
| 76 | with an exec command. In such cases, the get_arg_name cannot figure out |
| 77 | the host variable name. |
| 78 | |
| 79 | This function will then create similar global variable names by |
| 80 | removing "_host" and appending "_host_name" or "_ip" to the host variable |
| 81 | name. |
| 82 | |
| 83 | Example: |
| 84 | |
| 85 | If a call is made like this: |
| 86 | process_host(openbmc_host) |
| 87 | |
| 88 | Global variables openbmc_host_name and openbmc_ip will be set. |
| 89 | |
| 90 | Description of argument(s): |
| 91 | host A host name or IP. The name of the variable used should |
| 92 | have a suffix of "_host". |
| 93 | host_var_name The name of the variable being used as the host parm. |
| 94 | """ |
| 95 | |
| 96 | if host_var_name == "": |
| 97 | host_var_name = gp.get_arg_name(0, 1, stack_frame_ix=2) |
| 98 | |
| 99 | host_name_var_name = re.sub("host", "host_name", host_var_name) |
| 100 | ip_var_name = re.sub("host", "ip", host_var_name) |
| 101 | cmd_buf = "global " + host_name_var_name + ", " + ip_var_name + " ; " +\ |
| 102 | host_name_var_name + ", " + ip_var_name + " = gm.get_host_name_ip('" +\ |
| 103 | host + "')" |
| 104 | exec(cmd_buf) |
| 105 | |
| 106 | ############################################################################### |
| 107 | |
| 108 | |
| 109 | ############################################################################### |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 110 | def process_pgm_parms(): |
| 111 | |
| 112 | r""" |
| 113 | Process the program parameters by assigning them all to corresponding |
| 114 | globals. Also, set some global values that depend on program parameters. |
| 115 | """ |
| 116 | |
| 117 | # Program parameter processing. |
| 118 | # Assign all program parms to python variables which are global to this |
| 119 | # module. |
| 120 | |
| 121 | global parm_list |
| 122 | parm_list = BuiltIn().get_variable_value("${parm_list}") |
| 123 | # The following subset of parms should be processed as integers. |
| 124 | int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only', |
| 125 | 'boot_fail_threshold', 'quiet', 'test_mode', 'debug'] |
| 126 | for parm in parm_list: |
| 127 | if parm in int_list: |
| 128 | sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\ |
| 129 | "}\", \"0\"))" |
| 130 | else: |
| 131 | sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")" |
| 132 | cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd |
| 133 | exec(cmd_buf) |
Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 134 | if re.match(r".*_host$", parm): |
| 135 | cmd_buf = "process_host(" + parm + ", '" + parm + "')" |
| 136 | exec(cmd_buf) |
| 137 | if re.match(r".*_password$", parm): |
| 138 | # Register the value of any parm whose name ends in _password. |
| 139 | # This will cause the print functions to replace passwords with |
| 140 | # asterisks in the output. |
| 141 | cmd_buf = "gp.register_passwords(" + parm + ")" |
| 142 | exec(cmd_buf) |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 143 | |
| 144 | global ffdc_dir_path_style |
| 145 | global boot_list |
| 146 | global boot_stack |
| 147 | global boot_results_file_path |
| 148 | global boot_results |
| 149 | global ffdc_list_file_path |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 150 | global ffdc_report_list_path |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 151 | |
| 152 | if ffdc_dir_path_style == "": |
| 153 | ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0')) |
| 154 | |
| 155 | # Convert these program parms to lists for easier processing.. |
| 156 | boot_list = filter(None, boot_list.split(":")) |
| 157 | boot_stack = filter(None, boot_stack.split(":")) |
| 158 | |
| 159 | boot_results_file_path = "/tmp/" + openbmc_nickname + ":pid_" +\ |
| 160 | str(master_pid) + ":boot_results" |
| 161 | |
| 162 | if os.path.isfile(boot_results_file_path): |
| 163 | # We've been called before in this run so we'll load the saved |
| 164 | # boot_results object. |
| 165 | boot_results = pickle.load(open(boot_results_file_path, 'rb')) |
| 166 | else: |
| 167 | boot_results = boot_results(boot_table, boot_pass, boot_fail) |
| 168 | |
| 169 | ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\ |
| 170 | "/FFDC_FILE_LIST" |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 171 | ffdc_report_list_path = base_tool_dir_path + openbmc_nickname +\ |
| 172 | "/FFDC_REPORT_FILE_LIST" |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 173 | |
| 174 | ############################################################################### |
| 175 | |
| 176 | |
| 177 | ############################################################################### |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 178 | def initial_plug_in_setup(): |
| 179 | |
| 180 | r""" |
| 181 | Initialize all plug-in environment variables which do not change for the |
| 182 | duration of the program. |
| 183 | |
| 184 | """ |
| 185 | |
| 186 | global LOG_LEVEL |
| 187 | BuiltIn().set_log_level("NONE") |
| 188 | |
| 189 | BuiltIn().set_global_variable("${master_pid}", master_pid) |
| 190 | BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path) |
| 191 | BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path) |
| 192 | BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path) |
| 193 | BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}", |
| 194 | ffdc_list_file_path) |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 195 | BuiltIn().set_global_variable("${FFDC_REPORT_LIST_PATH}", |
| 196 | ffdc_report_list_path) |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 197 | |
| 198 | BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}", |
| 199 | ffdc_dir_path_style) |
| 200 | BuiltIn().set_global_variable("${FFDC_CHECK}", |
| 201 | ffdc_check) |
| 202 | |
| 203 | # For each program parameter, set the corresponding AUTOBOOT_ environment |
| 204 | # variable value. Also, set an AUTOBOOT_ environment variable for every |
| 205 | # element in additional_values. |
| 206 | additional_values = ["program_pid", "master_pid", "ffdc_dir_path", |
| 207 | "status_dir_path", "base_tool_dir_path", |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 208 | "ffdc_list_file_path", "ffdc_report_list_path"] |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 209 | |
| 210 | plug_in_vars = parm_list + additional_values |
| 211 | |
| 212 | for var_name in plug_in_vars: |
| 213 | var_value = BuiltIn().get_variable_value("${" + var_name + "}") |
| 214 | var_name = var_name.upper() |
| 215 | if var_value is None: |
| 216 | var_value = "" |
| 217 | os.environ["AUTOBOOT_" + var_name] = str(var_value) |
| 218 | |
| 219 | BuiltIn().set_log_level(LOG_LEVEL) |
| 220 | |
Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 221 | # Make sure the ffdc list directory exists. |
| 222 | ffdc_list_dir_path = os.path.dirname(ffdc_list_file_path) + os.sep |
| 223 | if not os.path.exists(ffdc_list_dir_path): |
| 224 | os.makedirs(ffdc_list_dir_path) |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 225 | |
| 226 | ############################################################################### |
| 227 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 228 | |
| 229 | ############################################################################### |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 230 | def plug_in_setup(): |
| 231 | |
| 232 | r""" |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 233 | Initialize all changing plug-in environment variables for use by the |
| 234 | plug-in programs. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 235 | """ |
| 236 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 237 | global LOG_LEVEL |
| 238 | global test_really_running |
| 239 | |
| 240 | BuiltIn().set_log_level("NONE") |
| 241 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 242 | boot_pass, boot_fail = boot_results.return_total_pass_fail() |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 243 | if boot_pass > 1: |
| 244 | test_really_running = 1 |
| 245 | else: |
| 246 | test_really_running = 0 |
| 247 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 248 | seconds = time.time() |
| 249 | loc_time = time.localtime(seconds) |
| 250 | time_string = time.strftime("%y%m%d.%H%M%S.", loc_time) |
| 251 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 252 | ffdc_prefix = openbmc_nickname + "." + time_string |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 253 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 254 | BuiltIn().set_global_variable("${test_really_running}", |
| 255 | test_really_running) |
| 256 | BuiltIn().set_global_variable("${boot_type_desc}", next_boot) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 257 | BuiltIn().set_global_variable("${boot_pass}", boot_pass) |
| 258 | BuiltIn().set_global_variable("${boot_fail}", boot_fail) |
| 259 | BuiltIn().set_global_variable("${boot_success}", boot_success) |
| 260 | BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix) |
Michael Walsh | 4c9a645 | 2016-12-13 16:03:11 -0600 | [diff] [blame] | 261 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 262 | # For each program parameter, set the corresponding AUTOBOOT_ environment |
| 263 | # variable value. Also, set an AUTOBOOT_ environment variable for every |
| 264 | # element in additional_values. |
| 265 | additional_values = ["boot_type_desc", "boot_success", "boot_pass", |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 266 | "boot_fail", "test_really_running", "ffdc_prefix"] |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 267 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 268 | plug_in_vars = additional_values |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 269 | |
| 270 | for var_name in plug_in_vars: |
| 271 | var_value = BuiltIn().get_variable_value("${" + var_name + "}") |
| 272 | var_name = var_name.upper() |
| 273 | if var_value is None: |
| 274 | var_value = "" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 275 | os.environ["AUTOBOOT_" + var_name] = str(var_value) |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 276 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 277 | if debug: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 278 | shell_rc, out_buf = \ |
| 279 | gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u") |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 280 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 281 | BuiltIn().set_log_level(LOG_LEVEL) |
| 282 | |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 283 | ############################################################################### |
| 284 | |
| 285 | |
| 286 | ############################################################################### |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 287 | def pre_boot_plug_in_setup(): |
| 288 | |
| 289 | # Clear the ffdc_list_file_path file. Plug-ins may now write to it. |
| 290 | try: |
| 291 | os.remove(ffdc_list_file_path) |
| 292 | except OSError: |
| 293 | pass |
| 294 | |
| 295 | # Clear the ffdc_report_list_path file. Plug-ins may now write to it. |
| 296 | try: |
| 297 | os.remove(ffdc_report_list_path) |
| 298 | except OSError: |
| 299 | pass |
| 300 | |
| 301 | ############################################################################### |
| 302 | |
| 303 | |
| 304 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 305 | def setup(): |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 306 | |
| 307 | r""" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 308 | Do general program setup tasks. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 309 | """ |
| 310 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 311 | global cp_setup_called |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 312 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 313 | gp.qprintn() |
| 314 | |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 315 | robot_pgm_dir_path = os.path.dirname(__file__) + os.sep |
| 316 | repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/") |
Michael Walsh | d061c04 | 2017-05-23 14:46:57 -0500 | [diff] [blame] | 317 | # If we can't find process_plug_in_packages.py, ssh_pw or |
| 318 | # validate_plug_ins.py, then we don't have our repo bin in PATH. |
| 319 | shell_rc, out_buf = gc.cmd_fnc_u("which process_plug_in_packages.py" + |
| 320 | " ssh_pw validate_plug_ins.py", quiet=1, |
| 321 | print_output=0, show_err=0) |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 322 | if shell_rc != 0: |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 323 | os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "") |
| 324 | # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH. |
| 325 | if robot_pgm_dir_path not in sys.path: |
| 326 | sys.path.append(robot_pgm_dir_path) |
| 327 | PYTHONPATH = os.environ.get("PYTHONPATH", "") |
| 328 | if PYTHONPATH == "": |
| 329 | os.environ['PYTHONPATH'] = robot_pgm_dir_path |
| 330 | else: |
| 331 | os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 332 | |
| 333 | validate_parms() |
| 334 | |
| 335 | grp.rqprint_pgm_header() |
| 336 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 337 | grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE") |
Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 338 | |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 339 | initial_plug_in_setup() |
| 340 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 341 | plug_in_setup() |
| 342 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 343 | call_point='setup') |
| 344 | if rc != 0: |
| 345 | error_message = "Plug-in setup failed.\n" |
| 346 | grp.rprint_error_report(error_message) |
| 347 | BuiltIn().fail(error_message) |
| 348 | # Setting cp_setup_called lets our Teardown know that it needs to call |
| 349 | # the cleanup plug-in call point. |
| 350 | cp_setup_called = 1 |
| 351 | |
| 352 | # Keyword "FFDC" will fail if TEST_MESSAGE is not set. |
| 353 | BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}") |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 354 | # FFDC_LOG_PATH is used by "FFDC" keyword. |
| 355 | BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 356 | |
Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 357 | # Also printed by FFDC. |
| 358 | global host_name |
| 359 | global host_ip |
| 360 | host = socket.gethostname() |
| 361 | host_name, host_ip = gm.get_host_name_ip(host) |
| 362 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 363 | gp.dprint_var(boot_table, 1) |
| 364 | gp.dprint_var(boot_lists) |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 365 | |
| 366 | ############################################################################### |
| 367 | |
| 368 | |
| 369 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 370 | def validate_parms(): |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 371 | |
| 372 | r""" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 373 | Validate all program parameters. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 374 | """ |
| 375 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 376 | process_pgm_parms() |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 377 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 378 | gp.qprintn() |
| 379 | |
| 380 | global openbmc_model |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 381 | grv.rvalid_value("openbmc_host") |
| 382 | grv.rvalid_value("openbmc_username") |
| 383 | grv.rvalid_value("openbmc_password") |
| 384 | if os_host != "": |
| 385 | grv.rvalid_value("os_username") |
| 386 | grv.rvalid_value("os_password") |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 387 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 388 | if pdu_host != "": |
| 389 | grv.rvalid_value("pdu_username") |
| 390 | grv.rvalid_value("pdu_password") |
Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 391 | grv.rvalid_integer("pdu_slot_no") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 392 | if openbmc_serial_host != "": |
| 393 | grv.rvalid_integer("openbmc_serial_port") |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 394 | if openbmc_model == "": |
| 395 | status, ret_values =\ |
| 396 | grk.run_key_u("Get BMC System Model") |
| 397 | openbmc_model = ret_values |
| 398 | BuiltIn().set_global_variable("${openbmc_model}", openbmc_model) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 399 | grv.rvalid_value("openbmc_model") |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 400 | grv.rvalid_integer("max_num_tests") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 401 | grv.rvalid_integer("boot_pass") |
| 402 | grv.rvalid_integer("boot_fail") |
| 403 | |
| 404 | plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths) |
| 405 | BuiltIn().set_global_variable("${plug_in_packages_list}", |
| 406 | plug_in_packages_list) |
| 407 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 408 | grv.rvalid_value("stack_mode", valid_values=['normal', 'skip']) |
Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 409 | if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 410 | error_message = "You must provide either a value for either the" +\ |
| 411 | " boot_list or the boot_stack parm.\n" |
| 412 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 413 | |
| 414 | valid_boot_list(boot_list, valid_boot_types) |
| 415 | valid_boot_list(boot_stack, valid_boot_types) |
| 416 | |
Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 417 | selected_PDU_boots = list(set(boot_list + boot_stack) & |
| 418 | set(boot_lists['PDU_reboot'])) |
| 419 | |
| 420 | if len(selected_PDU_boots) > 0 and pdu_host == "": |
| 421 | error_message = "You have selected the following boots which" +\ |
| 422 | " require a PDU host but no value for pdu_host:\n" |
| 423 | error_message += gp.sprint_var(selected_PDU_boots) |
| 424 | error_message += gp.sprint_var(pdu_host, 2) |
| 425 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 426 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 427 | return |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 428 | |
| 429 | ############################################################################### |
| 430 | |
| 431 | |
| 432 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 433 | def my_get_state(): |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 434 | |
| 435 | r""" |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 436 | Get the system state plus a little bit of wrapping. |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 437 | """ |
| 438 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 439 | global state |
| 440 | |
| 441 | req_states = ['epoch_seconds'] + st.default_req_states |
| 442 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 443 | gp.qprint_timen("Getting system state.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 444 | if test_mode: |
| 445 | state['epoch_seconds'] = int(time.time()) |
| 446 | else: |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 447 | state = st.get_state(req_states=req_states, quiet=quiet) |
| 448 | gp.qprint_var(state) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 449 | |
| 450 | ############################################################################### |
| 451 | |
| 452 | |
| 453 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 454 | def select_boot(): |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 455 | |
| 456 | r""" |
| 457 | Select a boot test to be run based on our current state and return the |
| 458 | chosen boot type. |
| 459 | |
| 460 | Description of arguments: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 461 | state The state of the machine. |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 462 | """ |
| 463 | |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 464 | global boot_stack |
| 465 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 466 | gp.qprint_timen("Selecting a boot test.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 467 | |
| 468 | my_get_state() |
| 469 | |
| 470 | stack_popped = 0 |
| 471 | if len(boot_stack) > 0: |
| 472 | stack_popped = 1 |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 473 | gp.qprint_dashes() |
| 474 | gp.qprint_var(boot_stack) |
| 475 | gp.qprint_dashes() |
| 476 | skip_boot_printed = 0 |
| 477 | while len(boot_stack) > 0: |
| 478 | boot_candidate = boot_stack.pop() |
| 479 | if stack_mode == 'normal': |
| 480 | break |
| 481 | else: |
| 482 | if st.compare_states(state, boot_table[boot_candidate]['end']): |
| 483 | if not skip_boot_printed: |
| 484 | gp.print_var(stack_mode) |
| 485 | gp.printn() |
| 486 | gp.print_timen("Skipping the following boot tests" + |
| 487 | " which are unnecessary since their" + |
| 488 | " required end states match the" + |
| 489 | " current machine state:") |
| 490 | skip_boot_printed = 1 |
| 491 | gp.print_var(boot_candidate) |
| 492 | boot_candidate = "" |
| 493 | if boot_candidate == "": |
| 494 | gp.qprint_dashes() |
| 495 | gp.qprint_var(boot_stack) |
| 496 | gp.qprint_dashes() |
| 497 | return boot_candidate |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 498 | if st.compare_states(state, boot_table[boot_candidate]['start']): |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 499 | gp.qprint_timen("The machine state is valid for a '" + |
| 500 | boot_candidate + "' boot test.") |
| 501 | gp.qprint_dashes() |
| 502 | gp.qprint_var(boot_stack) |
| 503 | gp.qprint_dashes() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 504 | return boot_candidate |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 505 | else: |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 506 | gp.qprint_timen("The machine state does not match the required" + |
| 507 | " starting state for a '" + boot_candidate + |
| 508 | "' boot test:") |
| 509 | gp.print_varx("boot_table[" + boot_candidate + "][start]", |
| 510 | boot_table[boot_candidate]['start'], 1) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 511 | boot_stack.append(boot_candidate) |
| 512 | popped_boot = boot_candidate |
| 513 | |
| 514 | # Loop through your list selecting a boot_candidates |
| 515 | boot_candidates = [] |
| 516 | for boot_candidate in boot_list: |
| 517 | if st.compare_states(state, boot_table[boot_candidate]['start']): |
| 518 | if stack_popped: |
| 519 | if st.compare_states(boot_table[boot_candidate]['end'], |
| 520 | boot_table[popped_boot]['start']): |
| 521 | boot_candidates.append(boot_candidate) |
| 522 | else: |
| 523 | boot_candidates.append(boot_candidate) |
| 524 | |
| 525 | if len(boot_candidates) == 0: |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 526 | gp.qprint_timen("The user's boot list contained no boot tests" + |
| 527 | " which are valid for the current machine state.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 528 | boot_candidate = default_power_on |
| 529 | if not st.compare_states(state, boot_table[default_power_on]['start']): |
| 530 | boot_candidate = default_power_off |
| 531 | boot_candidates.append(boot_candidate) |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 532 | gp.qprint_timen("Using default '" + boot_candidate + |
| 533 | "' boot type to transition to valid state.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 534 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 535 | gp.dprint_var(boot_candidates) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 536 | |
| 537 | # Randomly select a boot from the candidate list. |
| 538 | boot = random.choice(boot_candidates) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 539 | |
| 540 | return boot |
Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 541 | |
| 542 | ############################################################################### |
Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 543 | |
| 544 | |
| 545 | ############################################################################### |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 546 | def print_last_boots(): |
| 547 | |
| 548 | r""" |
| 549 | Print the last ten boots done with their time stamps. |
| 550 | """ |
| 551 | |
| 552 | # indent 0, 90 chars wide, linefeed, char is "=" |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 553 | gp.qprint_dashes(0, 90) |
| 554 | gp.qprintn("Last 10 boots:\n") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 555 | |
| 556 | for boot_entry in last_ten: |
| 557 | grp.rqprint(boot_entry) |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 558 | gp.qprint_dashes(0, 90) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 559 | |
| 560 | ############################################################################### |
| 561 | |
| 562 | |
| 563 | ############################################################################### |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 564 | def print_defect_report(): |
| 565 | |
| 566 | r""" |
| 567 | Print a defect report. |
| 568 | """ |
| 569 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 570 | # At some point I'd like to have the 'Call FFDC Methods' return a list |
| 571 | # of files it has collected. In that case, the following "ls" command |
| 572 | # would no longer be needed. For now, however, glob shows the files |
| 573 | # named in FFDC_LIST_FILE_PATH so I will refrain from printing those |
| 574 | # out (so we don't see duplicates in the list). |
| 575 | |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 576 | # Get additional header data which may have been created by ffdc plug-ins. |
| 577 | # Also, delete the individual header files to cleanup. |
| 578 | cmd_buf = "file_list=$(cat " + ffdc_report_list_path + " 2>/dev/null)" +\ |
| 579 | " ; [ ! -z \"${file_list}\" ] && cat ${file_list}" +\ |
| 580 | " 2>/dev/null ; rm -rf ${file_list} 2>/dev/null || :" |
| 581 | shell_rc, more_header_info = gc.cmd_fnc_u(cmd_buf, print_output=0, |
| 582 | show_err=0) |
| 583 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 584 | LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}") |
| 585 | |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 586 | output = '\n'.join(sorted(glob.glob(LOG_PREFIX + '*'))) |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 587 | try: |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 588 | ffdc_list = open(ffdc_list_file_path, 'r') |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 589 | except IOError: |
| 590 | ffdc_list = "" |
| 591 | |
Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 592 | # Open ffdc_file_list for writing. We will write a complete list of |
| 593 | # FFDC files to it for possible use by plug-ins like cp_stop_check. |
| 594 | ffdc_list_file = open(ffdc_list_file_path, 'w') |
| 595 | |
| 596 | gp.qprintn() |
| 597 | # indent=0, width=90, linefeed=1, char="=" |
| 598 | gp.qprint_dashes(0, 90, 1, "=") |
| 599 | gp.qprintn("Copy this data to the defect:\n") |
| 600 | |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 601 | if len(more_header_info) > 0: |
| 602 | gp.printn(more_header_info) |
Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 603 | gp.qpvars(host_name, host_ip, openbmc_nickname, openbmc_host, |
| 604 | openbmc_host_name, openbmc_ip, openbmc_username, |
| 605 | openbmc_password, os_host, os_host_name, os_ip, os_username, |
| 606 | os_password, pdu_host, pdu_host_name, pdu_ip, pdu_username, |
| 607 | pdu_password, pdu_slot_no, openbmc_serial_host, |
| 608 | openbmc_serial_host_name, openbmc_serial_ip, openbmc_serial_port) |
Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 609 | |
| 610 | gp.qprintn() |
| 611 | |
| 612 | print_last_boots() |
| 613 | gp.qprintn() |
| 614 | gp.qprint_var(state) |
| 615 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 616 | gp.qprintn() |
| 617 | gp.qprintn("FFDC data files:") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 618 | if status_file_path != "": |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 619 | gp.qprintn(status_file_path) |
Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 620 | ffdc_list_file.write(status_file_path + "\n") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 621 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 622 | gp.qprintn(output) |
| 623 | # gp.qprintn(ffdc_list) |
| 624 | gp.qprintn() |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 625 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 626 | gp.qprint_dashes(0, 90, 1, "=") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 627 | |
Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 628 | ffdc_list_file.write(output + "\n") |
| 629 | ffdc_list_file.close() |
| 630 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 631 | ############################################################################### |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 632 | |
| 633 | |
| 634 | ############################################################################### |
| 635 | def my_ffdc(): |
| 636 | |
| 637 | r""" |
| 638 | Collect FFDC data. |
| 639 | """ |
| 640 | |
| 641 | global state |
| 642 | |
| 643 | plug_in_setup() |
| 644 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 645 | call_point='ffdc', stop_on_plug_in_failure=1) |
| 646 | |
| 647 | AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX'] |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 648 | status, ret_values = grk.run_key_u("FFDC ffdc_prefix=" + |
| 649 | AUTOBOOT_FFDC_PREFIX + |
| 650 | " ffdc_function_list=" + |
| 651 | ffdc_function_list, ignore=1) |
| 652 | if status != 'PASS': |
Michael Walsh | 3328caf | 2017-03-21 17:04:08 -0500 | [diff] [blame] | 653 | gp.print_error("Call to ffdc failed.\n") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 654 | |
| 655 | my_get_state() |
| 656 | |
| 657 | print_defect_report() |
| 658 | |
| 659 | ############################################################################### |
| 660 | |
| 661 | |
| 662 | ############################################################################### |
| 663 | def print_test_start_message(boot_keyword): |
| 664 | |
| 665 | r""" |
| 666 | Print a message indicating what boot test is about to run. |
| 667 | |
| 668 | Description of arguments: |
| 669 | boot_keyword The name of the boot which is to be run |
| 670 | (e.g. "BMC Power On"). |
| 671 | """ |
| 672 | |
| 673 | global last_ten |
| 674 | |
| 675 | doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".") |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 676 | gp.qprint(doing_msg) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 677 | |
| 678 | last_ten.append(doing_msg) |
| 679 | |
| 680 | if len(last_ten) > 10: |
| 681 | del last_ten[0] |
| 682 | |
| 683 | ############################################################################### |
| 684 | |
| 685 | |
| 686 | ############################################################################### |
| 687 | def run_boot(boot): |
| 688 | |
| 689 | r""" |
| 690 | Run the specified boot. |
| 691 | |
| 692 | Description of arguments: |
| 693 | boot The name of the boot test to be performed. |
| 694 | """ |
| 695 | |
| 696 | global state |
| 697 | |
| 698 | print_test_start_message(boot) |
| 699 | |
| 700 | plug_in_setup() |
| 701 | rc, shell_rc, failed_plug_in_name = \ |
| 702 | grpi.rprocess_plug_in_packages(call_point="pre_boot") |
| 703 | if rc != 0: |
| 704 | error_message = "Plug-in failed with non-zero return code.\n" +\ |
| 705 | gp.sprint_var(rc, 1) |
| 706 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 707 | |
| 708 | if test_mode: |
| 709 | # In test mode, we'll pretend the boot worked by assigning its |
| 710 | # required end state to the default state value. |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 711 | state = st.strip_anchor_state(boot_table[boot]['end']) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 712 | else: |
| 713 | # Assertion: We trust that the state data was made fresh by the |
| 714 | # caller. |
| 715 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 716 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 717 | |
| 718 | if boot_table[boot]['method_type'] == "keyword": |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 719 | rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''), |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 720 | boot_table[boot]['method'], |
| 721 | quiet=quiet) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 722 | |
| 723 | if boot_table[boot]['bmc_reboot']: |
| 724 | st.wait_for_comm_cycle(int(state['epoch_seconds'])) |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 725 | plug_in_setup() |
| 726 | rc, shell_rc, failed_plug_in_name = \ |
| 727 | grpi.rprocess_plug_in_packages(call_point="post_reboot") |
| 728 | if rc != 0: |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 729 | error_message = "Plug-in failed with non-zero return code.\n" |
| 730 | error_message += gp.sprint_var(rc, 1) |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 731 | BuiltIn().fail(gp.sprint_error(error_message)) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 732 | else: |
| 733 | match_state = st.anchor_state(state) |
| 734 | del match_state['epoch_seconds'] |
| 735 | # Wait for the state to change in any way. |
| 736 | st.wait_state(match_state, wait_time=state_change_timeout, |
| 737 | interval="3 seconds", invert=1) |
| 738 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 739 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 740 | if boot_table[boot]['end']['chassis'] == "Off": |
| 741 | boot_timeout = power_off_timeout |
| 742 | else: |
| 743 | boot_timeout = power_on_timeout |
| 744 | st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout, |
| 745 | interval="3 seconds") |
| 746 | |
| 747 | plug_in_setup() |
| 748 | rc, shell_rc, failed_plug_in_name = \ |
| 749 | grpi.rprocess_plug_in_packages(call_point="post_boot") |
| 750 | if rc != 0: |
| 751 | error_message = "Plug-in failed with non-zero return code.\n" +\ |
| 752 | gp.sprint_var(rc, 1) |
| 753 | BuiltIn().fail(gp.sprint_error(error_message)) |
| 754 | |
| 755 | ############################################################################### |
| 756 | |
| 757 | |
| 758 | ############################################################################### |
| 759 | def test_loop_body(): |
| 760 | |
| 761 | r""" |
| 762 | The main loop body for the loop in main_py. |
| 763 | |
| 764 | Description of arguments: |
| 765 | boot_count The iteration number (starts at 1). |
| 766 | """ |
| 767 | |
| 768 | global boot_count |
| 769 | global state |
| 770 | global next_boot |
| 771 | global boot_success |
| 772 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 773 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 774 | |
| 775 | next_boot = select_boot() |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 776 | if next_boot == "": |
| 777 | return True |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 778 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 779 | boot_count += 1 |
| 780 | gp.qprint_timen("Starting boot " + str(boot_count) + ".") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 781 | |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 782 | pre_boot_plug_in_setup() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 783 | |
| 784 | cmd_buf = ["run_boot", next_boot] |
| 785 | boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) |
| 786 | if boot_status == "FAIL": |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 787 | gp.qprint(msg) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 788 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 789 | gp.qprintn() |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 790 | if boot_status == "PASS": |
| 791 | boot_success = 1 |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 792 | gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 793 | else: |
| 794 | boot_success = 0 |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 795 | gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 796 | |
| 797 | boot_results.update(next_boot, boot_status) |
| 798 | |
| 799 | plug_in_setup() |
| 800 | # NOTE: A post_test_case call point failure is NOT counted as a boot |
| 801 | # failure. |
| 802 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 803 | call_point='post_test_case', stop_on_plug_in_failure=1) |
| 804 | |
| 805 | plug_in_setup() |
| 806 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 807 | call_point='ffdc_check', shell_rc=0x00000200, |
| 808 | stop_on_plug_in_failure=1, stop_on_non_zero_rc=1) |
| 809 | if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200: |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 810 | status, ret_values = grk.run_key_u("my_ffdc", ignore=1) |
| 811 | if status != 'PASS': |
Michael Walsh | 3328caf | 2017-03-21 17:04:08 -0500 | [diff] [blame] | 812 | gp.print_error("Call to my_ffdc failed.\n") |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 813 | |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 814 | # We need to purge error logs between boots or they build up. |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 815 | grk.run_key("Delete Error logs", ignore=1) |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 816 | |
Michael Walsh | 952f9b0 | 2017-03-09 13:11:14 -0600 | [diff] [blame] | 817 | boot_results.print_report() |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 818 | gp.qprint_timen("Finished boot " + str(boot_count) + ".") |
Michael Walsh | 952f9b0 | 2017-03-09 13:11:14 -0600 | [diff] [blame] | 819 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 820 | plug_in_setup() |
| 821 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 822 | call_point='stop_check') |
| 823 | if rc != 0: |
| 824 | error_message = "Stopping as requested by user.\n" |
| 825 | grp.rprint_error_report(error_message) |
| 826 | BuiltIn().fail(error_message) |
| 827 | |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 828 | # This should help prevent ConnectionErrors. |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 829 | grk.run_key_u("Delete All Sessions") |
Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 830 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 831 | return True |
| 832 | |
| 833 | ############################################################################### |
| 834 | |
| 835 | |
| 836 | ############################################################################### |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 837 | def obmc_boot_test_teardown(): |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 838 | |
| 839 | r""" |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 840 | Clean up after the Main keyword. |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 841 | """ |
| 842 | |
| 843 | if cp_setup_called: |
| 844 | plug_in_setup() |
| 845 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( |
| 846 | call_point='cleanup', stop_on_plug_in_failure=1) |
| 847 | |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 848 | # Save boot_results object to a file in case it is needed again. |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 849 | gp.qprint_timen("Saving boot_results to the following path.") |
| 850 | gp.qprint_var(boot_results_file_path) |
Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 851 | pickle.dump(boot_results, open(boot_results_file_path, 'wb'), |
| 852 | pickle.HIGHEST_PROTOCOL) |
| 853 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 854 | ############################################################################### |
| 855 | |
| 856 | |
| 857 | ############################################################################### |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 858 | def test_teardown(): |
| 859 | |
| 860 | r""" |
| 861 | Clean up after this test case. |
| 862 | """ |
| 863 | |
| 864 | gp.qprintn() |
| 865 | cmd_buf = ["Print Error", |
| 866 | "A keyword timeout occurred ending this program.\n"] |
| 867 | BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf) |
| 868 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 869 | grp.rqprint_pgm_footer() |
| 870 | |
Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 871 | ############################################################################### |
| 872 | |
| 873 | |
| 874 | ############################################################################### |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 875 | def obmc_boot_test_py(alt_boot_stack=None): |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 876 | |
| 877 | r""" |
| 878 | Do main program processing. |
| 879 | """ |
| 880 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 881 | if alt_boot_stack is not None: |
| 882 | BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack) |
| 883 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 884 | setup() |
| 885 | |
Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 886 | if ffdc_only: |
| 887 | gp.qprint_timen("Caller requested ffdc_only.") |
Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 888 | pre_boot_plug_in_setup() |
Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 889 | grk.run_key_u("my_ffdc") |
Michael Walsh | 764d2f8 | 2017-04-27 16:01:08 -0500 | [diff] [blame] | 890 | return |
Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 891 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 892 | # Process caller's boot_stack. |
| 893 | while (len(boot_stack) > 0): |
| 894 | test_loop_body() |
| 895 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 896 | gp.qprint_timen("Finished processing stack.") |
Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 897 | |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 898 | # Process caller's boot_list. |
| 899 | if len(boot_list) > 0: |
| 900 | for ix in range(1, max_num_tests + 1): |
| 901 | test_loop_body() |
| 902 | |
Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 903 | gp.qprint_timen("Completed all requested boot tests.") |
| 904 | |
| 905 | boot_pass, boot_fail = boot_results.return_total_pass_fail() |
| 906 | if boot_fail > boot_fail_threshold: |
| 907 | error_message = "Boot failures exceed the boot failure" +\ |
| 908 | " threshold:\n" +\ |
| 909 | gp.sprint_var(boot_fail) +\ |
| 910 | gp.sprint_var(boot_fail_threshold) |
| 911 | BuiltIn().fail(gp.sprint_error(error_message)) |
Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 912 | |
| 913 | ############################################################################### |