From c19d0b0ce34055d7ec64a266ab68937339caf1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Thu, 26 Sep 2019 14:31:24 -0300 Subject: [PATCH 1/2] Fix minion's remove_periodic_callback() --- salt/minion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/minion.py b/salt/minion.py index d1c0c00751a2..28b4956a49c4 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -2730,7 +2730,7 @@ def ping_timeout_handler(*_): self._fire_master('ping', 'minion_ping', sync=False, timeout_handler=ping_timeout_handler) except Exception: log.warning('Attempt to ping master failed.', exc_on_loglevel=logging.DEBUG) - self.remove_periodic_callbback('ping', ping_master) + self.remove_periodic_callback('ping') self.add_periodic_callback('ping', ping_master, ping_interval) # add handler to subscriber From a57f7d0affa25c739e82b7c3e56b556d6cc0d1ab Mon Sep 17 00:00:00 2001 From: Wayne Werner Date: Thu, 26 Sep 2019 12:27:27 -0600 Subject: [PATCH 2/2] Add tests --- tests/unit/test_minion.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/unit/test_minion.py b/tests/unit/test_minion.py index 90b529201816..b78e0f6abd8d 100644 --- a/tests/unit/test_minion.py +++ b/tests/unit/test_minion.py @@ -282,6 +282,29 @@ def test_scheduler_before_connect(self): finally: minion.destroy() + def test_when_ping_interval_is_set_the_callback_should_be_added_to_periodic_callbacks(self): + with patch('salt.minion.Minion.ctx', MagicMock(return_value={})), \ + patch('salt.minion.Minion.sync_connect_master', MagicMock(side_effect=RuntimeError('stop execution'))), \ + patch('salt.utils.process.SignalHandlingMultiprocessingProcess.start', MagicMock(return_value=True)), \ + patch('salt.utils.process.SignalHandlingMultiprocessingProcess.join', MagicMock(return_value=True)): + mock_opts = self.get_config('minion', from_scratch=True) + mock_opts['ping_interval'] = 10 + io_loop = tornado.ioloop.IOLoop() + io_loop.make_current() + minion = salt.minion.Minion(mock_opts, io_loop=io_loop) + try: + try: + minion.connected = MagicMock(side_effect=(False, True)) + minion._fire_master_minion_start = MagicMock() + minion.tune_in(start=False) + except RuntimeError: + pass + + # Make sure the scheduler is initialized but the beacons are not + self.assertTrue('ping' in minion.periodic_callbacks) + finally: + minion.destroy() + def test_minion_retry_dns_count(self): ''' Tests that the resolve_dns will retry dns look ups for a maximum of