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