mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Remove stack_context
This commit is contained in:
parent
79f240c2e9
commit
5edd2259d8
4 changed files with 47 additions and 63 deletions
|
@ -14,7 +14,6 @@ from collections.abc import Mapping, MutableMapping
|
|||
import salt._logging
|
||||
import salt.channel.client
|
||||
import salt.exceptions
|
||||
import salt.ext.tornado.stack_context
|
||||
import salt.minion
|
||||
import salt.output
|
||||
import salt.utils.args
|
||||
|
@ -379,29 +378,25 @@ class SyncClientMixin(ClientStateMixin):
|
|||
data["fun_args"] = list(args) + ([kwargs] if kwargs else [])
|
||||
func_globals["__jid_event__"].fire_event(data, "new")
|
||||
|
||||
# Initialize a context for executing the method.
|
||||
with salt.ext.tornado.stack_context.StackContext(
|
||||
self.functions.context_dict.clone
|
||||
):
|
||||
func = self.functions[fun]
|
||||
try:
|
||||
data["return"] = func(*args, **kwargs)
|
||||
except TypeError as exc:
|
||||
data[
|
||||
"return"
|
||||
] = "\nPassed invalid arguments: {}\n\nUsage:\n{}".format(
|
||||
exc, func.__doc__
|
||||
)
|
||||
try:
|
||||
data["success"] = self.context.get("retcode", 0) == 0
|
||||
except AttributeError:
|
||||
# Assume a True result if no context attribute
|
||||
data["success"] = True
|
||||
if isinstance(data["return"], dict) and "data" in data["return"]:
|
||||
# some functions can return boolean values
|
||||
data["success"] = salt.utils.state.check_result(
|
||||
data["return"]["data"]
|
||||
)
|
||||
func = self.functions[fun]
|
||||
try:
|
||||
data["return"] = func(*args, **kwargs)
|
||||
except TypeError as exc:
|
||||
data[
|
||||
"return"
|
||||
] = "\nPassed invalid arguments: {}\n\nUsage:\n{}".format(
|
||||
exc, func.__doc__
|
||||
)
|
||||
try:
|
||||
data["success"] = self.context.get("retcode", 0) == 0
|
||||
except AttributeError:
|
||||
# Assume a True result if no context attribute
|
||||
data["success"] = True
|
||||
if isinstance(data["return"], dict) and "data" in data["return"]:
|
||||
# some functions can return boolean values
|
||||
data["success"] = salt.utils.state.check_result(
|
||||
data["return"]["data"]
|
||||
)
|
||||
except (Exception, SystemExit) as ex: # pylint: disable=broad-except
|
||||
if isinstance(ex, salt.exceptions.NotImplemented):
|
||||
data["return"] = str(ex)
|
||||
|
|
|
@ -56,7 +56,6 @@ import salt.utils.zeromq
|
|||
import salt.wheel
|
||||
from salt.config import DEFAULT_INTERVAL
|
||||
from salt.defaults import DEFAULT_TARGET_DELIM
|
||||
from salt.ext.tornado.stack_context import StackContext
|
||||
from salt.transport import TRANSPORTS
|
||||
from salt.utils.channel import iter_transport_opts
|
||||
from salt.utils.ctx import RequestContext
|
||||
|
@ -1105,10 +1104,7 @@ class MWorker(salt.utils.process.SignalHandlingProcess):
|
|||
def run_func(data):
|
||||
return self.aes_funcs.run_func(data["cmd"], data)
|
||||
|
||||
with StackContext(
|
||||
functools.partial(RequestContext, {"data": data, "opts": self.opts})
|
||||
):
|
||||
ret = run_func(data)
|
||||
ret = run_func(data)
|
||||
|
||||
if self.opts["master_stats"]:
|
||||
self._post_stats(start, cmd)
|
||||
|
|
|
@ -1691,10 +1691,9 @@ class Minion(MinionBase):
|
|||
|
||||
timeout_handler = handle_timeout
|
||||
|
||||
with salt.ext.tornado.stack_context.ExceptionStackContext(timeout_handler):
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
self._send_req_async(load, timeout, callback=lambda f: None)
|
||||
# pylint: enable=unexpected-keyword-arg
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
self._send_req_async(load, timeout, callback=lambda f: None)
|
||||
# pylint: enable=unexpected-keyword-arg
|
||||
return True
|
||||
|
||||
@salt.ext.tornado.gen.coroutine
|
||||
|
@ -1829,11 +1828,7 @@ class Minion(MinionBase):
|
|||
else:
|
||||
return Minion._thread_return(minion_instance, opts, data)
|
||||
|
||||
with salt.ext.tornado.stack_context.StackContext(
|
||||
functools.partial(RequestContext, {"data": data, "opts": opts})
|
||||
):
|
||||
with salt.ext.tornado.stack_context.StackContext(minion_instance.ctx):
|
||||
run_func(minion_instance, opts, data)
|
||||
run_func(minion_instance, opts, data)
|
||||
|
||||
def _execute_job_function(
|
||||
self, function_name, function_args, executors, opts, data
|
||||
|
@ -2253,12 +2248,11 @@ class Minion(MinionBase):
|
|||
timeout_handler()
|
||||
return ""
|
||||
else:
|
||||
with salt.ext.tornado.stack_context.ExceptionStackContext(timeout_handler):
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
ret_val = self._send_req_async(
|
||||
load, timeout=timeout, callback=lambda f: None
|
||||
)
|
||||
# pylint: enable=unexpected-keyword-arg
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
ret_val = self._send_req_async(
|
||||
load, timeout=timeout, callback=lambda f: None
|
||||
)
|
||||
# pylint: enable=unexpected-keyword-arg
|
||||
|
||||
log.trace("ret_val = %s", ret_val) # pylint: disable=no-member
|
||||
return ret_val
|
||||
|
@ -2344,12 +2338,11 @@ class Minion(MinionBase):
|
|||
timeout_handler()
|
||||
return ""
|
||||
else:
|
||||
with salt.ext.tornado.stack_context.ExceptionStackContext(timeout_handler):
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
ret_val = self._send_req_async(
|
||||
load, timeout=timeout, callback=lambda f: None
|
||||
)
|
||||
# pylint: enable=unexpected-keyword-arg
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
ret_val = self._send_req_async(
|
||||
load, timeout=timeout, callback=lambda f: None
|
||||
)
|
||||
# pylint: enable=unexpected-keyword-arg
|
||||
|
||||
log.trace("ret_val = %s", ret_val) # pylint: disable=no-member
|
||||
return ret_val
|
||||
|
@ -3293,19 +3286,18 @@ class Syndic(Minion):
|
|||
log.warning("Unable to forward pub data: %s", args[1])
|
||||
return True
|
||||
|
||||
with salt.ext.tornado.stack_context.ExceptionStackContext(timeout_handler):
|
||||
self.local.pub_async(
|
||||
data["tgt"],
|
||||
data["fun"],
|
||||
data["arg"],
|
||||
data["tgt_type"],
|
||||
data["ret"],
|
||||
data["jid"],
|
||||
data["to"],
|
||||
io_loop=self.io_loop,
|
||||
callback=lambda _: None,
|
||||
**kwargs
|
||||
)
|
||||
self.local.pub_async(
|
||||
data["tgt"],
|
||||
data["fun"],
|
||||
data["arg"],
|
||||
data["tgt_type"],
|
||||
data["ret"],
|
||||
data["jid"],
|
||||
data["to"],
|
||||
io_loop=self.io_loop,
|
||||
callback=lambda _: None,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def _send_req_sync(self, load, timeout):
|
||||
if self.opts["minion_sign_messages"]:
|
||||
|
|
|
@ -363,6 +363,7 @@ class TCPReqServer(salt.transport.base.DaemonizedRequestServer):
|
|||
message_handler: function to call with your payloads
|
||||
"""
|
||||
self.message_handler = message_handler
|
||||
log.info("ReqServer workers %s", socket)
|
||||
|
||||
with salt.utils.asynchronous.current_ioloop(io_loop):
|
||||
if USE_LOAD_BALANCER:
|
||||
|
|
Loading…
Add table
Reference in a new issue