Updated tests and removed debugging statements

This commit is contained in:
David Murphy 2025-03-05 11:37:16 -07:00 committed by Daniel Wozniak
parent cb39a7d377
commit fa295250af
2 changed files with 4 additions and 118 deletions

View file

@ -6,7 +6,6 @@ import fnmatch
import glob
import logging
import os
import traceback
import salt.client
import salt.defaults.exitcodes
@ -342,12 +341,7 @@ class ReactWrap:
"""
Execute a reaction by invoking the proper wrapper func
"""
print(f"DGM class ReactWrap entry run, low '{low}'", flush=True)
self.populate_client_cache(low)
print(
f"DGM class ReactWrap run, self.client_cache '{self.client_cache}'",
flush=True,
)
try:
l_fun = getattr(self, low["state"])
except AttributeError:
@ -470,21 +464,10 @@ class ReactWrap:
"""
Wrap RunnerClient for executing :ref:`runner modules <all-salt.runners>`
"""
stk_summary = traceback.format_stack()
print(f"DGM class ReactWrap runner entry, backtrace '{stk_summary}'")
# pylint: disable=unsupported-membership-test,unsupported-assignment-operation
print(
f"DGM class ReactWrap runner, client_cache '{self.client_cache}', fun '{fun}', kwargs '{kwargs}'",
flush=True,
)
if "runner" not in self.client_cache:
log.debug("reactor edge case: re-populating client_cache for runner")
low = {"state": "runner"}
print(
f"DGM class ReactWrap runner not in client_cache, low '{low}'",
flush=True,
)
self.populate_client_cache(low)
return self.pool.fire_async(self.client_cache["runner"].low, args=(fun, kwargs))
@ -493,17 +476,9 @@ class ReactWrap:
Wrap Wheel to enable executing :ref:`wheel modules <all-salt.wheel>`
"""
# pylint: disable=unsupported-membership-test,unsupported-assignment-operation
print(
f"DGM class ReactWrap wheel, client_cache '{self.client_cache}', fun '{fun}', kwargs '{kwargs}'",
flush=True,
)
if "wheel" not in self.client_cache:
log.debug("reactor edge case: re-populating client_cache for wheel")
low = {"state": "wheel"}
print(
f"DGM class ReactWrap wheel not in client_cache, low '{low}'",
flush=True,
)
self.populate_client_cache(low)
return self.pool.fire_async(self.client_cache["wheel"].low, args=(fun, kwargs))
@ -512,17 +487,9 @@ class ReactWrap:
Wrap LocalClient for running :ref:`execution modules <all-salt.modules>`
"""
# pylint: disable=unsupported-membership-test,unsupported-assignment-operation
print(
f"DGM class ReactWrap local, client_cache '{self.client_cache}', fun '{fun}', kwargs '{kwargs}'",
flush=True,
)
if "local" not in self.client_cache:
log.debug("reactor edge case: re-populating client_cache for local")
low = {"state": "local"}
print(
f"DGM class ReactWrap local not in client_cache, low '{low}'",
flush=True,
)
self.populate_client_cache(low)
self.client_cache["local"].cmd_async(tgt, fun, **kwargs)
@ -531,16 +498,8 @@ class ReactWrap:
Wrap LocalCaller to execute remote exec functions locally on the Minion
"""
# pylint: disable=unsupported-membership-test,unsupported-assignment-operation
print(
f"DGM class ReactWrap caller, client_cache '{self.client_cache}', fun '{fun}', kwargs '{kwargs}'",
flush=True,
)
if "caller" not in self.client_cache:
log.debug("reactor edge case: re-populating client_cache for caller")
low = {"state": "caller"}
print(
f"DGM class ReactWrap caller not in client_cache, low '{low}'",
flush=True,
)
self.populate_client_cache(low)
self.client_cache["caller"].cmd(fun, *kwargs["arg"], **kwargs["kwarg"])

View file

@ -560,54 +560,7 @@ def test_caller(schema, react_wrap):
)
## DGM ## DGM @pytest.mark.parametrize("file_client", ["runner", "wheel", "local", "caller"])
## DGM @pytest.mark.parametrize("file_client", ["runner"])
## DGM def test_client_cache_missing_key(file_client, react_wrap):
## DGM """
## DGM Test client_cache file_client missing, gets repopulated
## DGM """
## DGM client_cache = {}
## DGM tag = f"new_{file_client}"
## DGM chunk = LOW_CHUNKS[tag][0]
## DGM print(
## DGM f"DGM test_client_cache_missing_key, file_client '{file_client}', tag '{tag}', chunk '{chunk}'",
## DGM flush=True,
## DGM )
## DGM thread_pool = Mock()
## DGM thread_pool.fire_async = Mock()
## DGM with patch.object(react_wrap, "client_cache", client_cache):
## DGM print(
## DGM f"DGM test_client_cache_missing_key patch client_cache, file_client '{file_client}', react_wrap.client_cache '{react_wrap.client_cache}'",
## DGM flush=True,
## DGM )
## DGM with patch.object(react_wrap, "pool", thread_pool):
## DGM print(
## DGM f"DGM test_client_cache_missing_key patch pool, file_client '{file_client}', react_wrap.client_cache '{react_wrap.client_cache}'",
## DGM flush=True,
## DGM )
## DGM ## DGM del react_wrap.client_cache[f"{file_client}"]
## DGM print(
## DGM f"DGM test_client_cache_missing_key post del key, file_client '{file_client}', react_wrap.client_cache '{react_wrap.client_cache}'",
## DGM flush=True,
## DGM )
## DGM react_wrap.run(chunk)
## DGM
## DGM print(
## DGM f"DGM test_client_cache_missing_key post patch, file_client '{file_client}', react_wrap.client_cache '{react_wrap.client_cache}'",
## DGM flush=True,
## DGM )
## DGM
## DGM thread_pool.fire_async.assert_called_with(
## DGM react_wrap.client_cache[file_client].low,
## DGM args=WRAPPER_CALLS[tag],
## DGM )
## DGM client_cache[file_client].cmd.assert_called_with(
## DGM *WRAPPER_CALLS[tag]["args"], **WRAPPER_CALLS[tag]["kwargs"]
## DGM )
## DGM @pytest.mark.parametrize("file_client", ["runner", "wheel", "local", "caller"])
@pytest.mark.parametrize("file_client", ["runner"])
@pytest.mark.parametrize("file_client", ["runner", "wheel", "local", "caller"])
def test_client_cache_missing_key(file_client, react_wrap):
"""
Test client_cache file_client missing, gets repopulated
@ -615,37 +568,11 @@ def test_client_cache_missing_key(file_client, react_wrap):
client_cache = {}
tag = f"new_{file_client}"
chunk = LOW_CHUNKS[tag][0]
print(
f"DGM test_client_cache_missing_key, file_client '{file_client}', tag '{tag}', chunk '{chunk}'",
flush=True,
)
thread_pool = Mock()
thread_pool.fire_async = Mock()
with patch.object(react_wrap, "client_cache", client_cache):
print(
f"DGM test_client_cache_missing_key patch client_cache, file_client '{file_client}', react_wrap.client_cache '{react_wrap.client_cache}'",
flush=True,
)
react_wrap.runner(chunk)
print(
f"DGM test_client_cache_missing_key post runner, file_client '{file_client}', react_wrap.client_cache '{react_wrap.client_cache}'",
flush=True,
)
## DGM dgm_key = react_wrap.client_cache.get(f"{file_client}")
## DGM dgm_key = [key for key in react_wrap.client_cache.keys() if key == f"{file_client}"]
## DGM dgm_key = None
## DGM dgm_key = [key if key == f"{file_client}" for key in react_wrap.client_cache.keys()]
dgm_keys = None
file_client_key = None
for key in react_wrap.client_cache.keys():
if key == f"{file_client}":
dgm_key = key
print(
f"DGM test_client_cache_missing_key check key, file_client '{file_client}', dgm_key '{dgm_key}', react_wrap.client_cache.keys '{react_wrap.client_cache.keys()}'",
flush=True,
)
file_client_key = key
print(
f"DGM test_client_cache_missing_key post get key, file_client '{file_client}', dgm_key '{dgm_key}', react_wrap.client_cache '{react_wrap.client_cache}'",
flush=True,
)
assert dgm_key == f"{file_client}"
assert file_client_key == f"{file_client}"