Changes to obmc_boot_test programs.

extended/obmc_boot_test.robot
  - I added support for state_change_timeout, power_on_timeout,
    power_on_timeout program parms.
  - New code to set default value for openbmc_nickname.
  - I added support for new ffdc_check call point.
  - Re-wrote "My FFDC" as my_ffdc in lib/obmc_boot_test.py.
  - Removed unnecessary 'Log Defect Information' keyword.
  - Made output improvements to "Print Defect Report"

lib/obmc_boot_test.py
  - add_trailing_slash:  Function moved to gen_misc.py.
  - plug_in_setup:
    - I added default assignment of openbmc_nickname.
    - I added support for some more variables.
    - my_ffdc:  Moved from obmc_boot_test.robot to this file.  Re-written in
      python

Change-Id: Id07a20f9c6c5f9ccbca4b71e5590d8fa8bcdcd79
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/extended/obmc_boot_test.robot b/extended/obmc_boot_test.robot
index 03a6157..c1f5399 100644
--- a/extended/obmc_boot_test.robot
+++ b/extended/obmc_boot_test.robot
@@ -9,6 +9,7 @@
 Resource  ../lib/openbmc_ffdc.robot
 
 Library   ../lib/gen_robot_print.py
+Library   ../lib/gen_misc.py
 Library   ../lib/gen_robot_plug_in.py
 Library   ../lib/gen_robot_valid.py
 Library   ../lib/state.py
@@ -27,7 +28,8 @@
 ...  pdu_username  pdu_password  pdu_slot_no  openbmc_serial_host
 ...  openbmc_serial_port  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  test_mode  quiet  debug
+...  ffdc_dir_path_style  ffdc_check  state_change_timeout  power_on_timeout
+...  power_on_timeout  test_mode  quiet  debug
 
 # Initialize each program parameter.
 ${openbmc_nickname}         ${EMPTY}
@@ -56,6 +58,9 @@
 ${boot_fail}                ${0}
 ${ffdc_dir_path_style}      ${EMPTY}
 ${ffdc_check}               ${EMPTY}
+${state_change_timeout}     1 min
+${power_on_timeout}         14 mins
+${power_off_timeout}        2 mins
 ${test_mode}                0
 ${quiet}                    0
 ${debug}                    0
@@ -140,7 +145,7 @@
     ${temp_state}=  Run Keyword If  '${test_mode}' == '0'  Get State
     ...  ELSE  Create Dictionary  &{default_state}
     Set Global Variable  &{state}  &{temp_state}
-    rpvars  state
+    Rpvars  state
 
 ###############################################################################
 
@@ -178,6 +183,9 @@
     ${temp_arr}=  Rvalidate Plug Ins  ${plug_in_dir_paths}
     Set Global Variable  @{plug_in_packages_list}  @{temp_arr}
 
+    Run Keyword If  '${openbmc_nickname}' == '${EMPTY}'
+    ...  Set Global Variable  ${openbmc_nickname}  ${openbmc_host}
+
     Set FFDC Dir Path Style
 
 ###############################################################################
@@ -221,6 +229,9 @@
     ${loc_next_boot}=  Select Boot  ${state['power']}
     Set Global Variable  ${next_boot}  ${loc_next_boot}
 
+    # Clear this file.  Plug-ins may now write to it.
+    Remove File  ${FFDC_LIST_FILE_PATH}
+
     ${status}  ${msg}=  Run Keyword And Ignore Error  Run Boot  ${next_boot}
     Run Keyword If  '${status}' == 'FAIL'  rprint  ${msg}
 
@@ -240,7 +251,12 @@
     ${rc}  ${shell_rc}  ${failed_plug_in_name}=  Rprocess Plug In Packages
     ...  call_point=post_test_case  stop_on_plug_in_failure=1
 
-    Run Keyword If  '${BOOT_STATUS}' != 'PASS' or '${FFDC_CHECK}' == 'All'
+    ${rc}  ${shell_rc}  ${failed_plug_in_name}=  Rprocess Plug In Packages
+    ...  call_point=ffdc_check  shell_rc=${0x00000200}
+    ...  stop_on_plug_in_failure=1  stop_on_non_zero_rc=1
+
+    Run Keyword If
+    ...  '${BOOT_STATUS}' != 'PASS' or '${FFDC_CHECK}' == 'All' or '${shell_rc}' == '${0x00000200}'
     ...  Run Keyword and Continue On Failure  My FFDC
 
     # Run plug-ins to see if we ought to stop execution.
@@ -279,7 +295,7 @@
     ...  **ERROR** BMC not in state to power on or off: "${power}"  AND
     ...  Fatal Error
 
-    [Return]  ${boot}
+    [return]  ${boot}
 
 ###############################################################################
 
@@ -296,7 +312,7 @@
     # selecting randomly.
     ${chosen}=  Set Variable  @{power_on_choices}[0]
 
-    [Return]  ${chosen}
+    [return]  ${chosen}
 
 ###############################################################################
 
@@ -313,7 +329,7 @@
     # selecting randomly.
     ${chosen}=  Set Variable  @{power_off_choices}[0]
 
-    [Return]  ${chosen}
+    [return]  ${chosen}
 
 ###############################################################################
 
@@ -363,29 +379,8 @@
 
 
 ###############################################################################
