Set and save stop_check_rc after each decision to stop test execution

This allows other programs to make decisions based on the activity of
the Stop plug-in.

Change-Id: I8b51edf75fcc310e7b3671ee4bb8ff394deb1c66
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/bin/plug_ins/Stop/cp_stop_check b/bin/plug_ins/Stop/cp_stop_check
index fcbd9c0..11527c9 100755
--- a/bin/plug_ins/Stop/cp_stop_check
+++ b/bin/plug_ins/Stop/cp_stop_check
@@ -103,6 +103,17 @@
     return True
 
 
+def stop_check():
+    r"""
+    Stop this program with the stop check return code.
+    """
+
+    if MASTER_PID != PROGRAM_PID:
+        stop_check_rc = stop_test_rc
+        save_plug_in_value(stop_check_rc)
+    exit(stop_test_rc)
+
+
 def rest_fail():
     r"""
     If STOP_REST_FAIL, then this function will determine whether REST commands
@@ -126,13 +137,14 @@
     set_mod_global(keyword_string)
 
     cmd_buf = create_robot_cmd_string("extended/run_keyword.robot",
-                                      OPENBMC_HOST, keyword_string,
+                                      OPENBMC_HOST, REST_USERNAME,
+                                      REST_PASSWORD, keyword_string,
                                       lib_file_path, quiet, test_mode, debug,
                                       outputdir, output, log, report, loglevel)
     if not robot_cmd_fnc(cmd_buf):
         print_timen("The caller wishes to stop test execution if REST" +
                     " commands are failing.")
-        exit(stop_test_rc)
+        stop_check()
     print_timen("REST commands are working so no reason as of yet to stop" +
                 " the test.")
 
@@ -153,7 +165,7 @@
     if shell_rc == stop_test_rc:
         print_timen("The caller wishes to stop test execution based on the" +
                     " presence of certain esel entries.")
-        exit(stop_test_rc)
+        stop_check()
 
 
 def main():
@@ -178,21 +190,21 @@
     if STOP_COMMAND.upper() == "FAIL":
         if AUTOBOOT_BOOT_SUCCESS == "0":
             print_timen("The caller wishes to stop after each boot failure.")
-            exit(stop_test_rc)
+            stop_check()
     elif STOP_COMMAND.upper() == "ALL":
         print_timen("The caller wishes to stop after each boot test.")
-        exit(stop_test_rc)
+        stop_check()
     elif len(STOP_COMMAND) > 0:
         shell_rc, out_buf = cmd_fnc_u(STOP_COMMAND, quiet=quiet, show_err=0)
         if shell_rc != 0:
             print_timen("The caller wishes to stop test execution.")
-            exit(stop_test_rc)
+            stop_check()
 
     qprint_timen("The caller does not wish to stop the test run.")
     return True
 
-# Main
 
+# Main
 
 if not main():
     exit(1)
diff --git a/lib/gen_misc.py b/lib/gen_misc.py
index ef0710d..0dc0d64 100755
--- a/lib/gen_misc.py
+++ b/lib/gen_misc.py
@@ -592,3 +592,23 @@
     """
 
     return [str(stack_frame[3]) for stack_frame in inspect.stack()]
+
+
+def username():
+    r"""
+    Return the username for the current process.
+    """
+
+    username = os.environ.get("USER", "")
+    if username != "":
+        return username
+    user_num = str(os.geteuid())
+    try:
+        username = os.getlogin()
+    except OSError:
+        if user_num == "0":
+            username = "root"
+        else:
+            username = "?"
+
+    return username
diff --git a/lib/gen_plug_in_utils.py b/lib/gen_plug_in_utils.py
index 769e73e..9af1be3 100755
--- a/lib/gen_plug_in_utils.py
+++ b/lib/gen_plug_in_utils.py
@@ -45,7 +45,7 @@
     Example excerpt of resulting dictionary:
 
     plug_var_dict:
-      [AUTOBOOT_BASE_TOOL_DIR_PATH]:  /fspmount/
+      [AUTOBOOT_BASE_TOOL_DIR_PATH]:  /tmp/
       [AUTOBOOT_BB_LEVEL]:            <blank>
       [AUTOBOOT_BOOT_FAIL]:           0
       ...
@@ -146,7 +146,7 @@
     package_name>_ in upper case letters.).
 
     Example excerpt of output:
-    AUTOBOOT_BASE_TOOL_DIR_PATH=/fspmount/
+    AUTOBOOT_BASE_TOOL_DIR_PATH=/tmp/
     AUTOBOOT_BB_LEVEL=
     AUTOBOOT_BOOT_FAIL=0
     AUTOBOOT_BOOT_FAIL_THRESHOLD=1000000
@@ -385,14 +385,15 @@
 
     BASE_TOOL_DIR_PATH = \
         gm.add_trailing_slash(os.environ.get(PLUG_VAR_PREFIX
-                                             + "BASE_TOOL_DIR_PATH",
-                                             "/fspmount/"))
+                                             + "_BASE_TOOL_DIR_PATH",
+                                             "/tmp/"))
     NICKNAME = os.environ.get("AUTOBOOT_OPENBMC_NICKNAME", "")
     if NICKNAME == "":
         NICKNAME = os.environ["AUTOIPL_FSP1_NICKNAME"]
     MASTER_PID = os.environ[PLUG_VAR_PREFIX + "_MASTER_PID"]
-    return BASE_TOOL_DIR_PATH + os.environ["USER"] + "/" + NICKNAME + "/" +\
-        plug_in_package_name + "/" + MASTER_PID + "/"
+    gp.pvars(BASE_TOOL_DIR_PATH, NICKNAME, plug_in_package_name, MASTER_PID)
+    return BASE_TOOL_DIR_PATH + gm.username() + "/" + NICKNAME + "/" +\
+        plug_in_package_name + "/" + str(MASTER_PID) + "/"
 
 
 def create_plug_in_save_dir(plug_in_package_name=None):