From f89f95eff8ee17da5857b4bfd22c331c6cc56027 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Sun, 27 Sep 2026 15:39:24 +0200 Subject: [PATCH] Fix test isolation of cachedir in TestCollectAll TestCollectAll.setUp() copies the global cfg.CONF object with copy.copy() and restores it during cleanup. With oslo.config >= 10.7.0 on Python 3.14 this no longer isolates the tests: a stale cachedir value (a fixtures.TempDir path) leaks into subsequent tests, making TestConf.test_setup_conf fail, and sometimes TestEc2.test_collect_ec2_collected too. Replace the copy/restore hack with the standard oslo.config test isolation pattern already used by the other test modules: register self.addCleanup(cfg.CONF.reset) and set cachedir/backup_cachedir with cfg.CONF.set_override(). Found in the Debian rebuild on forky/sid (oslo.config 10.7.0, Python 3.14): https://bugs.debian.org/1149108 Closes-Bug: #2168664 Change-Id: Ibcc09cbb50a843a8e5e6c1f0beb7f1f26a3b2254 Signed-off-by: Thomas Goirand --- os_collect_config/tests/test_collect.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/os_collect_config/tests/test_collect.py b/os_collect_config/tests/test_collect.py index 33d536e..3617394 100644 --- a/os_collect_config/tests/test_collect.py +++ b/os_collect_config/tests/test_collect.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy import json import os import signal @@ -360,16 +359,12 @@ class TestCollectAll(testtools.TestCase): super().setUp() self.log = self.useFixture(fixtures.FakeLogger()) collect.setup_conf() + self.addCleanup(cfg.CONF.reset) self.cache_dir = self.useFixture(fixtures.TempDir()) self.backup_cache_dir = self.useFixture(fixtures.TempDir()) - self.clean_conf = copy.copy(cfg.CONF) - def restore_copy(): - cfg.CONF = self.clean_conf - self.addCleanup(restore_copy) - - cfg.CONF.cachedir = self.cache_dir.path - cfg.CONF.backup_cachedir = self.backup_cache_dir.path + cfg.CONF.set_override('cachedir', self.cache_dir.path) + cfg.CONF.set_override('backup_cachedir', self.backup_cache_dir.path) cfg.CONF.cfn.metadata_url = 'http://192.0.2.1:8000/v1/' cfg.CONF.cfn.stack_name = 'foo' cfg.CONF.cfn.path = ['foo.Metadata']