Delete cache dirs even though repoclosure command failed

JIRA: COMPOSE-2565
Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2019-08-22 14:12:28 +08:00
parent 29224b02ff
commit 82349626c6

View File

@ -84,10 +84,31 @@ def run_repoclosure(compose):
else: else:
compose.log_warning('Repoclosure failed for %s.%s\n%s' compose.log_warning('Repoclosure failed for %s.%s\n%s'
% (variant.uid, arch, exc)) % (variant.uid, arch, exc))
finally:
if methods != "hybrid":
_delete_repoclosure_cache_dirs(compose, repos, lookaside)
compose.log_info("[DONE ] %s" % msg) 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): def _run_repoclosure_cmd(compose, repos, lookaside, arches, logfile):
cmd = repoclosure.get_repoclosure_cmd(backend=compose.conf["repoclosure_backend"], cmd = repoclosure.get_repoclosure_cmd(backend=compose.conf["repoclosure_backend"],
repos=repos, lookaside=lookaside, arch=arches) 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 # https://github.com/release-engineering/kobo/pull/26
run(cmd, logfile=logfile, workdir=tmp_dir, show_cmd=True) 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): def check_image_sanity(compose):
""" """