Merge lp:~nuclearbob/utah/ssh-stacktrace into lp:utah

Proposed by Max Brustkern
Status: Merged
Merged at revision: 987
Proposed branch: lp:~nuclearbob/utah/ssh-stacktrace
Merge into: lp:utah
Diff against target: 90 lines (+12/-0)
1 file modified
utah/provisioning/ssh.py (+12/-0)
To merge this branch: bzr merge lp:~nuclearbob/utah/ssh-stacktrace
Reviewer Review Type Date Requested Status
Andy Doan (community) Approve
Review via email: mp+178777@code.launchpad.net

Description of the change

I added stacktrace logging for external failures for ssh connections. When I run this command to connect to a machine that doesn't exist:
PYTHONPATH=. ./examples/run_utah_tests.py --skip-provisioning --name blarg /usr/share/utah/client/examples/pass.run
I get this:
2013-08-06 10:52:01,780 ssh INFO: Checking for ssh availability
2013-08-06 10:52:01,781 ssh DEBUG: Traceback (most recent call last):
  File "/home/max/bzr/utah/utah/provisioning/ssh.py", line 316, in sshcheck
    key_filename=config.sshprivatekey)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 282, in connect
    for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
gaierror: [Errno -2] Name or service not known

2013-08-06 10:52:01,781 ssh DEBUG: Caught [Errno -2] Name or service not known, retrying sshcheck() in 3 seconds

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) :
review: Approve
lp:~nuclearbob/utah/ssh-stacktrace updated
987. By Andy Doan

Logging stacktraces for SSH failures

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/provisioning/ssh.py'
2--- utah/provisioning/ssh.py 2013-06-10 07:07:59 +0000
3+++ utah/provisioning/ssh.py 2013-08-06 14:55:35 +0000
4@@ -24,6 +24,7 @@
5 import socket
6
7 from stat import S_ISDIR
8+from traceback import format_exc
9
10 import paramiko
11
12@@ -123,6 +124,7 @@
13 # Make sure socket.timeout is raised
14 channel.recv(0)
15 except socket.timeout:
16+ self.ssh_logger.debug(format_exc())
17 raise utah.timeout.UTAHTimeout(
18 'SSH command timed out {!r} after {} seconds'
19 .format(commandstring, timeout))
20@@ -130,12 +132,14 @@
21 retval = channel.recv_exit_status()
22
23 except paramiko.BadHostKeyException as err:
24+ self.ssh_logger.debug(format_exc())
25 raise UTAHProvisioningException(
26 'Host key exception encountered; '
27 'machine may be in use by another process: {}'
28 .format(err), external=True)
29 except (paramiko.AuthenticationException, paramiko.SSHException,
30 socket.error) as err:
31+ self.ssh_logger.debug(format_exc())
32 raise UTAHProvisioningException(err)
33 finally:
34 self.ssh_logger.debug('Closing SSH connection')
35@@ -206,12 +210,14 @@
36 remotepath = os.path.join(target, os.path.basename(localpath))
37 sftp_client.put(localpath, remotepath)
38 except paramiko.BadHostKeyException as err:
39+ self.ssh_logger.debug(format_exc())
40 raise UTAHProvisioningException(
41 'Host key exception encountered; '
42 'machine may be in use by another process: {}'
43 .format(err), external=True)
44 except (paramiko.AuthenticationException, paramiko.SSHException,
45 socket.error) as err:
46+ self.ssh_logger.debug(format_exc())
47 raise UTAHProvisioningException(err)
48 finally:
49 self.ssh_client.close()
50@@ -250,12 +256,14 @@
51 .format(remotepath, target))
52 sftp_client.get(remotepath, localpath)
53 except paramiko.BadHostKeyException as err:
54+ self.ssh_logger.debug(format_exc())
55 raise UTAHProvisioningException(
56 'Host key exception encountered; '
57 'machine may be in use by another process: {}'
58 .format(err), external=True)
59 except (paramiko.AuthenticationException, paramiko.SSHException,
60 socket.error) as err:
61+ self.ssh_logger.debug(format_exc())
62 raise UTAHProvisioningException(err)
63 finally:
64 self.ssh_client.close()
65@@ -307,14 +315,17 @@
66 username=config.user,
67 key_filename=config.sshprivatekey)
68 except paramiko.BadHostKeyException as err:
69+ self.ssh_logger.debug(format_exc())
70 raise UTAHProvisioningException(
71 'Host key exception encountered; '
72 'machine may be in use by another process: {}'
73 .format(err), external=True)
74 except (paramiko.AuthenticationException,
75 paramiko.SSHException) as err:
76+ self.ssh_logger.debug(format_exc())
77 raise UTAHProvisioningException(err)
78 except socket.error as err:
79+ self.ssh_logger.debug(format_exc())
80 raise UTAHProvisioningException(str(err), retry=True)
81 finally:
82 self.ssh_client.close()
83@@ -377,6 +388,7 @@
84 self.pingpoll(timeout=self.connectivity_timeout,
85 checktimeout=self.check_timeout)
86 except utah.timeout.UTAHTimeout:
87+ self.ssh_logger.debug(format_exc())
88 # Ignore timeout for ping, since depending on the network
89 # configuration ssh might still work despite the ping failure.
90 self.logger.warning('Network connectivity (ping) failure')

Subscribers

People subscribed via source and target branches