SHA256
1
0
forked from pool/salt
salt/restrict-the-start_event_grains-only-to-the-start-ev.patch

103 lines
3.9 KiB
Diff

From 127f0fa48ed2e5f05320c6c82f928f0d59a94bd9 Mon Sep 17 00:00:00 2001
From: Abid Mehmood <amehmood@suse.de>
Date: Thu, 16 Jan 2020 11:28:04 +0100
Subject: [PATCH] Restrict the 'start_event_grains' only to the start
events
add test for custom events
---
salt/minion.py | 11 ++++++++---
tests/unit/test_minion.py | 18 +++++++++++++++++-
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/salt/minion.py b/salt/minion.py
index 2b53da4f18..a2fb203bfe 100644
--- a/salt/minion.py
+++ b/salt/minion.py
@@ -1437,7 +1437,7 @@ class Minion(MinionBase):
finally:
channel.close()
- 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.
'''
@@ -1456,7 +1456,7 @@ class Minion(MinionBase):
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
@@ -2149,6 +2149,9 @@ class Minion(MinionBase):
})
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.
@@ -2157,7 +2160,8 @@ class Minion(MinionBase):
self.opts['id'],
time.asctime()
),
- 'minion_start'
+ 'minion_start',
+ include_startup_grains=include_grains
)
# send name spaced event
self._fire_master(
@@ -2166,6 +2170,7 @@ class Minion(MinionBase):
time.asctime()
),
tagify([self.opts['id'], 'start'], 'minion'),
+ include_startup_grains=include_grains
)
def module_refresh(self, force_refresh=False, notify=False):
diff --git a/tests/unit/test_minion.py b/tests/unit/test_minion.py
index 83215151ee..41dfab0f45 100644
--- a/tests/unit/test_minion.py
+++ b/tests/unit/test_minion.py
@@ -314,7 +314,7 @@ class MinionTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
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)
load = minion._send_req_sync.call_args[0][0]
self.assertTrue('grains' in load)
@@ -337,6 +337,22 @@ class MinionTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
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
--
2.16.4