From ade13bb7733b00b71dbc88e92bc67346c0683abc Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Mon, 29 Jul 2013 14:51:37 +0530 Subject: [PATCH] Remove duplicate while-loop retries during ssh Signed-off-by: Prasanna Santhanam (cherry picked from commit 53feae08de5f4d8072538e9060e5a6e074ebcdde) --- .../component/test_vpc_network_pfrules.py | 2 +- tools/marvin/marvin/integration/lib/utils.py | 30 ++++++++----------- tools/marvin/marvin/remoteSSHClient.py | 4 +-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index 6894c997aae..9e6243b6ed8 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -356,7 +356,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): vpcid=self.vpc.id ) - self.debug("Adding NetwrokACl rules to make NAT rule accessible") + self.debug("Adding NetworkACL rules to make NAT rule accessible") nwacl_nat = NetworkACL.create(self.apiclient, networkid=network.id, services=services, diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index 16bbb7e33ba..92aee836b96 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -111,23 +111,19 @@ def cleanup_resources(api_client, resources): def is_server_ssh_ready(ipaddress, port, username, password, retries=5, timeout=20, keyPairFileLocation=None): """Return ssh handle else wait till sshd is running""" - loop_cnt = retries - while True: - try: - ssh = remoteSSHClient( - host=ipaddress, - port=port, - user=username, - passwd=password, - keyPairFileLocation=keyPairFileLocation) - except Exception as e: - if loop_cnt == 0: - raise e - loop_cnt = loop_cnt - 1 - time.sleep(timeout) - else: - return ssh - raise Exception("Failed to bring up ssh service in time. Waited %ss" % retries*timeout) + try: + ssh = remoteSSHClient( + host=ipaddress, + port=port, + user=username, + passwd=password, + keyPairFileLocation=keyPairFileLocation, + retries=retries, + delay=timeout) + except Exception, e: + raise Exception("Failed to bring up ssh service in time. Waited %ss. Error is %s" % (retries * timeout, e)) + else: + return ssh def format_volume_to_ext3(ssh_client, device="/dev/sda"): diff --git a/tools/marvin/marvin/remoteSSHClient.py b/tools/marvin/marvin/remoteSSHClient.py index 597fc65f819..1dd1ef1a815 100644 --- a/tools/marvin/marvin/remoteSSHClient.py +++ b/tools/marvin/marvin/remoteSSHClient.py @@ -24,7 +24,7 @@ from contextlib import closing class remoteSSHClient(object): - def __init__(self, host, port, user, passwd, retries=10, + def __init__(self, host, port, user, passwd, retries=10, delay=5, log_lvl=logging.INFO, keyPairFileLocation=None): self.host = host self.port = port @@ -62,7 +62,7 @@ class remoteSSHClient(object): raise cloudstackException. \ InvalidParameterException(repr(sshex)) retry_count = retry_count - 1 - time.sleep(5) + time.sleep(delay) except paramiko.AuthenticationException, authEx: raise cloudstackException. \ InvalidParameterException("Invalid credentials to "