Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Handle connection to IPv6 hosts #51

Merged
merged 1 commit into from
Apr 20, 2020
Merged
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
20 changes: 11 additions & 9 deletions runner_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,20 @@ def timeout_handler():
raise SSHTimeout

socket.setdefaulttimeout(self.timeout)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((self.host, self.port))
family, *_, sockaddr = socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM, socket.SOL_TCP)[0]
except socket.gaierror:
raise HostNotFound
except ConnectionRefusedError:
raise SSHNotAccessible
except socket.timeout:
raise SSHTimeout
else:
s.shutdown(socket.SHUT_RDWR)
s.close()

with socket.socket(family, socket.SOCK_STREAM, socket.SOL_TCP) as s:
try:
s.connect(sockaddr)
except ConnectionRefusedError:
raise SSHNotAccessible
except socket.timeout:
raise SSHTimeout
else:
s.shutdown(socket.SHUT_RDWR)

# Now try and use the identity file to passwordless ssh
cmd = ('ssh -o "StrictHostKeyChecking=no" '
Expand Down