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/31531.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``salt-ssh`` ``TemplateNotFound`` when a managed Jinja template imports from another template (e.g. ``{% from "formula/map.jinja" import x with context %}``). ``SaltCacheLoader`` now prefers ``opts["_caller_cachedir"]`` (the master's cachedir, where the master-side fileclient caches requested files) over ``opts["cachedir"]`` (the thin minion's remote path) for its Jinja search path. Backport of the 3007.x/3008.x fix.
7 changes: 6 additions & 1 deletion salt/utils/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ def __init__(
else:
self.searchpath = opts["pillar_roots"][saltenv]
else:
self.searchpath = [os.path.join(opts["cachedir"], "files", saltenv)]
# In salt-ssh context, _caller_cachedir is the master's cachedir
# while cachedir points to the thin minion's remote path.
# The fileclient caches files to the master's cachedir, so we
# must use _caller_cachedir as the Jinja search path when present.
effective_cachedir = opts.get("_caller_cachedir", opts["cachedir"])
self.searchpath = [os.path.join(effective_cachedir, "files", saltenv)]
log.debug("Jinja search path: %s", self.searchpath)
self.cached = []
self._file_client = _file_client
Expand Down
18 changes: 18 additions & 0 deletions tests/pytests/unit/utils/jinja/test_salt_cache_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ def test_searchpath_bad_pillar_rend(minion_opts, get_loader):
assert loader.searchpath == []


def test_searchpath_uses_caller_cachedir(minion_opts, get_loader, tmp_path):
"""
When opts["_caller_cachedir"] is set (salt-ssh master-side wrapper
context), the searchpath must be built from it instead of opts["cachedir"].

Regression test for #31531: under salt-ssh, opts["cachedir"] points at
the thin minion's remote path while the master-side fileclient caches
files under opts["_caller_cachedir"]. Using opts["cachedir"] for the
Jinja searchpath caused TemplateNotFound on map.jinja imports.
"""
saltenv = "base"
master_cachedir = tmp_path / "master"
master_cachedir.mkdir()
minion_opts["_caller_cachedir"] = str(master_cachedir)
loader = get_loader(opts=minion_opts, saltenv=saltenv)
assert loader.searchpath == [os.path.join(str(master_cachedir), "files", saltenv)]


def test_mockclient(minion_opts, template_dir, hello_simple, get_loader):
"""
A MockFileClient is used that records all file requests normally sent
Expand Down
Loading