Skip to content

[master] Fix calculation of SLS context vars when trailing dots on targetted sls/state#65036

Merged
dwoz merged 3 commits intosaltstack:masterfrom
meaksh:master-fix-sls-context-vars-issue
Jan 30, 2026
Merged

[master] Fix calculation of SLS context vars when trailing dots on targetted sls/state#65036
dwoz merged 3 commits intosaltstack:masterfrom
meaksh:master-fix-sls-context-vars-issue

Conversation

@meaksh
Copy link
Contributor

@meaksh meaksh commented Aug 23, 2023

What does this PR do?

This PR fixes a problem on the behavior of SLS context vars, that has been identified when targetting an SLS with trailing dots.

Let say I have the following in my "file_roots":

/srv/salt/
/srv/salt/test/
/srv/salt/test/init.sls

where test/init.sls contains:

Show Variables:
  cmd.run:
    - name: echo "sls = {{sls}}\nslspath = {{slspath}}\nsls_path = {{sls_path}}\ntplfile = {{tplfile}}\ntpldir = {{tpldir}}\ntplpath = {{tplpath}}"

Now, depending how I trigger the state, I got wrong calculation of SLS context variables (slspath, slsdotpath, slscolonpath, sls_path), where the expected relative paths are actually rendered as absolute paths:

# This works as expected
# salt <minion> state.sls test 
...
                  sls = test
                  slspath = test
                  sls_path = test
                  tplfile = test/init.sls
                  tpldir = test
                  tplpath = /var/cache/salt/minion/files/test_edit/test/init.sls
...
# This DOES NOT work as expected
# salt <minion> state.sls test.
...
                  sls = test.
                  slspath = /var/cache/salt/minion/files/test_edit/test
                  sls_path = _var_cache_salt_minion_files_test_edit_test
                  tplfile = /var/cache/salt/minion/files/test_edit/test/init.sls
                  tpldir = /var/cache/salt/minion/files/test_edit/test
                  tplpath = /var/cache/salt/minion/files/test_edit/test/init.sls
# This works as expected
# salt <minion> state.sls test.init
...
                  sls = test.init
                  slspath = test
                  sls_path = test
                  tplfile = test/init.sls
                  tpldir = test
                  tplpath = /var/cache/salt/minion/files/test_edit/test/init.sls
...

Additionally, this PR fixes a bad logic for test comparison that was making related tests to always pass.

What issues does this PR fix or reference?

Fixes: #63411

Previous Behavior

As mentioned, when targetting as test., I got unexpected absolute paths:

                  sls = test.
                  slspath = /var/cache/salt/minion/files/test_edit/test
                  sls_path = _var_cache_salt_minion_files_test_edit_test
                  tplfile = /var/cache/salt/minion/files/test_edit/test/init.sls
                  tpldir = /var/cache/salt/minion/files/test_edit/test
                  tplpath = /var/cache/salt/minion/files/test_edit/test/init.sls

New Behavior

After this PR, I got expected values:

                  sls = test.
                  slspath = test
                  sls_path = test
                  tplfile = test/init.sls
                  tpldir = test
                  tplpath = /var/cache/salt/minion/files/test_edit/test/init.sls

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@meaksh meaksh requested a review from a team as a code owner August 23, 2023 12:23
@meaksh meaksh requested review from whytewolf and removed request for a team August 23, 2023 12:23
@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title Fix calculation of SLS context vars when trailing dots on targetted sls/state [master] Fix calculation of SLS context vars when trailing dots on targetted sls/state Aug 23, 2023
@meaksh meaksh temporarily deployed to ci August 23, 2023 12:41 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 12:42 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 12:49 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 12:50 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 12:59 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 13:07 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 14:08 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 14:08 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 14:08 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 14:08 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 14:08 — with GitHub Actions Inactive
@meaksh meaksh temporarily deployed to ci August 23, 2023 14:08 — with GitHub Actions Inactive
@s0undt3ch
Copy link
Contributor

Why would someone target a test. sls, and why should salt handle that extra dot?

@meaksh
Copy link
Contributor Author

meaksh commented Aug 29, 2023

Why would someone target a test. sls, and why should salt handle that extra dot?

Yeah, this is a bit strange, I don't think someone would do that on purpose, but this PR just prevents the inconsistent values to appear while it just mimic the behavior of state.apply and other state.* functions when it comes to resolve the state to run:

  • test -> test.init
  • test. -> test.init
  • test.init -> test.init

@dwoz dwoz added this to the Argon v3008.0 milestone Dec 18, 2023
agraul pushed a commit to agraul/salt that referenced this pull request Jan 27, 2025
…ls/state (bsc#1213518) (saltstack#598)

* Fix calculation of SLS context vars when trailing dots on targetted state

* Add changelog file

BACKPORT-UPSTREAM=saltstack#65036
@dwoz dwoz requested a review from a team as a code owner March 16, 2025 22:09
@dwoz dwoz force-pushed the master-fix-sls-context-vars-issue branch from 61f0b37 to e2d9b90 Compare January 28, 2026 21:46
@dwoz dwoz merged commit 8d0cf11 into saltstack:master Jan 30, 2026
816 of 819 checks passed
@meaksh meaksh deleted the master-fix-sls-context-vars-issue branch February 1, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Incorrect template variables in init.sls included as '.'

4 participants