Skip to content

Commit

Permalink
Merge pull request #52490 from dwoz/issue_52134
Browse files Browse the repository at this point in the history
Fix pillar include regression
  • Loading branch information
dwoz committed Apr 17, 2019
2 parents b0c0237 + 876dd18 commit 9faa49c
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 33 deletions.
62 changes: 29 additions & 33 deletions salt/pillar/__init__.py
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
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
@@ -0,0 +1,2 @@
include:
- 'glob_include*'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/glob_include_a.sls
@@ -0,0 +1,2 @@
glob-a:
- 'Entry A'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/glob_include_b.sls
@@ -0,0 +1,2 @@
glob-b:
- 'Entry B'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/include-a.sls
@@ -0,0 +1,2 @@
a:
- 'Entry A'
2 changes: 2 additions & 0 deletions tests/integration/files/pillar/base/include-b.sls
@@ -0,0 +1,2 @@
b:
- 'Entry B'
5 changes: 5 additions & 0 deletions tests/integration/files/pillar/base/include.sls
@@ -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
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
@@ -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
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

0 comments on commit 9faa49c

Please sign in to comment.