Skip to content

Commit

Permalink
[tests] Enhance options_tests to cover presets
Browse files Browse the repository at this point in the history
Add some basic tests for presets.

Add plugin option tests covering #3855 .

Relevant: #3855

Signed-off-by: Pavel Moravec <[email protected]>
  • Loading branch information
pmoravec committed Jan 19, 2025
1 parent 00ef201 commit 228d2ff
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
49 changes: 41 additions & 8 deletions tests/report_tests/options_tests/options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
from sos_tests import StageTwoReportTest


class OptionsFromConfigTest(StageTwoReportTest):
"""Ensure that we handle options specified in sos.conf properly
class OptionsConfigPresetCmdlineTest(StageTwoReportTest):
"""Ensure that we handle options specified in sos.conf and
merge them with cmdline and preset properly
:avocado: tags=stagetwo
"""

files = [('options_tests_sos.conf', '/etc/sos/sos.conf')]
sos_cmd = ''
sos_cmd = '--preset minimal --journal-size 20 --cmd-timeout 60'

def test_case_id_from_config(self):
self.assertTrue('8675309' in self.archive)
Expand All @@ -44,8 +45,40 @@ def test_plugopts_actually_set(self):
self.assertFileCollected('sys/kernel/debug/tracing/trace')

def test_effective_options_logged_correctly(self):
self.assertSosLogContains(
"effective options now: --batch --case-id 8675309 "
"--only-plugins host,kernel "
"--plugopts kernel.with-timer=on,kernel.trace=yes"
)
for option in [
"--case-id 8675309",
"--only-plugins host,kernel",
"--plugopts kernel.with-timer=on,kernel.trace=yes",
"--preset minimal",
"--cmd-timeout 60", # cmdline beats config and preset
"--journal-size 20", # cmdline beats preset
"--log-size 10", # preset setting is honored
"--plugin-timeout 30", # preset beats config file
]:
self.assertSosLogContains(f"effective options now: .* {option}")


class PlugOptsConfigPresetCmdlineTest(StageTwoReportTest):
"""Ensure that plugin options specified in sos.conf or preset or cmdline
are handled and merged properly.
:avocado: tags=stagetwo
"""

files = [
('options_tests_sos.conf', '/etc/sos/sos.conf'),
('options_tests_preset.json', '/etc/sos/presets.d/plugopts_preset')
]
sos_cmd = '--preset plugopts_preset --container-runtime=none ' \
'-k crio.timeout=10,networking.timeout=20 -o crio,networking'

def test_effective_plugopts_logged_correctly(self):
for option in [
"--only-plugins crio,networking",
"--preset plugopts_preset",
"networking.timeout=20", # cmd beats config&preset
"crio.timeout=10", # cmdline beats preset
"networking.ethtool-namespaces=False", # preset setting is honored
"networking.namespaces=100", # preset beats config file
]:
self.assertSosLogContains(f"effective options now: .* {option}")
13 changes: 13 additions & 0 deletions tests/report_tests/options_tests/options_tests_preset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugopts_preset": {
"desc": "test preset for plugin options",
"args": {
"plugopts": [
"crio.timeout=600",
"networking.namespaces=200",
"networking.ethtool-namespaces=False",
"networking.timeout=600"
]
}
}
}
4 changes: 4 additions & 0 deletions tests/report_tests/options_tests/options_tests_sos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[report]
only-plugins = host,kernel
case-id = 8675309
plugin-timeout = 150
cmd-timeout = 20

[collect]
#primary = myhost.example.com
Expand All @@ -16,3 +18,5 @@ case-id = 8675309
kernel.with-timer = on
kernel.trace = yes
networking.traceroute = yes
networking.timeout = 60
networking.namespaces = 100

0 comments on commit 228d2ff

Please sign in to comment.