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

Fixed issue #55149 #55497

Merged
merged 6 commits into from
Dec 12, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions salt/modules/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/modules/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down