From 234fb2f3fa28d90c1910d34604a1a459feb984d4 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Tue, 11 Aug 2026 19:37:09 +0200 Subject: [PATCH] [tests] Isolate cleaner's cache accross tests Similarly to --no-update and overriding default_mapping file, we need to isolate cleaner_cache per relevent test cases. Otherwise, items in the cach (like 'tmp') can pollute further tests. Closes: #4442 Signed-off-by: Pavel Moravec --- .../basic_function_tests/report_with_mask.py | 3 +++ tests/cleaner_tests/existing_archive.py | 3 +++ tests/cleaner_tests/full_report/default_mapping | 0 .../cleaner_tests/full_report/full_report_run.py | 5 ++--- tests/cleaner_tests/ipv6_test/default_mapping | 0 tests/cleaner_tests/ipv6_test/ipv6_test.py | 9 ++++----- tests/sos_tests.py | 15 +++++++++++++++ 7 files changed, 27 insertions(+), 8 deletions(-) delete mode 100644 tests/cleaner_tests/full_report/default_mapping delete mode 100644 tests/cleaner_tests/ipv6_test/default_mapping diff --git a/tests/cleaner_tests/basic_function_tests/report_with_mask.py b/tests/cleaner_tests/basic_function_tests/report_with_mask.py index 9b212e2c66..33729a6247 100644 --- a/tests/cleaner_tests/basic_function_tests/report_with_mask.py +++ b/tests/cleaner_tests/basic_function_tests/report_with_mask.py @@ -95,6 +95,9 @@ class ReportWithUserCustomisations(StageOneReportTest): 'BOOT_IMAGE,fs.dentry-state --skip-cleaning-files ' 'proc/cmdline,sos_commands/*/sysctl* --no-update') + def pre_sos_setup(self): + self.setup_isolated_cleaner_cache() + # Will the 'tmp' be properly treated in path to working dir without # raising an error? # To make this test effective, we assume the test runs on a system / with diff --git a/tests/cleaner_tests/existing_archive.py b/tests/cleaner_tests/existing_archive.py index da09824098..f15a18e70a 100644 --- a/tests/cleaner_tests/existing_archive.py +++ b/tests/cleaner_tests/existing_archive.py @@ -129,6 +129,9 @@ class ExistingArchiveCleanTmpTest(StageTwoReportTest): tests/test_data/{ARCHIVE}.tar.xz' sos_component = 'clean' + def pre_sos_setup(self): + self.setup_isolated_cleaner_cache() + def test_sys_tmp_not_obfuscated(self): """ Ensure that keywords avocado and ExistingArchiveCleanTmpTest remains in the final archive path despite they are parts of the diff --git a/tests/cleaner_tests/full_report/default_mapping b/tests/cleaner_tests/full_report/default_mapping deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/cleaner_tests/full_report/full_report_run.py b/tests/cleaner_tests/full_report/full_report_run.py index 0396e526ec..e0fa6e177e 100644 --- a/tests/cleaner_tests/full_report/full_report_run.py +++ b/tests/cleaner_tests/full_report/full_report_run.py @@ -22,9 +22,6 @@ class FullCleanTest(StageTwoReportTest): sos_cmd = '--clean' sos_timeout = 600 - # replace with an empty placeholder, make sure that this test case is not - # influenced by previous clean runs - files = [('default_mapping', '/etc/sos/cleaner/default_mapping')] packages = { 'rhel': ['python3-systemd'], 'ubuntu': ['python3-systemd'] @@ -32,6 +29,8 @@ class FullCleanTest(StageTwoReportTest): physical_or_vm_only = True def pre_sos_setup(self): + self.setup_isolated_cleaner_cache() + # ensure that case-insensitive matching of FQDNs and shortnames work from systemd import journal from socket import gethostname diff --git a/tests/cleaner_tests/ipv6_test/default_mapping b/tests/cleaner_tests/ipv6_test/default_mapping deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/cleaner_tests/ipv6_test/ipv6_test.py b/tests/cleaner_tests/ipv6_test/ipv6_test.py index e0a1fef60e..5a3f7c08d2 100644 --- a/tests/cleaner_tests/ipv6_test/ipv6_test.py +++ b/tests/cleaner_tests/ipv6_test/ipv6_test.py @@ -22,12 +22,11 @@ class IPv6Test(StageTwoReportTest): install_plugins = ['ipv6'] sos_cmd = '--clean -o ipv6' sos_timeout = 600 - # replace default mapping to avoid being influenced by previous runs # place mock file with crafted address used by mocked plugin - files = [ - ('default_mapping', '/etc/sos/cleaner/default_mapping'), - ('sos-test-ipv6.txt', MOCK_FILE) - ] + files = [('sos-test-ipv6.txt', MOCK_FILE)] + + def pre_sos_setup(self): + self.setup_isolated_cleaner_cache() def test_valid_ipv6(self): self.assertFileCollected(MOCK_FILE) diff --git a/tests/sos_tests.py b/tests/sos_tests.py index 7d6dc210b5..687249c50e 100644 --- a/tests/sos_tests.py +++ b/tests/sos_tests.py @@ -762,6 +762,21 @@ def get_plugin_manifest(self, plugin): raise Exception(f"Manifest for {plugin} not present") return self.manifest['components']['report']['plugins'][plugin] + def setup_isolated_cleaner_cache(self): + """Create an isolated mapping file in the test's tmpdir to ensure + each test run has its own cleaner_cache directory that doesn't + interfere with other test runs or the system's default cache. + + This ensures cleaner_cache will be at {tmpdir}/cleaner_cache/ + instead of /etc/sos/cleaner/cleaner_cache/ + """ + map_file = os.path.join(self.tmpdir, 'test_mapping') + # Create empty mapping file + with open(map_file, 'w', encoding='utf-8'): + pass + # Dynamically add --map-file to sos_cmd with the unique tmpdir path + self.sos_cmd += f' --map-file {map_file}' + class StageOneReportTest(BaseSoSReportTest): """This is the test class to subclass for all Stage One (no mocking) tests