Skip to content

Commit

Permalink
support ssh timeout (confluentinc#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-is-hate authored and gousteris committed Aug 30, 2023
1 parent 809e3d8 commit 47c4d12
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions ducktape/cluster/remoteaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def wrapper(self, *args, **kwargs):


class RemoteAccountSSHConfig(object):
def __init__(self, host=None, hostname=None, user=None, port=None, password=None, identityfile=None, **kwargs):
def __init__(self, host=None, hostname=None, user=None, port=None, password=None, identityfile=None,
connecttimeout=None, **kwargs):
"""Wrapper for ssh configs used by ducktape to connect to remote machines.
The fields in this class are lowercase versions of a small selection of ssh config properties
Expand All @@ -63,6 +64,8 @@ def __init__(self, host=None, hostname=None, user=None, port=None, password=None
self.port = int(self.port)
self.password = password
self.identityfile = identityfile
# None is default, and it means default TCP timeout will be used.
self.connecttimeout = int(connecttimeout) if connecttimeout is not None else None

@staticmethod
def from_string(config_str):
Expand Down Expand Up @@ -194,7 +197,8 @@ def _set_ssh_client(self):
username=self.ssh_config.user,
password=self.ssh_config.password,
key_filename=self.ssh_config.identityfile,
look_for_keys=False)
look_for_keys=False,
timeout=self.ssh_config.connecttimeout)

if self._ssh_client:
self._ssh_client.close()
Expand Down
6 changes: 4 additions & 2 deletions tests/cluster/check_remoteaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ def check_wait_for_http_timeout(self):
[raise_error_checker, raise_no_error_checker]])
def check_ssh_checker(self, checkers):
self.server.start()
self.account = RemoteAccount(RemoteAccountSSHConfig.from_string(
ssh_config = RemoteAccountSSHConfig.from_string(
"""
Host dummy_host.com
Hostname dummy_host.name.com
Port 22
User dummy
"""), ssh_exception_checks=checkers)
ConnectTimeout 1
""")
self.account = RemoteAccount(ssh_config, ssh_exception_checks=checkers)
with pytest.raises(DummyException):
self.account.ssh('echo test')

Expand Down
9 changes: 6 additions & 3 deletions tests/cluster/check_vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def check_cluster_file_write(self, monkeypatch):
"user": node_account.ssh_config.user,
"identityfile": node_account.ssh_config.identityfile,
"password": node_account.ssh_config.password,
"port": node_account.ssh_config.port
"port": node_account.ssh_config.port,
"connecttimeout": None
}
}
for node_account in cluster._available_accounts
Expand Down Expand Up @@ -135,7 +136,8 @@ def check_cluster_file_read(self, monkeypatch):
"user": "vagrant",
"port": 2222,
"password": "password",
"identityfile": "/path/to/identfile3"
"identityfile": "/path/to/identfile3",
"connecttimeout": None
}
}
nodes_expected.append(node1_expected)
Expand All @@ -148,7 +150,8 @@ def check_cluster_file_read(self, monkeypatch):
"user": "vagrant",
"port": 2223,
"password": None,
"identityfile": "/path/to/indentfile2"
"identityfile": "/path/to/indentfile2",
"connecttimeout": 10
}
}
nodes_expected.append(node2_expected)
Expand Down

0 comments on commit 47c4d12

Please sign in to comment.