blob: 8eb8e05db51e0d39d31cf72cc6727a789bc38cdf [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh3ba8ecd2018-04-24 11:33:25 -05002
3r"""
4Check for stop conditions. Return code of 2 if stop conditions are found.
5"""
6
Patrick Williamsa57fef42022-12-03 07:00:14 -06007import argparse
George Keishinge635ddc2022-12-08 07:38:02 -06008import sys
9import subprocess
Michael Sheposb3dffe82022-01-06 07:17:16 -060010import os
Michael Sheposf7129672022-01-13 11:00:37 -060011import re
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050012
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050013from gen_print import *
14from gen_valid import *
George Keishinge635ddc2022-12-08 07:38:02 -060015from gen_arg import *
16from gen_misc import *
17from gen_cmd import *
18from gen_plug_in_utils import *
19from gen_call_robot import *
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050020
Michael Walsh2ea965c2019-08-01 16:14:25 -050021# Set exit_on_error for gen_valid functions.
22set_exit_on_error(True)
23
Michael Walsh71fec432020-04-09 17:25:31 -050024# Initialize default plug-in parms..
25STOP_REST_FAIL = 0
George Keishinge635ddc2022-12-08 07:38:02 -060026STOP_COMMAND = ''
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050027stop_test_rc = 2
Michael Walsh71fec432020-04-09 17:25:31 -050028STOP_VERIFY_HARDWARE_FAIL = 0
29
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050030
31# Create parser object to process command line parameters and args.
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050032parser = argparse.ArgumentParser(
George Keishinge635ddc2022-12-08 07:38:02 -060033 usage='%(prog)s [OPTIONS]',
34 description="If the \"Stop\" plug-in is selected by the user, %(prog)s"
Patrick Williamsa57fef42022-12-03 07:00:14 -060035 + " is called by OBMC Boot Test after each boot test. If %(prog)s returns"
George Keishinge635ddc2022-12-08 07:38:02 -060036 + " " + str(stop_test_rc) + ", then OBMC Boot Test will stop. The user"
Patrick Williamsa57fef42022-12-03 07:00:14 -060037 + " may set environment variable STOP_COMMAND to contain any valid bash"
38 + " command or program. %(prog)s will run this stop command. If the stop"
39 + " command returns non-zero, then %(prog)s will return "
George Keishinge635ddc2022-12-08 07:38:02 -060040 + str(stop_test_rc) + ". %(prog)s recognizes some special values for"
41 + " STOP_COMMAND: 1) \"FAIL\" means that OBMC Boot Test should stop"
42 + " whenever a boot test fails. 2) \"ALL\" means that OBMC Boot Test"
Patrick Williamsa57fef42022-12-03 07:00:14 -060043 + " should stop after any boot test. If environment variable"
44 + " STOP_REST_FAIL is set, OBMC Boot Test will stop if REST commands are"
45 + " no longer working.",
Michael Walsh8d6bf602020-05-05 13:56:50 -050046 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
George Keishinge635ddc2022-12-08 07:38:02 -060047 prefix_chars='-+')
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050048
Michael Walsh410b1782019-10-22 15:56:18 -050049# The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we
50# want. These stock parms are pre-defined by gen_get_options.
George Keishinge635ddc2022-12-08 07:38:02 -060051stock_list = [("test_mode", get_plug_default("test_mode", 0)),
52 ("quiet", get_plug_default("quiet", 0)),
53 ("debug", get_plug_default("debug", 0))]
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050054
55
George Keishinge635ddc2022-12-08 07:38:02 -060056def exit_function(signal_number=0,
57 frame=None):
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050058 r"""
Michael Walsh410b1782019-10-22 15:56:18 -050059 Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT).
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050060
Michael Walsh71fec432020-04-09 17:25:31 -050061 This function will be called by gen_exit_function().
62 """
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050063
Michael Walsha0ce75a2018-07-31 13:54:29 -050064 process_robot_output_files()
65
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050066
67def validate_parms():
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050068 r"""
Michael Walsh71fec432020-04-09 17:25:31 -050069 Validate program parameters, etc.
70
71 This function will be called by gen_setup().
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050072 """
73
74 get_plug_vars()
75
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050076
Michael Walsh2ce1dba2019-02-05 19:29:28 +000077def stop_check():
78 r"""
79 Stop this program with the stop check return code.
80 """
81
82 if MASTER_PID != PROGRAM_PID:
Michael Walshc213d492019-11-20 14:26:05 -060083 save_plug_in_value(stop_check_rc=stop_test_rc)
Michael Walsh2ce1dba2019-02-05 19:29:28 +000084 exit(stop_test_rc)
85
86
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050087def rest_fail():
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050088 r"""
Michael Walsh410b1782019-10-22 15:56:18 -050089 If STOP_REST_FAIL, then this function will determine whether REST commands to the target are working. If
90 not, this function will stop the program by returning stop_test_rc.
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050091 """
92
Michael Walsh71fec432020-04-09 17:25:31 -050093 if not STOP_REST_FAIL:
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050094 return
95
George Keishinge635ddc2022-12-08 07:38:02 -060096 REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \
97 int(os.environ.get('AUTOBOOT_REDFISH_SUPPORT_TRANS_STATE', 0))
Michael Sheposb3dffe82022-01-06 07:17:16 -060098
99 if REDFISH_SUPPORT_TRANS_STATE:
100 interface = "redfish"
101 else:
102 interface = "rest"
103
104 print_timen("Checking to see whether %s commands are working." % interface)
Michael Walsh8ab9aea2018-11-01 16:30:45 -0500105 init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
George Keishinge635ddc2022-12-08 07:38:02 -0600106 lib_file_path = init_robot_file_path("lib/utils.robot") + ":" \
Michael Walsh8ab9aea2018-11-01 16:30:45 -0500107 + init_robot_file_path("lib/gen_robot_print.py")
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500108 set_mod_global(lib_file_path)
George Keishinge635ddc2022-12-08 07:38:02 -0600109 timeout = '0 seconds'
110 interval = '1 second'
111 keyword_string = "${match_state}= Create Dictionary %s=1 ;" % interface +\
112 " ${state}= Wait State ${match_state} " + timeout + " " +\
113 interval + " quiet=${1} ; Rpvar state"
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500114 set_mod_global(keyword_string)
George Keishinge635ddc2022-12-08 07:38:02 -0600115 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT,
116 REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD,
117 REDFISH_SUPPORT_TRANS_STATE, keyword_string, lib_file_path, quiet,
118 test_mode, debug, outputdir, output, log, report, loglevel)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500119 if not robot_cmd_fnc(cmd_buf):
George Keishinge635ddc2022-12-08 07:38:02 -0600120 print_timen("The caller wishes to stop test execution if %s commands are failing." % interface)
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000121 stop_check()
George Keishinge635ddc2022-12-08 07:38:02 -0600122 print_timen("%s commands are working so no reason as of yet to stop the test." % interface)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500123
124
125def esel_stop_check():
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500126 r"""
Michael Walsh410b1782019-10-22 15:56:18 -0500127 Run the esel_stop_check program to determine whether any eSEL entries found warrant stopping the test
128 run. See esel_stop_check help text for details.
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500129 """
130
131 if STOP_ESEL_STOP_FILE_PATH == "":
132 return
133
George Keishinge635ddc2022-12-08 07:38:02 -0600134 cmd_buf = "esel_stop_check --esel_stop_file_path=" + STOP_ESEL_STOP_FILE_PATH
Michael Walsh71fec432020-04-09 17:25:31 -0500135 shell_rc, out_buf = shell_cmd(cmd_buf, show_err=0)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500136 if shell_rc == stop_test_rc:
George Keishinge635ddc2022-12-08 07:38:02 -0600137 print_timen("The caller wishes to stop test execution based on the presence of certain esel entries.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000138 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500139
140
Michael Sheposf7129672022-01-13 11:00:37 -0600141def pel_stop_check():
142 r"""
143 Determine whether any PEL entries found warrant stopping the test
144 run.
145 """
146
147 if STOP_PEL_STOP_FILE_PATH == "":
148 return
149
George Keishinge635ddc2022-12-08 07:38:02 -0600150 pel_txt_file_path = os.environ.get("AUTOBOOT_FFDC_DIR_PATH", "") + \
151 os.environ.get("AUTOBOOT_FFDC_PREFIX", "") + "PEL_logs_list.json"
Michael Sheposf7129672022-01-13 11:00:37 -0600152
153 if not os.path.isfile(pel_txt_file_path):
George Keishinge635ddc2022-12-08 07:38:02 -0600154 qprint_timen("The following file was not present so no further"
155 + " action will be taken.")
Michael Sheposf7129672022-01-13 11:00:37 -0600156 qprint_var(pel_txt_file_path)
157 return
158
159 default_stop_dir_path = "/afs/rchland.ibm.com/projects/esw/dvt/"
160
161 # If pel_stop_file_path is unqualified and cannot be found, pre-pend
162 # default_stop_dir_path for the user.
163 pel_stop_file_path = os.environ.get("STOP_PEL_STOP_FILE_PATH", "")
George Keishinge635ddc2022-12-08 07:38:02 -0600164 if not os.path.isfile(pel_stop_file_path) and \
165 os.path.isfile(default_stop_dir_path + pel_stop_file_path):
Michael Sheposf7129672022-01-13 11:00:37 -0600166 pel_stop_file_path = default_stop_dir_path + pel_stop_file_path
167 qprint_timen("Using default stop file path.")
168 qprint_var(pel_stop_file_path)
169
170 # First, read the file in and convert it to a list.
171 pel_stop_list = file_to_list(pel_stop_file_path, newlines=0, comments=0)
172
173 if len(pel_stop_list) == 0:
George Keishinge635ddc2022-12-08 07:38:02 -0600174 print_timen("There are no records to process in "
175 + pel_stop_file_path + ".")
Michael Sheposf7129672022-01-13 11:00:37 -0600176 return
177
178 pel_all_list = file_to_list(pel_txt_file_path, newlines=0, comments=0)
179
180 if len(pel_all_list) == 0:
George Keishinge635ddc2022-12-08 07:38:02 -0600181 print_timen("There are no records to process in "
182 + pel_txt_file_path + ".")
Michael Sheposf7129672022-01-13 11:00:37 -0600183 return
184
185 for stop_pel in pel_stop_list:
186 for pel_all in pel_all_list:
187 pel_match = re.search(".*SRC.*" + stop_pel + ".*", pel_all)
188 if pel_match:
George Keishinge635ddc2022-12-08 07:38:02 -0600189 print_timen("The caller wishes to stop test execution based on "
190 + "the presence of certain PEL entries.")
Michael Sheposf7129672022-01-13 11:00:37 -0600191 stop_check()
192
193
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500194def main():
George Keishinge635ddc2022-12-08 07:38:02 -0600195
Michael Walsh71fec432020-04-09 17:25:31 -0500196 gen_setup()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500197
Michael Walsh80caea02019-06-21 11:31:41 -0500198 print_plug_in_header()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500199
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500200 if STOP_COMMAND.upper() == "FAIL":
201 if AUTOBOOT_BOOT_SUCCESS == "0":
202 print_timen("The caller wishes to stop after each boot failure.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000203 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500204 elif STOP_COMMAND.upper() == "ALL":
205 print_timen("The caller wishes to stop after each boot test.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000206 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500207 elif len(STOP_COMMAND) > 0:
Michael Walsh71fec432020-04-09 17:25:31 -0500208 shell_rc, out_buf = shell_cmd(STOP_COMMAND, quiet=quiet, show_err=0)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500209 if shell_rc != 0:
210 print_timen("The caller wishes to stop test execution.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000211 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500212
Michael Walsh3c4869a2019-07-17 10:29:31 -0500213 rest_fail()
214
215 esel_stop_check()
216
Michael Sheposf7129672022-01-13 11:00:37 -0600217 pel_stop_check()
218
Michael Walsh71fec432020-04-09 17:25:31 -0500219 if STOP_VERIFY_HARDWARE_FAIL:
George Keishinge635ddc2022-12-08 07:38:02 -0600220 hardware_error_found = restore_plug_in_value(0, 'Verify_hardware')
Michael Walsh71fec432020-04-09 17:25:31 -0500221 if hardware_error_found:
George Keishinge635ddc2022-12-08 07:38:02 -0600222 print_timen("The caller wishes to stop test execution when the Verify_hardware plug-in detects a"
223 + " hardware error.")
Michael Walsh71fec432020-04-09 17:25:31 -0500224 stop_check()
225
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500226 qprint_timen("The caller does not wish to stop the test run.")
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500227
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -0500228
Michael Walsh71fec432020-04-09 17:25:31 -0500229main()