Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ssh timeout #311

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions ducktape/cluster/remoteaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 @@ -57,6 +58,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 @@ -188,7 +191,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