Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/58736.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue when pillar files are included in the `top.sls` and then later included in another pillar file.
48 changes: 23 additions & 25 deletions salt/pillar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def render_pstate(self, sls, saltenv, mods, defaults=None):
)
else:
errors.append(msg)
mods.add(sls)
mods[sls] = state
nstate = None
if state:
if not isinstance(state, dict):
Expand Down Expand Up @@ -950,29 +950,27 @@ def render_pstate(self, sls, saltenv, mods, defaults=None):
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
else:
nstate = mods[m_sub_sls]
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
Expand Down Expand Up @@ -1002,7 +1000,7 @@ def render_pillar(self, matches, errors=None):
errors = []
for saltenv, pstates in matches.items():
pstatefiles = []
mods = set()
mods = {}
for sls_match in pstates:
matched_pstates = []
try:
Expand Down
32 changes: 31 additions & 1 deletion tests/pytests/integration/pillar/test_pillar_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def pillar_include_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cl
'{}':
- include
- glob-include
- include-c
- include-d
""".format(
salt_minion.id
)
Expand All @@ -29,6 +31,15 @@ def pillar_include_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cl
b:
- 'Entry B'
"""
include_c_pillar_file = """
c:
- 'Entry C'
"""
include_d_pillar_file = """
include:
- include-c:
key: element:d
"""
top_tempfile = pytest.helpers.temp_file(
"top.sls", top_file, base_env_pillar_tree_root_dir
)
Expand All @@ -41,6 +52,12 @@ def pillar_include_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cl
include_b_tempfile = pytest.helpers.temp_file(
"include-b.sls", include_b_pillar_file, base_env_pillar_tree_root_dir
)
include_c_tempfile = pytest.helpers.temp_file(
"include-c.sls", include_c_pillar_file, base_env_pillar_tree_root_dir
)
include_d_tempfile = pytest.helpers.temp_file(
"include-d.sls", include_d_pillar_file, base_env_pillar_tree_root_dir
)
glob_include_pillar_file = """
include:
- 'glob-include-*'
Expand All @@ -66,7 +83,7 @@ def pillar_include_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cl
"glob-include-b.sls", glob_include_b_pillar_file, base_env_pillar_tree_root_dir
)
try:
with top_tempfile, include_tempfile, include_a_tempfile, include_b_tempfile:
with top_tempfile, include_tempfile, include_a_tempfile, include_b_tempfile, include_c_tempfile, include_d_tempfile:
with glob_include_tempfile, glob_include_a_tempfile, glob_include_b_tempfile:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0
Expand Down Expand Up @@ -104,3 +121,16 @@ def test_pillar_glob_include(pillar_include_tree, salt_call_cli):
assert ret.json["glob-a"] == ["Entry A"]
assert "glob-b" in ret.json
assert ret.json["glob-b"] == ["Entry B"]


def test_pillar_include_already_included(pillar_include_tree, salt_call_cli):
"""
Test pillar include when a pillar file
has already been included.
"""
ret = salt_call_cli.run("pillar.items")
assert ret.exitcode == 0
assert ret.json
assert "element" in ret.json
assert "d" in ret.json["element"]
assert ret.json["element"]["d"] == {"c": ["Entry C"]}