Merge pull request #27286 from terminalmage/return_retry_timer

Add a configurable timer for minion return retries
This commit is contained in:
Mike Place 2015-09-22 10:35:07 -06:00
commit 775a4f9ad0
2 changed files with 40 additions and 3 deletions

View File

@ -150,6 +150,8 @@ VALID_OPTS = {
'recon_max': float,
'recon_default': float,
'recon_randomize': float,
'return_retry_timer': int,
'return_retry_random': bool,
'event_return': str,
'event_return_queue': int,
'event_return_whitelist': list,
@ -413,6 +415,8 @@ DEFAULT_MINION_OPTS = {
'recon_max': 10000,
'recon_default': 1000,
'recon_randomize': True,
'return_retry_timer': 4,
'return_retry_random': True,
'syndic_log_file': os.path.join(salt.syspaths.LOGS_DIR, 'syndic'),
'syndic_pidfile': os.path.join(salt.syspaths.PIDFILE_DIR, 'salt-syndic.pid'),
'random_reauth_delay': 10,

View File

@ -21,6 +21,7 @@ import time
import traceback
import types
from random import randint, shuffle
from salt.config import DEFAULT_MINION_OPTS
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
from stat import S_IMODE
@ -901,6 +902,30 @@ class Minion(MinionBase):
self.connected = True
return opts['master']
def _return_retry_timer(self):
'''
Based on the minion configuration, either return a randomized timer or
just return the value of the return_retry_timer.
'''
msg = 'Minion return retry timer set to {0} seconds'
if self.opts['return_retry_random']:
try:
random_retry = randint(1, self.opts['return_retry_timer'])
except ValueError:
# Catch wiseguys using negative integers here
log.error(
'Invalid value ({0}) for return_retry_timer, must be a '
'positive integer'.format(self.opts['return_retry_timer'])
)
log.debug(msg.format(DEFAULT_MINION_OPTS['return_retry_timer']))
return DEFAULT_MINION_OPTS['return_retry_timer']
else:
log.debug(msg.format(random_retry) + ' (randomized)')
return random_retry
else:
log.debug(msg.format(self.opts['return_retry_timer']))
return self.opts['return_retry_timer']
def _prep_mod_opts(self):
'''
Returns a copy of the opts with key bits stripped out
@ -1253,7 +1278,10 @@ class Minion(MinionBase):
ret['metadata'] = data['metadata']
else:
log.warning('The metadata parameter must be a dictionary. Ignoring.')
minion_instance._return_pub(ret)
minion_instance._return_pub(
ret,
timeout=minion_instance._return_retry_timer()
)
if data['ret']:
if 'ret_config' in data:
ret['ret_config'] = data['ret_config']
@ -1310,7 +1338,10 @@ class Minion(MinionBase):
ret['fun_args'] = data['arg']
if 'metadata' in data:
ret['metadata'] = data['metadata']
minion_instance._return_pub(ret)
minion_instance._return_pub(
ret,
timeout=minion_instance._return_retry_timer()
)
if data['ret']:
if 'ret_config' in data:
ret['ret_config'] = data['ret_config']
@ -2316,7 +2347,9 @@ class Syndic(Minion):
pretag=tagify(self.opts['id'], base='syndic'),
)
for jid in self.jids:
self._return_pub(self.jids[jid], '_syndic_return')
self._return_pub(self.jids[jid],
'_syndic_return',
timeout=self._return_retry_timer())
self._reset_event_aggregation()
def destroy(self):