|
| 1 | +From c00801d2f9807e49769d0e0d848ec12be555dbc1 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Victor Zhestkov < [email protected]> |
| 3 | +Date: Wed, 25 Sep 2024 14:07:05 +0300 |
| 4 | +Subject: [PATCH] Revert the change making reactor less blocking |
| 5 | + (bsc#1230322) |
| 6 | + |
| 7 | +This reverts commit 0d35f09288700f5c961567442c3fcc25838b8de4. |
| 8 | +--- |
| 9 | + salt/utils/reactor.py | 45 ++++++++++++++++--------------------------- |
| 10 | + 1 file changed, 17 insertions(+), 28 deletions(-) |
| 11 | + |
| 12 | +diff --git a/salt/utils/reactor.py b/salt/utils/reactor.py |
| 13 | +index 78adad34da..19420a51cf 100644 |
| 14 | +--- a/salt/utils/reactor.py |
| 15 | ++++ b/salt/utils/reactor.py |
| 16 | +@@ -1,12 +1,10 @@ |
| 17 | + """ |
| 18 | + Functions which implement running reactor jobs |
| 19 | + """ |
| 20 | +- |
| 21 | + import fnmatch |
| 22 | + import glob |
| 23 | + import logging |
| 24 | + import os |
| 25 | +-from threading import Lock |
| 26 | + |
| 27 | + import salt.client |
| 28 | + import salt.defaults.exitcodes |
| 29 | +@@ -196,6 +194,13 @@ class Reactor(salt.utils.process.SignalHandlingProcess, salt.state.Compiler): |
| 30 | + self.resolve_aliases(chunks) |
| 31 | + return chunks |
| 32 | + |
| 33 | ++ def call_reactions(self, chunks): |
| 34 | ++ """ |
| 35 | ++ Execute the reaction state |
| 36 | ++ """ |
| 37 | ++ for chunk in chunks: |
| 38 | ++ self.wrap.run(chunk) |
| 39 | ++ |
| 40 | + def run(self): |
| 41 | + """ |
| 42 | + Enter into the server loop |
| 43 | +@@ -213,7 +218,7 @@ class Reactor(salt.utils.process.SignalHandlingProcess, salt.state.Compiler): |
| 44 | + ) as event: |
| 45 | + self.wrap = ReactWrap(self.opts) |
| 46 | + |
| 47 | +- for data in event.iter_events(full=True, auto_reconnect=True): |
| 48 | ++ for data in event.iter_events(full=True): |
| 49 | + # skip all events fired by ourselves |
| 50 | + if data["data"].get("user") == self.wrap.event_user: |
| 51 | + continue |
| 52 | +@@ -263,9 +268,15 @@ class Reactor(salt.utils.process.SignalHandlingProcess, salt.state.Compiler): |
| 53 | + if not self.is_leader: |
| 54 | + continue |
| 55 | + else: |
| 56 | +- self.wrap.call_reactions( |
| 57 | +- data, self.list_reactors, self.reactions |
| 58 | +- ) |
| 59 | ++ reactors = self.list_reactors(data["tag"]) |
| 60 | ++ if not reactors: |
| 61 | ++ continue |
| 62 | ++ chunks = self.reactions(data["tag"], data["data"], reactors) |
| 63 | ++ if chunks: |
| 64 | ++ try: |
| 65 | ++ self.call_reactions(chunks) |
| 66 | ++ except SystemExit: |
| 67 | ++ log.warning("Exit ignored by reactor") |
| 68 | + |
| 69 | + |
| 70 | + class ReactWrap: |
| 71 | +@@ -286,7 +297,6 @@ class ReactWrap: |
| 72 | + |
| 73 | + def __init__(self, opts): |
| 74 | + self.opts = opts |
| 75 | +- self._run_lock = Lock() |
| 76 | + if ReactWrap.client_cache is None: |
| 77 | + ReactWrap.client_cache = salt.utils.cache.CacheDict( |
| 78 | + opts["reactor_refresh_interval"] |
| 79 | +@@ -470,24 +480,3 @@ class ReactWrap: |
| 80 | + Wrap LocalCaller to execute remote exec functions locally on the Minion |
| 81 | + """ |
| 82 | + self.client_cache["caller"].cmd(fun, *kwargs["arg"], **kwargs["kwarg"]) |
| 83 | +- |
| 84 | +- def _call_reactions(self, data, list_reactors, get_reactions): |
| 85 | +- reactors = list_reactors(data["tag"]) |
| 86 | +- if not reactors: |
| 87 | +- return |
| 88 | +- chunks = get_reactions(data["tag"], data["data"], reactors) |
| 89 | +- if not chunks: |
| 90 | +- return |
| 91 | +- with self._run_lock: |
| 92 | +- try: |
| 93 | +- for chunk in chunks: |
| 94 | +- self.run(chunk) |
| 95 | +- except Exception as exc: # pylint: disable=broad-except |
| 96 | +- log.error( |
| 97 | +- "Exception while calling the reactions: %s", exc, exc_info=True |
| 98 | +- ) |
| 99 | +- |
| 100 | +- def call_reactions(self, data, list_reactors, get_reactions): |
| 101 | +- return self.pool.fire_async( |
| 102 | +- self._call_reactions, args=(data, list_reactors, get_reactions) |
| 103 | +- ) |
| 104 | +-- |
| 105 | +2.46.1 |
| 106 | + |
0 commit comments