xref: /openbmc/openbmc-test-automation/bin/plug_ins/Stop/cp_stop_check (revision 8d6bf60fec1ad9687ad4835dd8c0056f53684a29)
13ba8ecdcSMichael Walsh#!/usr/bin/env python
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
93ba8ecdcSMichael Walsh
103ba8ecdcSMichael Walshfrom gen_print import *
113ba8ecdcSMichael Walshfrom gen_valid import *
123ba8ecdcSMichael Walshfrom gen_arg import *
133ba8ecdcSMichael Walshfrom gen_misc import *
143ba8ecdcSMichael Walshfrom gen_cmd import *
153ba8ecdcSMichael Walshfrom gen_plug_in_utils import *
163ba8ecdcSMichael Walshfrom gen_call_robot import *
173ba8ecdcSMichael Walsh
182ea965ceSMichael Walsh# Set exit_on_error for gen_valid functions.
192ea965ceSMichael Walshset_exit_on_error(True)
202ea965ceSMichael Walsh
2171fec43fSMichael Walsh# Initialize default plug-in parms..
2271fec43fSMichael WalshSTOP_REST_FAIL = 0
233ba8ecdcSMichael WalshSTOP_COMMAND = ''
243ba8ecdcSMichael Walshstop_test_rc = 2
2571fec43fSMichael WalshSTOP_VERIFY_HARDWARE_FAIL = 0
2671fec43fSMichael Walsh
273ba8ecdcSMichael Walsh
283ba8ecdcSMichael Walsh# Create parser object to process command line parameters and args.
293ba8ecdcSMichael Walshparser = argparse.ArgumentParser(
303ba8ecdcSMichael Walsh    usage='%(prog)s [OPTIONS]',
313ba8ecdcSMichael Walsh    description="If the \"Stop\" plug-in is selected by the user, %(prog)s" +
323ba8ecdcSMichael Walsh    " is called by OBMC Boot Test after each boot test.  If %(prog)s returns" +
333ba8ecdcSMichael Walsh    " " + str(stop_test_rc) + ", then OBMC Boot Test will stop.  The user" +
343ba8ecdcSMichael Walsh    " may set environment variable STOP_COMMAND to contain any valid bash" +
353ba8ecdcSMichael Walsh    " command or program.  %(prog)s will run this stop command.  If the stop" +
363ba8ecdcSMichael Walsh    " command returns non-zero, then %(prog)s will return " +
373ba8ecdcSMichael Walsh    str(stop_test_rc) + ".  %(prog)s recognizes some special values for" +
383ba8ecdcSMichael Walsh    " STOP_COMMAND: 1) \"FAIL\" means that OBMC Boot Test should stop" +
393ba8ecdcSMichael Walsh    " whenever a boot test fails. 2) \"ALL\" means that OBMC Boot Test" +
403ba8ecdcSMichael Walsh    " should stop after any boot test.  If environment variable" +
413ba8ecdcSMichael Walsh    " STOP_REST_FAIL is set, OBMC Boot Test will stop if REST commands are" +
423ba8ecdcSMichael Walsh    " no longer working.",
43*8d6bf60fSMichael Walsh    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
443ba8ecdcSMichael Walsh    prefix_chars='-+')
453ba8ecdcSMichael Walsh
46410b1787SMichael Walsh# The stock_list will be passed to gen_get_options.  We populate it with the names of stock parm options we
47410b1787SMichael Walsh# want.  These stock parms are pre-defined by gen_get_options.
481ea9b7a6SMichael Walshstock_list = [("test_mode", get_plug_default("test_mode", 0)),
493ba8ecdcSMichael Walsh              ("quiet", get_plug_default("quiet", 0)),
503ba8ecdcSMichael Walsh              ("debug", get_plug_default("debug", 0))]
513ba8ecdcSMichael Walsh
523ba8ecdcSMichael Walsh
533ba8ecdcSMichael Walshdef exit_function(signal_number=0,
543ba8ecdcSMichael Walsh                  frame=None):
553ba8ecdcSMichael Walsh    r"""
56410b1787SMichael Walsh    Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT).
573ba8ecdcSMichael Walsh
5871fec43fSMichael Walsh    This function will be called by gen_exit_function().
5971fec43fSMichael Walsh    """
603ba8ecdcSMichael Walsh
61a0ce75a7SMichael Walsh    process_robot_output_files()
62a0ce75a7SMichael Walsh
633ba8ecdcSMichael Walsh
643ba8ecdcSMichael Walshdef validate_parms():
653ba8ecdcSMichael Walsh    r"""
6671fec43fSMichael Walsh    Validate program parameters, etc.
6771fec43fSMichael Walsh
6871fec43fSMichael Walsh    This function will be called by gen_setup().
693ba8ecdcSMichael Walsh    """
703ba8ecdcSMichael Walsh
713ba8ecdcSMichael Walsh    get_plug_vars()
723ba8ecdcSMichael Walsh
733ba8ecdcSMichael Walsh
742ce1dbaeSMichael Walshdef stop_check():
752ce1dbaeSMichael Walsh    r"""
762ce1dbaeSMichael Walsh    Stop this program with the stop check return code.
772ce1dbaeSMichael Walsh    """
782ce1dbaeSMichael Walsh
792ce1dbaeSMichael Walsh    if MASTER_PID != PROGRAM_PID:
80c213d499SMichael Walsh        save_plug_in_value(stop_check_rc=stop_test_rc)
812ce1dbaeSMichael Walsh    exit(stop_test_rc)
822ce1dbaeSMichael Walsh
832ce1dbaeSMichael Walsh
843ba8ecdcSMichael Walshdef rest_fail():
853ba8ecdcSMichael Walsh    r"""
86410b1787SMichael Walsh    If STOP_REST_FAIL, then this function will determine whether REST commands to the target are working.  If
87410b1787SMichael Walsh    not, this function will stop the program by returning stop_test_rc.
883ba8ecdcSMichael Walsh    """
893ba8ecdcSMichael Walsh
9071fec43fSMichael Walsh    if not STOP_REST_FAIL:
913ba8ecdcSMichael Walsh        return
923ba8ecdcSMichael Walsh
933ba8ecdcSMichael Walsh    print_timen("Checking to see whether REST commands are working.")
948ab9aea6SMichael Walsh    init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
958ab9aea6SMichael Walsh    lib_file_path = init_robot_file_path("lib/state.py") + ":" \
968ab9aea6SMichael Walsh        + init_robot_file_path("lib/gen_robot_print.py")
973ba8ecdcSMichael Walsh    set_mod_global(lib_file_path)
983ba8ecdcSMichael Walsh    timeout = '0 seconds'
993ba8ecdcSMichael Walsh    interval = '1 second'
1003ba8ecdcSMichael Walsh    keyword_string = "${match_state}=  Create Dictionary  rest=1 ;" +\
1013ba8ecdcSMichael Walsh        " ${state}=  Wait State  ${match_state}  " + timeout + "  " +\
1023ba8ecdcSMichael Walsh        interval + "  quiet=${1} ; Rpvar  state"
1033ba8ecdcSMichael Walsh    set_mod_global(keyword_string)
1043ba8ecdcSMichael Walsh
105046fe223SMichael Walsh    cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT,
106046fe223SMichael Walsh                                      REST_USERNAME, REST_PASSWORD, keyword_string, lib_file_path, quiet,
107046fe223SMichael Walsh                                      test_mode, debug, outputdir, output, log, report, loglevel)
1083ba8ecdcSMichael Walsh    if not robot_cmd_fnc(cmd_buf):
10971fec43fSMichael Walsh        print_timen("The caller wishes to stop test execution if REST commands are failing.")
1102ce1dbaeSMichael Walsh        stop_check()
11171fec43fSMichael Walsh    print_timen("REST commands are working so no reason as of yet to stop the test.")
1123ba8ecdcSMichael Walsh
1133ba8ecdcSMichael Walsh
1143ba8ecdcSMichael Walshdef esel_stop_check():
1153ba8ecdcSMichael Walsh    r"""
116410b1787SMichael Walsh    Run the esel_stop_check program to determine whether any eSEL entries found warrant stopping the test
117410b1787SMichael Walsh    run.  See esel_stop_check help text for details.
1183ba8ecdcSMichael Walsh    """
1193ba8ecdcSMichael Walsh
1203ba8ecdcSMichael Walsh    if STOP_ESEL_STOP_FILE_PATH == "":
1213ba8ecdcSMichael Walsh        return
1223ba8ecdcSMichael Walsh
12371fec43fSMichael Walsh    cmd_buf = "esel_stop_check --esel_stop_file_path=" + STOP_ESEL_STOP_FILE_PATH
12471fec43fSMichael Walsh    shell_rc, out_buf = shell_cmd(cmd_buf, show_err=0)
1253ba8ecdcSMichael Walsh    if shell_rc == stop_test_rc:
12671fec43fSMichael Walsh        print_timen("The caller wishes to stop test execution based on the presence of certain esel entries.")
1272ce1dbaeSMichael Walsh        stop_check()
1283ba8ecdcSMichael Walsh
1293ba8ecdcSMichael Walsh
1303ba8ecdcSMichael Walshdef main():
1313ba8ecdcSMichael Walsh
13271fec43fSMichael Walsh    gen_setup()
1333ba8ecdcSMichael Walsh
13480caea09SMichael Walsh    print_plug_in_header()
1353ba8ecdcSMichael Walsh
1363ba8ecdcSMichael Walsh    if STOP_COMMAND.upper() == "FAIL":
1373ba8ecdcSMichael Walsh        if AUTOBOOT_BOOT_SUCCESS == "0":
1383ba8ecdcSMichael Walsh            print_timen("The caller wishes to stop after each boot failure.")
1392ce1dbaeSMichael Walsh            stop_check()
1403ba8ecdcSMichael Walsh    elif STOP_COMMAND.upper() == "ALL":
1413ba8ecdcSMichael Walsh        print_timen("The caller wishes to stop after each boot test.")
1422ce1dbaeSMichael Walsh        stop_check()
1433ba8ecdcSMichael Walsh    elif len(STOP_COMMAND) > 0:
14471fec43fSMichael Walsh        shell_rc, out_buf = shell_cmd(STOP_COMMAND, quiet=quiet, show_err=0)
1453ba8ecdcSMichael Walsh        if shell_rc != 0:
1463ba8ecdcSMichael Walsh            print_timen("The caller wishes to stop test execution.")
1472ce1dbaeSMichael Walsh            stop_check()
1483ba8ecdcSMichael Walsh
1493c4869a2SMichael Walsh    rest_fail()
1503c4869a2SMichael Walsh
1513c4869a2SMichael Walsh    esel_stop_check()
1523c4869a2SMichael Walsh
15371fec43fSMichael Walsh    if STOP_VERIFY_HARDWARE_FAIL:
15471fec43fSMichael Walsh        hardware_error_found = restore_plug_in_value(0, 'Verify_hardware')
15571fec43fSMichael Walsh        if hardware_error_found:
15671fec43fSMichael Walsh            print_timen("The caller wishes to stop test execution when the Verify_hardware plug-in detects a"
15771fec43fSMichael Walsh                        + " hardware error.")
15871fec43fSMichael Walsh            stop_check()
15971fec43fSMichael Walsh
1603ba8ecdcSMichael Walsh    qprint_timen("The caller does not wish to stop the test run.")
1613ba8ecdcSMichael Walsh
162004ad3c9SJoy Onyerikwu
16371fec43fSMichael Walshmain()
164