70 lines
2.4 KiB
Diff
70 lines
2.4 KiB
Diff
From 3403a7391df785be31b6fbe401a8229c2007ac19 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
|
|
<psuarezhernandez@suse.com>
|
|
Date: Mon, 2 Oct 2023 10:44:05 +0100
|
|
Subject: [PATCH] Fix calculation of SLS context vars when trailing dots
|
|
on targetted sls/state (bsc#1213518) (#598)
|
|
|
|
* Fix calculation of SLS context vars when trailing dots on targetted state
|
|
|
|
* Add changelog file
|
|
---
|
|
changelog/63411.fixed.md | 1 +
|
|
salt/utils/templates.py | 5 +++--
|
|
tests/unit/utils/test_templates.py | 14 ++++++++++++++
|
|
3 files changed, 18 insertions(+), 2 deletions(-)
|
|
create mode 100644 changelog/63411.fixed.md
|
|
|
|
diff --git a/changelog/63411.fixed.md b/changelog/63411.fixed.md
|
|
new file mode 100644
|
|
index 0000000000..65340e3652
|
|
--- /dev/null
|
|
+++ b/changelog/63411.fixed.md
|
|
@@ -0,0 +1 @@
|
|
+Fix calculation of SLS context vars when trailing dots on targetted state
|
|
diff --git a/salt/utils/templates.py b/salt/utils/templates.py
|
|
index 4a8adf2a14..8639ea703e 100644
|
|
--- a/salt/utils/templates.py
|
|
+++ b/salt/utils/templates.py
|
|
@@ -113,8 +113,9 @@ def generate_sls_context(tmplpath, sls):
|
|
|
|
sls_context = {}
|
|
|
|
- # Normalize SLS as path.
|
|
- slspath = sls.replace(".", "/")
|
|
+ # Normalize SLS as path and remove possible trailing slashes
|
|
+ # to prevent matching issues and wrong vars calculation
|
|
+ slspath = sls.replace(".", "/").rstrip("/")
|
|
|
|
if tmplpath:
|
|
# Normalize template path
|
|
diff --git a/tests/unit/utils/test_templates.py b/tests/unit/utils/test_templates.py
|
|
index 4ba2f52d7b..264b4ae801 100644
|
|
--- a/tests/unit/utils/test_templates.py
|
|
+++ b/tests/unit/utils/test_templates.py
|
|
@@ -320,6 +320,20 @@ class WrapRenderTestCase(TestCase):
|
|
slspath="foo",
|
|
)
|
|
|
|
+ def test_generate_sls_context__one_level_init_implicit_with_trailing_dot(self):
|
|
+ """generate_sls_context - Basic one level with implicit init.sls with trailing dot"""
|
|
+ self._test_generated_sls_context(
|
|
+ "/tmp/foo/init.sls",
|
|
+ "foo.",
|
|
+ tplfile="foo/init.sls",
|
|
+ tpldir="foo",
|
|
+ tpldot="foo",
|
|
+ slsdotpath="foo",
|
|
+ slscolonpath="foo",
|
|
+ sls_path="foo",
|
|
+ slspath="foo",
|
|
+ )
|
|
+
|
|
def test_generate_sls_context__one_level_init_explicit(self):
|
|
"""generate_sls_context - Basic one level with explicit init.sls"""
|
|
self._test_generated_sls_context(
|
|
--
|
|
2.42.0
|
|
|
|
|