George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
| 4 | Check for stop conditions. Return code of 2 if stop conditions are found. |
| 5 | """ |
| 6 | |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 7 | import argparse |
Michael Shepos | b3dffe8 | 2022-01-06 07:17:16 -0600 | [diff] [blame] | 8 | import os |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 9 | import re |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 10 | import subprocess |
| 11 | import sys |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 12 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 13 | from gen_arg import * |
| 14 | from gen_call_robot import * |
| 15 | from gen_cmd import * |
| 16 | from gen_misc import * |
| 17 | from gen_plug_in_utils import * |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 18 | from gen_print import * |
| 19 | from gen_valid import * |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 20 | |
Michael Walsh | 2ea965c | 2019-08-01 16:14:25 -0500 | [diff] [blame] | 21 | # Set exit_on_error for gen_valid functions. |
| 22 | set_exit_on_error(True) |
| 23 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 24 | # Initialize default plug-in parms.. |
| 25 | STOP_REST_FAIL = 0 |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 26 | STOP_COMMAND = "" |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 27 | stop_test_rc = 2 |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 28 | STOP_VERIFY_HARDWARE_FAIL = 0 |
| 29 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 30 | |
| 31 | # Create parser object to process command line parameters and args. |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 32 | parser = argparse.ArgumentParser( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 33 | usage="%(prog)s [OPTIONS]", |
| 34 | description='If the "Stop" plug-in is selected by the user, %(prog)s' |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 35 | + " is called by OBMC Boot Test after each boot test. If %(prog)s returns" |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 36 | + " " |
| 37 | + str(stop_test_rc) |
| 38 | + ", then OBMC Boot Test will stop. The user" |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 39 | + " may set environment variable STOP_COMMAND to contain any valid bash" |
| 40 | + " command or program. %(prog)s will run this stop command. If the stop" |
| 41 | + " command returns non-zero, then %(prog)s will return " |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 42 | + str(stop_test_rc) |
| 43 | + ". %(prog)s recognizes some special values for" |
| 44 | + ' STOP_COMMAND: 1) "FAIL" means that OBMC Boot Test should stop' |
| 45 | + ' whenever a boot test fails. 2) "ALL" means that OBMC Boot Test' |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 46 | + " should stop after any boot test. If environment variable" |
| 47 | + " STOP_REST_FAIL is set, OBMC Boot Test will stop if REST commands are" |
| 48 | + " no longer working.", |
Michael Walsh | 8d6bf60 | 2020-05-05 13:56:50 -0500 | [diff] [blame] | 49 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 50 | prefix_chars="-+", |
| 51 | ) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 52 | |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 53 | # The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we |
| 54 | # want. These stock parms are pre-defined by gen_get_options. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 55 | stock_list = [ |
| 56 | ("test_mode", get_plug_default("test_mode", 0)), |
| 57 | ("quiet", get_plug_default("quiet", 0)), |
| 58 | ("debug", get_plug_default("debug", 0)), |
| 59 | ] |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 60 | |
| 61 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 62 | def exit_function(signal_number=0, frame=None): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 63 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 64 | Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT). |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 65 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 66 | This function will be called by gen_exit_function(). |
| 67 | """ |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 68 | |
Michael Walsh | a0ce75a | 2018-07-31 13:54:29 -0500 | [diff] [blame] | 69 | process_robot_output_files() |
| 70 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 71 | |
| 72 | def validate_parms(): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 73 | r""" |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 74 | Validate program parameters, etc. |
| 75 | |
| 76 | This function will be called by gen_setup(). |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 77 | """ |
| 78 | |
| 79 | get_plug_vars() |
| 80 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 81 | |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 82 | def stop_check(): |
| 83 | r""" |
| 84 | Stop this program with the stop check return code. |
| 85 | """ |
| 86 | |
| 87 | if MASTER_PID != PROGRAM_PID: |
Michael Walsh | c213d49 | 2019-11-20 14:26:05 -0600 | [diff] [blame] | 88 | save_plug_in_value(stop_check_rc=stop_test_rc) |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 89 | exit(stop_test_rc) |
| 90 | |
| 91 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 92 | def rest_fail(): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 93 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 94 | If STOP_REST_FAIL, then this function will determine whether REST commands to the target are working. If |
| 95 | not, this function will stop the program by returning stop_test_rc. |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 96 | """ |
| 97 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 98 | if not STOP_REST_FAIL: |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 99 | return |
| 100 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 101 | REDFISH_SUPPORT_TRANS_STATE = int( |
| 102 | os.environ.get("REDFISH_SUPPORT_TRANS_STATE", 0) |
| 103 | ) or int(os.environ.get("AUTOBOOT_REDFISH_SUPPORT_TRANS_STATE", 0)) |
Michael Shepos | b3dffe8 | 2022-01-06 07:17:16 -0600 | [diff] [blame] | 104 | |
| 105 | if REDFISH_SUPPORT_TRANS_STATE: |
| 106 | interface = "redfish" |
| 107 | else: |
| 108 | interface = "rest" |
| 109 | |
| 110 | print_timen("Checking to see whether %s commands are working." % interface) |
Michael Walsh | 8ab9aea | 2018-11-01 16:30:45 -0500 | [diff] [blame] | 111 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 112 | lib_file_path = ( |
| 113 | init_robot_file_path("lib/utils.robot") |
| 114 | + ":" |
Michael Walsh | 8ab9aea | 2018-11-01 16:30:45 -0500 | [diff] [blame] | 115 | + init_robot_file_path("lib/gen_robot_print.py") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 116 | ) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 117 | set_mod_global(lib_file_path) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 118 | timeout = "0 seconds" |
| 119 | interval = "1 second" |
| 120 | keyword_string = ( |
| 121 | "${match_state}= Create Dictionary %s=1 ;" % interface |
| 122 | + " ${state}= Wait State ${match_state} " |
| 123 | + timeout |
| 124 | + " " |
| 125 | + interval |
| 126 | + " quiet=${1} ; Rpvar state" |
| 127 | ) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 128 | set_mod_global(keyword_string) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 129 | cmd_buf = create_robot_cmd_string( |
| 130 | "extended/run_keyword.robot", |
| 131 | OPENBMC_HOST, |
| 132 | SSH_PORT, |
| 133 | HTTPS_PORT, |
| 134 | REST_USERNAME, |
| 135 | REST_PASSWORD, |
| 136 | OPENBMC_USERNAME, |
| 137 | OPENBMC_PASSWORD, |
| 138 | REDFISH_SUPPORT_TRANS_STATE, |
| 139 | keyword_string, |
| 140 | lib_file_path, |
| 141 | quiet, |
| 142 | test_mode, |
| 143 | debug, |
| 144 | outputdir, |
| 145 | output, |
| 146 | log, |
| 147 | report, |
| 148 | loglevel, |
| 149 | ) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 150 | if not robot_cmd_fnc(cmd_buf): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 151 | print_timen( |
| 152 | "The caller wishes to stop test execution if %s commands are" |
| 153 | " failing." % interface |
| 154 | ) |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 155 | stop_check() |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 156 | print_timen( |
| 157 | "%s commands are working so no reason as of yet to stop the test." |
| 158 | % interface |
| 159 | ) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 160 | |
| 161 | |
| 162 | def esel_stop_check(): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 163 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 164 | Run the esel_stop_check program to determine whether any eSEL entries found warrant stopping the test |
| 165 | run. See esel_stop_check help text for details. |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 166 | """ |
| 167 | |
| 168 | if STOP_ESEL_STOP_FILE_PATH == "": |
| 169 | return |
| 170 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 171 | cmd_buf = ( |
| 172 | "esel_stop_check --esel_stop_file_path=" + STOP_ESEL_STOP_FILE_PATH |
| 173 | ) |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 174 | shell_rc, out_buf = shell_cmd(cmd_buf, show_err=0) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 175 | if shell_rc == stop_test_rc: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 176 | print_timen( |
| 177 | "The caller wishes to stop test execution based on the presence of" |
| 178 | " certain esel entries." |
| 179 | ) |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 180 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 181 | |
| 182 | |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 183 | def pel_stop_check(): |
| 184 | r""" |
| 185 | Determine whether any PEL entries found warrant stopping the test |
| 186 | run. |
| 187 | """ |
| 188 | |
| 189 | if STOP_PEL_STOP_FILE_PATH == "": |
| 190 | return |
| 191 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 192 | pel_txt_file_path = ( |
| 193 | os.environ.get("AUTOBOOT_FFDC_DIR_PATH", "") |
| 194 | + os.environ.get("AUTOBOOT_FFDC_PREFIX", "") |
| 195 | + "PEL_logs_list.json" |
| 196 | ) |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 197 | |
| 198 | if not os.path.isfile(pel_txt_file_path): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 199 | qprint_timen( |
| 200 | "The following file was not present so no further" |
| 201 | + " action will be taken." |
| 202 | ) |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 203 | qprint_var(pel_txt_file_path) |
| 204 | return |
| 205 | |
| 206 | default_stop_dir_path = "/afs/rchland.ibm.com/projects/esw/dvt/" |
| 207 | |
| 208 | # If pel_stop_file_path is unqualified and cannot be found, pre-pend |
| 209 | # default_stop_dir_path for the user. |
| 210 | pel_stop_file_path = os.environ.get("STOP_PEL_STOP_FILE_PATH", "") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 211 | if not os.path.isfile(pel_stop_file_path) and os.path.isfile( |
| 212 | default_stop_dir_path + pel_stop_file_path |
| 213 | ): |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 214 | pel_stop_file_path = default_stop_dir_path + pel_stop_file_path |
| 215 | qprint_timen("Using default stop file path.") |
| 216 | qprint_var(pel_stop_file_path) |
| 217 | |
| 218 | # First, read the file in and convert it to a list. |
| 219 | pel_stop_list = file_to_list(pel_stop_file_path, newlines=0, comments=0) |
| 220 | |
| 221 | if len(pel_stop_list) == 0: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 222 | print_timen( |
| 223 | "There are no records to process in " + pel_stop_file_path + "." |
| 224 | ) |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 225 | return |
| 226 | |
| 227 | pel_all_list = file_to_list(pel_txt_file_path, newlines=0, comments=0) |
| 228 | |
| 229 | if len(pel_all_list) == 0: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 230 | print_timen( |
| 231 | "There are no records to process in " + pel_txt_file_path + "." |
| 232 | ) |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 233 | return |
| 234 | |
| 235 | for stop_pel in pel_stop_list: |
| 236 | for pel_all in pel_all_list: |
| 237 | pel_match = re.search(".*SRC.*" + stop_pel + ".*", pel_all) |
| 238 | if pel_match: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 239 | print_timen( |
| 240 | "The caller wishes to stop test execution based on " |
| 241 | + "the presence of certain PEL entries." |
| 242 | ) |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 243 | stop_check() |
| 244 | |
| 245 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 246 | def main(): |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 247 | gen_setup() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 248 | |
Michael Walsh | 80caea0 | 2019-06-21 11:31:41 -0500 | [diff] [blame] | 249 | print_plug_in_header() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 250 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 251 | if STOP_COMMAND.upper() == "FAIL": |
| 252 | if AUTOBOOT_BOOT_SUCCESS == "0": |
| 253 | print_timen("The caller wishes to stop after each boot failure.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 254 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 255 | elif STOP_COMMAND.upper() == "ALL": |
| 256 | print_timen("The caller wishes to stop after each boot test.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 257 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 258 | elif len(STOP_COMMAND) > 0: |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 259 | shell_rc, out_buf = shell_cmd(STOP_COMMAND, quiet=quiet, show_err=0) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 260 | if shell_rc != 0: |
| 261 | print_timen("The caller wishes to stop test execution.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 262 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 263 | |
Michael Walsh | 3c4869a | 2019-07-17 10:29:31 -0500 | [diff] [blame] | 264 | rest_fail() |
| 265 | |
| 266 | esel_stop_check() |
| 267 | |
Michael Shepos | f712967 | 2022-01-13 11:00:37 -0600 | [diff] [blame] | 268 | pel_stop_check() |
| 269 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 270 | if STOP_VERIFY_HARDWARE_FAIL: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 271 | hardware_error_found = restore_plug_in_value(0, "Verify_hardware") |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 272 | if hardware_error_found: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 273 | print_timen( |
| 274 | "The caller wishes to stop test execution when the" |
| 275 | " Verify_hardware plug-in detects a" |
| 276 | + " hardware error." |
| 277 | ) |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 278 | stop_check() |
| 279 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 280 | qprint_timen("The caller does not wish to stop the test run.") |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 281 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 282 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 283 | main() |