1e7e9171eSGeorge Keishing#!/usr/bin/env python3 23ba8ecdcSMichael Walsh 33ba8ecdcSMichael Walshr""" 43ba8ecdcSMichael WalshCheck for stop conditions. Return code of 2 if stop conditions are found. 53ba8ecdcSMichael Walsh""" 63ba8ecdcSMichael Walsh 73ba8ecdcSMichael Walshimport sys 83ba8ecdcSMichael Walshimport subprocess 9*b3dffe8cSMichael Sheposimport os 103ba8ecdcSMichael Walsh 113ba8ecdcSMichael Walshfrom gen_print import * 123ba8ecdcSMichael Walshfrom gen_valid import * 133ba8ecdcSMichael Walshfrom gen_arg import * 143ba8ecdcSMichael Walshfrom gen_misc import * 153ba8ecdcSMichael Walshfrom gen_cmd import * 163ba8ecdcSMichael Walshfrom gen_plug_in_utils import * 173ba8ecdcSMichael Walshfrom gen_call_robot import * 183ba8ecdcSMichael Walsh 192ea965ceSMichael Walsh# Set exit_on_error for gen_valid functions. 202ea965ceSMichael Walshset_exit_on_error(True) 212ea965ceSMichael Walsh 2271fec43fSMichael Walsh# Initialize default plug-in parms.. 2371fec43fSMichael WalshSTOP_REST_FAIL = 0 243ba8ecdcSMichael WalshSTOP_COMMAND = '' 253ba8ecdcSMichael Walshstop_test_rc = 2 2671fec43fSMichael WalshSTOP_VERIFY_HARDWARE_FAIL = 0 2771fec43fSMichael Walsh 283ba8ecdcSMichael Walsh 293ba8ecdcSMichael Walsh# Create parser object to process command line parameters and args. 303ba8ecdcSMichael Walshparser = argparse.ArgumentParser( 313ba8ecdcSMichael Walsh usage='%(prog)s [OPTIONS]', 323ba8ecdcSMichael Walsh description="If the \"Stop\" plug-in is selected by the user, %(prog)s" + 333ba8ecdcSMichael Walsh " is called by OBMC Boot Test after each boot test. If %(prog)s returns" + 343ba8ecdcSMichael Walsh " " + str(stop_test_rc) + ", then OBMC Boot Test will stop. The user" + 353ba8ecdcSMichael Walsh " may set environment variable STOP_COMMAND to contain any valid bash" + 363ba8ecdcSMichael Walsh " command or program. %(prog)s will run this stop command. If the stop" + 373ba8ecdcSMichael Walsh " command returns non-zero, then %(prog)s will return " + 383ba8ecdcSMichael Walsh str(stop_test_rc) + ". %(prog)s recognizes some special values for" + 393ba8ecdcSMichael Walsh " STOP_COMMAND: 1) \"FAIL\" means that OBMC Boot Test should stop" + 403ba8ecdcSMichael Walsh " whenever a boot test fails. 2) \"ALL\" means that OBMC Boot Test" + 413ba8ecdcSMichael Walsh " should stop after any boot test. If environment variable" + 423ba8ecdcSMichael Walsh " STOP_REST_FAIL is set, OBMC Boot Test will stop if REST commands are" + 433ba8ecdcSMichael Walsh " no longer working.", 448d6bf60fSMichael Walsh formatter_class=argparse.ArgumentDefaultsHelpFormatter, 453ba8ecdcSMichael Walsh prefix_chars='-+') 463ba8ecdcSMichael Walsh 47410b1787SMichael Walsh# The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we 48410b1787SMichael Walsh# want. These stock parms are pre-defined by gen_get_options. 491ea9b7a6SMichael Walshstock_list = [("test_mode", get_plug_default("test_mode", 0)), 503ba8ecdcSMichael Walsh ("quiet", get_plug_default("quiet", 0)), 513ba8ecdcSMichael Walsh ("debug", get_plug_default("debug", 0))] 523ba8ecdcSMichael Walsh 533ba8ecdcSMichael Walsh 543ba8ecdcSMichael Walshdef exit_function(signal_number=0, 553ba8ecdcSMichael Walsh frame=None): 563ba8ecdcSMichael Walsh r""" 57410b1787SMichael Walsh Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT). 583ba8ecdcSMichael Walsh 5971fec43fSMichael Walsh This function will be called by gen_exit_function(). 6071fec43fSMichael Walsh """ 613ba8ecdcSMichael Walsh 62a0ce75a7SMichael Walsh process_robot_output_files() 63a0ce75a7SMichael Walsh 643ba8ecdcSMichael Walsh 653ba8ecdcSMichael Walshdef validate_parms(): 663ba8ecdcSMichael Walsh r""" 6771fec43fSMichael Walsh Validate program parameters, etc. 6871fec43fSMichael Walsh 6971fec43fSMichael Walsh This function will be called by gen_setup(). 703ba8ecdcSMichael Walsh """ 713ba8ecdcSMichael Walsh 723ba8ecdcSMichael Walsh get_plug_vars() 733ba8ecdcSMichael Walsh 743ba8ecdcSMichael Walsh 752ce1dbaeSMichael Walshdef stop_check(): 762ce1dbaeSMichael Walsh r""" 772ce1dbaeSMichael Walsh Stop this program with the stop check return code. 782ce1dbaeSMichael Walsh """ 792ce1dbaeSMichael Walsh 802ce1dbaeSMichael Walsh if MASTER_PID != PROGRAM_PID: 81c213d499SMichael Walsh save_plug_in_value(stop_check_rc=stop_test_rc) 822ce1dbaeSMichael Walsh exit(stop_test_rc) 832ce1dbaeSMichael Walsh 842ce1dbaeSMichael Walsh 853ba8ecdcSMichael Walshdef rest_fail(): 863ba8ecdcSMichael Walsh r""" 87410b1787SMichael Walsh If STOP_REST_FAIL, then this function will determine whether REST commands to the target are working. If 88410b1787SMichael Walsh not, this function will stop the program by returning stop_test_rc. 893ba8ecdcSMichael Walsh """ 903ba8ecdcSMichael Walsh 9171fec43fSMichael Walsh if not STOP_REST_FAIL: 923ba8ecdcSMichael Walsh return 933ba8ecdcSMichael Walsh 94*b3dffe8cSMichael Shepos REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \ 95*b3dffe8cSMichael Shepos int(os.environ.get('AUTOBOOT_REDFISH_SUPPORT_TRANS_STATE', 0)) 96*b3dffe8cSMichael Shepos 97*b3dffe8cSMichael Shepos if REDFISH_SUPPORT_TRANS_STATE: 98*b3dffe8cSMichael Shepos interface = "redfish" 99*b3dffe8cSMichael Shepos else: 100*b3dffe8cSMichael Shepos interface = "rest" 101*b3dffe8cSMichael Shepos 102*b3dffe8cSMichael Shepos print_timen("Checking to see whether %s commands are working." % interface) 1038ab9aea6SMichael Walsh init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") 104*b3dffe8cSMichael Shepos lib_file_path = init_robot_file_path("lib/utils.robot") + ":" \ 1058ab9aea6SMichael Walsh + init_robot_file_path("lib/gen_robot_print.py") 1063ba8ecdcSMichael Walsh set_mod_global(lib_file_path) 1073ba8ecdcSMichael Walsh timeout = '0 seconds' 1083ba8ecdcSMichael Walsh interval = '1 second' 109*b3dffe8cSMichael Shepos keyword_string = "${match_state}= Create Dictionary %s=1 ;" % interface +\ 1103ba8ecdcSMichael Walsh " ${state}= Wait State ${match_state} " + timeout + " " +\ 1113ba8ecdcSMichael Walsh interval + " quiet=${1} ; Rpvar state" 1123ba8ecdcSMichael Walsh set_mod_global(keyword_string) 113046fe223SMichael Walsh cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, 114a7d6614fSMichael Shepos REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD, 115*b3dffe8cSMichael Shepos REDFISH_SUPPORT_TRANS_STATE, keyword_string, lib_file_path, quiet, 116046fe223SMichael Walsh test_mode, debug, outputdir, output, log, report, loglevel) 1173ba8ecdcSMichael Walsh if not robot_cmd_fnc(cmd_buf): 118*b3dffe8cSMichael Shepos print_timen("The caller wishes to stop test execution if %s commands are failing." % interface) 1192ce1dbaeSMichael Walsh stop_check() 120*b3dffe8cSMichael Shepos print_timen("%s commands are working so no reason as of yet to stop the test." % interface) 1213ba8ecdcSMichael Walsh 1223ba8ecdcSMichael Walsh 1233ba8ecdcSMichael Walshdef esel_stop_check(): 1243ba8ecdcSMichael Walsh r""" 125410b1787SMichael Walsh Run the esel_stop_check program to determine whether any eSEL entries found warrant stopping the test 126410b1787SMichael Walsh run. See esel_stop_check help text for details. 1273ba8ecdcSMichael Walsh """ 1283ba8ecdcSMichael Walsh 1293ba8ecdcSMichael Walsh if STOP_ESEL_STOP_FILE_PATH == "": 1303ba8ecdcSMichael Walsh return 1313ba8ecdcSMichael Walsh 13271fec43fSMichael Walsh cmd_buf = "esel_stop_check --esel_stop_file_path=" + STOP_ESEL_STOP_FILE_PATH 13371fec43fSMichael Walsh shell_rc, out_buf = shell_cmd(cmd_buf, show_err=0) 1343ba8ecdcSMichael Walsh if shell_rc == stop_test_rc: 13571fec43fSMichael Walsh print_timen("The caller wishes to stop test execution based on the presence of certain esel entries.") 1362ce1dbaeSMichael Walsh stop_check() 1373ba8ecdcSMichael Walsh 1383ba8ecdcSMichael Walsh 1393ba8ecdcSMichael Walshdef main(): 1403ba8ecdcSMichael Walsh 14171fec43fSMichael Walsh gen_setup() 1423ba8ecdcSMichael Walsh 14380caea09SMichael Walsh print_plug_in_header() 1443ba8ecdcSMichael Walsh 1453ba8ecdcSMichael Walsh if STOP_COMMAND.upper() == "FAIL": 1463ba8ecdcSMichael Walsh if AUTOBOOT_BOOT_SUCCESS == "0": 1473ba8ecdcSMichael Walsh print_timen("The caller wishes to stop after each boot failure.") 1482ce1dbaeSMichael Walsh stop_check() 1493ba8ecdcSMichael Walsh elif STOP_COMMAND.upper() == "ALL": 1503ba8ecdcSMichael Walsh print_timen("The caller wishes to stop after each boot test.") 1512ce1dbaeSMichael Walsh stop_check() 1523ba8ecdcSMichael Walsh elif len(STOP_COMMAND) > 0: 15371fec43fSMichael Walsh shell_rc, out_buf = shell_cmd(STOP_COMMAND, quiet=quiet, show_err=0) 1543ba8ecdcSMichael Walsh if shell_rc != 0: 1553ba8ecdcSMichael Walsh print_timen("The caller wishes to stop test execution.") 1562ce1dbaeSMichael Walsh stop_check() 1573ba8ecdcSMichael Walsh 1583c4869a2SMichael Walsh rest_fail() 1593c4869a2SMichael Walsh 1603c4869a2SMichael Walsh esel_stop_check() 1613c4869a2SMichael Walsh 16271fec43fSMichael Walsh if STOP_VERIFY_HARDWARE_FAIL: 16371fec43fSMichael Walsh hardware_error_found = restore_plug_in_value(0, 'Verify_hardware') 16471fec43fSMichael Walsh if hardware_error_found: 16571fec43fSMichael Walsh print_timen("The caller wishes to stop test execution when the Verify_hardware plug-in detects a" 16671fec43fSMichael Walsh + " hardware error.") 16771fec43fSMichael Walsh stop_check() 16871fec43fSMichael Walsh 1693ba8ecdcSMichael Walsh qprint_timen("The caller does not wish to stop the test run.") 1703ba8ecdcSMichael Walsh 171004ad3c9SJoy Onyerikwu 17271fec43fSMichael Walshmain() 173