forked from TrueCloudLab/frostfs-testlib
Adding interval between ssh connection attempts
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
b039ee9940
commit
fc1f373477
1 changed files with 10 additions and 4 deletions
|
@ -91,8 +91,9 @@ class SSHShell(Shell):
|
|||
# to allow remote command to flush its output buffer
|
||||
DELAY_AFTER_EXIT = 0.2
|
||||
|
||||
SSH_CONNECTION_ATTEMPTS: ClassVar[int] = 3
|
||||
CONNECTION_TIMEOUT = 90
|
||||
SSH_CONNECTION_ATTEMPTS: ClassVar[int] = 4
|
||||
SSH_ATTEMPTS_INTERVAL: ClassVar[int] = 10
|
||||
CONNECTION_TIMEOUT = 60
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -251,7 +252,9 @@ class SSHShell(Shell):
|
|||
|
||||
return (full_stdout.decode(errors="ignore"), full_stderr.decode(errors="ignore"))
|
||||
|
||||
def _create_connection(self, attempts: int = SSH_CONNECTION_ATTEMPTS) -> SSHClient:
|
||||
def _create_connection(
|
||||
self, attempts: int = SSH_CONNECTION_ATTEMPTS, interval: int = SSH_ATTEMPTS_INTERVAL
|
||||
) -> SSHClient:
|
||||
for attempt in range(attempts):
|
||||
connection = SSHClient()
|
||||
connection.set_missing_host_key_policy(AutoAddPolicy())
|
||||
|
@ -295,7 +298,10 @@ class SSHShell(Shell):
|
|||
connection.close()
|
||||
can_retry = attempt + 1 < attempts
|
||||
if can_retry:
|
||||
logger.warn(f"Can't connect to host {self.host}, will retry. Error: {exc}")
|
||||
logger.warn(
|
||||
f"Can't connect to host {self.host}, will retry after {interval}s. Error: {exc}"
|
||||
)
|
||||
sleep(interval)
|
||||
continue
|
||||
logger.exception(f"Can't connect to host {self.host}")
|
||||
raise HostIsNotAvailable(self.host) from exc
|
||||
|
|
Loading…
Reference in a new issue