When using preq on a state, then prereq state will first be run with test=True to determine if there are changes. When there are changes, the state with the prereq option will be run prior to the prereq state. If this state fails then the prereq state will not run and the state output uses the test=True run. However, the proposed changes are included for the prereq state are included from the test=True run. We should pull those out as there weren't actually changes since the prereq state did not run.

This commit is contained in:
Gareth J. Greenaway 2022-08-09 14:56:40 -07:00 committed by Megan Wilhite
parent 0ae15d5620
commit 7ac9b427d6
2 changed files with 48 additions and 0 deletions

View file

@ -3115,6 +3115,13 @@ class State:
# if the requisite that failed was due to a prereq on this low state
# show the normal error
if tag in self.pre:
# This is the previous run of the state with the prereq
# which was run with test=True, so it will include
# the proposed changes not actual changes.
# So we remove them from the final output
# since the prereq requisite failed.
if self.pre[tag].get("changes"):
self.pre[tag]["changes"] = {}
running[tag] = self.pre[tag]
running[tag]["__run_num__"] = self.__run_num
running[tag]["__sls__"] = low["__sls__"]

View file

@ -688,3 +688,44 @@ def test_infinite_recursion_prereq2(state, state_tree):
ret = state.sls("requisite")
for state_return in ret:
assert state_return.result is True
def test_requisites_prereq_fail_in_prereq(state, state_tree):
sls_contents = """
State A:
test.configurable_test_state:
- result: True
- changes: True
- name: fail
State B:
test.configurable_test_state:
- changes: True
- result: False
- prereq:
- test: State A
State C:
test.nop:
- onchanges:
- test: State A
"""
with pytest.helpers.temp_file("requisite.sls", sls_contents, state_tree):
ret = state.sls("requisite")
assert ret["test_|-State A_|-fail_|-configurable_test_state"].result is None
assert (
ret["test_|-State A_|-fail_|-configurable_test_state"].full_return[
"changes"
]
== {}
)
assert not ret["test_|-State B_|-State B_|-configurable_test_state"].result
assert ret["test_|-State C_|-State C_|-nop"].result
assert not ret["test_|-State C_|-State C_|-nop"].full_return["__state_ran__"]
assert (
ret["test_|-State C_|-State C_|-nop"].full_return["comment"]
== "State was not run because none of the onchanges reqs changed"
)