Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warning when rendering non-SLS files #67067

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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/67067.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove warning when running `slsutil.renderer` on non-SLS files
12 changes: 10 additions & 2 deletions salt/utils/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,16 @@ def generate_sls_context(tmplpath, sls):
elif template.endswith(f"{slspath}/init.sls"):
template = template[-(9 + len(slspath)) :]
else:
# Something went wrong
log.warning("Failed to determine proper template path")
# It is not an SLS file being processed,
template = sls
sls_context.update(
dict(
tplpath=tmplpath,
tplfile=template,
tpldir=str(pathlib.Path(sls).parents[0]),
)
)
return sls_context

slspath = template.rsplit("/", 1)[0] if "/" in template else ""

Expand Down
44 changes: 43 additions & 1 deletion tests/pytests/unit/utils/templates/test_wrap_tmpl_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _test_generated_sls_context(tmplpath, sls, **expected):
tmplpath = f"C:{tmplpath}"
expected["tplpath"] = tmplpath
actual = generate_sls_context(tmplpath, sls)
assert {key: actual[key] for key in expected if key in actual} == actual
assert {key: expected[key] for key in expected if key in actual} == actual


def test_sls_context_call(tmp_path):
Expand Down Expand Up @@ -216,3 +216,45 @@ def test_generate_sls_context__backslash_in_path():
sls_path="foo",
slspath="foo",
)


def test_generate_sls_context__non_sls_root():
"""generate_sls_context - Non-SLS template in the root directory

(Issue #56410)
"""
_test_generated_sls_context(
"jinja.yaml",
"jinja.yaml",
tplpath="jinja.yaml",
tplfile="jinja.yaml",
tpldir=".",
)


def test_generate_sls_context__non_sls_one_level():
"""generate_sls_context - Non-SLS template with one-level directory

(Issue #56410)
"""
_test_generated_sls_context(
"one/jinja.yaml",
"one/jinja.yaml",
tplpath="one/jinja.yaml",
tplfile="one/jinja.yaml",
tpldir="one",
)


def test_generate_sls_context__non_sls_two_level():
"""generate_sls_context - Non-SLS template with two-level directory

(Issue #56410)
"""
_test_generated_sls_context(
"one/two/jinja.yaml",
"one/two/jinja.yaml",
tplpath="one/two/jinja.yaml",
tplfile="one/two/jinja.yaml",
tpldir="one/two",
)
Loading