Include SSH retry logic when encountering channel failures.

Only on SSHExceptions we attempted retries, but during socket failures,
like Network Unreachable we failed the ssh connection immediately.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
(cherry picked from commit dcbb2fcaa18e3faaf1c0765633300f7d0fa46d2c)
This commit is contained in:
Prasanna Santhanam 2013-07-31 17:16:48 +05:30
parent 476bd93e43
commit cce14f3974
2 changed files with 4 additions and 5 deletions

View File

@ -109,7 +109,7 @@ def cleanup_resources(api_client, resources):
obj.delete(api_client)
def is_server_ssh_ready(ipaddress, port, username, password, retries=5, timeout=20, keyPairFileLocation=None):
def is_server_ssh_ready(ipaddress, port, username, password, retries=5, timeout=30, keyPairFileLocation=None):
"""Return ssh handle else wait till sshd is running"""
try:
ssh = remoteSSHClient(

View File

@ -17,6 +17,7 @@
import paramiko
import time
import socket
import cloudstackException
import contextlib
import logging
@ -57,10 +58,10 @@ class remoteSSHClient(object):
(str(host), user, keyPairFileLocation))
self.logger.debug("SSH connect: %s@%s with passwd %s" %
(user, str(host), passwd))
except paramiko.SSHException, sshex:
except (paramiko.SSHException, paramiko.ChannelException, socket.error) as se:
if retry_count == 0:
raise cloudstackException. \
InvalidParameterException(repr(sshex))
InvalidParameterException(repr(se))
retry_count = retry_count - 1
time.sleep(delay)
except paramiko.AuthenticationException, authEx:
@ -68,8 +69,6 @@ class remoteSSHClient(object):
InvalidParameterException("Invalid credentials to "
+ "login to %s on port %s" %
(str(host), port))
else:
return self.ssh
def execute(self, command):
stdin, stdout, stderr = self.ssh.exec_command(command)