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

fix dns_check to return uri-compatible ipv6 addresses, add tests #54784

Merged
merged 4 commits into from
Sep 28, 2019
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: 1 addition & 1 deletion requirements/static/py2.7/raet-amzn-2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-amzn-2018.03.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-arch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ kubernetes==3.0.0
libnacl==1.6.1
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-centos-6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-centos-7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-debian-8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-debian-9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-fedora-29.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-fedora-30.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-opensuse-leap-15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kubernetes==3.0.0
libnacl==1.6.1
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-osx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ lxml==4.3.3 # via junos-eznc, ncclient
mako==1.0.7
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-ubuntu-16.04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-ubuntu-18.04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ libnacl==1.6.1
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/raet-windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ lxml==4.3.0
mako==1.0.7
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-amzn-2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-amzn-2018.03.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-arch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ keyring==5.7.1
kubernetes==3.0.0
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-centos-6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-centos-7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-debian-8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-debian-9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-fedora-29.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-fedora-30.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-opensuse-leap-15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ keyring==5.7.1
kubernetes==3.0.0
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-osx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ lxml==4.3.3 # via junos-eznc, ncclient
mako==1.0.7
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-ubuntu-16.04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-ubuntu-18.04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kubernetes==3.0.0
lxml==4.3.3 # via junos-eznc, ncclient
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/static/py2.7/zeromq-windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lxml==4.3.0
mako==1.0.7
markupsafe==1.1.1
meld3==1.0.2 # via supervisor
mock==2.0.0 ; python_version < "3.6"
mock==3.0.5 ; python_version < "3.6"
more-itertools==5.0.0
moto==1.3.7
msgpack-python==0.5.6
Expand Down
89 changes: 40 additions & 49 deletions salt/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,61 +1899,25 @@ def refresh_dns():
@jinja_filter('dns_check')
def dns_check(addr, port, safe=False, ipv6=None):
'''
Return the ip resolved by dns, but do not exit on failure, only raise an
exception. Obeys system preference for IPv4/6 address resolution - this
can be overridden by the ipv6 flag.
Tries to connect to the address before considering it useful. If no address
can be reached, the first one resolved is used as a fallback.
'''
error = False
lookup = addr
seen_ipv6 = False
Return an ip address resolved by dns in a format usable in URLs (ipv6 in brackets).
Obeys system preference for IPv4/6 address resolution - this can be overridden by
the ipv6 flag. Tries to connect to the address before considering it useful. If no
address can be reached, the first one resolved is used as a fallback.
Does not exit on failure, raises an exception.
'''
ip_addrs = []
family = socket.AF_INET6 if ipv6 else socket.AF_INET if ipv6 is False else socket.AF_UNSPEC
try:
refresh_dns()
hostnames = socket.getaddrinfo(addr, port, family, socket.SOCK_STREAM)
if not hostnames:
error = True
else:
resolved = False
candidates = []
for h in hostnames:
# Input is IP address, passed through unchanged, just return it
if h[4][0] == addr:
resolved = salt.utils.zeromq.ip_bracket(addr)
break

if h[0] == socket.AF_INET and ipv6 is True:
continue
if h[0] == socket.AF_INET6 and ipv6 is False:
continue

candidate_addr = h[4][0]

if h[0] != socket.AF_INET6 or ipv6 is not None:
candidates.append(candidate_addr)

try:
s = socket.socket(h[0], socket.SOCK_STREAM)
s.connect((candidate_addr, port))
s.close()

resolved = candidate_addr
break
except socket.error:
pass
if not resolved:
if len(candidates) > 0:
resolved = candidates[0]
else:
error = True
addrinfo = socket.getaddrinfo(addr, port, family, socket.SOCK_STREAM)
ip_addrs = _test_addrs(addrinfo, port)
except TypeError:
err = ('Attempt to resolve address \'{0}\' failed. Invalid or unresolveable address').format(lookup)
err = ('Attempt to resolve address \'{0}\' failed. Invalid or unresolveable address').format(addr)
raise SaltSystemExit(code=42, msg=err)
except socket.error:
error = True
pass

if error:
if not ip_addrs:
err = ('DNS lookup or connection check of \'{0}\' failed.').format(addr)
if safe:
if salt.log.is_console_configured():
Expand All @@ -1963,7 +1927,34 @@ def dns_check(addr, port, safe=False, ipv6=None):
log.error(err)
raise SaltClientError()
raise SaltSystemExit(code=42, msg=err)
return resolved

return salt.utils.zeromq.ip_bracket(ip_addrs[0])


def _test_addrs(addrinfo, port):
'''
Attempt to connect to all addresses, return one if it succeeds.
Otherwise, return all addrs.
'''
ip_addrs = []
# test for connectivity, short circuit on success
for a in addrinfo:
ip_family = a[0]
ip_addr = a[4][0]
if ip_addr in ip_addrs:
continue
ip_addrs.append(ip_addr)

try:
s = socket.socket(ip_family, socket.SOCK_STREAM)
s.connect((ip_addr, port))
s.close()

ip_addrs = [ip_addr]
break
except socket.error:
pass
return ip_addrs


def parse_host_port(host_port):
Expand Down
Loading