Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | Check for stop conditions. Return code of 2 if stop conditions are found. |
| 5 | """ |
| 6 | |
| 7 | import sys |
| 8 | import subprocess |
| 9 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 10 | from gen_print import * |
| 11 | from gen_valid import * |
| 12 | from gen_arg import * |
| 13 | from gen_misc import * |
| 14 | from gen_cmd import * |
| 15 | from gen_plug_in_utils import * |
| 16 | from gen_call_robot import * |
| 17 | |
Michael Walsh | 2ea965c | 2019-08-01 16:14:25 -0500 | [diff] [blame] | 18 | # Set exit_on_error for gen_valid functions. |
| 19 | set_exit_on_error(True) |
| 20 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 21 | # Initialize default plug-in parms.. |
| 22 | STOP_REST_FAIL = 0 |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 23 | STOP_COMMAND = '' |
| 24 | stop_test_rc = 2 |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 25 | STOP_VERIFY_HARDWARE_FAIL = 0 |
| 26 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 27 | |
| 28 | # Create parser object to process command line parameters and args. |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 29 | parser = 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 Walsh | 8d6bf60 | 2020-05-05 13:56:50 -0500 | [diff] [blame] | 43 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 44 | prefix_chars='-+') |
| 45 | |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 46 | # 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 Walsh | 1ea9b7a | 2020-04-02 13:39:25 -0500 | [diff] [blame] | 48 | stock_list = [("test_mode", get_plug_default("test_mode", 0)), |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 49 | ("quiet", get_plug_default("quiet", 0)), |
| 50 | ("debug", get_plug_default("debug", 0))] |
| 51 | |
| 52 | |
| 53 | def exit_function(signal_number=0, |
| 54 | frame=None): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 55 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 56 | 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] | 57 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 58 | This function will be called by gen_exit_function(). |
| 59 | """ |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 60 | |
Michael Walsh | a0ce75a | 2018-07-31 13:54:29 -0500 | [diff] [blame] | 61 | process_robot_output_files() |
| 62 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 63 | |
| 64 | def validate_parms(): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 65 | r""" |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 66 | Validate program parameters, etc. |
| 67 | |
| 68 | This function will be called by gen_setup(). |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 69 | """ |
| 70 | |
| 71 | get_plug_vars() |
| 72 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 73 | |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 74 | def stop_check(): |
| 75 | r""" |
| 76 | Stop this program with the stop check return code. |
| 77 | """ |
| 78 | |
| 79 | if MASTER_PID != PROGRAM_PID: |
Michael Walsh | c213d49 | 2019-11-20 14:26:05 -0600 | [diff] [blame] | 80 | save_plug_in_value(stop_check_rc=stop_test_rc) |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 81 | exit(stop_test_rc) |
| 82 | |
| 83 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 84 | def rest_fail(): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 85 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 86 | 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 Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 88 | """ |
| 89 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 90 | if not STOP_REST_FAIL: |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 91 | return |
| 92 | |
| 93 | print_timen("Checking to see whether REST commands are working.") |
Michael Walsh | 8ab9aea | 2018-11-01 16:30:45 -0500 | [diff] [blame] | 94 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 95 | lib_file_path = init_robot_file_path("lib/state.py") + ":" \ |
Michael Walsh | 8ab9aea | 2018-11-01 16:30:45 -0500 | [diff] [blame] | 96 | + init_robot_file_path("lib/gen_robot_print.py") |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 97 | 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 Walsh | 046fe22 | 2019-11-08 14:33:53 -0600 | [diff] [blame] | 105 | cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, |
| 106 | REST_USERNAME, REST_PASSWORD, keyword_string, lib_file_path, quiet, |
| 107 | test_mode, debug, outputdir, output, log, report, loglevel) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 108 | if not robot_cmd_fnc(cmd_buf): |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 109 | print_timen("The caller wishes to stop test execution if REST commands are failing.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 110 | stop_check() |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 111 | print_timen("REST commands are working so no reason as of yet to stop the test.") |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 112 | |
| 113 | |
| 114 | def esel_stop_check(): |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 115 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 116 | Run the esel_stop_check program to determine whether any eSEL entries found warrant stopping the test |
| 117 | run. See esel_stop_check help text for details. |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 118 | """ |
| 119 | |
| 120 | if STOP_ESEL_STOP_FILE_PATH == "": |
| 121 | return |
| 122 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 123 | cmd_buf = "esel_stop_check --esel_stop_file_path=" + STOP_ESEL_STOP_FILE_PATH |
| 124 | shell_rc, out_buf = shell_cmd(cmd_buf, show_err=0) |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 125 | if shell_rc == stop_test_rc: |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 126 | print_timen("The caller wishes to stop test execution based on the presence of certain esel entries.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 127 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 128 | |
| 129 | |
| 130 | def main(): |
| 131 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 132 | gen_setup() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 133 | |
Michael Walsh | 80caea0 | 2019-06-21 11:31:41 -0500 | [diff] [blame] | 134 | print_plug_in_header() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 135 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 136 | if STOP_COMMAND.upper() == "FAIL": |
| 137 | if AUTOBOOT_BOOT_SUCCESS == "0": |
| 138 | print_timen("The caller wishes to stop after each boot failure.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 139 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 140 | elif STOP_COMMAND.upper() == "ALL": |
| 141 | print_timen("The caller wishes to stop after each boot test.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 142 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 143 | elif len(STOP_COMMAND) > 0: |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 144 | 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] | 145 | if shell_rc != 0: |
| 146 | print_timen("The caller wishes to stop test execution.") |
Michael Walsh | 2ce1dba | 2019-02-05 19:29:28 +0000 | [diff] [blame] | 147 | stop_check() |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 148 | |
Michael Walsh | 3c4869a | 2019-07-17 10:29:31 -0500 | [diff] [blame] | 149 | rest_fail() |
| 150 | |
| 151 | esel_stop_check() |
| 152 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 153 | if STOP_VERIFY_HARDWARE_FAIL: |
| 154 | hardware_error_found = restore_plug_in_value(0, 'Verify_hardware') |
| 155 | if hardware_error_found: |
| 156 | print_timen("The caller wishes to stop test execution when the Verify_hardware plug-in detects a" |
| 157 | + " hardware error.") |
| 158 | stop_check() |
| 159 | |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 160 | qprint_timen("The caller does not wish to stop the test run.") |
Michael Walsh | 3ba8ecd | 2018-04-24 11:33:25 -0500 | [diff] [blame] | 161 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 162 | |
Michael Walsh | 71fec43 | 2020-04-09 17:25:31 -0500 | [diff] [blame] | 163 | main() |