-
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
Introduce "module.xrun" #39891
Introduce "module.xrun" #39891
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.
This looks great, I never liked the module.run interface. I think this is significantly cleaner
@thatch45 thanks! :) Before @cachedout pointed me to the Lint, I am already fixing it!! |
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.
👍
@cachedout I do not understand Lint error of W1699 against |
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.
Very nice! This will be great to have.
I only have one small request: Can you add this new option to the Nitrogen Release Notes? I think people will find this useful and will want to know about it!
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.
Might be worth adding a deprecation notice to module.run
for this release or the next.
Given how heavily used it is we might not want to actually put it on a deprecation path but rather just add a notice to that docstring -- the 'ol file.sed
treatment. 😉
@rallytime I added release notes and hopefully it is correct. @whiteinge I added decorator-based deprecation (and also fixed it is now working for state modules as well). Now it will simply be using new Hint for packagers: create a |
@cachedout by now all the issues were addressed. If you think those two lints are just misbehaviour of custom scripts (at my side it doesn't hurt for Python 3 actually), then we are clean to merge. |
@isbm sorry my comment above wasn't very clear. I strongly think that we should not deprecate the old Thoughts from the Core team? Agree/disagree? |
@whiteinge But this is what exactly is happening. Add to your minion config: use_deprecated:
- module.run And you will have the old one. All is needed to be done is to package it properly. E.g. we will ship something like So let's just slowly migrate the world. Two years should be enough to write |
Both good points, I think that slowly moving the world would be a good idea, we could easily make sure that the comment returned from module.run specifies that it is going to be deprecated... |
I can't speak directly to pros/cons of relying on package upgrades to put that config file in place. Personally, I'd prefer an opt-in rather than an opt-out for such a core module. That said, I'll defer to the Core team since they will be on the front lines of any user upgrade problems. |
I would also prefer for opt-in, we do not have the luxury that SUSE has of dictating how the platform is going to be used unfortunately :( |
@whiteinge @thatch45 no problems for opt-in. I will change that in the entire mechanism, so all the deprecation will work always on opt-in with "nag messages" to the log. Good point! But now is 1:00AM in Germany, so let me fix that tomorrow CEST. :-) |
@thatch45 @whiteinge specially for your preference! Have a nice weekend, guys. P.S. Hmm, nice deprecation mechanism we've just got, BTW... |
salt/states/module.py
Outdated
ret['result'] = False | ||
elif __opts__['test']: | ||
ret['comment'] = "Module function '{0}' is set to execute".format(func) | ||
ret['result'] = True |
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.
Could potentially overwrite the ret['comment']
& ret['result']
from a previous loop iteration where it fails, depending on the content of the SLS file and the order of the dict.
This would mask a failure under some circumstances when test=True
.
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.
Oh, knapp, you're right. And I forgot to update docstring. Give me a sec...
@ScoreUnder done! |
15bdcd6
to
55ab664
Compare
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.
I think the config options can be better retrieved using config.get
. There are also a number of things I noticed in the RST that we can clean up.
doc/topics/releases/nitrogen.rst
Outdated
@@ -61,6 +61,49 @@ State Module Changes | |||
start/stop the service using the ``--no-block`` flag in the ``systemctl`` | |||
command. On non-systemd minions, a warning will be issued. | |||
|
|||
- The :py:func:`module.run <salt.states.module.run>` state dropped its previous |
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.
Should be "has dropped".
doc/topics/releases/nitrogen.rst
Outdated
- The :py:func:`module.run <salt.states.module.run>` state dropped its previous | ||
syntax with ``m_`` prefix for reserved keywords. Additionally, it allows | ||
running several functions in a batch. | ||
**NOTE: you need explicitly turn on new behaviour (see below how)** |
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.
This can be expressed better in RST using:
.. note::
It is necessary to explicitly turn on the new behavior (see below)
- do_stuff: True | ||
|
||
- Previous behaviour of the function :py:func:`module.run <salt.states.module.run>` is | ||
still kept by default and can be bypassed in case you want to use behaviour above. |
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.
@thatch45 Did we ever make a firm decision on whether to use US or international spelling for words ending in -or
/-our
?
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.
Not american here, sry.
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.
I honestly don't care which we use, but I think that we should choose one for consistency across the docs.
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.
They are mixed in the docs. I agree we should pick a style but since we haven't, I see no reason to block on 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.
In that case, yes I definitely agree.
doc/topics/releases/nitrogen.rst
Outdated
|
||
- Previous behaviour of the function :py:func:`module.run <salt.states.module.run>` is | ||
still kept by default and can be bypassed in case you want to use behaviour above. | ||
Please keep in mind that old implementation will be entirely removed in version "Oxygen". |
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.
This should be
Please keep in mind that the old syntax will no longer be supported in the ``Oxygen`` release of Salt.
doc/topics/releases/nitrogen.rst
Outdated
still kept by default and can be bypassed in case you want to use behaviour above. | ||
Please keep in mind that old implementation will be entirely removed in version "Oxygen". | ||
In order to access new function behaviour, please add the following configuration to the | ||
minion setup. Note that the configuration below you can also deploy separately to all |
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.
The note here could also be put in a .. note::
RST block.
I don't understand this note though, to be honest. Are you suggesting that all minions should have their config files edited? Have you considered using config.get to get these configuration options? It checks grains and pillar as well as the minion config file. This would allow for this option to be turned on simply by editing the pillar data (or using grains.setval
to set the value in the minion's /etc/salt/grains). Both of these options seem less intrusive IMO than editing all minions' config files.
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.
@terminalmage good point on grains. I will extend that, but with a different PR, since I would like to have a different tests for it.
doc/topics/releases/nitrogen.rst
Outdated
- Previous behaviour of the function :py:func:`module.run <salt.states.module.run>` is | ||
still kept by default and can be bypassed in case you want to use behaviour above. | ||
Please keep in mind that old implementation will be entirely removed in version "Oxygen". | ||
In order to access new function behaviour, please add the following configuration to 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.
This would read better as:
To enable the new behavior, add the following to the minion config file:
Final call for comments on this one. Otherwise, everything is looking good for a merge. |
@cachedout What do you want to do about the PY3 lint errors for the changes in https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/9449/violations/file/salt/states/module.py/ |
@rallytime I already asked this 5 days ago: please advice what it does mean. Because the code is not incompatible with Python 3 as lint claims. I would think that the script/lint check is flawed, as it does not provide even the reason and proposed fix. Just complaining and complaining wrong (unless I am missing something). Suggestions? I can fix it in 5 minutes, but if I know what... |
@isbm Right, all good points. For the record, and so everyone doesn't have to click around and find it, the console output for the PY3 violation displays the following:
But, as you stated, this should be working in both versions. If this is something wrong with our linter, then we need to address that. I am thinking @s0undt3ch or @cachedout should provide some direction on this. |
@rallytime Hmm. I don't think this is needed fix: the only difference that |
36070a8
to
5592b49
Compare
@cachedout OK, today I re-based it one more time against |
@isbm That's all I think we need. If the tests pass, I'll merge it. |
@cachedout it is all @rallytime 's fault. 😆 (no, not really: thanks for adding unit tests for |
What does this PR do?
Adds a feature:
module.xrun
for states.Motivation
Current way of calling Salt modules with
module.run
has pretty cumbersome interface along with the fact it has also reserved words. This leads to a strange states, something like:Or even worse:
This led to the reasoning make it easier and simpler to use, throw away
m_
prefix (this just sucks, sorry). Also write better unit tests. 😄 So the above can be done something like this:Look, Ma! No
m_
prefix! How about another example:One more thing you can do (optionally, of course, you don't have to):
😎
Tests written?
Yes