ffdc: Add OPENBMC_DUMPS stanza

Set 1: Initial commit.
Set 2: Fix directory structure for /var/lib/phosphor-debug-collector/dumps/
Set 3: Fix directory structure for dumps and hostbootdump

Test:
- Run tests to OPENBMC's with combinations of dump availabilies.
- Run tests to RHEL, Ubuntu, AIX to verify new scp paramaters.
- Regression tests with patch set 2.
- Regression tests with patch set 3.

Signed-off-by: Peter D  Phan <peterp@us.ibm.com>
Change-Id: Idedfa1e4cb4e968c494d82d0e0cc79a213be306f
diff --git a/ffdc/collect_ffdc.py b/ffdc/collect_ffdc.py
index eeeb79d..0163512 100644
--- a/ffdc/collect_ffdc.py
+++ b/ffdc/collect_ffdc.py
@@ -45,11 +45,11 @@
         thisFFDC = FFDCCollector(remote, username, password, ffdc_config, location, remote_type)
         thisFFDC.collect_ffdc()
 
-        if not thisFFDC.receive_file_list:
+        if len(os.listdir(thisFFDC.ffdc_dir_path)) == 0:
             click.echo("\n\tFFDC Collection from " + remote + " has failed.\n\n")
         else:
-            click.echo(str("\t" + str(len(thisFFDC.receive_file_list)))
-                       + " files were retrieved from " + remote)
+            click.echo(str("\t" + str(len(os.listdir(thisFFDC.ffdc_dir_path)))
+                       + " files were retrieved from " + remote))
             click.echo("\tFiles are stored in " + thisFFDC.ffdc_dir_path + "\n\n")
 
     click.echo("\n********** FFDC Finishes **********\n\n")
diff --git a/ffdc/ffdc_collector.py b/ffdc/ffdc_collector.py
index bd823df..2568042 100644
--- a/ffdc/ffdc_collector.py
+++ b/ffdc/ffdc_collector.py
@@ -45,7 +45,6 @@
             self.remote_client = None
             self.ffdc_dir_path = ""
             self.ffdc_prefix = ""
-            self.receive_file_list = []
             self.target_type = remote_type.upper()
         else:
             sys.exit(-1)
@@ -213,6 +212,7 @@
 
                         self.collect_and_copy_ffdc(ffdc_actions['GENERAL'],
                                                    form_filename=True)
+                        self.group_copy(ffdc_actions['OPENBMC_DUMPS'])
 
                     # For RHEL and UBUNTU, collect common Linux OS FFDC.
                     if self.target_type == 'RHEL' \
@@ -262,6 +262,36 @@
         else:
             print("\n\n\tSkip copying FFDC files from remote system %s.\n" % self.hostname)
 
+    def group_copy(self,
+                   ffdc_actions_for_machine_type):
+
+        r"""
+        scp group of files (wild card) from remote host.
+
+        Description of argument(s):
+        ffdc_actions_for_machine_type    commands and files for the selected remote host type.
+        """
+        if self.remoteclient.scpclient:
+            print("\n\tCopying files from remote system %s.\n" % self.hostname)
+
+            # Retrieving files from target system, if any
+            list_of_files = ffdc_actions_for_machine_type['FILES']
+
+            for filename in list_of_files:
+                command = 'ls -AX ' + filename
+                response = self.remoteclient.execute_command(command)
+                # self.remoteclient.scp_file_from_remote() completed without exception,
+                # if any
+                if response:
+                    scp_result = self.remoteclient.scp_file_from_remote(filename, self.ffdc_dir_path)
+                    if scp_result:
+                        print("\t\tSuccessfully copied from " + self.hostname + ':' + filename)
+                else:
+                    print("\t\tThere is no  " + filename)
+
+        else:
+            print("\n\n\tSkip copying files from remote system %s.\n" % self.hostname)
+
     def scp_ffdc(self,
                  targ_dir_path,
                  targ_file_prefix,
@@ -289,8 +319,6 @@
             # self.remoteclient.scp_file_from_remote() completed without exception,
             # add file to the receiving file list.
             scp_result = self.remoteclient.scp_file_from_remote(source_file_path, targ_file_path)
-            if scp_result:
-                self.receive_file_list.append(targ_file_path)
 
             if not quiet:
                 if scp_result:
diff --git a/ffdc/ffdc_config.yaml b/ffdc/ffdc_config.yaml
index f899a33..9146c13 100644
--- a/ffdc/ffdc_config.yaml
+++ b/ffdc/ffdc_config.yaml
@@ -78,6 +78,19 @@
     PROTOCOL:
         - 'SSH'
 
+# Commands and Files to collect OPENBMC dumps
+OPENBMC_DUMPS:
+    COMMANDS:
+        - 'ls -AX /tmp/core_*'
+        - 'ls -AX /var/lib/phosphor-debug-collector/dumps/*/*.tar.xz'
+        - 'ls -AX /var/lib/phosphor-debug-collector/hostbootdump/*/*.tar.gz'
+    FILES:
+        - '/tmp/core_*'
+        - '/var/lib/phosphor-debug-collector/dumps/*/*.tar.xz'
+        - '/var/lib/phosphor-debug-collector/hostbootdump/*/*.tar.gz'
+    PROTOCOL:
+        - 'SSH'
+
 # Commands and Files to collect for all Linux distributions
 LINUX:
     COMMANDS:
diff --git a/ffdc/ssh_utility.py b/ffdc/ssh_utility.py
index f1524a7..2110b74 100644
--- a/ffdc/ssh_utility.py
+++ b/ffdc/ssh_utility.py
@@ -95,7 +95,7 @@
         Create a scp connection for file transfer.
         """
         try:
-            self.scpclient = SCPClient(self.sshclient.get_transport())
+            self.scpclient = SCPClient(self.sshclient.get_transport(), sanitize=lambda x: x)
             print("\n\t[Check] %s SCP transport established.\t [OK]" % self.hostname)
         except (SCPException, SocketTimeout, PipeTimeout) as e:
             self.scpclient = None
@@ -117,7 +117,7 @@
         """
 
         try:
-            self.scpclient.get(remote_file, local_file)
+            self.scpclient.get(remote_file, local_file, recursive=True)
         except (SCPException, SocketTimeout, PipeTimeout) as e:
             # Log command with error. Return to caller for next file, if any.
             print("\n>>>>>\tERROR: Fail scp %s from remotehost %s %s\n\n" % (remote_file, e.__class__, e))