Created
September 24, 2018 17:17
-
-
Save garethgreenaway/c907c91ad22ec3bb22c069286dc085c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/salt/config/__init__.py b/salt/config/__init__.py | |
index 9c4e6bd7c4..38494079e3 100644 | |
--- a/salt/config/__init__.py | |
+++ b/salt/config/__init__.py | |
@@ -518,6 +518,7 @@ VALID_OPTS = { | |
# The number of seconds to sleep between retrying an attempt to resolve the hostname of a | |
# salt master | |
'retry_dns': float, | |
+ 'retry_dns_count': float, | |
# In the case when the resolve of the salt master hostname fails, fall back to localhost | |
'resolve_dns_fallback': bool, | |
@@ -1397,6 +1398,7 @@ DEFAULT_MINION_OPTS = { | |
'update_url': False, | |
'update_restart_services': [], | |
'retry_dns': 30, | |
+ 'retry_dns_count': 3, | |
'resolve_dns_fallback': True, | |
'recon_max': 10000, | |
'recon_default': 1000, | |
diff --git a/salt/minion.py b/salt/minion.py | |
index af2f1d10a9..ce9405ffbe 100644 | |
--- a/salt/minion.py | |
+++ b/salt/minion.py | |
@@ -157,6 +157,7 @@ def resolve_dns(opts, fallback=True): | |
True, | |
opts['ipv6']) | |
except SaltClientError: | |
+ retry_dns_count = opts.get('retry_dns_count', None) | |
if opts['retry_dns']: | |
while True: | |
import salt.log | |
@@ -176,6 +177,12 @@ def resolve_dns(opts, fallback=True): | |
break | |
except SaltClientError: | |
pass | |
+ if retry_dns_count is not None: | |
+ if retry_dns_count == 0: | |
+ ret['master_ip'] = '127.0.0.1' | |
+ opts['dns_check_failed'] = True | |
+ break | |
+ retry_dns_count -= 1 | |
else: | |
if fallback: | |
ret['master_ip'] = '127.0.0.1' | |
@@ -669,6 +676,7 @@ class MinionBase(object): | |
yield tornado.gen.sleep(opts['acceptance_wait_time']) | |
attempts += 1 | |
if tries > 0: | |
+ | |
log.debug( | |
'Connecting to master. Attempt %s of %s', | |
attempts, tries | |
@@ -679,6 +687,11 @@ class MinionBase(object): | |
attempts | |
) | |
opts.update(prep_ip_port(opts)) | |
+ _opts = resolve_dns(opts) | |
+ if _opts['master_ip'] is None: | |
+ self.connected = False | |
+ break | |
+ | |
opts.update(resolve_dns(opts)) | |
try: | |
if self.opts['transport'] == 'detect': | |
@@ -1003,6 +1016,16 @@ class MinionManager(MinionBase): | |
'Error while bringing up minion for multi-master. Is ' | |
'master at %s responding?', minion.opts['master'] | |
) | |
+ if minion.opts.get('dns_check_failed', False): | |
+ err = 'Master address: \'{0}\' could not be resolved. Invalid or unresolveable address. ' \ | |
+ 'Set \'master\' value in minion config.'.format(minion.opts['master']) | |
+ log.error(err) | |
+ log.error( | |
+ 'Destroying minion connected to ' | |
+ 'master at %s', minion.opts['master'] | |
+ ) | |
+ minion.destroy() | |
+ break | |
last = time.time() | |
if auth_wait < self.max_auth_wait: | |
auth_wait += self.auth_wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment