-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Cleanup calculation of template sls/tpl context #58238
Merged
dwoz
merged 38 commits into
saltstack:master
from
mlasevich:feature/56410-tpldir-calculation
Oct 8, 2020
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3c3e953
Cleanup calculation of template sls/tpl context
2e99347
fix string formatting
3aec8c0
Add unit test that works against old version (with bugs)
1c6d51b
Updated unit tests with non-buggy values and fix found bugs
8d371c8
cleanup unit tests to test underlying function
31a62b0
remove old unit test components no longer used
938d517
Cleanup
fd85b92
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich 08253f4
More Cleanup
52aebff
Merge branch 'feature/56410-tpldir-calculation' of github.com:mlasevi…
237c62b
More cleanup. Add Mock to test.support.unit
0b626a0
Add changelog entries
05d0a5c
Fix Mockery
6617911
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich e8e0b3c
Import order fix
baef2d7
Handle backslashes in sls names under *nix
1c5b224
Cleanup
40cb816
Make sure we return a dictionary from jinja.load_map
ccf8e54
Fix scenario when sls is empty but present
ec298bb
Touched another file - Cleanup to make pre-commit happy
1d68a9f
Adding variables to docs
ff67a24
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich 74186a3
Fix expected tplpath value to be OS specific and note so in docs
d9cd4ae
Merge branch 'master' into feature/56410-tpldir-calculation
sagetherage ff6f4d0
Merge branch 'master' into feature/56410-tpldir-calculation
sagetherage 0a3ed38
Merge branch 'master' into feature/56410-tpldir-calculation
sagetherage 4de3f4e
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich f4df5b5
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich 1df0116
removing comments from imports as per pre-commit
88483e9
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich 2fef670
removing comments from imports as per pre-commit
ce7fd94
Merge branch 'feature/56410-tpldir-calculation' of github.com:mlasevi…
d841bc5
Merge branch 'master' into feature/56410-tpldir-calculation
mlasevich 9380b56
Put slsvars changes behind a feature flag
dwoz e3dc751
Better documentation for enable_slsvars_fixes feature flag
dwoz 6cd8f56
Merge branch 'master' into feature/56410-tpldir-calculation
twangboy be8ece2
Merge branch 'master' into feature/56410-tpldir-calculation
dwoz 2ff0dc8
Fix test that should be skipped on windows
dwoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Proper calculation of tpldir and related context parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix blank tplfile context parameter when loading top level sls files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Do not include init directory in sls context parameters if explicitly specified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Added features config option for feature flags. Added a feature flag | ||
`enable_slsvars_fixes` to enable fixes to tpldir, tplfile and sls_path. | ||
This flag will be depricated in the Phosphorus release when this functionality | ||
becomes the default. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,21 @@ | |||||
SLS Template Variable Reference | ||||||
=============================== | ||||||
|
||||||
|
||||||
.. warning:: | ||||||
In the 3002 release sls_path, tplfile, and tpldir have had some significate | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo mainly, formatting for consistency:
Suggested change
|
||||||
improvements which have the potential to break states that rely on old and | ||||||
broken functionality. These fixes can be enabled by setting the | ||||||
``use_slsvars_fixes`` feature flag to ``True`` in your minion's config file. | ||||||
This functionality will become the default in the 3005 release. | ||||||
|
||||||
.. code-block:: yaml | ||||||
|
||||||
features: | ||||||
use_slsvars_fixes: True | ||||||
|
||||||
|
||||||
|
||||||
The template engines available to sls files and file templates come loaded | ||||||
with a number of context variables. These variables contain information and | ||||||
functions to assist in the generation of templates. See each variable below | ||||||
|
@@ -81,8 +96,13 @@ from an environment. | |||||
|
||||||
{{ saltenv }} | ||||||
|
||||||
SLS Only Variables | ||||||
================== | ||||||
The following are only available when processing sls files. If you need these | ||||||
in other templates, you can usually pass them in as template context. | ||||||
|
||||||
sls | ||||||
==== | ||||||
--- | ||||||
|
||||||
The `sls` variable contains the sls reference value, and is only available in | ||||||
the actual SLS file (not in any files referenced in that SLS). The sls | ||||||
|
@@ -94,14 +114,96 @@ include option. | |||||
{{ sls }} | ||||||
|
||||||
slspath | ||||||
======= | ||||||
------- | ||||||
|
||||||
The `slspath` variable contains the path to the directory of the current sls | ||||||
file. The value of `slspath` in files referenced in the current sls depends on | ||||||
the reference method. For jinja includes `slspath` is the path to the current | ||||||
directory of the file. For salt includes `slspath` is the path to the directory | ||||||
of the included file. | ||||||
of the included file. If current sls file is in root of the file roots, this | ||||||
will return "" | ||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ slspath }} | ||||||
|
||||||
|
||||||
sls_path | ||||||
-------- | ||||||
|
||||||
A version of `slspath` with underscores as path separators instead of slashes. | ||||||
So, if `slspath` is `path/to/state` then `sls_path` is `path_to_state` | ||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ sls_path }} | ||||||
|
||||||
slsdotpath | ||||||
---------- | ||||||
|
||||||
A version of `slspath` with dots as path separators instead of slashes. So, if | ||||||
`slspath` is `path/to/state` then `slsdotpath` is `path.to.state`. This is same | ||||||
as `sls` if `sls` points to a directory instead if a file. | ||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ slsdotpath }} | ||||||
|
||||||
|
||||||
slscolonpath | ||||||
------------ | ||||||
|
||||||
A version of `slspath` with colons (`:`) as path separators instead of slashes. | ||||||
So, if `slspath` is `path/to/state` then `slscolonpath` is `path:to:state`. | ||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ slscolonpath }} | ||||||
|
||||||
tplpath | ||||||
------- | ||||||
|
||||||
Full path to sls template file being process on local disk. This is usually | ||||||
pointing to a copy of the sls file in a cache directory. This will be in OS | ||||||
specific format (windows vs posix). (It is probably best not to use this.) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ tplpath }} | ||||||
|
||||||
|
||||||
tplfile | ||||||
------- | ||||||
|
||||||
Relative path to exact sls template file being processed relative to file | ||||||
roots. | ||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ tplfile }} | ||||||
|
||||||
tpldir | ||||||
------ | ||||||
|
||||||
Directory, relative to file roots, of the current sls file. If current sls file | ||||||
is in root of the file roots, this will return ".". This is usually identical | ||||||
to `slspath` except in case of root-level sls, where this will return a "`.`". | ||||||
|
||||||
A Common use case for this variable is to generate relative salt urls like: | ||||||
.. code-block:: jinja | ||||||
|
||||||
my-file: | ||||||
file.managed: | ||||||
source: salt://{{ tpldir }}/files/my-template | ||||||
|
||||||
|
||||||
tpldot | ||||||
------ | ||||||
|
||||||
A version of `tpldir` with dots as path separators instead of slashes. So, if | ||||||
`tpldir` is `path/to/state` then `tpldot` is `path.to.state`. NOTE: if `tpldir` | ||||||
is `.`, this will be set to "" | ||||||
|
||||||
.. code-block:: jinja | ||||||
|
||||||
{{ tpldot }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Feature flags | ||
""" | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Features: | ||
def __init__(self, _features=None): | ||
if _features is None: | ||
self.features = {} | ||
else: | ||
self.features = _features | ||
self.setup = False | ||
|
||
def setup_features(self, opts): | ||
if not self.setup: | ||
self.features.update(opts.get("features", {})) | ||
else: | ||
log.warn("Features already setup") | ||
|
||
def get(self, key, default=None): | ||
return self.features.get(key, default) | ||
|
||
|
||
features = Features() | ||
setup_features = features.setup_features |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: