diff --git a/pycloudlib/instance.py b/pycloudlib/instance.py index ed8f4b2b..260f29dc 100644 --- a/pycloudlib/instance.py +++ b/pycloudlib/instance.py @@ -312,9 +312,10 @@ def _ssh_connect(self): except SSHException: pass - retries = 60 + start = time.time() + end = start + 600 last_exception = None - while retries: + while True: try: client.connect( username=self.username, @@ -328,13 +329,15 @@ def _ssh_connect(self): except (ConnectionRefusedError, AuthenticationException, BadHostKeyException, ConnectionResetError, SSHException, OSError) as e: - self._log.info( - "%s\nRetrying ssh connection %d more time(s) to %s@%s:%s", - e, retries, self.username, self.ip, self.port - ) last_exception = e - retries -= 1 - time.sleep(10) + if time.time() > end: + break + self._log.info( + "%s\nRetrying SSH connection to %s@%s:%s (%ds left)", + last_exception, self.username, self.ip, self.port, + end - time.time() + ) + time.sleep(1) self._log.error('Failed ssh connection to %s@%s:%s after 10 minutes', self.username, self.ip, self.port) @@ -372,7 +375,7 @@ def _wait_for_execute(self): test_instance_command = "whoami" result = self.execute(test_instance_command) if result.failed: - retries = 10 + retries = 100 while retries: result = self.execute(test_instance_command) @@ -380,7 +383,7 @@ def _wait_for_execute(self): break retries -= 1 - time.sleep(10) + time.sleep(1) if result.failed: raise OSError( diff --git a/pycloudlib/lxd/instance.py b/pycloudlib/lxd/instance.py index 0f223087..ccad1380 100644 --- a/pycloudlib/lxd/instance.py +++ b/pycloudlib/lxd/instance.py @@ -73,7 +73,7 @@ def ip(self): IP address assigned to instance. """ - retries = 5 + retries = 150 while retries != 0: command = 'lxc list {} -c 4 --format csv'.format(self.name) @@ -83,7 +83,7 @@ def ip(self): break retries -= 1 - time.sleep(20) + time.sleep(1) ip_address = result.split()[0] return ip_address diff --git a/pycloudlib/tests/test_instance.py b/pycloudlib/tests/test_instance.py index ab42c519..c4387634 100644 --- a/pycloudlib/tests/test_instance.py +++ b/pycloudlib/tests/test_instance.py @@ -52,14 +52,14 @@ def test_wait_execute_failure( expected_msg = "{}\n{}".format( "Instance can't be reached", "Failed to execute whoami command" ) - expected_call_args = [mock.call("whoami")] * 11 + expected_call_args = [mock.call("whoami")] * 101 with pytest.raises(OSError) as excinfo: instance.wait() assert expected_msg == str(excinfo.value) assert expected_call_args == m_execute.call_args_list - assert m_sleep.call_count == 10 + assert m_sleep.call_count == 100 class TestWaitForCloudinit: