From bc4f6c91f8def589d61a4cf58d54070deb6ac58c Mon Sep 17 00:00:00 2001 From: BharatDeva <278575558+BharatDeva@users.noreply.github.com> Date: Sat, 9 May 2026 20:51:13 -0500 Subject: [PATCH] Handle missing intelmqdump defaults When loading global settings fails in an incomplete setup, intelmqdump falls back to the default log level but still needs an empty defaults mapping for later logging configuration. Reuse that mapping instead of loading the same settings a second time. Add a regression test covering dump listing when global defaults cannot be loaded. Signed-off-by: BharatDeva <278575558+BharatDeva@users.noreply.github.com> --- intelmq/bin/intelmqdump.py | 2 +- intelmq/tests/bin/test_intelmqdump.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/intelmq/bin/intelmqdump.py b/intelmq/bin/intelmqdump.py index eb254d166d..9360469056 100644 --- a/intelmq/bin/intelmqdump.py +++ b/intelmq/bin/intelmqdump.py @@ -191,6 +191,7 @@ def main(argv=None): try: defaults = utils.get_global_settings() except Exception: + defaults = {} log_level = DEFAULT_LOGGING_LEVEL try: @@ -207,7 +208,6 @@ def main(argv=None): readline.parse_and_bind("tab: complete") readline.set_completer_delims('') - defaults = utils.get_global_settings() runtime_config = utils.get_runtime() pipeline_pipes = {} logging_paths = {defaults.get('logging_path', DEFAULT_LOGGING_PATH)} diff --git a/intelmq/tests/bin/test_intelmqdump.py b/intelmq/tests/bin/test_intelmqdump.py index fc1973eb62..05e609f063 100644 --- a/intelmq/tests/bin/test_intelmqdump.py +++ b/intelmq/tests/bin/test_intelmqdump.py @@ -108,6 +108,18 @@ def test_list_dumps_for_all_bots_from_default_log_path(self, _): self.assertIn("0: test-1 empty file", output[1]) self.assertIn("1: test-2 empty file", output[2]) + @skip_installation() + @mock.patch.object(intelmqdump, "input", return_value='q') + def test_list_dumps_when_defaults_cannot_be_loaded(self, _): + self._prepare_empty_dump('test-1') + + intelmqdump.utils.get_global_settings.side_effect = OSError("missing runtime") + + with mock.patch.object(intelmqdump, "DEFAULT_LOGGING_PATH", self.tmp_log_dir.name): + output = self._run_main([]) + + self.assertIn("0: test-1 empty file", output[1]) + @skip_installation() @mock.patch.object(intelmqdump, "input", return_value='q') def test_list_dumps_for_all_bots_from_custom_locations(self, _):