Skip to content

Commit

Permalink
Merge pull request #52008 from waynew/51832-re-allow-slash-includes
Browse files Browse the repository at this point in the history
Allow `/` in pillar includes
  • Loading branch information
dwoz authored Apr 12, 2019
2 parents d3159cb + ee3115f commit b551bbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 5 additions & 2 deletions salt/pillar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def compile_pillar(self):
return ret_pillar

def destroy(self):
if self._closing:
if hasattr(self, '_closing') and self._closing:
return

self._closing = True
Expand Down Expand Up @@ -773,7 +773,10 @@ def render_pstate(self, sls, saltenv, mods, defaults=None):
key = None

try:
matched_pstates += fnmatch.filter(self.avail[saltenv], sub_sls)
matched_pstates.extend(fnmatch.filter(
self.avail[saltenv],
sub_sls.lstrip('.').replace('/', '.'),
))
except KeyError:
errors.extend(
['No matching pillar environment for environment '
Expand Down
33 changes: 30 additions & 3 deletions tests/unit/test_pillar.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,21 @@ def test_include(self, tempdir):
'oscodename': 'raring',
'osfullname': 'Ubuntu',
'osrelease': '13.04',
'kernel': 'Linux'
'kernel': 'Linux',
}
sls_files = self._setup_test_include_sls(tempdir)
fc_mock = MockFileclient(
cache_file=sls_files['top']['dest'],
get_state=sls_files,
list_states=['top', 'test.init', 'test.sub1',
'test.sub2', 'test.sub_wildcard_1'],
list_states=[
'top',
'test.init',
'test.sub1',
'test.sub2',
'test.sub_wildcard_1',
'test.sub_with_init_dot',
'test.sub.with.slashes',
],
)
with patch.object(salt.fileclient, 'get_file_client',
MagicMock(return_value=fc_mock)):
Expand All @@ -677,6 +684,8 @@ def test_include(self, tempdir):
self.assertEqual(compiled_pillar['foo_wildcard'], 'bar_wildcard')
self.assertEqual(compiled_pillar['foo1'], 'bar1')
self.assertEqual(compiled_pillar['foo2'], 'bar2')
self.assertEqual(compiled_pillar['sub_with_slashes'], 'sub_slashes_worked')
self.assertEqual(compiled_pillar['sub_init_dot'], 'sub_with_init_dot_worked')

def _setup_test_include_sls(self, tempdir):
top_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
Expand All @@ -695,6 +704,8 @@ def _setup_test_include_sls(self, tempdir):
include:
- test.sub1
- test.sub_wildcard*
- .test.sub_with_init_dot
- test/sub/with/slashes
''')
init_sls.flush()
sub1_sls = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
Expand All @@ -717,12 +728,28 @@ def _setup_test_include_sls(self, tempdir):
''')
sub_wildcard_1_sls.flush()

sub_with_init_dot_sls = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
sub_with_init_dot_sls.write(b'''
sub_init_dot:
sub_with_init_dot_worked
''')
sub_with_init_dot_sls.flush()

sub_with_slashes_sls = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
sub_with_slashes_sls.write(b'''
sub_with_slashes:
sub_slashes_worked
''')
sub_with_slashes_sls.flush()

return {
'top': {'path': '', 'dest': top_file.name},
'test': {'path': '', 'dest': init_sls.name},
'test.sub1': {'path': '', 'dest': sub1_sls.name},
'test.sub2': {'path': '', 'dest': sub2_sls.name},
'test.sub_wildcard_1': {'path': '', 'dest': sub_wildcard_1_sls.name},
'test.sub_with_init_dot': {'path': '', 'dest': sub_with_init_dot_sls.name},
'test.sub.with.slashes': {'path': '', 'dest': sub_with_slashes_sls.name},
}


Expand Down

0 comments on commit b551bbd

Please sign in to comment.