Merge pull request #52490 from dwoz/issue_52134

Fix pillar include regression
This commit is contained in:
Daniel Wozniak 2019-04-17 06:54:38 -07:00 committed by GitHub
commit 9faa49cca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 78 additions and 33 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,2 @@
include:
- 'glob_include*'

View file

@ -0,0 +1,2 @@
glob-a:
- 'Entry A'

View file

@ -0,0 +1,2 @@
glob-b:
- 'Entry B'

View file

@ -0,0 +1,2 @@
a:
- 'Entry A'

View file

@ -0,0 +1,2 @@
b:
- 'Entry B'

View file

@ -0,0 +1,5 @@
include:
- include-a:
key: element:a
- include-b:
key: element:b

View file

@ -3,6 +3,8 @@ base:
- generic
- blackout
- sdb
- include
- glob_include
'sub_minion':
- sdb
- generic

View 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']

View file

@ -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',