diff --git a/changelog/68332.fixed.md b/changelog/68332.fixed.md new file mode 100644 index 000000000000..ea0d32d84c6e --- /dev/null +++ b/changelog/68332.fixed.md @@ -0,0 +1 @@ +Fixed worker process crash when salt is used outside CLI tools. diff --git a/salt/_logging/impl.py b/salt/_logging/impl.py index b73f2ee98f4e..e8749d9a470b 100644 --- a/salt/_logging/impl.py +++ b/salt/_logging/impl.py @@ -449,6 +449,8 @@ def set_logging_options_dict(opts): """ Create a logging related options dictionary based off of the loaded salt config """ + if opts is None: + return try: if isinstance(set_logging_options_dict.__options_dict__, ImmutableDict): raise RuntimeError( @@ -999,7 +1001,7 @@ def setup_log_granular_levels(log_granular_levels): def setup_logging(): opts = get_logging_options_dict() if not opts: - raise RuntimeError("The logging options have not been set yet.") + return if ( opts.get("configure_console_logger", True) and not is_console_handler_configured() diff --git a/tests/pytests/functional/utils/test_process.py b/tests/pytests/functional/utils/test_process.py index 067d3a1d7e65..979435768cd2 100644 --- a/tests/pytests/functional/utils/test_process.py +++ b/tests/pytests/functional/utils/test_process.py @@ -203,3 +203,18 @@ def run_sync(): assert ran == [True] finally: process_manager.terminate() + + +def test_process_unseeded_logging_options(): + """ + Regression test for issue #68332. + """ + + def target(): + pass + + salt._logging.set_logging_options_dict.__options_dict__ = None + proc = salt.utils.process.Process(target=target) + proc.start() + proc.join() + assert proc.exitcode == 0 diff --git a/tests/pytests/unit/_logging/test_impl.py b/tests/pytests/unit/_logging/test_impl.py new file mode 100644 index 000000000000..0961737dff7d --- /dev/null +++ b/tests/pytests/unit/_logging/test_impl.py @@ -0,0 +1,23 @@ +""" +tests.pytests.unit._logging.test_impl +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Test salt's logging implementation +""" + +import salt._logging.impl + + +def test_set_logging_options_dict_with_none(): + """ + Regression test for issue #68332. + """ + salt._logging.impl.set_logging_options_dict(None) + + +def test_setup_logging_with_unseeded_options(): + """ + Regression test for issue #68332. + """ + salt._logging.impl.set_logging_options_dict.__options_dict__ = None + salt._logging.impl.setup_logging()