def test_minion_module_refresh_beacons_refresh(tmp_path): """ Tests that 'module_refresh' calls beacons_refresh and that the minion object has a beacons attribute with beacons. """ with patch("salt.minion.Minion.ctx", MagicMock(return_value={})), patch( "salt.utils.process.SignalHandlingProcess.start", MagicMock(return_value=True), ), patch( "salt.utils.process.SignalHandlingProcess.join", MagicMock(return_value=True), ): try: mock_opts = salt.config.DEFAULT_MINION_OPTS.copy() mock_opts["cachedir"] = str(tmp_path) minion = salt.minion.Minion( mock_opts, io_loop=salt.ext.tornado.ioloop.IOLoop(), ) minion.schedule = salt.utils.schedule.Schedule(mock_opts, {}, returners={}) assert not hasattr(minion, "beacons") minion.module_refresh() assert hasattr(minion, "beacons") assert hasattr(minion.beacons, "beacons") assert "service.beacon" in minion.beacons.beacons minion.destroy() finally: minion.destroy()
def test_minion_module_refresh(tmp_path): """ Tests that the 'module_refresh' just return in case there is no 'schedule' because destroy method was already called. """ with patch("salt.minion.Minion.ctx", MagicMock(return_value={})), patch( "salt.utils.process.SignalHandlingProcess.start", MagicMock(return_value=True), ), patch( "salt.utils.process.SignalHandlingProcess.join", MagicMock(return_value=True), ): try: mock_opts = salt.config.DEFAULT_MINION_OPTS.copy() mock_opts["cachedir"] = str(tmp_path) minion = salt.minion.Minion( mock_opts, io_loop=salt.ext.tornado.ioloop.IOLoop(), ) minion.schedule = salt.utils.schedule.Schedule(mock_opts, {}, returners={}) assert hasattr(minion, "schedule") minion.destroy() assert not hasattr(minion, "schedule") assert not minion.module_refresh() finally: minion.destroy()