Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9356b2d

Browse files
Uniquify requisite_in'd states checks.
Fix #68408
1 parent 5bdbaae commit 9356b2d

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

salt/state.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,29 @@ def apply_exclude(self, high):
19031903
high.pop(id_)
19041904
return high
19051905

1906+
@staticmethod
1907+
def _add_to_extend(extend, name, state, rkey, rstate, id_):
1908+
found = False
1909+
if name not in extend:
1910+
extend[name] = HashableOrderedDict()
1911+
if rstate not in extend[name]:
1912+
extend[name][rstate] = []
1913+
for ind in range(len(extend[name][rstate])):
1914+
if next(iter(extend[name][rstate][ind])) == rkey:
1915+
for key in extend[name][rstate][ind][rkey]:
1916+
if key.get(state) == id_:
1917+
break
1918+
else:
1919+
# Extending again
1920+
extend[name][rstate][ind][rkey].append({state: id_})
1921+
found = True
1922+
1923+
if not found:
1924+
# The rkey is not present yet, create it
1925+
extend[name][rstate].append({rkey: [{state: id_}]})
1926+
1927+
return found
1928+
19061929
def requisite_in(self, high):
19071930
"""
19081931
Extend the data reference with requisite_in arguments
@@ -1953,11 +1976,7 @@ def requisite_in(self, high):
19531976
if isinstance(items, dict):
19541977
# Formatted as a single req_in
19551978
for _state, name in items.items():
1956-
19571979
# Not a use requisite_in
1958-
found = False
1959-
if name not in extend:
1960-
extend[name] = HashableOrderedDict()
19611980
if "." in _state:
19621981
errors.append(
19631982
"Invalid requisite in {}: {} for "
@@ -1971,21 +1990,13 @@ def requisite_in(self, high):
19711990
)
19721991
)
19731992
_state = _state.split(".")[0]
1974-
if _state not in extend[name]:
1975-
extend[name][_state] = []
1993+
found = self._add_to_extend(
1994+
extend, name, _state, rkey, state, id_
1995+
)
19761996
extend[name]["__env__"] = body["__env__"]
19771997
extend[name]["__sls__"] = body["__sls__"]
1978-
for ind in range(len(extend[name][_state])):
1979-
if next(iter(extend[name][_state][ind])) == rkey:
1980-
# Extending again
1981-
extend[name][_state][ind][rkey].append(
1982-
{state: id_}
1983-
)
1984-
found = True
19851998
if found:
19861999
continue
1987-
# The rkey is not present yet, create it
1988-
extend[name][_state].append({rkey: [{state: id_}]})
19892000

19902001
if isinstance(items, list):
19912002
# Formed as a list of requisite additions
@@ -2123,27 +2134,15 @@ def requisite_in(self, high):
21232134
continue
21242135
extend[id_][state].append(arg)
21252136
continue
2126-
found = False
2127-
if name not in extend:
2128-
extend[name] = HashableOrderedDict()
2129-
if _state not in extend[name]:
2130-
extend[name][_state] = []
2137+
found = self._add_to_extend(
2138+
extend, name, _state, rkey, state, id_
2139+
)
2140+
21312141
extend[name]["__env__"] = body["__env__"]
21322142
extend[name]["__sls__"] = body["__sls__"]
2133-
for ind in range(len(extend[name][_state])):
2134-
if (
2135-
next(iter(extend[name][_state][ind]))
2136-
== rkey
2137-
):
2138-
# Extending again
2139-
extend[name][_state][ind][rkey].append(
2140-
{state: id_}
2141-
)
2142-
found = True
2143+
21432144
if found:
21442145
continue
2145-
# The rkey is not present yet, create it
2146-
extend[name][_state].append({rkey: [{state: id_}]})
21472146
high["__extend__"] = []
21482147
for key, val in extend.items():
21492148
high["__extend__"].append({key: val})

0 commit comments

Comments
 (0)