First pass at an automated check in the minion tune-in loop, using a threaded approach to periodically refresh the master if the grains on a minion have changed.

This commit is contained in:
Mike Place 2013-10-18 12:56:54 -06:00
parent 4b013d9b90
commit b5c6ead7a6
3 changed files with 45 additions and 0 deletions

View File

@ -182,6 +182,15 @@
# often lower this value
#loop_interval: 60
# The grains_refresh_every setting allows for a minion to periodically check
# its grains to see if they have changed and, if so, to inform the master
# of the new grains. This operation is moderately expensive, therefore
# care should be taken not to set this value too low. A value of 600 seconds
# is a reasonable place to start.
#
# If the value is set to zero, this check is disabled.
grains_refresh_every = 0
# When healing, a dns_check is run. This is to make sure that the originally
# resolved dns has not changed. If this is something that does not happen in
# your environment, set this value to False.

View File

@ -165,6 +165,7 @@ VALID_OPTS = {
'win_repo_mastercachefile': str,
'win_gitrepos': list,
'modules_max_memory': int,
'grains_refresh_every': int,
}
# default configurations
@ -252,6 +253,7 @@ DEFAULT_MINION_OPTS = {
'tcp_keepalive_cnt': -1,
'tcp_keepalive_intvl': -1,
'modules_max_memory': -1,
'grains_refresh_every': 0,
}
DEFAULT_MASTER_OPTS = {

View File

@ -911,6 +911,24 @@ class Minion(object):
data['arg'] = []
self._handle_decoded_payload(data)
def _refresh_grains_watcher(self, refresh_interval_in_seconds):
'''
Create a loop that will fire a pillar refresh to inform a master about a change in the grains of this minion
:param refresh_interval_in_seconds:
:return: None
'''
def _do_refresh():
if grain_cache != self.opts['grains']:
log.debug('Grain refresh is launching Pillar refresh!')
self.pillar_refresh()
threading.Timer(refresh_interval_in_seconds, _do_refresh).start()
grain_cache = self.opts['grains']
threading.Timer(refresh_interval_in_seconds, _do_refresh).start()
log.debug('Starting grain refresh routine')
@property
def master_pub(self):
'''
@ -982,6 +1000,7 @@ class Minion(object):
def tune_in(self):
'''
Lock onto the publisher. This is the main event loop for the minion
:rtype : None
'''
try:
log.info(
@ -1134,6 +1153,21 @@ class Minion(object):
time.sleep(.5)
loop_interval = int(self.opts['loop_interval'])
# Calculate the refresh interval for grain refresh
if loop_interval and self.opts['grains_refresh_every']:
grains_refresh_interval = self.opts['grains_refresh_every']
if loop_interval > grains_refresh_interval: # We can't refresh grains more frequently
# than we check for events
grains_refresh_interval = int(int(self.opts['grains_refresh_every']) / (loop_interval * 1000))
try:
if grains_refresh_interval:
self._refresh_grains_watcher(grains_refresh_interval)
except Exception:
log.error(
'Exception occurred in attempt to initialize grain refresh routine during minion tune-in'
)
while True:
try:
self.schedule.eval()