From 82349626c68313a608555d5c5e9009fdedc75613 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Thu, 22 Aug 2019 14:12:28 +0800 Subject: [PATCH] Delete cache dirs even though repoclosure command failed JIRA: COMPOSE-2565 Signed-off-by: Haibo Lin --- pungi/phases/test.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pungi/phases/test.py b/pungi/phases/test.py index fdd6bb07..f0ed6d7e 100644 --- a/pungi/phases/test.py +++ b/pungi/phases/test.py @@ -84,10 +84,31 @@ def run_repoclosure(compose): else: compose.log_warning('Repoclosure failed for %s.%s\n%s' % (variant.uid, arch, exc)) + finally: + if methods != "hybrid": + _delete_repoclosure_cache_dirs(compose, repos, lookaside) compose.log_info("[DONE ] %s" % msg) +def _delete_repoclosure_cache_dirs(compose, repos, lookaside): + 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) + + def _run_repoclosure_cmd(compose, repos, lookaside, arches, logfile): cmd = repoclosure.get_repoclosure_cmd(backend=compose.conf["repoclosure_backend"], repos=repos, lookaside=lookaside, arch=arches) @@ -100,22 +121,6 @@ def _run_repoclosure_cmd(compose, repos, lookaside, arches, logfile): # https://github.com/release-engineering/kobo/pull/26 run(cmd, logfile=logfile, workdir=tmp_dir, show_cmd=True) - # Delete cache dir - 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) - def check_image_sanity(compose): """