mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #38158 from cachedout/issue_38094
Fix type problem in grains.filter_by
This commit is contained in:
commit
8355adc535
2 changed files with 7 additions and 0 deletions
|
@ -558,6 +558,8 @@ def filter_by(lookup_dict, grain='os_family', merge=None, default='default', bas
|
|||
# Iterate over the list of grain values to match against patterns in the lookup_dict keys
|
||||
for each in val if isinstance(val, list) else [val]:
|
||||
for key in sorted(lookup_dict):
|
||||
if key not in six.string_types:
|
||||
key = str(key)
|
||||
if fnmatch.fnmatchcase(each, key):
|
||||
ret = lookup_dict[key]
|
||||
break
|
||||
|
|
|
@ -157,6 +157,11 @@ class GrainsModuleTestCase(TestCase):
|
|||
dict1 = {'*OS': 'B', 'C': {'D': {'E': 'F', 'G': 'H'}}}
|
||||
res = grainsmod.filter_by(dict1)
|
||||
self.assertEqual(res, 'B')
|
||||
# Test with non-strings in lookup_dict keys
|
||||
# Issue #38094
|
||||
dict1 = {1: 2, 3: {4: 5}, '*OS': 'B'}
|
||||
res = grainsmod.filter_by(dict1)
|
||||
self.assertEqual(res, 'B')
|
||||
# Test with sequence pattern with roles
|
||||
dict1 = {'Z': 'B', '[BC]': {'D': {'E': 'F', 'G': 'H'}}}
|
||||
res = grainsmod.filter_by(dict1, grain='roles', default='Z')
|
||||
|
|
Loading…
Add table
Reference in a new issue