mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #52490 from dwoz/issue_52134
Fix pillar include regression
This commit is contained in:
commit
9faa49cca4
11 changed files with 78 additions and 33 deletions
|
@ -763,8 +763,6 @@ class Pillar(object):
|
|||
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))
|
||||
|
@ -772,45 +770,43 @@ class Pillar(object):
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
2
tests/integration/files/pillar/base/glob_include.sls
Normal file
2
tests/integration/files/pillar/base/glob_include.sls
Normal file
|
@ -0,0 +1,2 @@
|
|||
include:
|
||||
- 'glob_include*'
|
2
tests/integration/files/pillar/base/glob_include_a.sls
Normal file
2
tests/integration/files/pillar/base/glob_include_a.sls
Normal file
|
@ -0,0 +1,2 @@
|
|||
glob-a:
|
||||
- 'Entry A'
|
2
tests/integration/files/pillar/base/glob_include_b.sls
Normal file
2
tests/integration/files/pillar/base/glob_include_b.sls
Normal file
|
@ -0,0 +1,2 @@
|
|||
glob-b:
|
||||
- 'Entry B'
|
2
tests/integration/files/pillar/base/include-a.sls
Normal file
2
tests/integration/files/pillar/base/include-a.sls
Normal file
|
@ -0,0 +1,2 @@
|
|||
a:
|
||||
- 'Entry A'
|
2
tests/integration/files/pillar/base/include-b.sls
Normal file
2
tests/integration/files/pillar/base/include-b.sls
Normal file
|
@ -0,0 +1,2 @@
|
|||
b:
|
||||
- 'Entry B'
|
5
tests/integration/files/pillar/base/include.sls
Normal file
5
tests/integration/files/pillar/base/include.sls
Normal file
|
@ -0,0 +1,5 @@
|
|||
include:
|
||||
- include-a:
|
||||
key: element:a
|
||||
- include-b:
|
||||
key: element:b
|
|
@ -3,6 +3,8 @@ base:
|
|||
- generic
|
||||
- blackout
|
||||
- sdb
|
||||
- include
|
||||
- glob_include
|
||||
'sub_minion':
|
||||
- sdb
|
||||
- generic
|
||||
|
|
30
tests/integration/pillar/test_pillar_include.py
Normal file
30
tests/integration/pillar/test_pillar_include.py
Normal file
|
@ -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']
|
|
@ -142,6 +142,7 @@ class BadTestModuleNamesTestCase(TestCase):
|
|||
'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',
|
||||
|
|
Loading…
Add table
Reference in a new issue