Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions krater/compute/ssh_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

def probe_tcp(host: str, port: int) -> bool | None:
"""`True` when a TCP connection to `host:port` opens, `False` when it is refused, `None` with no answer."""
if not 1 <= port <= 65535:
return None # Linux would take it modulo 65536 and test another port
try:
with socket.create_connection((host, port), timeout=CONNECT_TIMEOUT_SECONDS):
return True
Expand Down
9 changes: 9 additions & 0 deletions tests/compute/test_ssh_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,12 @@ def test_a_proxy_that_changes_host_keeps_the_box_off_the_dead_port(db_session, m
_checked_pass(db_session, client, _Check(True), 12) # quiet runner: untested

assert row.ssh_host == "ssh7.vast.ai"


def test_a_timeout_is_no_answer(monkeypatch) -> None:
def times_out(*args, **kwargs):
raise TimeoutError

monkeypatch.setattr(ssh_reach.socket, "create_connection", times_out)

assert ssh_reach.probe_tcp("38.114.93.198", 20056) is None
Loading