ffdc: Add checking for scp get_transport error.
When there is an error on scp get_transport,
- Inform user of the error.
- Continue FFDC generation on remote host.
- Inform user to manually offload data.
Test:
- Run OK scenarios.
- Run SCPException and SocketException scenarios.
Signed-off-by: Peter D Phan <peterp@us.ibm.com>
Change-Id: I606bc9530fb1f4b1b1bbe75c5797337f0bd76f2a
diff --git a/ffdc/collect_ffdc.py b/ffdc/collect_ffdc.py
index 21c67ef..49e89fa 100644
--- a/ffdc/collect_ffdc.py
+++ b/ffdc/collect_ffdc.py
@@ -44,7 +44,7 @@
thisFFDC.collect_ffdc()
if not thisFFDC.receive_file_list:
- click.echo("\n\tFFDC Collection from " + remote + " has failed\n\n.")
+ 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)
diff --git a/ffdc/ffdc_collector.py b/ffdc/ffdc_collector.py
index 3e4f788..5b84106 100644
--- a/ffdc/ffdc_collector.py
+++ b/ffdc/ffdc_collector.py
@@ -120,6 +120,11 @@
self.remoteclient.ssh_remoteclient_login()
print("\n\t[Check] %s SSH connection established.\t [OK]" % self.hostname)
+
+ # Check scp connection.
+ # If scp connection fails,
+ # continue with FFDC generation but skip scp files to local host.
+ self.remoteclient.scp_connection()
return True
def generate_ffdc(self, working_protocol_list):
@@ -146,15 +151,18 @@
self.remoteclient.execute_command(command)
progress_counter += 1
self.print_progress(progress_counter)
- print("\n\t[Run] Commands execution completed \t\t [OK]")
+ print("\n\t[Run] Commands execution completed.\t\t [OK]")
- print("\n\n\tCopying FFDC files from remote system %s \n\n" % self.hostname)
- # Get default values for scp action.
- # self.location == local system for now
- self.set_ffdc_defaults()
- # Retrieving files from target system
- list_of_files = ffdc_actions[machine_type]['FILES']
- self.scp_ffdc(self.ffdc_dir_path, self.ffdc_prefix, list_of_files)
+ if self.remoteclient.scpclient:
+ print("\n\n\tCopying FFDC files from remote system %s.\n" % self.hostname)
+ # Get default values for scp action.
+ # self.location == local system for now
+ self.set_ffdc_defaults()
+ # Retrieving files from target system
+ list_of_files = ffdc_actions[machine_type]['FILES']
+ self.scp_ffdc(self.ffdc_dir_path, self.ffdc_prefix, list_of_files)
+ else:
+ print("\n\n\tSkip copying FFDC files from remote system %s.\n" % self.hostname)
else:
print("\n\tProtocol %s is not yet supported by this script.\n"
% ffdc_actions[machine_type]['PROTOCOL'][0])
@@ -175,8 +183,6 @@
"""
- self.remoteclient.scp_connection()
-
self.receive_file_list = []
progress_counter = 0
for filename in file_list:
diff --git a/ffdc/ssh_utility.py b/ffdc/ssh_utility.py
index 3a028e6..f1524a7 100644
--- a/ffdc/ssh_utility.py
+++ b/ffdc/ssh_utility.py
@@ -6,7 +6,7 @@
from paramiko.ssh_exception import SSHException
from paramiko.ssh_exception import BadHostKeyException
from paramiko.buffered_pipe import PipeTimeout as PipeTimeout
-import scp
+from scp import SCPClient, SCPException
import sys
import socket
from socket import timeout as SocketTimeout
@@ -94,7 +94,14 @@
r"""
Create a scp connection for file transfer.
"""
- self.scpclient = scp.SCPClient(self.sshclient.get_transport())
+ try:
+ self.scpclient = SCPClient(self.sshclient.get_transport())
+ print("\n\t[Check] %s SCP transport established.\t [OK]" % self.hostname)
+ except (SCPException, SocketTimeout, PipeTimeout) as e:
+ self.scpclient = None
+ print("\n>>>>>\tERROR: SCP get_transport has failed. %s %s" % (e.__class__, e))
+ print(">>>>>\tScript continues generating FFDC on %s." % self.hostname)
+ print(">>>>>\tCollected data will need to be manually offloaded.")
def scp_file_from_remote(self, remote_file, local_file):
@@ -111,7 +118,7 @@
try:
self.scpclient.get(remote_file, local_file)
- except (scp.SCPException, SocketTimeout, PipeTimeout) as e:
+ 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))
return False