mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #28375 from Precis/fix-pillar-include-loop
Merge pillar includes correctly
This commit is contained in:
commit
5efac26c10
@ -522,20 +522,20 @@ class Pillar(object):
|
||||
mods,
|
||||
defaults
|
||||
)
|
||||
if nstate:
|
||||
if key:
|
||||
nstate = {
|
||||
key: nstate
|
||||
}
|
||||
if nstate:
|
||||
if key:
|
||||
nstate = {
|
||||
key: nstate
|
||||
}
|
||||
|
||||
state = merge(
|
||||
state,
|
||||
nstate,
|
||||
self.merge_strategy,
|
||||
self.opts.get('renderer', 'yaml'))
|
||||
state = merge(
|
||||
state,
|
||||
nstate,
|
||||
self.merge_strategy,
|
||||
self.opts.get('renderer', 'yaml'))
|
||||
|
||||
if err:
|
||||
errors += err
|
||||
if err:
|
||||
errors += err
|
||||
return state, mods, errors
|
||||
|
||||
def render_pillar(self, matches):
|
||||
|
@ -232,6 +232,86 @@ generic:
|
||||
|
||||
client.get_state.side_effect = get_state
|
||||
|
||||
@patch('salt.pillar.salt.fileclient.get_file_client', autospec=True)
|
||||
@patch('salt.pillar.salt.minion.Matcher') # autospec=True disabled due to py3 mock bug
|
||||
def test_pillar_include(self, Matcher, get_file_client):
|
||||
# Uses the ``recurse_list`` strategy.
|
||||
opts = {
|
||||
'renderer': 'yaml',
|
||||
'state_top': '',
|
||||
'pillar_roots': [],
|
||||
'extension_modules': '',
|
||||
'environment': 'base',
|
||||
'file_roots': [],
|
||||
'pillar_source_merging_strategy': 'recurse_list',
|
||||
}
|
||||
grains = {
|
||||
'os': 'Ubuntu',
|
||||
'os_family': 'Debian',
|
||||
'oscodename': 'raring',
|
||||
'osfullname': 'Ubuntu',
|
||||
'osrelease': '13.04',
|
||||
'kernel': 'Linux'
|
||||
}
|
||||
self._setup_test_include_mocks(Matcher, get_file_client)
|
||||
pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base').compile_pillar()
|
||||
# Both pillar modules should only be loaded once.
|
||||
self.assertEqual(pillar['p1'], ['value1_3', 'value1_1', 'value1_2'])
|
||||
self.assertEqual(pillar['p2'], ['value2_1', 'value2_2'])
|
||||
|
||||
def _setup_test_include_mocks(self, Matcher, get_file_client):
|
||||
self.top_file = top_file = tempfile.NamedTemporaryFile()
|
||||
top_file.write(b'''
|
||||
base:
|
||||
'*':
|
||||
- order: 1
|
||||
- test.sub2
|
||||
minion:
|
||||
- order: 2
|
||||
- test
|
||||
''')
|
||||
top_file.flush()
|
||||
self.init_sls = init_sls = tempfile.NamedTemporaryFile()
|
||||
init_sls.write(b'''
|
||||
include:
|
||||
- test.sub1
|
||||
- test.sub2
|
||||
''')
|
||||
init_sls.flush()
|
||||
self.sub1_sls = sub1_sls = tempfile.NamedTemporaryFile()
|
||||
sub1_sls.write(b'''
|
||||
p1:
|
||||
- value1_1
|
||||
- value1_2
|
||||
''')
|
||||
sub1_sls.flush()
|
||||
self.sub2_sls = sub2_sls = tempfile.NamedTemporaryFile()
|
||||
sub2_sls.write(b'''
|
||||
p1:
|
||||
- value1_3
|
||||
p2:
|
||||
- value2_1
|
||||
- value2_2
|
||||
''')
|
||||
sub2_sls.flush()
|
||||
|
||||
# Setup Matcher mock
|
||||
matcher = Matcher.return_value
|
||||
matcher.confirm_top.return_value = True
|
||||
|
||||
# Setup fileclient mock
|
||||
client = get_file_client.return_value
|
||||
client.cache_file.return_value = self.top_file.name
|
||||
|
||||
def get_state(sls, env):
|
||||
return {
|
||||
'test': {'path': '', 'dest': init_sls.name},
|
||||
'test.sub1': {'path': '', 'dest': sub1_sls.name},
|
||||
'test.sub2': {'path': '', 'dest': sub2_sls.name},
|
||||
}[sls]
|
||||
|
||||
client.get_state.side_effect = get_state
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
Loading…
Reference in New Issue
Block a user