Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict the 'start_event_grains' only to the start events #55885

Merged
merged 2 commits into from Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions salt/minion.py
Expand Up @@ -1431,7 +1431,7 @@ def _send_req_async(self, load, timeout):
ret = yield channel.send(load, timeout=timeout)
raise tornado.gen.Return(ret)

def _fire_master(self, data=None, tag=None, events=None, pretag=None, timeout=60, sync=True, timeout_handler=None):
def _fire_master(self, data=None, tag=None, events=None, pretag=None, timeout=60, sync=True, timeout_handler=None, include_startup_grains=False):
'''
Fire an event on the master, or drop message if unable to send.
'''
Expand All @@ -1450,7 +1450,7 @@ def _fire_master(self, data=None, tag=None, events=None, pretag=None, timeout=60
else:
return

if self.opts['start_event_grains']:
if include_startup_grains:
grains_to_add = dict(
[(k, v) for k, v in six.iteritems(self.opts.get('grains', {})) if k in self.opts['start_event_grains']])
load['grains'] = grains_to_add
Expand Down Expand Up @@ -2146,6 +2146,9 @@ def _refresh_grains_watcher(self, refresh_interval_in_minutes):
})

def _fire_master_minion_start(self):
include_grains = False
if self.opts['start_event_grains']:
include_grains = True
# Send an event to the master that the minion is live
if self.opts['enable_legacy_startup_events']:
# Old style event. Defaults to False in Sodium release.
Expand All @@ -2154,7 +2157,8 @@ def _fire_master_minion_start(self):
self.opts['id'],
time.asctime()
),
'minion_start'
'minion_start',
include_startup_grains=include_grains
)
# send name spaced event
self._fire_master(
Expand All @@ -2163,6 +2167,7 @@ def _fire_master_minion_start(self):
time.asctime()
),
tagify([self.opts['id'], 'start'], 'minion'),
include_startup_grains=include_grains
)

def module_refresh(self, force_refresh=False, notify=False):
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/test_minion.py
Expand Up @@ -318,7 +318,7 @@ def test_when_passed_start_event_grains(self):
try:
minion.tok = MagicMock()
minion._send_req_sync = MagicMock()
minion._fire_master('Minion has started', 'minion_start')
minion._fire_master('Minion has started', 'minion_start', include_startup_grains=True)
Ch3LL marked this conversation as resolved.
Show resolved Hide resolved
load = minion._send_req_sync.call_args[0][0]

self.assertTrue('grains' in load)
Expand All @@ -341,6 +341,22 @@ def test_when_not_passed_start_event_grains(self):
finally:
minion.destroy()

def test_when_other_events_fired_and_start_event_grains_are_set(self):
mock_opts = self.get_config('minion', from_scratch=True)
mock_opts['start_event_grains'] = ["os"]
io_loop = tornado.ioloop.IOLoop()
io_loop.make_current()
minion = salt.minion.Minion(mock_opts, io_loop=io_loop)
try:
minion.tok = MagicMock()
minion._send_req_sync = MagicMock()
minion._fire_master('Custm_event_fired', 'custom_event')
load = minion._send_req_sync.call_args[0][0]

self.assertTrue('grains' not in load)
finally:
minion.destroy()

def test_minion_retry_dns_count(self):
'''
Tests that the resolve_dns will retry dns look ups for a maximum of
Expand Down