Merge pull request #41918 from rongzeng54/develop

force glibc to re-read resolv.conf for fix unexpected error dns parsing
This commit is contained in:
Mike Place 2017-06-23 11:39:20 -05:00 committed by GitHub
commit aff5d76081
2 changed files with 14 additions and 3 deletions

View File

@ -763,6 +763,14 @@ def ip_bracket(addr):
return addr return addr
def refresh_dns():
'''
issue #21397: force glibc to re-read resolv.conf
'''
if HAS_RESINIT:
res_init()
@jinja_filter('dns_check') @jinja_filter('dns_check')
def dns_check(addr, port, safe=False, ipv6=None): def dns_check(addr, port, safe=False, ipv6=None):
''' '''
@ -775,9 +783,7 @@ def dns_check(addr, port, safe=False, ipv6=None):
lookup = addr lookup = addr
seen_ipv6 = False seen_ipv6 = False
try: try:
# issue #21397: force glibc to re-read resolv.conf refresh_dns()
if HAS_RESINIT:
res_init()
hostnames = socket.getaddrinfo( hostnames = socket.getaddrinfo(
addr, None, socket.AF_UNSPEC, socket.SOCK_STREAM addr, None, socket.AF_UNSPEC, socket.SOCK_STREAM
) )

View File

@ -15,6 +15,7 @@ import os.path
import pprint import pprint
import socket import socket
import yaml import yaml
import re
import ssl import ssl
try: try:
@ -157,6 +158,10 @@ def query(url,
if not backend: if not backend:
backend = opts.get('backend', 'tornado') backend = opts.get('backend', 'tornado')
match = re.match(r'https?://((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)($|/)', url)
if not match:
salt.utils.refresh_dns()
if backend == 'requests': if backend == 'requests':
if HAS_REQUESTS is False: if HAS_REQUESTS is False:
ret['error'] = ('http.query has been set to use requests, but the ' ret['error'] = ('http.query has been set to use requests, but the '