1#!/usr/bin/env python3
2
3from gen_arg import *
4from gen_call_robot import *
5from gen_cmd import *
6from gen_misc import *
7from gen_plug_in_utils import *
8from gen_print import *
9from gen_valid import *
10
11# Set exit_on_error for gen_valid functions.
12set_exit_on_error(True)
13
14parser = argparse.ArgumentParser(
15    usage="%(prog)s [OPTIONS]",
16    description=(
17        "%(prog)s will determine whether FFDC should be collected.  If so, it"
18        " will return "
19    )
20    + repr(dump_ffdc_rc())
21    + ".",
22    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
23    prefix_chars="-+",
24)
25
26# The stock_list will be passed to gen_get_options.  We populate it with the names of stock parm options we
27# want.  These stock parms are pre-defined by gen_get_options.
28stock_list = [
29    ("test_mode", get_plug_default("test_mode", 0)),
30    ("quiet", get_plug_default("quiet", 0)),
31    ("debug", get_plug_default("debug", 0)),
32]
33
34# For now we are hard-coding this value vs adding a soft_errors=boolean entry in the parm_def file.
35FFDC_SOFT_ERRORS = 1
36
37
38def exit_function(signal_number=0, frame=None):
39    r"""
40    Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT).
41
42    This function will be called by gen_exit_function().
43    """
44
45    process_robot_output_files()
46
47
48def validate_parms():
49    r"""
50    Validate program parameters, etc.
51
52    This function will be called by gen_setup().
53    """
54
55    get_plug_vars()
56
57    valid_value(AUTOBOOT_OPENBMC_HOST)
58
59
60def main():
61    gen_setup()
62
63    print_plug_in_header()
64
65    if FFDC_COMMAND.upper() == "FAIL":
66        if AUTOBOOT_BOOT_SUCCESS == "0":
67            print_timen(
68                "The caller wishes to dump FFDC after each boot failure."
69            )
70            exit(dump_ffdc_rc())
71    elif FFDC_COMMAND.upper() == "ALL":
72        print_timen("The caller wishes to dump FFDC after each boot test.")
73        exit(dump_ffdc_rc())
74    elif len(FFDC_COMMAND) > 0:
75        shell_rc, out_buf = shell_cmd(FFDC_COMMAND, quiet=quiet)
76        if shell_rc != 0:
77            print_timen("The caller wishes to dump FFDC.")
78            exit(dump_ffdc_rc())
79    if FFDC_SOFT_ERRORS:
80        # Check the num_error_logs value left by the Soft_errors plug-in.
81        num_error_logs = int(restore_plug_in_value(0, "Soft_errors"))
82        if num_error_logs > 0:
83            print_timen(
84                'The "Soft_errors" plug-in found soft_errors and the'
85                + " caller wishes to dump FFDC on soft errors."
86            )
87            exit(dump_ffdc_rc())
88
89    print_timen("The caller does not wish for any FFDC to be collected.")
90
91
92main()
93