Skip to content
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

Always populate __sls__, __id__ and name on state requirements #63012

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/63012.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Requisite state chunks now all consistently contain `__id__`, `__sls__` and `name`.
39 changes: 28 additions & 11 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ def _run_check(self, low_data):
Check that unless doesn't return 0, and that onlyif returns a 0.
"""
ret = {"result": False, "comment": []}
for key in ("__sls__", "__id__", "name"):
ret[key] = low_data.get(key)
cmd_opts = {}

# Set arguments from cmd.run state as appropriate
Expand Down Expand Up @@ -979,6 +981,8 @@ def _run_check_onlyif(self, low_data, cmd_opts):
command returns False (non 0), the state will not run
"""
ret = {"result": False}
for key in ("__sls__", "__id__", "name"):
ret[key] = low_data.get(key)

if not isinstance(low_data["onlyif"], list):
low_data_onlyif = [low_data["onlyif"]]
Expand Down Expand Up @@ -1054,6 +1058,8 @@ def _run_check_unless(self, low_data, cmd_opts):
state will run.
"""
ret = {"result": False}
for key in ("__sls__", "__id__", "name"):
ret[key] = low_data.get(key)

if not isinstance(low_data["unless"], list):
low_data_unless = [low_data["unless"]]
Expand Down Expand Up @@ -1131,6 +1137,8 @@ def _run_check_cmd(self, low_data):
Alter the way a successful state run is determined
"""
ret = {"result": False}
for key in ("__sls__", "__id__", "name"):
ret[key] = low_data.get(key)
cmd_opts = {}
if "shell" in self.opts["grains"]:
cmd_opts["shell"] = self.opts["grains"].get("shell")
Expand Down Expand Up @@ -1161,6 +1169,8 @@ def _run_check_creates(self, low_data):
Check that listed files exist
"""
ret = {"result": False}
for key in ("__sls__", "__id__", "name"):
ret[key] = low_data.get(key)

if isinstance(low_data["creates"], str) and os.path.exists(low_data["creates"]):
ret["comment"] = "{} exists".format(low_data["creates"])
Expand Down Expand Up @@ -3086,8 +3096,9 @@ def call_chunk(self, low, running, chunks, depth=0):
"start_time": start_time,
"comment": comment,
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
run_dict[tag][key] = low.get(key)
self.__run_num += 1
self.event(run_dict[tag], len(chunks), fire_event=low.get("fire_event"))
return running
Expand All @@ -3112,8 +3123,9 @@ def call_chunk(self, low, running, chunks, depth=0):
"result": False,
"comment": "Recursive requisite found",
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
running[tag][key] = low.get(key)
self.__run_num += 1
self.event(
running[tag], len(chunks), fire_event=low.get("fire_event")
Expand All @@ -3140,8 +3152,9 @@ def call_chunk(self, low, running, chunks, depth=0):
"result": False,
"comment": "Recursive requisite found",
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
running[tag][key] = low.get(key)
else:
running = self.call_chunk(low, running, chunks, depth)
if self.check_failhard(chunk, running):
Expand All @@ -3165,7 +3178,8 @@ def call_chunk(self, low, running, chunks, depth=0):
self.pre[tag]["changes"] = {}
running[tag] = self.pre[tag]
running[tag]["__run_num__"] = self.__run_num
running[tag]["__sls__"] = low["__sls__"]
for key in ("__sls__", "__id__", "name"):
running[tag][key] = low.get(key)
# otherwise the failure was due to a requisite down the chain
else:
# determine what the requisite failures where, and return
Expand Down Expand Up @@ -3199,8 +3213,9 @@ def call_chunk(self, low, running, chunks, depth=0):
"start_time": start_time,
"comment": _cmt,
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
running[tag][key] = low.get(key)
self.pre[tag] = running[tag]
self.__run_num += 1
elif status == "change" and not low.get("__prereq__"):
Expand All @@ -3221,8 +3236,9 @@ def call_chunk(self, low, running, chunks, depth=0):
"start_time": start_time,
"comment": "No changes detected",
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
pre_ret[key] = low.get(key)
running[tag] = pre_ret
self.pre[tag] = pre_ret
self.__run_num += 1
Expand All @@ -3236,8 +3252,9 @@ def call_chunk(self, low, running, chunks, depth=0):
"comment": "State was not run because onfail req did not change",
"__state_ran__": False,
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
running[tag][key] = low.get(key)
self.__run_num += 1
elif status == "onchanges":
start_time, duration = _calculate_fake_duration()
Expand All @@ -3251,8 +3268,9 @@ def call_chunk(self, low, running, chunks, depth=0):
),
"__state_ran__": False,
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
running[tag][key] = low.get(key)
self.__run_num += 1
else:
if low.get("__prereq__"):
Expand All @@ -3275,17 +3293,16 @@ def call_chunk(self, low, running, chunks, depth=0):
"comment": sub_state_data.get("comment", ""),
"__state_ran__": True,
"__run_num__": self.__run_num,
"__sls__": low["__sls__"],
}
for key in ("__sls__", "__id__", "name"):
running[sub_tag][key] = low.get(key)

return running

def call_beacons(self, chunks, running):
"""
Find all of the beacon routines and call the associated mod_beacon runs
"""
listeners = []
crefs = {}
beacons = []
for chunk in chunks:
if "beacon" in chunk:
Expand Down
Loading