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