Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions pycloudlib/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -372,15 +375,15 @@ 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)

if result.ok:
break

retries -= 1
time.sleep(10)
time.sleep(1)

if result.failed:
raise OSError(
Expand Down
4 changes: 2 additions & 2 deletions pycloudlib/lxd/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -83,7 +83,7 @@ def ip(self):
break

retries -= 1
time.sleep(20)
time.sleep(1)

ip_address = result.split()[0]
return ip_address
Expand Down
4 changes: 2 additions & 2 deletions pycloudlib/tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down