mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Ensure injected globals are defined on spawning platforms
This ensures dunders like __env__ are defined in states running in parallel on spawning platforms. The __running__ dict can contain salt.utils.process.Process instances, which are still picklable.
This commit is contained in:
parent
0e3d73e35e
commit
c4361cf828
2 changed files with 9 additions and 4 deletions
1
changelog/66996.fixed.md
Normal file
1
changelog/66996.fixed.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Ensured global dunders like __env__ are defined in state module that are run in parallel on spawning platforms
|
|
@ -2151,12 +2151,15 @@ class State:
|
||||||
return req_in_high, errors
|
return req_in_high, errors
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _call_parallel_target(cls, instance, init_kwargs, name, cdata, low):
|
def _call_parallel_target(
|
||||||
|
cls, instance, init_kwargs, name, cdata, low, inject_globals
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
The target function to call that will create the parallel thread/process
|
The target function to call that will create the parallel thread/process
|
||||||
"""
|
"""
|
||||||
if instance is None:
|
if instance is None:
|
||||||
instance = cls(**init_kwargs)
|
instance = cls(**init_kwargs)
|
||||||
|
instance.states.inject_globals = inject_globals
|
||||||
# we need to re-record start/end duration here because it is impossible to
|
# we need to re-record start/end duration here because it is impossible to
|
||||||
# correctly calculate further down the chain
|
# correctly calculate further down the chain
|
||||||
utc_start_time = datetime.datetime.utcnow()
|
utc_start_time = datetime.datetime.utcnow()
|
||||||
|
@ -2261,7 +2264,7 @@ class State:
|
||||||
with salt.utils.files.fopen(tfile, "wb+") as fp_:
|
with salt.utils.files.fopen(tfile, "wb+") as fp_:
|
||||||
fp_.write(msgpack_serialize(ret))
|
fp_.write(msgpack_serialize(ret))
|
||||||
|
|
||||||
def call_parallel(self, cdata, low):
|
def call_parallel(self, cdata, low, inject_globals):
|
||||||
"""
|
"""
|
||||||
Call the state defined in the given cdata in parallel
|
Call the state defined in the given cdata in parallel
|
||||||
"""
|
"""
|
||||||
|
@ -2278,10 +2281,11 @@ class State:
|
||||||
instance = None
|
instance = None
|
||||||
else:
|
else:
|
||||||
instance = self
|
instance = self
|
||||||
|
inject_globals = None
|
||||||
|
|
||||||
proc = salt.utils.process.Process(
|
proc = salt.utils.process.Process(
|
||||||
target=self._call_parallel_target,
|
target=self._call_parallel_target,
|
||||||
args=(instance, self._init_kwargs, name, cdata, low),
|
args=(instance, self._init_kwargs, name, cdata, low, inject_globals),
|
||||||
name=f"ParallelState({name})",
|
name=f"ParallelState({name})",
|
||||||
)
|
)
|
||||||
proc.start()
|
proc.start()
|
||||||
|
@ -2428,7 +2432,7 @@ class State:
|
||||||
)
|
)
|
||||||
elif not low.get("__prereq__") and low.get("parallel"):
|
elif not low.get("__prereq__") and low.get("parallel"):
|
||||||
# run the state call in parallel, but only if not in a prereq
|
# run the state call in parallel, but only if not in a prereq
|
||||||
ret = self.call_parallel(cdata, low)
|
ret = self.call_parallel(cdata, low, inject_globals)
|
||||||
else:
|
else:
|
||||||
self.format_slots(cdata)
|
self.format_slots(cdata)
|
||||||
with salt.utils.files.set_umask(low.get("__umask__")):
|
with salt.utils.files.set_umask(low.get("__umask__")):
|
||||||
|
|
Loading…
Add table
Reference in a new issue