blob: e3ef1cb6e62ac4e3a1750e7121366a28ecd577aa [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
7import sys
8import subprocess
9
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050010from gen_print import *
11from gen_valid import *
12from gen_arg import *
13from gen_misc import *
14from gen_cmd import *
15from gen_plug_in_utils import *
16from gen_call_robot import *
17
Michael Walsh2ea965c2019-08-01 16:14:25 -050018# Set exit_on_error for gen_valid functions.
19set_exit_on_error(True)
20
Michael Walsh71fec432020-04-09 17:25:31 -050021# Initialize default plug-in parms..
22STOP_REST_FAIL = 0
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050023STOP_COMMAND = ''
24stop_test_rc = 2
Michael Walsh71fec432020-04-09 17:25:31 -050025STOP_VERIFY_HARDWARE_FAIL = 0
26
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050027
28# Create parser object to process command line parameters and args.
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050029parser = argparse.ArgumentParser(
30 usage='%(prog)s [OPTIONS]',
31 description="If the \"Stop\" plug-in is selected by the user, %(prog)s" +
32 " is called by OBMC Boot Test after each boot test. If %(prog)s returns" +
33 " " + str(stop_test_rc) + ", then OBMC Boot Test will stop. The user" +
34 " may set environment variable STOP_COMMAND to contain any valid bash" +
35 " command or program. %(prog)s will run this stop command. If the stop" +
36 " command returns non-zero, then %(prog)s will return " +
37 str(stop_test_rc) + ". %(prog)s recognizes some special values for" +
38 " STOP_COMMAND: 1) \"FAIL\" means that OBMC Boot Test should stop" +
39 " whenever a boot test fails. 2) \"ALL\" means that OBMC Boot Test" +
40 " should stop after any boot test. If environment variable" +
41 " STOP_REST_FAIL is set, OBMC Boot Test will stop if REST commands are" +
42 " no longer working.",
Michael Walsh8d6bf602020-05-05 13:56:50 -050043 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050044 prefix_chars='-+')
45
Michael Walsh410b1782019-10-22 15:56:18 -050046# The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we
47# want. These stock parms are pre-defined by gen_get_options.
Michael Walsh1ea9b7a2020-04-02 13:39:25 -050048stock_list = [("test_mode", get_plug_default("test_mode", 0)),
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050049 ("quiet", get_plug_default("quiet", 0)),
50 ("debug", get_plug_default("debug", 0))]
51
52
53def exit_function(signal_number=0,
54 frame=None):
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050055 r"""
Michael Walsh410b1782019-10-22 15:56:18 -050056 Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT).
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050057
Michael Walsh71fec432020-04-09 17:25:31 -050058 This function will be called by gen_exit_function().
59 """
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050060
Michael Walsha0ce75a2018-07-31 13:54:29 -050061 process_robot_output_files()
62
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050063
64def validate_parms():
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050065 r"""
Michael Walsh71fec432020-04-09 17:25:31 -050066 Validate program parameters, etc.
67
68 This function will be called by gen_setup().
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050069 """
70
71 get_plug_vars()
72
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050073
Michael Walsh2ce1dba2019-02-05 19:29:28 +000074def stop_check():
75 r"""
76 Stop this program with the stop check return code.
77 """
78
79 if MASTER_PID != PROGRAM_PID:
Michael Walshc213d492019-11-20 14:26:05 -060080 save_plug_in_value(stop_check_rc=stop_test_rc)
Michael Walsh2ce1dba2019-02-05 19:29:28 +000081 exit(stop_test_rc)
82
83
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050084def rest_fail():
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050085 r"""
Michael Walsh410b1782019-10-22 15:56:18 -050086 If STOP_REST_FAIL, then this function will determine whether REST commands to the target are working. If
87 not, this function will stop the program by returning stop_test_rc.
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050088 """
89
Michael Walsh71fec432020-04-09 17:25:31 -050090 if not STOP_REST_FAIL:
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050091 return
92
93 print_timen("Checking to see whether REST commands are working.")
Michael Walsh8ab9aea2018-11-01 16:30:45 -050094 init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
Michael Walsh71fec432020-04-09 17:25:31 -050095 lib_file_path = init_robot_file_path("lib/state.py") + ":" \
Michael Walsh8ab9aea2018-11-01 16:30:45 -050096 + init_robot_file_path("lib/gen_robot_print.py")
Michael Walsh3ba8ecd2018-04-24 11:33:25 -050097 set_mod_global(lib_file_path)
98 timeout = '0 seconds'
99 interval = '1 second'
100 keyword_string = "${match_state}= Create Dictionary rest=1 ;" +\
101 " ${state}= Wait State ${match_state} " + timeout + " " +\
102 interval + " quiet=${1} ; Rpvar state"
103 set_mod_global(keyword_string)
104
Michael Walsh046fe222019-11-08 14:33:53 -0600105 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT,
Michael Sheposa7d66142021-01-11 11:19:51 -0600106 REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD,
107 keyword_string, lib_file_path, quiet,
Michael Walsh046fe222019-11-08 14:33:53 -0600108 test_mode, debug, outputdir, output, log, report, loglevel)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500109 if not robot_cmd_fnc(cmd_buf):
Michael Walsh71fec432020-04-09 17:25:31 -0500110 print_timen("The caller wishes to stop test execution if REST commands are failing.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000111 stop_check()
Michael Walsh71fec432020-04-09 17:25:31 -0500112 print_timen("REST commands are working so no reason as of yet to stop the test.")
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500113
114
115def esel_stop_check():
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500116 r"""
Michael Walsh410b1782019-10-22 15:56:18 -0500117 Run the esel_stop_check program to determine whether any eSEL entries found warrant stopping the test
118 run. See esel_stop_check help text for details.
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500119 """
120
121 if STOP_ESEL_STOP_FILE_PATH == "":
122 return
123
Michael Walsh71fec432020-04-09 17:25:31 -0500124 cmd_buf = "esel_stop_check --esel_stop_file_path=" + STOP_ESEL_STOP_FILE_PATH
125 shell_rc, out_buf = shell_cmd(cmd_buf, show_err=0)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500126 if shell_rc == stop_test_rc:
Michael Walsh71fec432020-04-09 17:25:31 -0500127 print_timen("The caller wishes to stop test execution based on the presence of certain esel entries.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000128 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500129
130
131def main():
132
Michael Walsh71fec432020-04-09 17:25:31 -0500133 gen_setup()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500134
Michael Walsh80caea02019-06-21 11:31:41 -0500135 print_plug_in_header()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500136
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500137 if STOP_COMMAND.upper() == "FAIL":
138 if AUTOBOOT_BOOT_SUCCESS == "0":
139 print_timen("The caller wishes to stop after each boot failure.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000140 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500141 elif STOP_COMMAND.upper() == "ALL":
142 print_timen("The caller wishes to stop after each boot test.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000143 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500144 elif len(STOP_COMMAND) > 0:
Michael Walsh71fec432020-04-09 17:25:31 -0500145 shell_rc, out_buf = shell_cmd(STOP_COMMAND, quiet=quiet, show_err=0)
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500146 if shell_rc != 0:
147 print_timen("The caller wishes to stop test execution.")
Michael Walsh2ce1dba2019-02-05 19:29:28 +0000148 stop_check()
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500149
Michael Walsh3c4869a2019-07-17 10:29:31 -0500150 rest_fail()
151
152 esel_stop_check()
153
Michael Walsh71fec432020-04-09 17:25:31 -0500154 if STOP_VERIFY_HARDWARE_FAIL:
155 hardware_error_found = restore_plug_in_value(0, 'Verify_hardware')
156 if hardware_error_found:
157 print_timen("The caller wishes to stop test execution when the Verify_hardware plug-in detects a"
158 + " hardware error.")
159 stop_check()
160
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500161 qprint_timen("The caller does not wish to stop the test run.")
Michael Walsh3ba8ecd2018-04-24 11:33:25 -0500162
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -0500163
Michael Walsh71fec432020-04-09 17:25:31 -0500164main()