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

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions runner_service/utils.py
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