Added support for ffdc_function_list to ffdc functions.

- This allows a user to specify what kinds of FFDC they want collected.
  If they specify nothing for this parm, they got all possible kinds of
  FFDC.
- Also, added some use of run_key to improve output and allow for
  test_mode.

Change-Id: I96b40f0ddcea7269c0fe3828076ca489816b699a
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/openbmc_ffdc.py b/lib/openbmc_ffdc.py
index 80a5c96..36c011c 100644
--- a/lib/openbmc_ffdc.py
+++ b/lib/openbmc_ffdc.py
@@ -8,13 +8,15 @@
 
 import gen_robot_print as grp
 import gen_valid as gv
+import gen_robot_keyword as grk
 
 from robot.libraries.BuiltIn import BuiltIn
 
 
 ###############################################################################
 def ffdc(ffdc_dir_path=None,
-         ffdc_prefix=None):
+         ffdc_prefix=None,
+         ffdc_function_list=""):
 
     r"""
     Gather First Failure Data Capture (FFDC).
@@ -26,21 +28,26 @@
     - Call BMC methods to write/collect FFDC data.
 
     Description of arguments:
-    ffdc_dir_path  The dir path where FFDC data should be put.
-    ffdc_prefix    The prefix to be given to each FFDC file name generated.
+    ffdc_dir_path       The dir path where FFDC data should be put.
+    ffdc_prefix         The prefix to be given to each FFDC file name
+                        generated.
+    ffdc_function_list  A colon-delimited list of all the types of FFDC data
+                        you wish to have collected.  A blank value means that
+                        all possible kinds of FFDC are to be collected.  See
+                        FFDC_METHOD_CALL object in lib/openbmc_ffdc_list.py
+                        for possible choices.
     """
 
     # Check if Ping and SSH connection is alive
     OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}")
-    cmd_buf = ["Ping Host", OPENBMC_HOST]
-    grp.rpissuing_keyword(cmd_buf)
-    status_ping = BuiltIn().run_keyword_and_return_status(*cmd_buf)
+    status, status_ping = grk.run_key("Ping Host  " + OPENBMC_HOST)
     grp.rprint_var(status_ping)
-    if status_ping == True:
+    if status_ping:
         status_ssh = \
-          BuiltIn().run_keyword_and_return_status("Open Connection And Log In")
+            BuiltIn().run_keyword_and_return_status("Open Connection And" +
+                                                    " Log In")
         grp.rprint_var(status_ssh)
-        if status_ssh != True:
+        if not status_ssh:
             grp.rprint_error("BMC is not communicating. \
                               Aborting FFDC collection.\n")
             BuiltIn().run_keyword_and_return_status("Close All Connections")
@@ -77,13 +84,10 @@
     FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt"
     BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH)
 
-    cmd_buf = ["Header Message"]
-    grp.rpissuing_keyword(cmd_buf)
-    BuiltIn().run_keyword(*cmd_buf)
+    grk.run_key("Header Message")
 
-    cmd_buf = ["Call FFDC Methods"]
-    grp.rpissuing_keyword(cmd_buf)
-    BuiltIn().run_keyword(*cmd_buf)
+    grk.run_key_u("Call FFDC Methods  ffdc_function_list=" +
+                  ffdc_function_list)
 
     grp.rprint_timen("Finished collecting FFDC.")
 
diff --git a/lib/openbmc_ffdc_list.py b/lib/openbmc_ffdc_list.py
index 62072eb..01e6d48 100755
--- a/lib/openbmc_ffdc_list.py
+++ b/lib/openbmc_ffdc_list.py
@@ -211,6 +211,16 @@
         """
         return FFDC_METHOD_CALL.keys()
 
+    def get_ffdc_method_desc(self,
+                             index):
+        r"""
+        ########################################################################
+        #   @brief   This method returns the just the keys from the dictionary.
+        #   @return  List of ffdc descriptions.
+        ########################################################################
+        """
+        return FFDC_METHOD_CALL[index].keys()
+
     def get_ffdc_method_call(self, i_type):
         r"""
         ########################################################################
diff --git a/lib/openbmc_ffdc_methods.robot b/lib/openbmc_ffdc_methods.robot
index 2cd8207..4911469 100755
--- a/lib/openbmc_ffdc_methods.robot
+++ b/lib/openbmc_ffdc_methods.robot
@@ -8,6 +8,8 @@
 Library            SSHLibrary
 Library            OperatingSystem
 Library            Collections
