Merge pull request #40349 from ferringb/develop

ticket #40348: fix pillar include key nested support
This commit is contained in:
Mike Place 2017-03-28 11:04:19 -06:00 committed by GitHub
commit d8cabca9a6
2 changed files with 35 additions and 3 deletions

View File

@ -688,9 +688,11 @@ class Pillar(object):
)
if nstate:
if key:
nstate = {
key: nstate
}
# If key is x:y, convert it to {x: {y: nstate}}
for key_fragment in reversed(key.split(":")):
nstate = {
key_fragment: nstate
}
state = merge(
state,

View File

@ -121,6 +121,36 @@ class PillarTestCase(TestCase):
({'foo': 'bar2'}, [])
)
# Test includes using empty key directive
compile_template.side_effect = [
{'foo': 'bar', 'include': [{'blah': {'key': ''}}]},
{'foo': 'bar2'}
]
self.assertEqual(
pillar.render_pillar({'base': ['foo.sls']}),
({'foo': 'bar2'}, [])
)
# Test includes using simple non-nested key
compile_template.side_effect = [
{'foo': 'bar', 'include': [{'blah': {'key': 'nested'}}]},
{'foo': 'bar2'}
]
self.assertEqual(
pillar.render_pillar({'base': ['foo.sls']}),
({'foo': 'bar', 'nested': {'foo': 'bar2'}}, [])
)
# Test includes using nested key
compile_template.side_effect = [
{'foo': 'bar', 'include': [{'blah': {'key': 'nested:level'}}]},
{'foo': 'bar2'}
]
self.assertEqual(
pillar.render_pillar({'base': ['foo.sls']}),
({'foo': 'bar', 'nested': {'level': {'foo': 'bar2'}}}, [])
)
@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_topfile_order(self, Matcher, get_file_client):