add disable option to 'master_type' minion config token

It's desirable to have a minion running without it trying to access a
master since, with engines on the minion support, the minion (via
engines) can perform tasks that don't require a master connection.

Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com>
This commit is contained in:
Alejandro del Castillo 2016-03-09 18:28:45 +00:00
parent 538ec983f7
commit 4277ac6d90
3 changed files with 26 additions and 15 deletions

View File

@ -38,6 +38,8 @@
# value to "str". Failover masters can be requested by setting
# to "failover". MAKE SURE TO SET master_alive_interval if you are
# using failover.
# Setting master_type to 'disable' let's you have a running minion (with engines and
# beacons) without a master connection
# master_type: str
# Poll interval in seconds for checking if the master is still there. Only

View File

@ -70,8 +70,9 @@ VALID_OPTS = {
'master_port': int,
# The behaviour of the minion when connecting to a master. Can specify 'failover',
# or 'func'. If 'func' is specified, the 'master' option should be set to an exec
# module function to run to determine the master hostname.
# 'disable' or 'func'. If 'func' is specified, the 'master' option should be set to an
# exec module function to run to determine the master hostname. If 'disable' is specified
# the minion will run, but will not try to connect to a master.
'master_type': str,
# Specify the format in which the master address will be specified. Can

View File

@ -396,8 +396,13 @@ class MinionBase(object):
loss was detected), 'failed' should be set to True. The current
(possibly failed) master will then be removed from the list of masters.
'''
# return early if we are not connecting to a master
if opts['master_type'] == 'disable':
log.warning('Master is set to disable, skipping connection')
self.connected = False
raise tornado.gen.Return((None, None))
# check if master_type was altered from its default
if opts['master_type'] != 'str' and opts['__role'] != 'syndic':
elif opts['master_type'] != 'str' and opts['__role'] != 'syndic':
# check for a valid keyword
if opts['master_type'] == 'func':
# split module and function and try loading the module
@ -854,16 +859,18 @@ class Minion(MinionBase):
This is primarily loading modules, pillars, etc. (since they need
to know which master they connected to)
'''
self.opts['master'] = master
if self.connected:
self.opts['master'] = master
# Initialize pillar before loader to make pillar accessible in modules
self.opts['pillar'] = yield salt.pillar.get_async_pillar(
self.opts,
self.opts['grains'],
self.opts['id'],
self.opts['environment'],
pillarenv=self.opts.get('pillarenv')
).compile_pillar()
# Initialize pillar before loader to make pillar accessible in modules
self.opts['pillar'] = yield salt.pillar.get_async_pillar(
self.opts,
self.opts['grains'],
self.opts['id'],
self.opts['environment'],
pillarenv=self.opts.get('pillarenv')
).compile_pillar()
self.functions, self.returners, self.function_errors, self.executors = self._load_modules()
self.serial = salt.payload.Serial(self.opts)
self.mod_opts = self._prep_mod_opts()
@ -895,7 +902,8 @@ class Minion(MinionBase):
# add master_alive job if enabled
if (self.opts['transport'] != 'tcp' and
self.opts['master_alive_interval'] > 0):
self.opts['master_alive_interval'] > 0 and
self.connected):
self.schedule.add_job({
'__master_alive':
{
@ -1917,7 +1925,7 @@ class Minion(MinionBase):
periodic_cb.start()
# add handler to subscriber
if hasattr(self, 'pub_channel'):
if hasattr(self, 'pub_channel') and self.pub_channel is not None:
self.pub_channel.on_recv(self._handle_payload)
else:
log.error('No connection to master found. Scheduled jobs will not run.')
@ -1976,7 +1984,7 @@ class Minion(MinionBase):
self._running = False
if hasattr(self, 'schedule'):
del self.schedule
if hasattr(self, 'pub_channel'):
if hasattr(self, 'pub_channel') and self.pub_channel is not None:
self.pub_channel.on_recv(None)
if hasattr(self.pub_channel, 'close'):
self.pub_channel.close()