From 7aafd06df6a5c8fffe336e0168de6d5fe22083b3 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Wed, 31 Jul 2013 17:16:48 +0530 Subject: [PATCH] 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 --- tools/marvin/marvin/integration/lib/utils.py | 2 +- tools/marvin/marvin/remoteSSHClient.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index 92aee836b96..2da9272c7aa 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -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( diff --git a/tools/marvin/marvin/remoteSSHClient.py b/tools/marvin/marvin/remoteSSHClient.py index 764ba2eb95f..e0ead9315a9 100644 --- a/tools/marvin/marvin/remoteSSHClient.py +++ b/tools/marvin/marvin/remoteSSHClient.py @@ -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)