New Auto_reboot plug-in

Plug-in to set auto reboot value for obmc boot testing according to user's
wishes.

Change-Id: I3250141ec32ed0d529ba44f980221c86bc8d67dd
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/bin/plug_ins/Auto_reboot/cp_cleanup b/bin/plug_ins/Auto_reboot/cp_cleanup
new file mode 120000
index 0000000..2cb0b31
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/cp_cleanup
@@ -0,0 +1 @@
+cp_master
\ No newline at end of file
diff --git a/bin/plug_ins/Auto_reboot/cp_master b/bin/plug_ins/Auto_reboot/cp_master
new file mode 100755
index 0000000..3ce7ee6
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/cp_master
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+
+r"""
+Set the auto_boot policy according to the caller's wishes.
+"""
+
+import os
+import sys
+
+save_path_0 = sys.path[0]
+del sys.path[0]
+
+from gen_print import *
+from gen_valid import *
+from gen_arg import *
+from gen_misc import *
+from gen_cmd import *
+from gen_plug_in_utils import *
+from gen_call_robot import *
+
+# Restore sys.path[0].
+sys.path.insert(0, save_path_0)
+
+# Set exit_on_error for gen_valid functions.
+set_exit_on_error(True)
+
+parser = argparse.ArgumentParser(
+    usage='%(prog)s [OPTIONS]',
+    description="%(prog)s will set the auto_boot policy according to the"
+        + " user's wishes.",
+    formatter_class=argparse.RawTextHelpFormatter,
+    prefix_chars='-+')
+
+
+# Populate stock_list with options we want.
+stock_list = [("test_mode", get_plug_default("test_mode", 0)),
+              ("quiet", get_plug_default("quiet", 0)),
+              ("debug", get_plug_default("debug", 0))]
+
+AUTO_REBOOT_DISABLE = "1"
+
+def exit_function(signal_number=0,
+                  frame=None):
+    r"""
+    Execute whenever the program ends normally or with the signals that we
+    catch (i.e. TERM, INT).
+    """
+
+    dprint_executing()
+    dprint_var(signal_number)
+
+    # Your cleanup code here.
+
+    qprint_pgm_footer()
+
+
+def signal_handler(signal_number,
+                   frame):
+    r"""
+    Handle signals.  Without a function to catch a SIGTERM or SIGINT, our
+    program would terminate immediately with return code 143 and without
+    calling our exit_function.
+    """
+
+    # Our convention is to set up exit_function with atexit.register() so
+    # there is no need to explicitly call exit_function from here.
+
+    dprint_executing()
+
+    # Calling exit prevents us from returning to the code that was running
+    # when we received the signal.
+    exit(0)
+
+
+def validate_parms():
+
+    r"""
+    Validate program parameters, etc.  Return True or False (i.e. pass/fail)
+    accordingly.
+    """
+
+    get_plug_vars()
+
+    valid_value(AUTOBOOT_OPENBMC_HOST, ["", None])
+    global AUTO_REBOOT_DISABLE
+    if pgm_name == "cp_cleanup":
+        AUTO_REBOOT_DISABLE = 0
+    else:
+        valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"])
+        AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE)
+
+    gen_post_validation(exit_function, signal_handler)
+
+
+def main():
+
+    gen_get_options(parser, stock_list)
+
+    validate_parms()
+
+    qprint_pgm_header()
+
+    dprint_plug_vars()
+
+    init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
+
+    lib_file_path = init_robot_file_path("lib/utils.robot")
+
+    keyword_string = "Set Auto Reboot  ${%i}" % AUTO_REBOOT_DISABLE
+
+    cmd_buf = create_robot_cmd_string("extended/run_keyword.robot",
+                                      OPENBMC_HOST, keyword_string,
+                                      lib_file_path, quiet, test_mode, debug,
+                                      outputdir, output, log, report)
+    if not robot_cmd_fnc(cmd_buf):
+        print_error_report("Robot command execution failed.")
+        exit(1)
+
+
+main()
diff --git a/bin/plug_ins/Auto_reboot/cp_post_reboot b/bin/plug_ins/Auto_reboot/cp_post_reboot
new file mode 120000
index 0000000..2cb0b31
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/cp_post_reboot
@@ -0,0 +1 @@
+cp_master
\ No newline at end of file
diff --git a/bin/plug_ins/Auto_reboot/cp_pre_boot b/bin/plug_ins/Auto_reboot/cp_pre_boot
new file mode 120000
index 0000000..2cb0b31
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/cp_pre_boot
@@ -0,0 +1 @@
+cp_master
\ No newline at end of file
diff --git a/bin/plug_ins/Auto_reboot/cp_setup b/bin/plug_ins/Auto_reboot/cp_setup
new file mode 120000
index 0000000..2cb0b31
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/cp_setup
@@ -0,0 +1 @@
+cp_master
\ No newline at end of file
diff --git a/bin/plug_ins/Auto_reboot/integrated b/bin/plug_ins/Auto_reboot/integrated
new file mode 100755
index 0000000..050dfc4
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/integrated
@@ -0,0 +1,2 @@
+# The presence of this file tells our software that this plug-in is
+# integrated.  In other words, the user can't choose to unselect it.
diff --git a/bin/plug_ins/Auto_reboot/parm_def b/bin/plug_ins/Auto_reboot/parm_def
new file mode 100755
index 0000000..748be18
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/parm_def
@@ -0,0 +1,2 @@
+# Indicates whether auto_boot should be disabled.
+disable=boolean
diff --git a/bin/plug_ins/Auto_reboot/supports_obmc b/bin/plug_ins/Auto_reboot/supports_obmc
new file mode 100755
index 0000000..ffa0963
--- /dev/null
+++ b/bin/plug_ins/Auto_reboot/supports_obmc
@@ -0,0 +1,2 @@
+# The presence of this file tells programs like validate_plug_ins.py that
+# this plug-in supports OBMC.