-
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
Cleanup calculation of template sls/tpl context #58238
Conversation
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.
Thanks for the PR! I know you're already aware of the need for tests 🙃
I've added a couple of points of feedback that should help. If you need help getting some tests going on this, let me know!
…ch/salt into feature/56410-tpldir-calculation
9d7286c
to
237c62b
Compare
Been trying to satisfy the quality gates, but this is starting to spin out of control... |
Because we definitely want these fixes but we need to avoid breaking existing state trees I have added a feature flag for this functionality. To use these fixes add the following to your minion's config:
This feature flag will go away in the Phosphorus (3005) and the fixed functionality will become the default. |
re-run windows |
re-run full all |
re-run full all |
2ff0dc8
Congratulations on your first PR being merged! 🎉 |
I spent some time actually trying to use this feature, and it resulted in nothing but frustration:
The example state looks like this (it doesn't matter if it is placed in the root or in a subfolder): {% do salt.log.warning('VAR tpldir="{}"'.format(tpldir)) %}
{% do salt.log.warning('VAR slspath="{}"'.format(slspath)) %}
{% do salt.log.warning('VAR tplfile="{}"'.format(tplfile)) %}
{% do salt.log.warning('VAR tpldot="{}"'.format(tpldot)) %}
We already have the (badly named) And (unlike
Maybe it worth to delay this feature until they are fixed too? Otherwise, when/if they got fixed later, we'll need another feature flag ( [ADDED LATER]:
There is a requirement for PRs to have unit tests. What was tested in this specific case? Why a unit test didn't trigger the crash? Why the incomplete test coverage wasn't caught during the review phase? What about actually running the code and examples from the documentation? I understand that these questions are rhetorical at this point, but just can't ignore the problem. After all, there is SEP-10 and some expectations about code quality it should bring... |
Can't speak to the feature flags, that was not part of my original PR and was added by @dwoz as a compromise to get things merged "safely" to not affect existing functionality. Unfortunately the issue you see in #3 is a direct result of a bug that was apparently introduced with the feature flags - a simple, but devastating bug. When the old implementation was re-introduced in 9380b56, a bug was added that completely broke the new implementation. It is a simple enough fix(missing return statement) - I will open a new PR to fix it. :-( As for your last point, as the names of those variables suggest, they are designed with SLS files in mind - so mapping them to non-sls files may not produce what you would expect. That said, remember that you are loading those files from an sls file, and as such, passing in the sls context into it - so you can probably pass in whatever context items you want. I will glance at it when I have a sec. FWIW, we moved away from using map.jinja files in general, as there are much better ( at least for us), ways to handle those needs. |
Thanks for the quick response! Hopefully the fix will be merged before the Magnesium is out of the doors 🤞 I also Cc'ed @myii, maybe he will provide some additional feedback on these changes after running the |
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.
@mlasevich When providing the fix you've been discussing with @max-arnold, please consider these items as well.
@@ -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 |
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:
This flag will be depricated in the Phosphorus release when this functionality | |
This flag will be deprecated in the Phosphorus release when this functionality |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Typo mainly, formatting for consistency:
In the 3002 release sls_path, tplfile, and tpldir have had some significate | |
In the 3002 release ``sls_path``, ``tplfile``, and ``tpldir`` have had some significant |
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
specific format (windows vs posix). (It is probably best not to use this.) | |
specific format (Windows vs POSIX). (It is probably best not to use this.) |
) | ||
|
||
def test_generate_sls_context__one_level_init_implicit(self): | ||
""" generate_sls_context - Basic one level with impliocit init.sls """ |
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:
""" generate_sls_context - Basic one level with impliocit init.sls """ | |
""" generate_sls_context - Basic one level with implicit init.sls """ |
What does this PR do?
Cleanup calculation of sls* and tpl* context parameters when parsing sls files. Fix bug which under some circumstances produced wrong value for tpldir
What issues does this PR fix or reference?
tpldir
and related are calculated incorrectly when name repeats in the pathsls*
values when sls path explicitly contains it. i.e. if sls is foo.bar.init - expected path isfoo/bar
and notfoo/bar/init
as previouslytplfile
variable not set in some sls files #58249 - Blanktplfile
value when loading top level sls filesPrevious Behavior
See issue #56410. If directory name matched part of the path name, wrong value was calculated
New Behavior
There should be no functional difference, all the same values are being produced, the key difference is how the template path and related variables are calculated.
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
No
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.