From 15d138ad6e8fd0e55f8bbe4ab9521cb52ceea24d Mon Sep 17 00:00:00 2001 From: Jose Castillo Date: Wed, 3 Jun 2026 09:12:43 +0100 Subject: [PATCH] [tests] Add tests for skip/enable-plugins merge from config and cmdline Verify that skip-plugins and enable-plugins are merged (not replaced) when specified in both sos.conf and command line. Also verify that the option only-plugins uses replacement (not merge) approach, and that preset options take precedence over config file values. This is a regression test for commit 8fc655a6, which fixed the merge behavior. The new tests verify both effective options logging in sos.log and actual plugin execution. Signed-off-by: Jose Castillo --- .../config_cmdline_enabled_tests_sos.conf | 2 + .../config_cmdline_only_tests_sos.conf | 2 + .../config_cmdline_skipped_tests_sos.conf | 2 + .../config_cmdline/config_cmdline_tests.py | 90 +++++++++++++++++++ .../config_preset_precedence_tests.json | 10 +++ .../config_preset_precedence_tests_sos.conf | 2 + 6 files changed, 108 insertions(+) create mode 100644 tests/report_tests/plugin_tests/config_cmdline/config_cmdline_enabled_tests_sos.conf create mode 100644 tests/report_tests/plugin_tests/config_cmdline/config_cmdline_only_tests_sos.conf create mode 100644 tests/report_tests/plugin_tests/config_cmdline/config_cmdline_skipped_tests_sos.conf create mode 100644 tests/report_tests/plugin_tests/config_cmdline/config_cmdline_tests.py create mode 100644 tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests.json create mode 100644 tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests_sos.conf diff --git a/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_enabled_tests_sos.conf b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_enabled_tests_sos.conf new file mode 100644 index 0000000000..a81d228d35 --- /dev/null +++ b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_enabled_tests_sos.conf @@ -0,0 +1,2 @@ +[report] +enable-plugins = networking diff --git a/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_only_tests_sos.conf b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_only_tests_sos.conf new file mode 100644 index 0000000000..535080c0f7 --- /dev/null +++ b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_only_tests_sos.conf @@ -0,0 +1,2 @@ +[report] +only-plugins = host diff --git a/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_skipped_tests_sos.conf b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_skipped_tests_sos.conf new file mode 100644 index 0000000000..2a6da17217 --- /dev/null +++ b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_skipped_tests_sos.conf @@ -0,0 +1,2 @@ +[report] +skip-plugins = host diff --git a/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_tests.py b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_tests.py new file mode 100644 index 0000000000..07616f61a8 --- /dev/null +++ b/tests/report_tests/plugin_tests/config_cmdline/config_cmdline_tests.py @@ -0,0 +1,90 @@ +# Copyright (C) 2026 Red Hat, Inc., Jose Castillo + +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + +from sos_tests import StageTwoReportTest + + +class SkippedPluginConfigCmdlineTest(StageTwoReportTest): + """Ensure that we handle skipped plugins specified + in sos.conf and merge them with cmdline properly + + :avocado: tags=stagetwo + """ + + files = [('config_cmdline_skipped_tests_sos.conf', '/etc/sos/sos.conf')] + sos_cmd = '-n kernel' + + def test_skip_plugins_merged_from_conf_and_cmdline(self): + # Plugin host is deactivated via sos.conf file + # Plugin kernel is deactivated via cmdline + options = r'--skip-plugins (host,kernel|kernel,host)' + self.assertSosLogContains(f"effective options now: .*{options}") + self.assertPluginNotIncluded('host') + self.assertPluginNotIncluded('kernel') + + +class EnabledPluginConfigCmdlineTest(StageTwoReportTest): + """Ensure that we handle enabled plugins specified in sos.conf + and merge them with cmdline properly + + :avocado: tags=stagetwo + """ + + files = [('config_cmdline_enabled_tests_sos.conf', '/etc/sos/sos.conf')] + sos_cmd = '-e memory' + + def test_enabled_plugins_merged_from_conf_and_cmdline(self): + # Plugin networking is enabled via sos.conf file + # Plugin memory is enabled via cmdline + options = r'--enable-plugins (networking,memory|memory,networking)' + self.assertSosLogContains(f"effective options now: .*{options}") + self.assertPluginIncluded('networking') + self.assertPluginIncluded('memory') + + +class PreferPluginPresetConfigTest(StageTwoReportTest): + """Test that the preset takes precedence over config file + + :avocado: tags=stagetwo + """ + + files = [('config_preset_precedence_tests_sos.conf', '/etc/sos/sos.conf'), + ('config_preset_precedence_tests.json', + '/etc/sos/presets.d/plugins_preset')] + sos_cmd = '--preset plugins_preset' + + def test_precedence_preset_config(self): + # Plugin memory is enabled via sos.conf file + # Plugin memory is skipped via preset file + options = r'--skip-plugins memory' + self.assertSosLogContains(f"effective options now: .*{options}") + self.assertPluginNotIncluded('memory') + + +class OnlyPluginConfigCmdlineTest(StageTwoReportTest): + """Test that only-plugins from cmdline replaces rather than merges + config value + + Unlike skip-plugins and enable-plugins, which merge, only-plugins uses + replacement since it defines an exclusive set. + + :avocado: tags=stagetwo + """ + + files = [('config_cmdline_only_tests_sos.conf', '/etc/sos/sos.conf')] + sos_cmd = '-o kernel' + + def test_only_plugins_cmdline_replaces_config(self): + # Plugin host is enabled (only) via sos.conf file + # Plugin kernel is specified via cmdline + options = r'--only-plugins kernel' + self.assertSosLogContains(f"effective options now: .*{options}") + self.assertPluginIncluded('kernel') + self.assertPluginNotIncluded('host') diff --git a/tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests.json b/tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests.json new file mode 100644 index 0000000000..702150a70e --- /dev/null +++ b/tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests.json @@ -0,0 +1,10 @@ +{ + "plugins_preset": { + "desc": "test preset for plugin skipping", + "args": { + "skip_plugins": [ + "memory" + ] + } + } +} diff --git a/tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests_sos.conf b/tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests_sos.conf new file mode 100644 index 0000000000..30bb6db5e0 --- /dev/null +++ b/tests/report_tests/plugin_tests/config_cmdline/config_preset_precedence_tests_sos.conf @@ -0,0 +1,2 @@ +[report] +enable-plugins = memory