Fixes to obmc_boot_test.py for re-use by other keywords.

- Needed to set sys.path if PYTHONPATH doesn't contain <git-repo>/lib/.
- Made greater use of new run_key functions.
- Renamed main_keyword_teardown to obmc_boot_test_teardown.
- Renamed obmc_boot_test to obmc_boot_test_py.
- Renamed Main to OBMC Boot Test and moved it from obmc_boot_test.robot
  to obmc_boot_test_resource.robot.  Also changed the call within it to
  pass along all arguments and to call the newly named
  OBMC Boot Test Py.
- Added support for ffdc_function_list.

Change-Id: Ie5b1145e0046e57b896fd11c402317a154d5db7b
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/extended/obmc_boot_test.robot b/extended/obmc_boot_test.robot
index c6031a0..d0b8696 100644
--- a/extended/obmc_boot_test.robot
+++ b/extended/obmc_boot_test.robot
@@ -10,19 +10,4 @@
     [Tags]  General_boot_testing
     [Teardown]  Test Teardown
 
-    # Call the Main keyword to prevent any dots from appearing in the console
-    # due to top level keywords.
-    Main
-
-*** Keywords ***
-###############################################################################
-Main
-    [Teardown]  Main Keyword Teardown
-
-    # This is the "Main" keyword.  The advantages of having this keyword vs
-    # just putting the code in the *** Test Cases *** table are:
-    # 1) You won't get a green dot in the output every time you run a keyword.
-
     OBMC Boot Test
-
-###############################################################################
diff --git a/extended/obmc_boot_test_resource.robot b/extended/obmc_boot_test_resource.robot
index da59112..f3ffaa5 100644
--- a/extended/obmc_boot_test_resource.robot
+++ b/extended/obmc_boot_test_resource.robot
@@ -16,9 +16,9 @@
 ...  pdu_username  pdu_password  pdu_slot_no  openbmc_serial_host
 ...  openbmc_serial_port  stack_mode  boot_stack  boot_list  max_num_tests
 ...  plug_in_dir_paths  status_file_path  openbmc_model  boot_pass  boot_fail
-...  ffdc_dir_path_style  ffdc_check  state_change_timeout  power_on_timeout
-...  power_off_timeout  ffdc_only  boot_fail_threshold  test_mode  quiet
-...  debug
+...  ffdc_dir_path_style  ffdc_check  ffdc_only  ffdc_function_list
+...  state_change_timeout  power_on_timeout  power_off_timeout
+...  boot_fail_threshold  test_mode  quiet  debug
 
 # Initialize each program parameter.
 ${openbmc_host}             ${EMPTY}
@@ -48,10 +48,11 @@
 ${boot_fail}                ${0}
 ${ffdc_dir_path_style}      ${EMPTY}
 ${ffdc_check}               ${EMPTY}
+${ffdc_only}                ${0}
+${ffdc_function_list}       ${EMPTY}
 ${state_change_timeout}     3 mins
 ${power_on_timeout}         14 mins
 ${power_off_timeout}        2 mins
-${ffdc_only}                ${0}
 # If the number of boot failures, exceeds boot_fail_threshold, this program
 # returns non-zero.
 ${boot_fail_threshold}      ${1000000}
@@ -63,3 +64,17 @@
 # test_really_running is needed by DB_Logging plug-in.
 ${test_really_running}      ${1}
 
+
+*** Keywords ***
+###############################################################################
+OBMC Boot Test
+    [Teardown]  OBMC Boot Test Teardown
+    [Arguments]  @{arguments}
+
+    # Note: If I knew how to specify a keyword teardown in python, I would
+    # rename the "OBMC Boot Test Py" python function to "OBMC Boot Test" and
+    # do away with this robot keyword.
+
+    OBMC Boot Test Py  @{arguments}
+
+###############################################################################
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index f43ae7c..bf10ec9 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -230,14 +230,21 @@
 
     gp.qprintn()
 
+    robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
+    repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/")
+    # If we can't find ssh_pw, then we don't have our repo bin in PATH.
     shell_rc, out_buf = gc.cmd_fnc_u("which ssh_pw", quiet=1, print_output=0,
                                      show_err=0)
     if shell_rc != 0:
-        robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
-        os.environ['PATH'] = robot_pgm_dir_path +\
-            "../bin:" + os.environ.get('PATH', "")
-        os.environ['PYTHONPATH'] = robot_pgm_dir_path +\
-            os.environ.get('PYTHONPATH', "")
+        os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "")
+    # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH.
+    if robot_pgm_dir_path not in sys.path:
+        sys.path.append(robot_pgm_dir_path)
+        PYTHONPATH = os.environ.get("PYTHONPATH", "")
+        if PYTHONPATH == "":
+            os.environ['PYTHONPATH'] = robot_pgm_dir_path
+        else:
+            os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH
 
     validate_parms()
 
@@ -525,12 +532,11 @@
         call_point='ffdc', stop_on_plug_in_failure=1)
 
     AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
-
-    cmd_buf = ["FFDC", "ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX]
-    grp.rpissuing_keyword(cmd_buf)
-    try:
-        BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
-    except:
+    status, ret_values = grk.run_key_u("FFDC  ffdc_prefix=" +
+                                       AUTOBOOT_FFDC_PREFIX +
+                                       "  ffdc_function_list=" +
+                                       ffdc_function_list, ignore=1)
+    if status != 'PASS':
         gp.print_error("Call to ffdc failed.\n")
 
     my_get_state()
@@ -692,11 +698,8 @@
         call_point='ffdc_check', shell_rc=0x00000200,
         stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
     if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
-        cmd_buf = ["my_ffdc"]
-        grp.rpissuing_keyword(cmd_buf)
-        try:
-            BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
-        except:
+        status, ret_values = grk.run_key_u("my_ffdc", ignore=1)
+        if status != 'PASS':
             gp.print_error("Call to my_ffdc failed.\n")
 
     # We need to purge error logs between boots or they build up.
@@ -722,7 +725,7 @@
 
 
 ###############################################################################
-def main_keyword_teardown():
+def obmc_boot_test_teardown():
 
     r"""
     Clean up after the Main keyword.
@@ -760,7 +763,7 @@
 
 
 ###############################################################################
-def obmc_boot_test(alt_boot_stack=None):
+def obmc_boot_test_py(alt_boot_stack=None):
 
     r"""
     Do main program processing.
@@ -773,12 +776,7 @@
 
     if ffdc_only:
         gp.qprint_timen("Caller requested ffdc_only.")
-        cmd_buf = ["my_ffdc"]
-        grp.rpissuing_keyword(cmd_buf)
-        try:
-            BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
-        except:
-            gp.print_error("Call to my_ffdc failed.\n")
+        grk.run_key_u("my_ffdc")
 
     # Process caller's boot_stack.
     while (len(boot_stack) > 0):