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

Fix #22063: pillar wildcard support include #45269

Merged
merged 19 commits into from Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions salt/pillar/__init__.py
Expand Up @@ -754,13 +754,25 @@ def render_pstate(self, sls, saltenv, mods, defaults=None):
else:
# render included state(s)
include_states = []

matched_pstates = []
for sub_sls in state.pop('include'):
if isinstance(sub_sls, dict):
sub_sls, v = next(six.iteritems(sub_sls))
defaults = v.get('defaults', {})
key = v.get('key', None)
else:
key = None

try:
matched_pstates = fnmatch.filter(self.avail[saltenv], sub_sls)
except KeyError:
errors.extend(
['No matching pillar environment for environment '
'\'{0}\' found'.format(saltenv)]
)

for sub_sls in matched_pstates:
if sub_sls not in mods:
nstate, mods, err = self.render_pstate(
sub_sls,
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test_pillar.py
Expand Up @@ -296,7 +296,8 @@ def test_ext_pillar_with_extra_minion_data_val_elem(self):
'mocked-minion', 'fake_pillar', 'bar',
extra_minion_data={'fake_key': 'foo'})

def test_malformed_pillar_sls(self):
@patch('salt.fileclient.Client.list_states')
def test_malformed_pillar_sls(self, mock_list_states):
with patch('salt.pillar.compile_template') as compile_template:
opts = {
'renderer': 'json',
Expand All @@ -315,6 +316,7 @@ def test_malformed_pillar_sls(self):
'osrelease': '13.04',
'kernel': 'Linux'
}
mock_list_states.return_value = ['foo', 'blah']
pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base')
# Mock getting the proper template files
pillar.client.get_state = MagicMock(
Expand Down Expand Up @@ -366,6 +368,16 @@ def test_malformed_pillar_sls(self):
({'foo': 'bar', 'foo2': 'bar2'}, [])
)

# Test includes as a list with wildcard
compile_template.side_effect = [
{'foo': 'bar', 'include': ['bl*']},
{'foo2': 'bar2'}
]
self.assertEqual(
pillar.render_pillar({'base': ['foo.sls']}),
({'foo': 'bar', 'foo2': 'bar2'}, [])
)

# Test includes as a list overriding data
compile_template.side_effect = [
{'foo': 'bar', 'include': ['blah']},
Expand Down