| 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 | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 13 | import signal | 
| George Keishing | d54bbc2 | 2018-08-03 08:24:58 -0500 | [diff] [blame] | 14 | try: | 
|  | 15 | import cPickle as pickle | 
|  | 16 | except ImportError: | 
|  | 17 | import pickle | 
| Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 18 | import socket | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 19 |  | 
|  | 20 | from robot.utils import DotDict | 
|  | 21 | from robot.libraries.BuiltIn import BuiltIn | 
|  | 22 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 23 | from boot_data import * | 
| Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 24 | import gen_print as gp | 
| Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 25 | import gen_robot_plug_in as grpi | 
| Michael Walsh | f75d435 | 2019-12-05 17:01:20 -0600 | [diff] [blame] | 26 | import gen_arg as ga | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 27 | import gen_valid as gv | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 28 | import gen_misc as gm | 
|  | 29 | import gen_cmd as gc | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 30 | import gen_robot_keyword as grk | 
| Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 31 | import state as st | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 32 | import var_stack as vs | 
| Michael Walsh | c9bd2e8 | 2019-04-18 11:06:52 -0500 | [diff] [blame] | 33 | import gen_plug_in_utils as gpu | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 34 |  | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 35 | base_path = os.path.dirname(os.path.dirname( | 
|  | 36 | imp.find_module("gen_robot_print")[1])) +\ | 
| Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 37 | os.sep | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 38 | sys.path.append(base_path + "extended/") | 
|  | 39 | import run_keyword as rk | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 40 |  | 
| Michael Walsh | e1e2644 | 2017-03-06 17:50:07 -0600 | [diff] [blame] | 41 | # Setting master_pid correctly influences the behavior of plug-ins like | 
|  | 42 | # DB_Logging | 
|  | 43 | program_pid = os.getpid() | 
|  | 44 | master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid) | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 45 | pgm_name = re.sub('\\.py$', '', os.path.basename(__file__)) | 
| Michael Walsh | e1e2644 | 2017-03-06 17:50:07 -0600 | [diff] [blame] | 46 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 47 | # Set up boot data structures. | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 48 | os_host = BuiltIn().get_variable_value("${OS_HOST}", default="") | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 49 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 50 | boot_lists = read_boot_lists() | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 51 |  | 
|  | 52 | # The maximum number of entries that can be in the boot_history global variable. | 
| Michael Walsh | 815b1d5 | 2018-10-30 13:32:26 -0500 | [diff] [blame] | 53 | max_boot_history = 10 | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 54 | boot_history = [] | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 55 |  | 
| Michael Walsh | 7dc885b | 2018-03-14 17:51:59 -0500 | [diff] [blame] | 56 | state = st.return_state_constant('default_state') | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 57 | cp_setup_called = 0 | 
|  | 58 | next_boot = "" | 
|  | 59 | base_tool_dir_path = os.path.normpath(os.environ.get( | 
|  | 60 | 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 61 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 62 | 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] | 63 | boot_success = 0 | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 64 | status_dir_path = os.environ.get('STATUS_DIR_PATH', "") | 
|  | 65 | if status_dir_path != "": | 
|  | 66 | status_dir_path = os.path.normpath(status_dir_path) + os.sep | 
| Michael Walsh | e58df1c | 2019-08-07 09:57:43 -0500 | [diff] [blame] | 67 | redfish_supported = BuiltIn().get_variable_value("${REDFISH_SUPPORTED}", default=False) | 
|  | 68 | if redfish_supported: | 
|  | 69 | default_power_on = "Redfish Power On" | 
|  | 70 | default_power_off = "Redfish Power Off" | 
|  | 71 | else: | 
|  | 72 | default_power_on = "REST Power On" | 
|  | 73 | default_power_off = "REST Power Off" | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 74 | boot_count = 0 | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 75 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 76 | LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}") | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 77 | AUTOBOOT_FFDC_PREFIX = os.environ.get('AUTOBOOT_FFDC_PREFIX', '') | 
|  | 78 | ffdc_prefix = AUTOBOOT_FFDC_PREFIX | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 79 | boot_start_time = "" | 
|  | 80 | boot_end_time = "" | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 81 | save_stack = vs.var_stack('save_stack') | 
|  | 82 | main_func_parm_list = ['boot_stack', 'stack_mode', 'quiet'] | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 83 |  | 
|  | 84 |  | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 85 | def dump_ffdc_rc(): | 
|  | 86 | r""" | 
|  | 87 | Return the constant dump ffdc test return code value. | 
|  | 88 |  | 
|  | 89 | When a plug-in call point program returns this value, it indicates that | 
|  | 90 | this program should collect FFDC. | 
|  | 91 | """ | 
|  | 92 |  | 
|  | 93 | return 0x00000200 | 
|  | 94 |  | 
|  | 95 |  | 
|  | 96 | def stop_test_rc(): | 
|  | 97 | r""" | 
|  | 98 | Return the constant stop test return code value. | 
|  | 99 |  | 
|  | 100 | When a plug-in call point program returns this value, it indicates that | 
|  | 101 | this program should stop running. | 
|  | 102 | """ | 
|  | 103 |  | 
|  | 104 | return 0x00000200 | 
|  | 105 |  | 
|  | 106 |  | 
| Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 107 | def process_host(host, | 
|  | 108 | host_var_name=""): | 
| Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 109 | r""" | 
|  | 110 | Process a host by getting the associated host name and IP address and | 
|  | 111 | setting them in global variables. | 
|  | 112 |  | 
|  | 113 | If the caller does not pass the host_var_name, this function will try to | 
|  | 114 | figure out the name of the variable used by the caller for the host parm. | 
|  | 115 | Callers are advised to explicitly specify the host_var_name when calling | 
|  | 116 | with an exec command.  In such cases, the get_arg_name cannot figure out | 
|  | 117 | the host variable name. | 
|  | 118 |  | 
|  | 119 | This function will then create similar global variable names by | 
|  | 120 | removing "_host" and appending "_host_name" or "_ip" to the host variable | 
|  | 121 | name. | 
|  | 122 |  | 
|  | 123 | Example: | 
|  | 124 |  | 
|  | 125 | If a call is made like this: | 
|  | 126 | process_host(openbmc_host) | 
|  | 127 |  | 
|  | 128 | Global variables openbmc_host_name and openbmc_ip will be set. | 
|  | 129 |  | 
|  | 130 | Description of argument(s): | 
|  | 131 | host           A host name or IP.  The name of the variable used should | 
|  | 132 | have a suffix of "_host". | 
|  | 133 | host_var_name  The name of the variable being used as the host parm. | 
|  | 134 | """ | 
|  | 135 |  | 
|  | 136 | if host_var_name == "": | 
|  | 137 | host_var_name = gp.get_arg_name(0, 1, stack_frame_ix=2) | 
|  | 138 |  | 
|  | 139 | host_name_var_name = re.sub("host", "host_name", host_var_name) | 
|  | 140 | ip_var_name = re.sub("host", "ip", host_var_name) | 
|  | 141 | cmd_buf = "global " + host_name_var_name + ", " + ip_var_name + " ; " +\ | 
|  | 142 | host_name_var_name + ", " + ip_var_name + " = gm.get_host_name_ip('" +\ | 
|  | 143 | host + "')" | 
|  | 144 | exec(cmd_buf) | 
|  | 145 |  | 
| Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 146 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 147 | def process_pgm_parms(): | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 148 | r""" | 
|  | 149 | Process the program parameters by assigning them all to corresponding | 
|  | 150 | globals.  Also, set some global values that depend on program parameters. | 
|  | 151 | """ | 
|  | 152 |  | 
|  | 153 | # Program parameter processing. | 
|  | 154 | # Assign all program parms to python variables which are global to this | 
|  | 155 | # module. | 
|  | 156 |  | 
|  | 157 | global parm_list | 
|  | 158 | parm_list = BuiltIn().get_variable_value("${parm_list}") | 
|  | 159 | # The following subset of parms should be processed as integers. | 
|  | 160 | int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only', | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 161 | 'boot_fail_threshold', 'delete_errlogs', | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 162 | 'call_post_stack_plug', 'do_pre_boot_plug_in_setup', 'quiet', | 
|  | 163 | 'test_mode', 'debug'] | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 164 | for parm in parm_list: | 
|  | 165 | if parm in int_list: | 
|  | 166 | sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\ | 
|  | 167 | "}\", \"0\"))" | 
|  | 168 | else: | 
|  | 169 | sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")" | 
|  | 170 | cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 171 | gp.dpissuing(cmd_buf) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 172 | exec(cmd_buf) | 
| Michael Walsh | 0ad0f7f | 2017-05-04 14:39:58 -0500 | [diff] [blame] | 173 | if re.match(r".*_host$", parm): | 
|  | 174 | cmd_buf = "process_host(" + parm + ", '" + parm + "')" | 
|  | 175 | exec(cmd_buf) | 
|  | 176 | if re.match(r".*_password$", parm): | 
|  | 177 | # Register the value of any parm whose name ends in _password. | 
|  | 178 | # This will cause the print functions to replace passwords with | 
|  | 179 | # asterisks in the output. | 
|  | 180 | cmd_buf = "gp.register_passwords(" + parm + ")" | 
|  | 181 | exec(cmd_buf) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 182 |  | 
|  | 183 | global ffdc_dir_path_style | 
|  | 184 | global boot_list | 
|  | 185 | global boot_stack | 
|  | 186 | global boot_results_file_path | 
|  | 187 | global boot_results | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 188 | global boot_history | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 189 | global ffdc_list_file_path | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 190 | global ffdc_report_list_path | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 191 | global ffdc_summary_list_path | 
| Michael Walsh | a3e7b22 | 2020-02-03 15:32:16 -0600 | [diff] [blame] | 192 | global boot_table | 
|  | 193 | global valid_boot_types | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 194 |  | 
|  | 195 | if ffdc_dir_path_style == "": | 
|  | 196 | ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0')) | 
|  | 197 |  | 
|  | 198 | # Convert these program parms to lists for easier processing.. | 
| George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 199 | boot_list = list(filter(None, boot_list.split(":"))) | 
|  | 200 | boot_stack = list(filter(None, boot_stack.split(":"))) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 201 |  | 
| Michael Walsh | a3e7b22 | 2020-02-03 15:32:16 -0600 | [diff] [blame] | 202 | boot_table = create_boot_table(boot_table_path, os_host=os_host) | 
|  | 203 | valid_boot_types = create_valid_boot_list(boot_table) | 
|  | 204 |  | 
| Michael Walsh | 903e0b2 | 2017-09-19 17:00:33 -0500 | [diff] [blame] | 205 | cleanup_boot_results_file() | 
|  | 206 | boot_results_file_path = create_boot_results_file_path(pgm_name, | 
|  | 207 | openbmc_nickname, | 
|  | 208 | master_pid) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 209 |  | 
|  | 210 | if os.path.isfile(boot_results_file_path): | 
|  | 211 | # We've been called before in this run so we'll load the saved | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 212 | # boot_results and boot_history objects. | 
|  | 213 | boot_results, boot_history =\ | 
| Michael Walsh | 6c64574 | 2018-08-17 15:02:17 -0500 | [diff] [blame] | 214 | pickle.load(open(boot_results_file_path, 'rb')) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 215 | else: | 
|  | 216 | boot_results = boot_results(boot_table, boot_pass, boot_fail) | 
|  | 217 |  | 
|  | 218 | ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\ | 
|  | 219 | "/FFDC_FILE_LIST" | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 220 | ffdc_report_list_path = base_tool_dir_path + openbmc_nickname +\ | 
|  | 221 | "/FFDC_REPORT_FILE_LIST" | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 222 |  | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 223 | ffdc_summary_list_path = base_tool_dir_path + openbmc_nickname +\ | 
|  | 224 | "/FFDC_SUMMARY_FILE_LIST" | 
|  | 225 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 226 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 227 | def initial_plug_in_setup(): | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 228 | r""" | 
|  | 229 | Initialize all plug-in environment variables which do not change for the | 
|  | 230 | duration of the program. | 
|  | 231 |  | 
|  | 232 | """ | 
|  | 233 |  | 
|  | 234 | global LOG_LEVEL | 
|  | 235 | BuiltIn().set_log_level("NONE") | 
|  | 236 |  | 
|  | 237 | BuiltIn().set_global_variable("${master_pid}", master_pid) | 
|  | 238 | BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path) | 
|  | 239 | BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path) | 
|  | 240 | BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path) | 
|  | 241 | BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}", | 
|  | 242 | ffdc_list_file_path) | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 243 | BuiltIn().set_global_variable("${FFDC_REPORT_LIST_PATH}", | 
|  | 244 | ffdc_report_list_path) | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 245 | BuiltIn().set_global_variable("${FFDC_SUMMARY_LIST_PATH}", | 
|  | 246 | ffdc_summary_list_path) | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 247 |  | 
|  | 248 | BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}", | 
|  | 249 | ffdc_dir_path_style) | 
|  | 250 | BuiltIn().set_global_variable("${FFDC_CHECK}", | 
|  | 251 | ffdc_check) | 
|  | 252 |  | 
|  | 253 | # For each program parameter, set the corresponding AUTOBOOT_ environment | 
|  | 254 | # variable value.  Also, set an AUTOBOOT_ environment variable for every | 
|  | 255 | # element in additional_values. | 
|  | 256 | additional_values = ["program_pid", "master_pid", "ffdc_dir_path", | 
|  | 257 | "status_dir_path", "base_tool_dir_path", | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 258 | "ffdc_list_file_path", "ffdc_report_list_path", | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 259 | "ffdc_summary_list_path", "execdir"] | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 260 |  | 
|  | 261 | plug_in_vars = parm_list + additional_values | 
|  | 262 |  | 
|  | 263 | for var_name in plug_in_vars: | 
|  | 264 | var_value = BuiltIn().get_variable_value("${" + var_name + "}") | 
|  | 265 | var_name = var_name.upper() | 
|  | 266 | if var_value is None: | 
|  | 267 | var_value = "" | 
|  | 268 | os.environ["AUTOBOOT_" + var_name] = str(var_value) | 
|  | 269 |  | 
|  | 270 | BuiltIn().set_log_level(LOG_LEVEL) | 
|  | 271 |  | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 272 | # Make sure the ffdc list directory exists. | 
|  | 273 | ffdc_list_dir_path = os.path.dirname(ffdc_list_file_path) + os.sep | 
|  | 274 | if not os.path.exists(ffdc_list_dir_path): | 
|  | 275 | os.makedirs(ffdc_list_dir_path) | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 276 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 277 |  | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 278 | def plug_in_setup(): | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 279 | r""" | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 280 | Initialize all changing plug-in environment variables for use by the | 
|  | 281 | plug-in programs. | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 282 | """ | 
|  | 283 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 284 | global LOG_LEVEL | 
|  | 285 | global test_really_running | 
|  | 286 |  | 
|  | 287 | BuiltIn().set_log_level("NONE") | 
|  | 288 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 289 | boot_pass, boot_fail = boot_results.return_total_pass_fail() | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 290 | if boot_pass > 1: | 
|  | 291 | test_really_running = 1 | 
|  | 292 | else: | 
|  | 293 | test_really_running = 0 | 
|  | 294 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 295 | BuiltIn().set_global_variable("${test_really_running}", | 
|  | 296 | test_really_running) | 
|  | 297 | BuiltIn().set_global_variable("${boot_type_desc}", next_boot) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 298 | BuiltIn().set_global_variable("${boot_pass}", boot_pass) | 
|  | 299 | BuiltIn().set_global_variable("${boot_fail}", boot_fail) | 
|  | 300 | BuiltIn().set_global_variable("${boot_success}", boot_success) | 
|  | 301 | BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix) | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 302 | BuiltIn().set_global_variable("${boot_start_time}", boot_start_time) | 
|  | 303 | BuiltIn().set_global_variable("${boot_end_time}", boot_end_time) | 
| Michael Walsh | 4c9a645 | 2016-12-13 16:03:11 -0600 | [diff] [blame] | 304 |  | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 305 | # For each program parameter, set the corresponding AUTOBOOT_ environment | 
|  | 306 | # variable value.  Also, set an AUTOBOOT_ environment variable for every | 
|  | 307 | # element in additional_values. | 
|  | 308 | additional_values = ["boot_type_desc", "boot_success", "boot_pass", | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 309 | "boot_fail", "test_really_running", "ffdc_prefix", | 
|  | 310 | "boot_start_time", "boot_end_time"] | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 311 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 312 | plug_in_vars = additional_values | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 313 |  | 
|  | 314 | for var_name in plug_in_vars: | 
|  | 315 | var_value = BuiltIn().get_variable_value("${" + var_name + "}") | 
|  | 316 | var_name = var_name.upper() | 
|  | 317 | if var_value is None: | 
|  | 318 | var_value = "" | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 319 | os.environ["AUTOBOOT_" + var_name] = str(var_value) | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 320 |  | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 321 | if debug: | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 322 | shell_rc, out_buf = \ | 
|  | 323 | gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u") | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 324 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 325 | BuiltIn().set_log_level(LOG_LEVEL) | 
|  | 326 |  | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 327 |  | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 328 | def pre_boot_plug_in_setup(): | 
|  | 329 |  | 
|  | 330 | # Clear the ffdc_list_file_path file.  Plug-ins may now write to it. | 
|  | 331 | try: | 
|  | 332 | os.remove(ffdc_list_file_path) | 
|  | 333 | except OSError: | 
|  | 334 | pass | 
|  | 335 |  | 
|  | 336 | # Clear the ffdc_report_list_path file.  Plug-ins may now write to it. | 
|  | 337 | try: | 
|  | 338 | os.remove(ffdc_report_list_path) | 
|  | 339 | except OSError: | 
|  | 340 | pass | 
|  | 341 |  | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 342 | # Clear the ffdc_summary_list_path file.  Plug-ins may now write to it. | 
|  | 343 | try: | 
|  | 344 | os.remove(ffdc_summary_list_path) | 
|  | 345 | except OSError: | 
|  | 346 | pass | 
|  | 347 |  | 
| Michael Walsh | e1974b9 | 2017-08-03 13:39:51 -0500 | [diff] [blame] | 348 | global ffdc_prefix | 
|  | 349 |  | 
|  | 350 | seconds = time.time() | 
|  | 351 | loc_time = time.localtime(seconds) | 
|  | 352 | time_string = time.strftime("%y%m%d.%H%M%S.", loc_time) | 
|  | 353 |  | 
|  | 354 | ffdc_prefix = openbmc_nickname + "." + time_string | 
|  | 355 |  | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 356 |  | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 357 | def default_sigusr1(signal_number=0, | 
|  | 358 | frame=None): | 
|  | 359 | r""" | 
|  | 360 | Handle SIGUSR1 by doing nothing. | 
|  | 361 |  | 
|  | 362 | This function assists in debugging SIGUSR1 processing by printing messages | 
|  | 363 | to stdout and to the log.html file. | 
|  | 364 |  | 
|  | 365 | Description of argument(s): | 
|  | 366 | signal_number  The signal number (should always be 10 for SIGUSR1). | 
|  | 367 | frame          The frame data. | 
|  | 368 | """ | 
|  | 369 |  | 
| Michael Walsh | 80dddde | 2019-10-22 13:54:38 -0500 | [diff] [blame] | 370 | gp.qprintn() | 
|  | 371 | gp.qprint_executing() | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 372 | gp.lprint_executing() | 
|  | 373 |  | 
|  | 374 |  | 
|  | 375 | def set_default_siguser1(): | 
|  | 376 | r""" | 
|  | 377 | Set the default_sigusr1 function to be the SIGUSR1 handler. | 
|  | 378 | """ | 
|  | 379 |  | 
| Michael Walsh | 80dddde | 2019-10-22 13:54:38 -0500 | [diff] [blame] | 380 | gp.qprintn() | 
|  | 381 | gp.qprint_executing() | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 382 | gp.lprint_executing() | 
|  | 383 | signal.signal(signal.SIGUSR1, default_sigusr1) | 
|  | 384 |  | 
|  | 385 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 386 | def setup(): | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 387 | r""" | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 388 | Do general program setup tasks. | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 389 | """ | 
|  | 390 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 391 | global cp_setup_called | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 392 | global transitional_boot_selected | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 393 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 394 | gp.qprintn() | 
|  | 395 |  | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 396 | set_default_siguser1() | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 397 | transitional_boot_selected = False | 
|  | 398 |  | 
| Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 399 | robot_pgm_dir_path = os.path.dirname(__file__) + os.sep | 
|  | 400 | repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/") | 
| Michael Walsh | d061c04 | 2017-05-23 14:46:57 -0500 | [diff] [blame] | 401 | # If we can't find process_plug_in_packages.py, ssh_pw or | 
|  | 402 | # validate_plug_ins.py, then we don't have our repo bin in PATH. | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 403 | shell_rc, out_buf = gc.cmd_fnc_u("which process_plug_in_packages.py" | 
|  | 404 | + " ssh_pw validate_plug_ins.py", quiet=1, | 
| Michael Walsh | d061c04 | 2017-05-23 14:46:57 -0500 | [diff] [blame] | 405 | print_output=0, show_err=0) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 406 | if shell_rc != 0: | 
| Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 407 | os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "") | 
|  | 408 | # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH. | 
|  | 409 | if robot_pgm_dir_path not in sys.path: | 
|  | 410 | sys.path.append(robot_pgm_dir_path) | 
|  | 411 | PYTHONPATH = os.environ.get("PYTHONPATH", "") | 
|  | 412 | if PYTHONPATH == "": | 
|  | 413 | os.environ['PYTHONPATH'] = robot_pgm_dir_path | 
|  | 414 | else: | 
|  | 415 | os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 416 |  | 
|  | 417 | validate_parms() | 
|  | 418 |  | 
| Michael Walsh | c108e42 | 2019-03-28 12:27:18 -0500 | [diff] [blame] | 419 | gp.qprint_pgm_header() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 420 |  | 
| George Keishing | efc3ff2 | 2017-12-12 11:49:25 -0600 | [diff] [blame] | 421 | grk.run_key("Set BMC Power Policy  ALWAYS_POWER_OFF") | 
| Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 422 |  | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 423 | initial_plug_in_setup() | 
|  | 424 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 425 | plug_in_setup() | 
|  | 426 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
|  | 427 | call_point='setup') | 
|  | 428 | if rc != 0: | 
|  | 429 | error_message = "Plug-in setup failed.\n" | 
| Michael Walsh | c108e42 | 2019-03-28 12:27:18 -0500 | [diff] [blame] | 430 | gp.print_error_report(error_message) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 431 | BuiltIn().fail(error_message) | 
|  | 432 | # Setting cp_setup_called lets our Teardown know that it needs to call | 
|  | 433 | # the cleanup plug-in call point. | 
|  | 434 | cp_setup_called = 1 | 
|  | 435 |  | 
|  | 436 | # Keyword "FFDC" will fail if TEST_MESSAGE is not set. | 
|  | 437 | BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}") | 
| Michael Walsh | 8567894 | 2017-03-27 14:34:22 -0500 | [diff] [blame] | 438 | # FFDC_LOG_PATH is used by "FFDC" keyword. | 
|  | 439 | BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 440 |  | 
| Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 441 | # Also printed by FFDC. | 
|  | 442 | global host_name | 
|  | 443 | global host_ip | 
|  | 444 | host = socket.gethostname() | 
|  | 445 | host_name, host_ip = gm.get_host_name_ip(host) | 
|  | 446 |  | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 447 | gp.dprint_var(boot_table) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 448 | gp.dprint_var(boot_lists) | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 449 |  | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 450 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 451 | def validate_parms(): | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 452 | r""" | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 453 | Validate all program parameters. | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 454 | """ | 
|  | 455 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 456 | process_pgm_parms() | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 457 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 458 | gp.qprintn() | 
|  | 459 |  | 
|  | 460 | global openbmc_model | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 461 | gv.valid_value(openbmc_host) | 
|  | 462 | gv.valid_value(openbmc_username) | 
|  | 463 | gv.valid_value(openbmc_password) | 
|  | 464 | gv.valid_value(rest_username) | 
|  | 465 | gv.valid_value(rest_password) | 
|  | 466 | gv.valid_value(ipmi_username) | 
|  | 467 | gv.valid_value(ipmi_password) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 468 | if os_host != "": | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 469 | gv.valid_value(os_username) | 
|  | 470 | gv.valid_value(os_password) | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 471 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 472 | if pdu_host != "": | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 473 | gv.valid_value(pdu_username) | 
|  | 474 | gv.valid_value(pdu_password) | 
|  | 475 | gv.valid_integer(pdu_slot_no) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 476 | if openbmc_serial_host != "": | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 477 | gv.valid_integer(openbmc_serial_port) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 478 | if openbmc_model == "": | 
|  | 479 | status, ret_values =\ | 
|  | 480 | grk.run_key_u("Get BMC System Model") | 
|  | 481 | openbmc_model = ret_values | 
|  | 482 | BuiltIn().set_global_variable("${openbmc_model}", openbmc_model) | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 483 | gv.valid_value(openbmc_model) | 
|  | 484 | gv.valid_integer(max_num_tests) | 
|  | 485 | gv.valid_integer(boot_pass) | 
|  | 486 | gv.valid_integer(boot_fail) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 487 |  | 
|  | 488 | plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths) | 
|  | 489 | BuiltIn().set_global_variable("${plug_in_packages_list}", | 
|  | 490 | plug_in_packages_list) | 
|  | 491 |  | 
| Michael Walsh | 44cef25 | 2019-08-01 12:38:56 -0500 | [diff] [blame] | 492 | gv.valid_value(stack_mode, valid_values=['normal', 'skip']) | 
| Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 493 | 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] | 494 | error_message = "You must provide either a value for either the" +\ | 
|  | 495 | " boot_list or the boot_stack parm.\n" | 
|  | 496 | BuiltIn().fail(gp.sprint_error(error_message)) | 
|  | 497 |  | 
|  | 498 | valid_boot_list(boot_list, valid_boot_types) | 
|  | 499 | valid_boot_list(boot_stack, valid_boot_types) | 
|  | 500 |  | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 501 | selected_PDU_boots = list(set(boot_list + boot_stack) | 
|  | 502 | & set(boot_lists['PDU_reboot'])) | 
| Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 503 |  | 
|  | 504 | if len(selected_PDU_boots) > 0 and pdu_host == "": | 
|  | 505 | error_message = "You have selected the following boots which" +\ | 
|  | 506 | " require a PDU host but no value for pdu_host:\n" | 
|  | 507 | error_message += gp.sprint_var(selected_PDU_boots) | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 508 | error_message += gp.sprint_var(pdu_host, fmt=gp.blank()) | 
| Michael Walsh | 11cfc8c | 2017-03-31 09:40:55 -0500 | [diff] [blame] | 509 | BuiltIn().fail(gp.sprint_error(error_message)) | 
|  | 510 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 511 | return | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 512 |  | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 513 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 514 | def my_get_state(): | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 515 | r""" | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 516 | Get the system state plus a little bit of wrapping. | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 517 | """ | 
|  | 518 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 519 | global state | 
|  | 520 |  | 
|  | 521 | req_states = ['epoch_seconds'] + st.default_req_states | 
|  | 522 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 523 | gp.qprint_timen("Getting system state.") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 524 | if test_mode: | 
|  | 525 | state['epoch_seconds'] = int(time.time()) | 
|  | 526 | else: | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 527 | state = st.get_state(req_states=req_states, quiet=quiet) | 
|  | 528 | gp.qprint_var(state) | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 529 |  | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 530 |  | 
| Michael Walsh | 45ca6e4 | 2017-09-14 17:29:12 -0500 | [diff] [blame] | 531 | def valid_state(): | 
| Michael Walsh | 45ca6e4 | 2017-09-14 17:29:12 -0500 | [diff] [blame] | 532 | r""" | 
|  | 533 | Verify that our state dictionary contains no blank values.  If we don't get | 
|  | 534 | valid state data, we cannot continue to work. | 
|  | 535 | """ | 
|  | 536 |  | 
|  | 537 | if st.compare_states(state, st.invalid_state_match, 'or'): | 
|  | 538 | error_message = "The state dictionary contains blank fields which" +\ | 
|  | 539 | " is illegal.\n" + gp.sprint_var(state) | 
|  | 540 | BuiltIn().fail(gp.sprint_error(error_message)) | 
|  | 541 |  | 
| Michael Walsh | 45ca6e4 | 2017-09-14 17:29:12 -0500 | [diff] [blame] | 542 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 543 | def select_boot(): | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 544 | r""" | 
|  | 545 | Select a boot test to be run based on our current state and return the | 
|  | 546 | chosen boot type. | 
|  | 547 |  | 
|  | 548 | Description of arguments: | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 549 | state  The state of the machine. | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 550 | """ | 
|  | 551 |  | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 552 | global transitional_boot_selected | 
| Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 553 | global boot_stack | 
|  | 554 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 555 | gp.qprint_timen("Selecting a boot test.") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 556 |  | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 557 | if transitional_boot_selected and not boot_success: | 
|  | 558 | prior_boot = next_boot | 
|  | 559 | boot_candidate = boot_stack.pop() | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 560 | gp.qprint_timen("The prior '" + next_boot + "' was chosen to" | 
|  | 561 | + " transition to a valid state for '" + boot_candidate | 
|  | 562 | + "' which was at the top of the boot_stack.  Since" | 
|  | 563 | + " the '" + next_boot + "' failed, the '" | 
|  | 564 | + boot_candidate + "' has been removed from the stack" | 
|  | 565 | + " to avoid and endless failure loop.") | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 566 | if len(boot_stack) == 0: | 
|  | 567 | return "" | 
|  | 568 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 569 | my_get_state() | 
| Michael Walsh | 45ca6e4 | 2017-09-14 17:29:12 -0500 | [diff] [blame] | 570 | valid_state() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 571 |  | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 572 | transitional_boot_selected = False | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 573 | stack_popped = 0 | 
|  | 574 | if len(boot_stack) > 0: | 
|  | 575 | stack_popped = 1 | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 576 | gp.qprint_dashes() | 
|  | 577 | gp.qprint_var(boot_stack) | 
|  | 578 | gp.qprint_dashes() | 
|  | 579 | skip_boot_printed = 0 | 
|  | 580 | while len(boot_stack) > 0: | 
|  | 581 | boot_candidate = boot_stack.pop() | 
|  | 582 | if stack_mode == 'normal': | 
|  | 583 | break | 
|  | 584 | else: | 
|  | 585 | if st.compare_states(state, boot_table[boot_candidate]['end']): | 
|  | 586 | if not skip_boot_printed: | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 587 | gp.qprint_var(stack_mode) | 
|  | 588 | gp.qprintn() | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 589 | gp.qprint_timen("Skipping the following boot tests" | 
|  | 590 | + " which are unnecessary since their" | 
|  | 591 | + " required end states match the" | 
|  | 592 | + " current machine state:") | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 593 | skip_boot_printed = 1 | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 594 | gp.qprint_var(boot_candidate) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 595 | boot_candidate = "" | 
|  | 596 | if boot_candidate == "": | 
|  | 597 | gp.qprint_dashes() | 
|  | 598 | gp.qprint_var(boot_stack) | 
|  | 599 | gp.qprint_dashes() | 
|  | 600 | return boot_candidate | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 601 | if st.compare_states(state, boot_table[boot_candidate]['start']): | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 602 | gp.qprint_timen("The machine state is valid for a '" | 
|  | 603 | + boot_candidate + "' boot test.") | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 604 | gp.qprint_dashes() | 
|  | 605 | gp.qprint_var(boot_stack) | 
|  | 606 | gp.qprint_dashes() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 607 | return boot_candidate | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 608 | else: | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 609 | gp.qprint_timen("The machine state does not match the required" | 
|  | 610 | + " starting state for a '" + boot_candidate | 
|  | 611 | + "' boot test:") | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 612 | gp.qprint_varx("boot_table_start_entry", | 
|  | 613 | boot_table[boot_candidate]['start']) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 614 | boot_stack.append(boot_candidate) | 
| Michael Walsh | 8181674 | 2017-09-27 11:02:29 -0500 | [diff] [blame] | 615 | transitional_boot_selected = True | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 616 | popped_boot = boot_candidate | 
|  | 617 |  | 
|  | 618 | # Loop through your list selecting a boot_candidates | 
|  | 619 | boot_candidates = [] | 
|  | 620 | for boot_candidate in boot_list: | 
|  | 621 | if st.compare_states(state, boot_table[boot_candidate]['start']): | 
|  | 622 | if stack_popped: | 
|  | 623 | if st.compare_states(boot_table[boot_candidate]['end'], | 
| Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 624 | boot_table[popped_boot]['start']): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 625 | boot_candidates.append(boot_candidate) | 
|  | 626 | else: | 
|  | 627 | boot_candidates.append(boot_candidate) | 
|  | 628 |  | 
|  | 629 | if len(boot_candidates) == 0: | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 630 | gp.qprint_timen("The user's boot list contained no boot tests" | 
|  | 631 | + " which are valid for the current machine state.") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 632 | boot_candidate = default_power_on | 
|  | 633 | if not st.compare_states(state, boot_table[default_power_on]['start']): | 
|  | 634 | boot_candidate = default_power_off | 
|  | 635 | boot_candidates.append(boot_candidate) | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 636 | gp.qprint_timen("Using default '" + boot_candidate | 
|  | 637 | + "' boot type to transition to valid state.") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 638 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 639 | gp.dprint_var(boot_candidates) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 640 |  | 
|  | 641 | # Randomly select a boot from the candidate list. | 
|  | 642 | boot = random.choice(boot_candidates) | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 643 |  | 
|  | 644 | return boot | 
| Michael Walsh | 0bbd860 | 2016-11-22 11:31:49 -0600 | [diff] [blame] | 645 |  | 
| Michael Walsh | 5530229 | 2017-01-10 11:43:02 -0600 | [diff] [blame] | 646 |  | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 647 | def print_defect_report(ffdc_file_list): | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 648 | r""" | 
|  | 649 | Print a defect report. | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 650 |  | 
|  | 651 | Description of argument(s): | 
|  | 652 | ffdc_file_list  A list of files which were collected by our ffdc functions. | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 653 | """ | 
|  | 654 |  | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 655 | # Making deliberate choice to NOT run plug_in_setup().  We don't want | 
|  | 656 | # ffdc_prefix updated. | 
|  | 657 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
|  | 658 | call_point='ffdc_report', stop_on_plug_in_failure=0) | 
|  | 659 |  | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 660 | # Get additional header data which may have been created by ffdc plug-ins. | 
|  | 661 | # Also, delete the individual header files to cleanup. | 
|  | 662 | cmd_buf = "file_list=$(cat " + ffdc_report_list_path + " 2>/dev/null)" +\ | 
|  | 663 | " ; [ ! -z \"${file_list}\" ] && cat ${file_list}" +\ | 
|  | 664 | " 2>/dev/null ; rm -rf ${file_list} 2>/dev/null || :" | 
|  | 665 | shell_rc, more_header_info = gc.cmd_fnc_u(cmd_buf, print_output=0, | 
|  | 666 | show_err=0) | 
|  | 667 |  | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 668 | # Get additional summary data which may have been created by ffdc plug-ins. | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 669 | # Also, delete the individual header files to cleanup. | 
|  | 670 | cmd_buf = "file_list=$(cat " + ffdc_summary_list_path + " 2>/dev/null)" +\ | 
|  | 671 | " ; [ ! -z \"${file_list}\" ] && cat ${file_list}" +\ | 
|  | 672 | " 2>/dev/null ; rm -rf ${file_list} 2>/dev/null || :" | 
|  | 673 | shell_rc, ffdc_summary_info = gc.cmd_fnc_u(cmd_buf, print_output=0, | 
|  | 674 | show_err=0) | 
|  | 675 |  | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 676 | # ffdc_list_file_path contains a list of any ffdc files created by plug- | 
|  | 677 | # ins, etc.  Read that data into a list. | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 678 | try: | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 679 | plug_in_ffdc_list = \ | 
|  | 680 | open(ffdc_list_file_path, 'r').read().rstrip("\n").split("\n") | 
| George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 681 | plug_in_ffdc_list = list(filter(None, plug_in_ffdc_list)) | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 682 | except IOError: | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 683 | plug_in_ffdc_list = [] | 
|  | 684 |  | 
|  | 685 | # Combine the files from plug_in_ffdc_list with the ffdc_file_list passed | 
|  | 686 | # in.  Eliminate duplicates and sort the list. | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 687 | ffdc_file_list = sorted(set(ffdc_file_list + plug_in_ffdc_list)) | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 688 |  | 
|  | 689 | if status_file_path != "": | 
|  | 690 | ffdc_file_list.insert(0, status_file_path) | 
|  | 691 |  | 
|  | 692 | # Convert the list to a printable list. | 
|  | 693 | printable_ffdc_file_list = "\n".join(ffdc_file_list) | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 694 |  | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 695 | # Open ffdc_file_list for writing.  We will write a complete list of | 
|  | 696 | # FFDC files to it for possible use by plug-ins like cp_stop_check. | 
|  | 697 | ffdc_list_file = open(ffdc_list_file_path, 'w') | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 698 | ffdc_list_file.write(printable_ffdc_file_list + "\n") | 
|  | 699 | ffdc_list_file.close() | 
|  | 700 |  | 
|  | 701 | indent = 0 | 
|  | 702 | width = 90 | 
|  | 703 | linefeed = 1 | 
|  | 704 | char = "=" | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 705 |  | 
|  | 706 | gp.qprintn() | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 707 | gp.qprint_dashes(indent, width, linefeed, char) | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 708 | gp.qprintn("Copy this data to the defect:\n") | 
|  | 709 |  | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 710 | if len(more_header_info) > 0: | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 711 | gp.qprintn(more_header_info) | 
| Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 712 | gp.qpvars(host_name, host_ip, openbmc_nickname, openbmc_host, | 
|  | 713 | openbmc_host_name, openbmc_ip, openbmc_username, | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 714 | openbmc_password, rest_username, rest_password, ipmi_username, | 
|  | 715 | ipmi_password, os_host, os_host_name, os_ip, os_username, | 
| Michael Walsh | dc80d67 | 2017-05-09 12:58:32 -0500 | [diff] [blame] | 716 | os_password, pdu_host, pdu_host_name, pdu_ip, pdu_username, | 
|  | 717 | pdu_password, pdu_slot_no, openbmc_serial_host, | 
|  | 718 | openbmc_serial_host_name, openbmc_serial_ip, openbmc_serial_port) | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 719 |  | 
|  | 720 | gp.qprintn() | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 721 | print_boot_history(boot_history) | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 722 | gp.qprintn() | 
|  | 723 | gp.qprint_var(state) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 724 | gp.qprintn() | 
|  | 725 | gp.qprintn("FFDC data files:") | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 726 | gp.qprintn(printable_ffdc_file_list) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 727 | gp.qprintn() | 
| Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 728 |  | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 729 | if len(ffdc_summary_info) > 0: | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 730 | gp.qprintn(ffdc_summary_info) | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 731 |  | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 732 | gp.qprint_dashes(indent, width, linefeed, char) | 
| Michael Walsh | 68a6116 | 2017-04-25 11:54:06 -0500 | [diff] [blame] | 733 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 734 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 735 | def my_ffdc(): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 736 | r""" | 
|  | 737 | Collect FFDC data. | 
|  | 738 | """ | 
|  | 739 |  | 
|  | 740 | global state | 
|  | 741 |  | 
|  | 742 | plug_in_setup() | 
|  | 743 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 744 | call_point='ffdc', stop_on_plug_in_failure=0) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 745 |  | 
|  | 746 | AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX'] | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 747 | status, ffdc_file_list = grk.run_key_u("FFDC  ffdc_prefix=" | 
|  | 748 | + AUTOBOOT_FFDC_PREFIX | 
|  | 749 | + "  ffdc_function_list=" | 
|  | 750 | + ffdc_function_list, ignore=1) | 
| Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 751 | if status != 'PASS': | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 752 | gp.qprint_error("Call to ffdc failed.\n") | 
| Michael Walsh | c9bd2e8 | 2019-04-18 11:06:52 -0500 | [diff] [blame] | 753 | if type(ffdc_file_list) is not list: | 
|  | 754 | ffdc_file_list = [] | 
|  | 755 | # Leave a record for caller that "soft" errors occurred. | 
|  | 756 | soft_errors = 1 | 
|  | 757 | gpu.save_plug_in_value(soft_errors, pgm_name) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 758 |  | 
|  | 759 | my_get_state() | 
|  | 760 |  | 
| Michael Walsh | b2e53ec | 2017-10-30 15:04:36 -0500 | [diff] [blame] | 761 | print_defect_report(ffdc_file_list) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 762 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 763 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 764 | def print_test_start_message(boot_keyword): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 765 | r""" | 
|  | 766 | Print a message indicating what boot test is about to run. | 
|  | 767 |  | 
|  | 768 | Description of arguments: | 
|  | 769 | boot_keyword  The name of the boot which is to be run | 
|  | 770 | (e.g. "BMC Power On"). | 
|  | 771 | """ | 
|  | 772 |  | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 773 | global boot_history | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 774 | global boot_start_time | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 775 |  | 
|  | 776 | doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".") | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 777 |  | 
|  | 778 | # Set boot_start_time for use by plug-ins. | 
|  | 779 | boot_start_time = doing_msg[1:33] | 
|  | 780 | gp.qprint_var(boot_start_time) | 
|  | 781 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 782 | gp.qprint(doing_msg) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 783 |  | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 784 | update_boot_history(boot_history, doing_msg, max_boot_history) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 785 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 786 |  | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 787 | def stop_boot_test(signal_number=0, | 
|  | 788 | frame=None): | 
|  | 789 | r""" | 
|  | 790 | Handle SIGUSR1 by aborting the boot test that is running. | 
|  | 791 |  | 
|  | 792 | Description of argument(s): | 
|  | 793 | signal_number  The signal number (should always be 10 for SIGUSR1). | 
|  | 794 | frame          The frame data. | 
|  | 795 | """ | 
|  | 796 |  | 
| Michael Walsh | 80dddde | 2019-10-22 13:54:38 -0500 | [diff] [blame] | 797 | gp.qprintn() | 
|  | 798 | gp.qprint_executing() | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 799 | gp.lprint_executing() | 
|  | 800 |  | 
|  | 801 | # Restore original sigusr1 handler. | 
|  | 802 | set_default_siguser1() | 
|  | 803 |  | 
|  | 804 | message = "The caller has asked that the boot test be stopped and marked" | 
|  | 805 | message += " as a failure." | 
|  | 806 |  | 
|  | 807 | function_stack = gm.get_function_stack() | 
|  | 808 | if "wait_state" in function_stack: | 
| Michael Walsh | c44aa53 | 2019-06-14 13:33:29 -0500 | [diff] [blame] | 809 | st.set_exit_wait_early_message(message) | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 810 | else: | 
|  | 811 | BuiltIn().fail(gp.sprint_error(message)) | 
|  | 812 |  | 
|  | 813 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 814 | def run_boot(boot): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 815 | r""" | 
|  | 816 | Run the specified boot. | 
|  | 817 |  | 
|  | 818 | Description of arguments: | 
|  | 819 | boot  The name of the boot test to be performed. | 
|  | 820 | """ | 
|  | 821 |  | 
|  | 822 | global state | 
|  | 823 |  | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 824 | signal.signal(signal.SIGUSR1, stop_boot_test) | 
|  | 825 | gp.qprint_timen("stop_boot_test is armed.") | 
|  | 826 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 827 | print_test_start_message(boot) | 
|  | 828 |  | 
|  | 829 | plug_in_setup() | 
|  | 830 | rc, shell_rc, failed_plug_in_name = \ | 
|  | 831 | grpi.rprocess_plug_in_packages(call_point="pre_boot") | 
|  | 832 | if rc != 0: | 
|  | 833 | error_message = "Plug-in failed with non-zero return code.\n" +\ | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 834 | gp.sprint_var(rc, fmt=gp.hexa()) | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 835 | set_default_siguser1() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 836 | BuiltIn().fail(gp.sprint_error(error_message)) | 
|  | 837 |  | 
|  | 838 | if test_mode: | 
|  | 839 | # In test mode, we'll pretend the boot worked by assigning its | 
|  | 840 | # required end state to the default state value. | 
| Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 841 | state = st.strip_anchor_state(boot_table[boot]['end']) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 842 | else: | 
|  | 843 | # Assertion:  We trust that the state data was made fresh by the | 
|  | 844 | # caller. | 
|  | 845 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 846 | gp.qprintn() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 847 |  | 
|  | 848 | if boot_table[boot]['method_type'] == "keyword": | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 849 | rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''), | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 850 | boot_table[boot]['method'], | 
|  | 851 | quiet=quiet) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 852 |  | 
|  | 853 | if boot_table[boot]['bmc_reboot']: | 
|  | 854 | st.wait_for_comm_cycle(int(state['epoch_seconds'])) | 
| Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 855 | plug_in_setup() | 
|  | 856 | rc, shell_rc, failed_plug_in_name = \ | 
|  | 857 | grpi.rprocess_plug_in_packages(call_point="post_reboot") | 
|  | 858 | if rc != 0: | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 859 | error_message = "Plug-in failed with non-zero return code.\n" | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 860 | error_message += gp.sprint_var(rc, fmt=gp.hexa()) | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 861 | set_default_siguser1() | 
| Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 862 | BuiltIn().fail(gp.sprint_error(error_message)) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 863 | else: | 
|  | 864 | match_state = st.anchor_state(state) | 
|  | 865 | del match_state['epoch_seconds'] | 
|  | 866 | # Wait for the state to change in any way. | 
|  | 867 | st.wait_state(match_state, wait_time=state_change_timeout, | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 868 | interval="10 seconds", invert=1) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 869 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 870 | gp.qprintn() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 871 | if boot_table[boot]['end']['chassis'] == "Off": | 
|  | 872 | boot_timeout = power_off_timeout | 
|  | 873 | else: | 
|  | 874 | boot_timeout = power_on_timeout | 
|  | 875 | st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout, | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 876 | interval="10 seconds") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 877 |  | 
|  | 878 | plug_in_setup() | 
|  | 879 | rc, shell_rc, failed_plug_in_name = \ | 
|  | 880 | grpi.rprocess_plug_in_packages(call_point="post_boot") | 
|  | 881 | if rc != 0: | 
|  | 882 | error_message = "Plug-in failed with non-zero return code.\n" +\ | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 883 | gp.sprint_var(rc, fmt=gp.hexa()) | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 884 | set_default_siguser1() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 885 | BuiltIn().fail(gp.sprint_error(error_message)) | 
|  | 886 |  | 
| Michael Walsh | f566fb1 | 2019-02-01 14:35:09 -0600 | [diff] [blame] | 887 | # Restore original sigusr1 handler. | 
|  | 888 | set_default_siguser1() | 
|  | 889 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 890 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 891 | def test_loop_body(): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 892 | r""" | 
|  | 893 | The main loop body for the loop in main_py. | 
|  | 894 |  | 
|  | 895 | Description of arguments: | 
|  | 896 | boot_count  The iteration number (starts at 1). | 
|  | 897 | """ | 
|  | 898 |  | 
|  | 899 | global boot_count | 
|  | 900 | global state | 
|  | 901 | global next_boot | 
|  | 902 | global boot_success | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 903 | global boot_end_time | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 904 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 905 | gp.qprintn() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 906 |  | 
|  | 907 | next_boot = select_boot() | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 908 | if next_boot == "": | 
|  | 909 | return True | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 910 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 911 | boot_count += 1 | 
|  | 912 | gp.qprint_timen("Starting boot " + str(boot_count) + ".") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 913 |  | 
| Michael Walsh | e0cf8d7 | 2017-05-17 13:20:46 -0500 | [diff] [blame] | 914 | pre_boot_plug_in_setup() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 915 |  | 
|  | 916 | cmd_buf = ["run_boot", next_boot] | 
|  | 917 | boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) | 
|  | 918 | if boot_status == "FAIL": | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 919 | gp.qprint(msg) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 920 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 921 | gp.qprintn() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 922 | if boot_status == "PASS": | 
|  | 923 | boot_success = 1 | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 924 | completion_msg = gp.sprint_timen("BOOT_SUCCESS: \"" + next_boot | 
|  | 925 | + "\" succeeded.") | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 926 | else: | 
|  | 927 | boot_success = 0 | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 928 | completion_msg = gp.sprint_timen("BOOT_FAILED: \"" + next_boot | 
|  | 929 | + "\" failed.") | 
| Sunil M | 325eb54 | 2017-08-10 07:09:43 -0500 | [diff] [blame] | 930 |  | 
|  | 931 | # Set boot_end_time for use by plug-ins. | 
|  | 932 | boot_end_time = completion_msg[1:33] | 
|  | 933 | gp.qprint_var(boot_end_time) | 
|  | 934 |  | 
|  | 935 | gp.qprint(completion_msg) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 936 |  | 
|  | 937 | boot_results.update(next_boot, boot_status) | 
|  | 938 |  | 
|  | 939 | plug_in_setup() | 
|  | 940 | # NOTE: A post_test_case call point failure is NOT counted as a boot | 
|  | 941 | # failure. | 
|  | 942 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 943 | call_point='post_test_case', stop_on_plug_in_failure=0) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 944 |  | 
|  | 945 | plug_in_setup() | 
|  | 946 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 947 | call_point='ffdc_check', shell_rc=dump_ffdc_rc(), | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 948 | stop_on_plug_in_failure=1, stop_on_non_zero_rc=1) | 
| Michael Walsh | 12059e2 | 2019-03-21 11:03:45 -0500 | [diff] [blame] | 949 | if ffdc_check == "All" or\ | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 950 | shell_rc == dump_ffdc_rc(): | 
| Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 951 | status, ret_values = grk.run_key_u("my_ffdc", ignore=1) | 
|  | 952 | if status != 'PASS': | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 953 | gp.qprint_error("Call to my_ffdc failed.\n") | 
| Michael Walsh | c9bd2e8 | 2019-04-18 11:06:52 -0500 | [diff] [blame] | 954 | # Leave a record for caller that "soft" errors occurred. | 
|  | 955 | soft_errors = 1 | 
|  | 956 | gpu.save_plug_in_value(soft_errors, pgm_name) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 957 |  | 
| Michael Walsh | aabef1e | 2017-09-20 15:16:17 -0500 | [diff] [blame] | 958 | if delete_errlogs: | 
|  | 959 | # We need to purge error logs between boots or they build up. | 
|  | 960 | grk.run_key("Delete Error logs", ignore=1) | 
| Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 961 |  | 
| Michael Walsh | 952f9b0 | 2017-03-09 13:11:14 -0600 | [diff] [blame] | 962 | boot_results.print_report() | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 963 | gp.qprint_timen("Finished boot " + str(boot_count) + ".") | 
| Michael Walsh | 952f9b0 | 2017-03-09 13:11:14 -0600 | [diff] [blame] | 964 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 965 | plug_in_setup() | 
|  | 966 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 967 | call_point='stop_check', shell_rc=stop_test_rc(), | 
|  | 968 | stop_on_non_zero_rc=1) | 
|  | 969 | if shell_rc == stop_test_rc(): | 
| Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 970 | message = "Stopping as requested by user.\n" | 
| Michael Walsh | 80dddde | 2019-10-22 13:54:38 -0500 | [diff] [blame] | 971 | gp.qprint_time(message) | 
| Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 972 | BuiltIn().fail(message) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 973 |  | 
| Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 974 | # This should help prevent ConnectionErrors. | 
| Michael Walsh | 0960b38 | 2017-06-22 16:23:37 -0500 | [diff] [blame] | 975 | grk.run_key_u("Close All Connections") | 
| Michael Walsh | d139f28 | 2017-04-04 18:00:23 -0500 | [diff] [blame] | 976 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 977 | return True | 
|  | 978 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 979 |  | 
| Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 980 | def obmc_boot_test_teardown(): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 981 | r""" | 
| Michael Walsh | f75d435 | 2019-12-05 17:01:20 -0600 | [diff] [blame] | 982 | Clean up after the main keyword. | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 983 | """ | 
| Michael Walsh | f75d435 | 2019-12-05 17:01:20 -0600 | [diff] [blame] | 984 | gp.qprint_executing() | 
|  | 985 |  | 
|  | 986 | if ga.psutil_imported: | 
|  | 987 | ga.terminate_descendants() | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 988 |  | 
|  | 989 | if cp_setup_called: | 
|  | 990 | plug_in_setup() | 
|  | 991 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 992 | call_point='cleanup', stop_on_plug_in_failure=0) | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 993 |  | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 994 | if 'boot_results_file_path' in globals(): | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 995 | # Save boot_results and boot_history objects to a file in case they are | 
| Michael Walsh | 6c64574 | 2018-08-17 15:02:17 -0500 | [diff] [blame] | 996 | # needed again. | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 997 | gp.qprint_timen("Saving boot_results to the following path.") | 
|  | 998 | gp.qprint_var(boot_results_file_path) | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 999 | pickle.dump((boot_results, boot_history), | 
| Michael Walsh | 6c64574 | 2018-08-17 15:02:17 -0500 | [diff] [blame] | 1000 | open(boot_results_file_path, 'wb'), | 
| Michael Walsh | 600876d | 2017-05-30 17:58:58 -0500 | [diff] [blame] | 1001 | pickle.HIGHEST_PROTOCOL) | 
| Michael Walsh | 0b93fbf | 2017-03-02 14:42:41 -0600 | [diff] [blame] | 1002 |  | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1003 | global save_stack | 
|  | 1004 | # Restore any global values saved on the save_stack. | 
|  | 1005 | for parm_name in main_func_parm_list: | 
|  | 1006 | # Get the parm_value if it was saved on the stack. | 
|  | 1007 | try: | 
|  | 1008 | parm_value = save_stack.pop(parm_name) | 
| Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 1009 | except BaseException: | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1010 | # If it was not saved, no further action is required. | 
|  | 1011 | continue | 
|  | 1012 |  | 
|  | 1013 | # Restore the saved value. | 
|  | 1014 | cmd_buf = "BuiltIn().set_global_variable(\"${" + parm_name +\ | 
|  | 1015 | "}\", parm_value)" | 
|  | 1016 | gp.dpissuing(cmd_buf) | 
|  | 1017 | exec(cmd_buf) | 
|  | 1018 |  | 
|  | 1019 | gp.dprintn(save_stack.sprint_obj()) | 
|  | 1020 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 1021 |  | 
| Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 1022 | def test_teardown(): | 
| Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 1023 | r""" | 
|  | 1024 | Clean up after this test case. | 
|  | 1025 | """ | 
|  | 1026 |  | 
|  | 1027 | gp.qprintn() | 
| Michael Walsh | f75d435 | 2019-12-05 17:01:20 -0600 | [diff] [blame] | 1028 | gp.qprint_executing() | 
|  | 1029 |  | 
|  | 1030 | if ga.psutil_imported: | 
|  | 1031 | ga.terminate_descendants() | 
|  | 1032 |  | 
| Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 1033 | cmd_buf = ["Print Error", | 
|  | 1034 | "A keyword timeout occurred ending this program.\n"] | 
|  | 1035 | BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf) | 
|  | 1036 |  | 
| Michael Walsh | c108e42 | 2019-03-28 12:27:18 -0500 | [diff] [blame] | 1037 | gp.qprint_pgm_footer() | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 1038 |  | 
| Michael Walsh | c911681 | 2017-03-10 14:23:06 -0600 | [diff] [blame] | 1039 |  | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 1040 | def post_stack(): | 
|  | 1041 | r""" | 
|  | 1042 | Process post_stack plug-in programs. | 
|  | 1043 | """ | 
|  | 1044 |  | 
|  | 1045 | if not call_post_stack_plug: | 
|  | 1046 | # The caller does not wish to have post_stack plug-in processing done. | 
|  | 1047 | return | 
|  | 1048 |  | 
|  | 1049 | global boot_success | 
|  | 1050 |  | 
|  | 1051 | # NOTE: A post_stack call-point failure is NOT counted as a boot failure. | 
|  | 1052 | pre_boot_plug_in_setup() | 
|  | 1053 | # For the purposes of the following plug-ins, mark the "boot" as a success. | 
|  | 1054 | boot_success = 1 | 
|  | 1055 | plug_in_setup() | 
| Michael Walsh | 815b1d5 | 2018-10-30 13:32:26 -0500 | [diff] [blame] | 1056 | rc, shell_rc, failed_plug_in_name, history =\ | 
|  | 1057 | grpi.rprocess_plug_in_packages(call_point='post_stack', | 
|  | 1058 | stop_on_plug_in_failure=0, | 
|  | 1059 | return_history=True) | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 1060 | for doing_msg in history: | 
|  | 1061 | update_boot_history(boot_history, doing_msg, max_boot_history) | 
| Michael Walsh | 815b1d5 | 2018-10-30 13:32:26 -0500 | [diff] [blame] | 1062 | if rc != 0: | 
|  | 1063 | boot_success = 0 | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 1064 |  | 
|  | 1065 | plug_in_setup() | 
| Michael Walsh | 815b1d5 | 2018-10-30 13:32:26 -0500 | [diff] [blame] | 1066 | rc, shell_rc, failed_plug_in_name =\ | 
|  | 1067 | grpi.rprocess_plug_in_packages(call_point='ffdc_check', | 
|  | 1068 | shell_rc=dump_ffdc_rc(), | 
|  | 1069 | stop_on_plug_in_failure=1, | 
|  | 1070 | stop_on_non_zero_rc=1) | 
|  | 1071 | if shell_rc == dump_ffdc_rc(): | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 1072 | status, ret_values = grk.run_key_u("my_ffdc", ignore=1) | 
|  | 1073 | if status != 'PASS': | 
|  | 1074 | gp.qprint_error("Call to my_ffdc failed.\n") | 
| Michael Walsh | c9bd2e8 | 2019-04-18 11:06:52 -0500 | [diff] [blame] | 1075 | # Leave a record for caller that "soft" errors occurred. | 
|  | 1076 | soft_errors = 1 | 
|  | 1077 | gpu.save_plug_in_value(soft_errors, pgm_name) | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 1078 |  | 
|  | 1079 | plug_in_setup() | 
|  | 1080 | rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( | 
|  | 1081 | call_point='stop_check', shell_rc=stop_test_rc(), | 
|  | 1082 | stop_on_non_zero_rc=1) | 
|  | 1083 | if shell_rc == stop_test_rc(): | 
|  | 1084 | message = "Stopping as requested by user.\n" | 
| Michael Walsh | 80dddde | 2019-10-22 13:54:38 -0500 | [diff] [blame] | 1085 | gp.qprint_time(message) | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 1086 | BuiltIn().fail(message) | 
|  | 1087 |  | 
|  | 1088 |  | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1089 | def obmc_boot_test_py(loc_boot_stack=None, | 
|  | 1090 | loc_stack_mode=None, | 
|  | 1091 | loc_quiet=None): | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 1092 | r""" | 
|  | 1093 | Do main program processing. | 
|  | 1094 | """ | 
|  | 1095 |  | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1096 | global save_stack | 
|  | 1097 |  | 
| Michael Walsh | f75d435 | 2019-12-05 17:01:20 -0600 | [diff] [blame] | 1098 | ga.set_term_options(term_requests={'pgm_names': ['process_plug_in_packages.py']}) | 
|  | 1099 |  | 
| George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 1100 | gp.dprintn() | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1101 | # Process function parms. | 
|  | 1102 | for parm_name in main_func_parm_list: | 
|  | 1103 | # Get parm's value. | 
| George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 1104 | parm_value = eval("loc_" + parm_name) | 
|  | 1105 | gp.dpvars(parm_name, parm_value) | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1106 |  | 
| George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 1107 | if parm_value is not None: | 
| Michael Walsh | ff34000 | 2017-08-29 11:18:27 -0500 | [diff] [blame] | 1108 | # Save the global value on a stack. | 
|  | 1109 | cmd_buf = "save_stack.push(BuiltIn().get_variable_value(\"${" +\ | 
|  | 1110 | parm_name + "}\"), \"" + parm_name + "\")" | 
|  | 1111 | gp.dpissuing(cmd_buf) | 
|  | 1112 | exec(cmd_buf) | 
|  | 1113 |  | 
|  | 1114 | # Set the global value to the passed value. | 
|  | 1115 | cmd_buf = "BuiltIn().set_global_variable(\"${" + parm_name +\ | 
|  | 1116 | "}\", loc_" + parm_name + ")" | 
|  | 1117 | gp.dpissuing(cmd_buf) | 
|  | 1118 | exec(cmd_buf) | 
|  | 1119 |  | 
|  | 1120 | gp.dprintn(save_stack.sprint_obj()) | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 1121 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 1122 | setup() | 
|  | 1123 |  | 
| Michael Walsh | cd9fbfd | 2017-09-19 12:00:08 -0500 | [diff] [blame] | 1124 | init_boot_pass, init_boot_fail = boot_results.return_total_pass_fail() | 
|  | 1125 |  | 
| Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 1126 | if ffdc_only: | 
|  | 1127 | gp.qprint_timen("Caller requested ffdc_only.") | 
| Michael Walsh | 986d8ae | 2019-07-17 10:02:23 -0500 | [diff] [blame] | 1128 | if do_pre_boot_plug_in_setup: | 
|  | 1129 | pre_boot_plug_in_setup() | 
| Michael Walsh | 83f4bc7 | 2017-04-20 16:49:43 -0500 | [diff] [blame] | 1130 | grk.run_key_u("my_ffdc") | 
| Michael Walsh | 764d2f8 | 2017-04-27 16:01:08 -0500 | [diff] [blame] | 1131 | return | 
| Michael Walsh | a20da40 | 2017-03-31 16:27:45 -0500 | [diff] [blame] | 1132 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 1133 | # Process caller's boot_stack. | 
|  | 1134 | while (len(boot_stack) > 0): | 
|  | 1135 | test_loop_body() | 
|  | 1136 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 1137 | gp.qprint_timen("Finished processing stack.") | 
| Michael Walsh | 30dadae | 2017-02-27 14:25:52 -0600 | [diff] [blame] | 1138 |  | 
| Michael Walsh | 89de14a | 2018-10-01 16:51:37 -0500 | [diff] [blame] | 1139 | post_stack() | 
|  | 1140 |  | 
| Michael Walsh | 6741f74 | 2017-02-20 16:16:38 -0600 | [diff] [blame] | 1141 | # Process caller's boot_list. | 
|  | 1142 | if len(boot_list) > 0: | 
|  | 1143 | for ix in range(1, max_num_tests + 1): | 
|  | 1144 | test_loop_body() | 
|  | 1145 |  | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 1146 | gp.qprint_timen("Completed all requested boot tests.") | 
|  | 1147 |  | 
|  | 1148 | boot_pass, boot_fail = boot_results.return_total_pass_fail() | 
| Michael Walsh | cd9fbfd | 2017-09-19 12:00:08 -0500 | [diff] [blame] | 1149 | new_fail = boot_fail - init_boot_fail | 
|  | 1150 | if new_fail > boot_fail_threshold: | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 1151 | error_message = "Boot failures exceed the boot failure" +\ | 
|  | 1152 | " threshold:\n" +\ | 
| Michael Walsh | cd9fbfd | 2017-09-19 12:00:08 -0500 | [diff] [blame] | 1153 | gp.sprint_var(new_fail) +\ | 
| Michael Walsh | b5839d0 | 2017-04-12 16:11:20 -0500 | [diff] [blame] | 1154 | gp.sprint_var(boot_fail_threshold) | 
|  | 1155 | BuiltIn().fail(gp.sprint_error(error_message)) |