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