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 pillar include regression #52490

Merged
merged 9 commits into from
Apr 17, 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
62 changes: 29 additions & 33 deletions salt/pillar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,54 +763,50 @@ 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.extend(fnmatch.filter(
matched_pstates = fnmatch.filter(
self.avail[saltenv],
sub_sls.lstrip('.').replace('/', '.'),
))
)
except KeyError:
errors.extend(
['No matching pillar environment for environment '
'\'{0}\' found'.format(saltenv)]
)

for sub_sls in set(matched_pstates):
if sub_sls not in mods:
nstate, mods, err = self.render_pstate(
sub_sls,
saltenv,
mods,
defaults
)
if nstate:
if key:
# If key is x:y, convert it to {x: {y: nstate}}
for key_fragment in reversed(key.split(":")):
nstate = {
key_fragment: nstate
}
if not self.opts.get('pillar_includes_override_sls', False):
include_states.append(nstate)
else:
state = merge(
state,
nstate,
self.merge_strategy,
self.opts.get('renderer', 'yaml'),
self.opts.get('pillar_merge_lists', False))
if err:
errors += err

matched_pstates = [sub_sls]
for m_sub_sls in matched_pstates:
if m_sub_sls not in mods:
nstate, mods, err = self.render_pstate(
m_sub_sls,
saltenv,
mods,
defaults
)
if nstate:
if key:
# If key is x:y, convert it to {x: {y: nstate}}
for key_fragment in reversed(key.split(":")):
nstate = {
key_fragment: nstate
}
if not self.opts.get('pillar_includes_override_sls', False):
include_states.append(nstate)
else:
state = merge(
state,
nstate,
self.merge_strategy,
self.opts.get('renderer', 'yaml'),
self.opts.get('pillar_merge_lists', False))
if err:
errors += err
if not self.opts.get('pillar_includes_override_sls', False):
# merge included state(s) with the current state
# merged last to ensure that its values are
Expand Down
1 change: 1 addition & 0 deletions tests/filename_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ salt/output/*:

salt/pillar/__init__.py:
- integration.minion.test_pillar
- integration.pillar.test_pillar_include

salt/(cli/run\.py|runner\.py):
- integration.shell.test_runner
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/glob_include.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include:
- 'glob_include*'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/glob_include_a.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
glob-a:
- 'Entry A'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/glob_include_b.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
glob-b:
- 'Entry B'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/include-a.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
- 'Entry A'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/include-b.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
b:
- 'Entry B'
5 changes: 5 additions & 0 deletions tests/integration/files/pillar/base/include.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include:
- include-a:
key: element:a
- include-b:
key: element:b
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/top.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ base:
- generic
- blackout
- sdb
- include
- glob_include
'sub_minion':
- sdb
- generic
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/pillar/test_pillar_include.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
'''
Pillar include tests
'''
from __future__ import absolute_import, unicode_literals

from tests.support.case import ModuleCase


class PillarIncludeTest(ModuleCase):

def test_pillar_include(self):
'''
Test pillar include
'''
ret = self.minion_run('pillar.items')
assert 'a' in ret['element']
assert ret['element']['a'] == {'a': ['Entry A']}
assert 'b' in ret['element']
assert ret['element']['b'] == {'b': ['Entry B']}

def test_pillar_glob_include(self):
'''
Test pillar include via glob pattern
'''
ret = self.minion_run('pillar.items')
assert 'glob-a' in ret
assert ret['glob-a'] == ['Entry A']
assert 'glob-b' in ret
assert ret['glob-b'] == ['Entry B']
1 change: 1 addition & 0 deletions tests/unit/test_module_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_module_name_source_match(self):
'integration.netapi.rest_tornado.test_app',
'integration.netapi.rest_cherrypy.test_app_pam',
'integration.output.test_output',
'integration.pillar.test_pillar_include',
'integration.proxy.test_shell',
'integration.proxy.test_simple',
'integration.reactor.test_reactor',
Expand Down