diff --git a/salt/modules/match.py b/salt/modules/match.py index ac16e1b23cc7..139f5aca9346 100644 --- a/salt/modules/match.py +++ b/salt/modules/match.py @@ -11,7 +11,6 @@ import copy # Import salt libs -import salt.minion import salt.loader from salt.defaults import DEFAULT_TARGET_DELIM from salt.ext import six @@ -47,7 +46,7 @@ def compound(tgt, minion_id=None): opts = __opts__ matchers = salt.loader.matchers(opts) try: - return matchers['compound_match.match'](tgt, opts=opts) + return matchers['compound_match.match'](tgt) except Exception as exc: log.exception(exc) return False diff --git a/tests/unit/modules/test_match.py b/tests/unit/modules/test_match.py index 1b9da2b1c0d6..fc1139966637 100644 --- a/tests/unit/modules/test_match.py +++ b/tests/unit/modules/test_match.py @@ -18,6 +18,7 @@ ) # Import Salt Libs +import salt.loader import salt.modules.match as match import salt.matchers.compound_match as compound_match import salt.matchers.glob_match as glob_match @@ -61,6 +62,43 @@ def setup_loader_modules(self): } } + def test_compound_with_minion_id(self): + ''' + Make sure that when a minion_id IS past, that it is contained in opts + ''' + mock_compound_match = MagicMock() + target = 'bar04' + new_minion_id = 'new_minion_id' + + with patch.object(salt.loader, 'matchers', return_value={'compound_match.match': mock_compound_match}) as matchers: + match.compound(target, minion_id=new_minion_id) + + # The matcher should get called with MINION_ID + matchers.assert_called_once() + matchers_opts = matchers.call_args[0][0] + self.assertEqual(matchers_opts.get('id'), new_minion_id) + + # The compound matcher should not get MINION_ID, no opts should be passed + mock_compound_match.assert_called_once_with(target) + + def test_compound(self): + ''' + Test issue #55149 + ''' + mock_compound_match = MagicMock() + target = 'bar04' + + with patch.object(salt.loader, 'matchers', return_value={'compound_match.match': mock_compound_match}) as matchers: + match.compound(target) + + # The matcher should get called with MINION_ID + matchers.assert_called_once() + self.assertEqual(len(matchers.call_args[0]), 1) + self.assertEqual(matchers.call_args[0][0].get('id'), MINION_ID) + + # The compound matcher should not get MINION_ID, no opts should be passed + mock_compound_match.assert_called_once_with(target) + def test_filter_by(self): ''' Tests if filter_by returns the correct dictionary.