From fc1f37347783bf326e5ec9653140a613cccb2383 Mon Sep 17 00:00:00 2001 From: Andrey Berezin Date: Tue, 19 Sep 2023 11:59:05 +0300 Subject: [PATCH] Adding interval between ssh connection attempts Signed-off-by: Andrey Berezin --- src/frostfs_testlib/shell/ssh_shell.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/frostfs_testlib/shell/ssh_shell.py b/src/frostfs_testlib/shell/ssh_shell.py index 5771274..435a494 100644 --- a/src/frostfs_testlib/shell/ssh_shell.py +++ b/src/frostfs_testlib/shell/ssh_shell.py @@ -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