Skip to content

Commit 89f484d

Browse files
committed
fix(logging): tolerate unset options dict in worker bootstrap
CLI parsers seed salt._logging's global options dict at startup via LogLevelMixIn.__setup_logging_config(). Non-CLI consumers (RunnerClient.asynchronous, SSHClient, salt.utils.process.Process subclasses, parallel states) have no parser, so the dict stays None. Process.__new__ snapshots that None into instance.__logging_config__; wrapped_run_func then calls set_logging_options_dict(None) defensively, which forwards to set_lowest_log_level_by_opts(None).get(...) and AttributeErrors on the worker. The parent exits 0 with a misleading "Target did not return any data" / dead jid / 'result': None. Make set_logging_options_dict(None) and setup_logging() (when nothing has been seeded) no-op gracefully. Workers fall back to whatever logger configuration they inherited from the parent. CLI tools always seed before calling and are unaffected. Fixes #68332 Signed-off-by: Teddy Andrieux <teddy.andrieux@scality.com>
1 parent 5b1e6b4 commit 89f484d

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

changelog/68332.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed worker process crash when salt is used outside CLI tools.

salt/_logging/impl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ def set_logging_options_dict(opts):
449449
"""
450450
Create a logging related options dictionary based off of the loaded salt config
451451
"""
452+
if opts is None:
453+
return
452454
try:
453455
if isinstance(set_logging_options_dict.__options_dict__, ImmutableDict):
454456
raise RuntimeError(
@@ -999,7 +1001,7 @@ def setup_log_granular_levels(log_granular_levels):
9991001
def setup_logging():
10001002
opts = get_logging_options_dict()
10011003
if not opts:
1002-
raise RuntimeError("The logging options have not been set yet.")
1004+
return
10031005
if (
10041006
opts.get("configure_console_logger", True)
10051007
and not is_console_handler_configured()

tests/pytests/functional/utils/test_process.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,18 @@ def run_sync():
203203
assert ran == [True]
204204
finally:
205205
process_manager.terminate()
206+
207+
208+
def test_process_unseeded_logging_options():
209+
"""
210+
Regression test for issue #68332.
211+
"""
212+
213+
def target():
214+
pass
215+
216+
salt._logging.set_logging_options_dict.__options_dict__ = None
217+
proc = salt.utils.process.Process(target=target)
218+
proc.start()
219+
proc.join()
220+
assert proc.exitcode == 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
tests.pytests.unit._logging.test_impl
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
Test salt's logging implementation
6+
"""
7+
8+
import salt._logging.impl
9+
10+
11+
def test_set_logging_options_dict_with_none():
12+
"""
13+
Regression test for issue #68332.
14+
"""
15+
salt._logging.impl.set_logging_options_dict(None)
16+
17+
18+
def test_setup_logging_with_unseeded_options():
19+
"""
20+
Regression test for issue #68332.
21+
"""
22+
salt._logging.impl.set_logging_options_dict.__options_dict__ = None
23+
salt._logging.impl.setup_logging()

0 commit comments

Comments
 (0)