+Library            String
+Library            gen_robot_keyword.py
 
 *** Keywords ***
 
@@ -19,31 +21,71 @@
 ################################################################
 
 Call FFDC Methods
-    [Documentation]   Calls into FFDC Keyword index list
+    [Documentation]   Call into FFDC Keyword index list.
+    [Arguments]  ${ffdc_function_list}=${EMPTY}
 
-    @{entries}=     Get ffdc method index
-    :FOR  ${index}  IN   @{entries}
-    \     Method Call Keyword List   ${index}
+    # Description of argument(s):
+    # ffdc_function_list  A colon-delimited list naming the kinds of FFDC that
+    #                     is to be collected
+    #                     (e.g. "FFDC Generic Report:BMC Specific Files").
+    #                     Acceptable values can be found in the description
+    #                     field of FFDC_METHOD_CALL in
+    #                     lib/openbmc_ffdc_list.py.  Those values can be
+    #                     obtained via a call to 'Get FFDC Method Desc' (also
+    #                     from lib/openbmc_ffdc_list.py).
+
+    @{entries}=  Get FFDC Method Index
+    :FOR  ${index}  IN  @{entries}
+    \    Method Call Keyword List  ${index}  ${ffdc_function_list}
     SSHLibrary.Close All Connections
 
-
 Method Call Keyword List
-    [Documentation]   Iterate the list through keyword index
-    [Arguments]       ${index}
+    [Documentation]  Iterate the list through keyword index.
+    [Arguments]  ${index}  ${ffdc_function_list}=${EMPTY}
 
-    @{method_list}=      Get ffdc method call   ${index}
+    # Description of argument(s):
+    # index               The index into the FFDC_METHOD_CALL dictionary (e.g.
+    #                     'BMC LOGS').
+    # ffdc_function_list  See ffdc_function_list description in
+    #                     "Call FFDC Methods" (above).
+
+    @{method_list}=  Get ffdc method call  ${index}
+
+    # If function list is empty assign default (i.e. a list of all allowable
+    # values).  In either case, convert ffdc_function_list from a string to
+    # a list.
+    @{ffdc_function_list}=
+    ...  Run Keyword If  '${ffdc_function_list}' == '${EMPTY}'
+    ...    Get FFDC Method Desc  ${index}
+    ...  ELSE
+    ...    Split String  ${ffdc_function_list}  separator=:
+
     :FOR  ${method}  IN  @{method_list}
-    \    Execute Keyword Method   ${method[1]}
-
+    \    Execute Keyword Method  ${method[0]}  ${method[1]}
+    ...      @{ffdc_function_list}
 
 Execute Keyword Method
-    [Documentation]   Calls into BMC method keywords. Don't let one
-    ...               failure skips the remaining. Get whatever data
-    ...               it could gather at worse case scenario.
-    [Arguments]   ${keyword_name}
+    [Documentation]  Call into BMC method keywords. Don't let one
+    ...              failure skip the remaining. Get whatever data
+    ...              it could gather at worse case scenario.
+    [Arguments]  ${description}  ${keyword_name}  @{ffdc_function_list}
 
-    Run Keyword And Continue On Failure   ${keyword_name}
+    # Description of argument(s):
+    # description         The description of the FFDC to be collected.  This
+    #                     would be any value returned by
+    #                     'Get FFDC Method Desc' (e.g. "FFDC Generic Report").
+    # keyword_name        The name of the keyword to call to collect the FFDC
+    #                     data (again, see FFDC_METHOD_CALL).
+    # ffdc_function_list  See ffdc_function_list description in
+    #                     "Call FFDC Methods" (above).  The only difference is
+    #                     in this case, it should be a list rather than a
+    #                     colon-delimited value.
 
+    ${status}  ${ret_values}=  Run Keyword And Ignore Error
+    ...  List Should Contain Value  ${ffdc_function_list}  ${description}
+    Run Keyword If  '${status}' != 'PASS'  Return from Keyword
+
+    Run Key  ${keyword_name}  ignore=1
 
 ################################################################
 # Method : BMC FFDC Manifest                                   #