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 <hlin@redhat.com>
This commit is contained in:
parent
82349626c6
commit
53a93f016a
@ -51,14 +51,15 @@ def run_repoclosure(compose):
|
|||||||
if conf and conf[-1] == 'off':
|
if conf and conf[-1] == 'off':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
prefix = "repoclosure-%s" % compose.compose_id
|
||||||
lookaside = {}
|
lookaside = {}
|
||||||
if variant.parent:
|
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)
|
repo_dir = compose.paths.compose.repository(arch=arch, variant=variant.parent)
|
||||||
lookaside[repo_id] = repo_dir
|
lookaside[repo_id] = repo_dir
|
||||||
|
|
||||||
repos = {}
|
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)
|
repo_dir = compose.paths.compose.repository(arch=arch, variant=variant)
|
||||||
repos[repo_id] = repo_dir
|
repos[repo_id] = repo_dir
|
||||||
|
|
||||||
@ -86,27 +87,25 @@ def run_repoclosure(compose):
|
|||||||
% (variant.uid, arch, exc))
|
% (variant.uid, arch, exc))
|
||||||
finally:
|
finally:
|
||||||
if methods != "hybrid":
|
if methods != "hybrid":
|
||||||
_delete_repoclosure_cache_dirs(compose, repos, lookaside)
|
_delete_repoclosure_cache_dirs(compose, prefix)
|
||||||
|
|
||||||
compose.log_info("[DONE ] %s" % msg)
|
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"]:
|
if 'dnf' == compose.conf["repoclosure_backend"]:
|
||||||
from dnf.yum.misc import getCacheDir
|
from dnf.yum.misc import getCacheDir
|
||||||
else:
|
else:
|
||||||
from yum.misc import getCacheDir
|
from yum.misc import getCacheDir
|
||||||
|
|
||||||
top_cache_dir = getCacheDir()
|
top_cache_dir = getCacheDir()
|
||||||
for repo_id in repos.keys():
|
for name in os.listdir(top_cache_dir):
|
||||||
cache_dir = os.path.join(top_cache_dir, repo_id)
|
if name.startswith(prefix):
|
||||||
if os.path.isdir(cache_dir):
|
cache_path = os.path.join(top_cache_dir, name)
|
||||||
shutil.rmtree(cache_dir)
|
if os.path.isdir(cache_path):
|
||||||
|
shutil.rmtree(cache_path)
|
||||||
for repo_id in lookaside.keys():
|
else:
|
||||||
cache_dir = os.path.join(top_cache_dir, repo_id)
|
os.remove(cache_path)
|
||||||
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):
|
||||||
|
@ -419,9 +419,10 @@ class TestRepoclosure(PungiTestCase):
|
|||||||
repos=self._get_repo(compose.compose_id, 'Server', 'x86_64')),
|
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.wrappers.repoclosure.get_repoclosure_cmd')
|
||||||
@mock.patch('pungi.phases.test.run')
|
@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, {
|
compose = DummyCompose(self.topdir, {
|
||||||
'repoclosure_backend': 'dnf',
|
'repoclosure_backend': 'dnf',
|
||||||
'repoclosure_strictness': [
|
'repoclosure_strictness': [
|
||||||
|
Loading…
Reference in New Issue
Block a user