Add a sleep with back-off to retries
The current implementation retries on socket error
without a sleep, and on auth error with a fixed
interval sleep. Replacing all with an exp backoff.
Default sleep time set to 1.5, default backoff 1.01.
Fixes bug #1180213
Change-Id: I764f2aa4f2c0f8e04718d69b842a574db7aca936
diff --git a/tempest/common/ssh.py b/tempest/common/ssh.py
index 448708e..04cc851 100644
--- a/tempest/common/ssh.py
+++ b/tempest/common/ssh.py
@@ -47,9 +47,10 @@
self.channel_timeout = float(channel_timeout)
self.buf_size = 1024
- def _get_ssh_connection(self):
+ def _get_ssh_connection(self, sleep=1.5, backoff=1.01):
"""Returns an ssh connection to the specified host."""
_timeout = True
+ bsleep = sleep
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
@@ -64,10 +65,10 @@
timeout=self.timeout, pkey=self.pkey)
_timeout = False
break
- except socket.error:
- continue
- except paramiko.AuthenticationException:
- time.sleep(5)
+ except (socket.error,
+ paramiko.AuthenticationException):
+ time.sleep(bsleep)
+ bsleep *= backoff
continue
if _timeout:
raise exceptions.SSHTimeout(host=self.host,