-
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
[BUG] Test mode does not propagate to __states__ when using prereq #62590
Comments
Some possible solutions from @mattp- --- a/salt/state.py
+++ b/salt/state.py
@@ -2228,14 +2228,15 @@ class State:
inject_globals["__env__"] = str(low["__env__"])
if self.inject_globals:
inject_globals.update(self.inject_globals)
if low.get("__prereq__"):
- test = sys.modules[self.states[cdata["full"]].__module__].__opts__["test"]
- sys.modules[self.states[cdata["full"]].__module__].__opts__["test"] = True
+ test_opts = copy.deepcopy(self.opts)
+ test_opts["test"] = True
+ inject_globals["__opts__"] = test_opts
try:
# Let's get a reference to the salt environment to use within this
# state call.
#
# If the state function accepts an 'env' keyword argument, it
# allows the state to be overridden(we look for that in cdata). If
@@ -2315,17 +2316,12 @@ class State:
"result": False,
"name": name,
"changes": {},
"comment": "An exception occurred in this state: {}".format(trb),
}
finally:
- if low.get("__prereq__"):
- sys.modules[self.states[cdata["full"]].__module__].__opts__[
- "test"
- ] = test
-
self.state_con.pop("runas", None)
self.state_con.pop("runas_password", None)
if not isinstance(ret, dict):
return ret --- a/salt/state.py
+++ b/salt/state.py
@@ -2230,12 +2230,13 @@ class State:
if self.inject_globals:
inject_globals.update(self.inject_globals)
if low.get("__prereq__"):
test = sys.modules[self.states[cdata["full"]].__module__].__opts__["test"]
sys.modules[self.states[cdata["full"]].__module__].__opts__["test"] = True
+ inject_globals["__opts__"] = sys.modules[self.states[cdata["full"]].__module__].__opts__
try:
# Let's get a reference to the salt environment to use within this
# state call.
#
# If the state function accepts an 'env' keyword argument, it
# allows the state to be overridden(we look for that in cdata). If |
@dwoz would the fix for that be planned for 3006.2 since it affects the x509_v2 state? |
I did the update to |
Hi everyone, I was about to submit a similar bug when I stumble upon this one, close enough from what I was experiencing on 3006.2 with this "minimal SLS to reproduce":
In my case, the
I've upgraded the Minion, it's now running 3006.5 and working as expected. Kudos to the ones who helped fixed this issue, many thanks! |
Description
When
prereq
is used, the target state is first run in test mode.If the target state calls other states via
__states__
, those states will not run in test mode, and will actually make changes.Then when it runs "for real" there may be nothing left to do and it will report no changes.
Setup
Steps to Reproduce the behavior
Expected behavior
Versions Report
salt --versions-report
Additional context
Also tested with 3005. Same result.
The text was updated successfully, but these errors were encountered: