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