From 7a4b15302016414fac3feed6921065dfc788b64d Mon Sep 17 00:00:00 2001 From: zr Date: Fri, 23 Jun 2017 22:08:59 +0800 Subject: [PATCH] - move the task of re-reading resolv.conf to a function - call the function of re-reading resolv.conf when the http server use domain name --- salt/utils/__init__.py | 12 +++++++++--- salt/utils/http.py | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index b39fda4165..d51dd07f65 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -763,6 +763,14 @@ def ip_bracket(addr): return addr +def refresh_dns(): + ''' + issue #21397: force glibc to re-read resolv.conf + ''' + if HAS_RESINIT: + res_init() + + @jinja_filter('dns_check') def dns_check(addr, port, safe=False, ipv6=None): ''' @@ -775,9 +783,7 @@ def dns_check(addr, port, safe=False, ipv6=None): lookup = addr seen_ipv6 = False try: - # issue #21397: force glibc to re-read resolv.conf - if HAS_RESINIT: - res_init() + refresh_dns() hostnames = socket.getaddrinfo( addr, None, socket.AF_UNSPEC, socket.SOCK_STREAM ) diff --git a/salt/utils/http.py b/salt/utils/http.py index 935bfb3a7f..51c50b00f7 100644 --- a/salt/utils/http.py +++ b/salt/utils/http.py @@ -15,6 +15,7 @@ import os.path import pprint import socket import yaml +import re import ssl try: @@ -157,6 +158,10 @@ def query(url, if not backend: 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 HAS_REQUESTS is False: ret['error'] = ('http.query has been set to use requests, but the '