-My FFDC
-    [Documentation]  Collect FFDC data.
-
-    # FFDC_LOG_PATH is used by "FFDC" keyword.
-    Set Global Variable  ${FFDC_LOG_PATH}  ${FFDC_DIR_PATH}
-
-    @{cmd_buf}=  Create List  FFDC
-    rqpissuing_keyword  ${cmd_buf}  ${test_mode}
-    Run Keyword If  '${test_mode}' == '0'  @{cmd_buf}
-
-    Plug In Setup
-    ${rc}  ${shell_rc}  ${failed_plug_in_name}=  Rprocess Plug In Packages
-    ...  call_point=ffdc  stop_on_plug_in_failure=1
-
-    Log Defect Information
-
-###############################################################################
-
-
-###############################################################################
-Log Defect Information
-    [Documentation]  Logs information needed for a defect. This information
-    ...  can also be found within the FFDC gathered.
+Print Defect Report
+    [Documentation]  Print a defect report.
 
     Rqprintn
     # indent=0, width=90, linefeed=1, char="="
@@ -395,18 +390,29 @@
 
     Rqpvars  @{parm_list}
     Print Last Ten Boots
+    Rqprintn
+    Rqpvars  state
 
-    ${rc}  ${output}=  Run Keyword If  '${test_mode}' == '0'
-    ...  Run and return RC and Output  ls ${LOG_PREFIX}*
-    ...  ELSE  Set Variable  ${0}  ${EMPTY}
+    # At some point I'd like to have the 'Call FFDC Methods' return a list
+    # of files it has collected.  In that case, the following "ls" command
+    # would no longer be needed.  For now, however, ls shows the files
+    # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
+    # out (so we don't see duplicates in the list).
+
+    ${rc}  ${output}=  Run and return RC and Output  ls ${LOG_PREFIX}*
 
     Run Keyword If  '${rc}' != '${0}' and '${rc}' != 'None'  rqpvars  rc
+    ${status}  ${ffdc_list}=  Run Keyword and Ignore Error
+    ...  OperatingSystem.Get File  ${FFDC_LIST_FILE_PATH}
 
     Rqprintn
     Rqprintn  FFDC data files:
+    Run Keyword If  '${status_file_path}' != '${EMPTY}'
+    ...  Rqprintn  ${status_file_path}
     Rqprintn  ${output}
-
+    # Run Keyword If  '${status}' == 'PASS'  Rqprintn  ${ffdc_list}
     Rqprintn
+
     Rqprint Dashes  ${0}  ${90}  ${1}  =
 
 ###############################################################################
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 24be494..eb379a4 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -6,6 +6,8 @@
 
 from tally_sheet import *
 import gen_robot_print as grp
+import gen_robot_plug_in as grpi
+import state as st
 
 import os
 import time
@@ -27,19 +29,6 @@
 
 
 ###############################################################################
-def add_trailing_slash(path):
-
-    r"""
-    Add a trailing slash to path if it doesn't already have one and return it.
-
-    """
-
-    return os.path.normpath(path) + os.path.sep
-
-###############################################################################
-
-
-###############################################################################
 def plug_in_setup():
 
     r"""
@@ -79,9 +68,8 @@
     openbmc_nickname = BuiltIn().get_variable_value("${openbmc_nickname}")
     openbmc_host = BuiltIn().get_variable_value("${openbmc_host}")
     if openbmc_nickname == "":
-        ffdc_prefix = openbmc_host
-    else:
-        ffdc_prefix = openbmc_nickname
+        openbmc_nickname = openbmc_host
+    ffdc_prefix = openbmc_nickname
 
     ffdc_prefix += "." + time_string
 
@@ -93,14 +81,18 @@
         ffdc_dir_path = ""
     BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
 
-    try:
-        base_tool_dir_path = os.environ['AUTOBOOT_BASE_TOOL_DIR_PATH']
-    except KeyError:
-        base_tool_dir_path = "/tmp/"
+    status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
+    if status_dir_path != "":
+        # Add trailing slash.
+        status_dir_path = os.path.normpath(status_dir_path) + os.sep
+    BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path)
+
+    base_tool_dir_path = os.environ.get('AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")
     base_tool_dir_path = os.path.normpath(base_tool_dir_path) + os.sep
     BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path)
 
-    ffdc_list_file_path = base_tool_dir_path + openbmc_host + "/FFDC_FILE_LIST"
+    ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\
+        "/FFDC_FILE_LIST"
 
     BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}",
                                   ffdc_list_file_path)
@@ -111,7 +103,8 @@
     additional_values = ["boot_type_desc", "boot_success", "boot_pass",
                          "boot_fail", "test_really_running", "program_pid",
                          "master_pid", "ffdc_prefix", "ffdc_dir_path",
-                         "base_tool_dir_path", "ffdc_list_file_path"]
+                         "status_dir_path", "base_tool_dir_path",
+                         "ffdc_list_file_path"]
     BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix)
 
     parm_list = BuiltIn().get_variable_value("@{parm_list}")
@@ -205,3 +198,36 @@
     grp.rprint(header_footer)
 
 ###############################################################################
+
+
+###############################################################################
+def my_ffdc():
+
+    r"""
+    Collect FFDC data.
+    """
+
+    plug_in_setup()
+    rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
+        call_point='ffdc', stop_on_plug_in_failure=1)
+
+    AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
+
+    # FFDC_LOG_PATH is used by "FFDC" keyword.
+    FFDC_DIR_PATH = BuiltIn().get_variable_value("${FFDC_DIR_PATH}")
+    BuiltIn().set_global_variable("${FFDC_LOG_PATH}",
+                                  FFDC_DIR_PATH)
+
+    cmd_buf = ["FFDC", "ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX]
+    grp.rpissuing_keyword(cmd_buf)
+    BuiltIn().run_keyword(*cmd_buf)
+
+    state = st.get_state()
+    BuiltIn().set_global_variable("${state}",
+                                  state)
+
+    cmd_buf = ["Print Defect Report"]
+    grp.rpissuing_keyword(cmd_buf)
+    BuiltIn().run_keyword(*cmd_buf)
+
+###############################################################################