From 53a93f016a3412279f58f94cafb574511a525f30 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Fri, 23 Aug 2019 02:23:44 +0000 Subject: [PATCH] Refactor code for removing repoclosure cache For 'yum' backend, only cache dirs following repoclosure-$COMPOSE_ID-$variant.$arch name convention are created, e.g. repoclosure-DP-1.0-20190822.t.0-Bar-Tools.x86_64 But for 'dnf' backend, the dir name looks like repoclosure-$COMPOSE_ID-$variant.$arch-$suffix and there are other files created, e.g. repoclosure-DP-1.0-20190822.t.0-Bar-Tools.x86_64-df9fe164317e314e repoclosure-DP-1.0-20190822.t.0-Bar-Tools.x86_64-filenames.solvx repoclosure-DP-1.0-20190822.t.0-Bar-Tools.x86_64.solv JIRA: COMPOSE-2565 Signed-off-by: Haibo Lin --- pungi/phases/test.py | 25 ++++++++++++------------- tests/test_test_phase.py | 3 ++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pungi/phases/test.py b/pungi/phases/test.py index f0ed6d7e..cf1b8d04 100644 --- a/pungi/phases/test.py +++ b/pungi/phases/test.py @@ -51,14 +51,15 @@ def run_repoclosure(compose): if conf and conf[-1] == 'off': continue + prefix = "repoclosure-%s" % compose.compose_id lookaside = {} if variant.parent: - repo_id = "repoclosure-%s-%s.%s" % (compose.compose_id, variant.parent.uid, arch) + repo_id = "%s-%s.%s" % (prefix, variant.parent.uid, arch) repo_dir = compose.paths.compose.repository(arch=arch, variant=variant.parent) lookaside[repo_id] = repo_dir repos = {} - repo_id = "repoclosure-%s-%s.%s" % (compose.compose_id, variant.uid, arch) + repo_id = "%s-%s.%s" % (prefix, variant.uid, arch) repo_dir = compose.paths.compose.repository(arch=arch, variant=variant) repos[repo_id] = repo_dir @@ -86,27 +87,25 @@ def run_repoclosure(compose): % (variant.uid, arch, exc)) finally: if methods != "hybrid": - _delete_repoclosure_cache_dirs(compose, repos, lookaside) + _delete_repoclosure_cache_dirs(compose, prefix) compose.log_info("[DONE ] %s" % msg) -def _delete_repoclosure_cache_dirs(compose, repos, lookaside): +def _delete_repoclosure_cache_dirs(compose, prefix): if 'dnf' == compose.conf["repoclosure_backend"]: from dnf.yum.misc import getCacheDir else: from yum.misc import getCacheDir top_cache_dir = getCacheDir() - for repo_id in repos.keys(): - cache_dir = os.path.join(top_cache_dir, repo_id) - if os.path.isdir(cache_dir): - shutil.rmtree(cache_dir) - - for repo_id in lookaside.keys(): - cache_dir = os.path.join(top_cache_dir, repo_id) - if os.path.isdir(cache_dir): - shutil.rmtree(cache_dir) + for name in os.listdir(top_cache_dir): + if name.startswith(prefix): + cache_path = os.path.join(top_cache_dir, name) + if os.path.isdir(cache_path): + shutil.rmtree(cache_path) + else: + os.remove(cache_path) def _run_repoclosure_cmd(compose, repos, lookaside, arches, logfile): diff --git a/tests/test_test_phase.py b/tests/test_test_phase.py index d39b9f74..ff2e8e66 100644 --- a/tests/test_test_phase.py +++ b/tests/test_test_phase.py @@ -419,9 +419,10 @@ class TestRepoclosure(PungiTestCase): repos=self._get_repo(compose.compose_id, 'Server', 'x86_64')), ]) + @mock.patch('pungi.phases.test._delete_repoclosure_cache_dirs') @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') @mock.patch('pungi.phases.test.run') - def test_repoclosure_uses_correct_behaviour(self, mock_run, mock_grc): + def test_repoclosure_uses_correct_behaviour(self, mock_run, mock_grc, mock_del): compose = DummyCompose(self.topdir, { 'repoclosure_backend': 'dnf', 'repoclosure_strictness': [