Create arch repo when reusing failed
Reusing old arch repo may fail for reasons such as arch not available in old compose or unexpected error when copying data from old compose. JIRA: RHELCMP-994 Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
parent
b193fa0ab7
commit
0ab6f48de3
@ -90,9 +90,8 @@ def run_create_global_repo(compose, cmd, logfile):
|
||||
|
||||
|
||||
def create_arch_repos(compose, path_prefix, paths, pkgset, mmds):
|
||||
reuse = getattr(pkgset, "reuse", None)
|
||||
run_in_threads(
|
||||
_create_arch_repo if reuse is None else _reuse_arch_repo,
|
||||
_create_arch_repo,
|
||||
[
|
||||
(
|
||||
compose,
|
||||
@ -111,12 +110,28 @@ def create_arch_repos(compose, path_prefix, paths, pkgset, mmds):
|
||||
def _create_arch_repo(worker_thread, args, task_num):
|
||||
"""Create a single pkgset repo for given arch."""
|
||||
compose, arch, path_prefix, paths, pkgset, mmd = args
|
||||
repo_dir = compose.paths.work.pkgset_repo(pkgset.name, arch=arch)
|
||||
paths[arch] = repo_dir
|
||||
|
||||
# Try to reuse arch repo from old compose
|
||||
reuse = getattr(pkgset, "reuse", None)
|
||||
if reuse:
|
||||
old_repo_dir = compose.paths.old_compose_path(repo_dir)
|
||||
if os.path.isdir(old_repo_dir):
|
||||
msg = "Copying repodata for reuse: %s" % old_repo_dir
|
||||
try:
|
||||
compose.log_info("[BEGIN] %s", msg)
|
||||
copy_all(old_repo_dir, repo_dir)
|
||||
compose.log_info("[DONE ] %s", msg)
|
||||
return
|
||||
except Exception as e:
|
||||
compose.log_debug(str(e))
|
||||
compose.log_info("[FAILED] %s will try to create arch repo", msg)
|
||||
|
||||
createrepo_c = compose.conf["createrepo_c"]
|
||||
createrepo_checksum = compose.conf["createrepo_checksum"]
|
||||
repo = CreaterepoWrapper(createrepo_c=createrepo_c)
|
||||
repo_dir_global = compose.paths.work.pkgset_repo(pkgset.name, arch="global")
|
||||
repo_dir = compose.paths.work.pkgset_repo(pkgset.name, arch=arch)
|
||||
paths[arch] = repo_dir
|
||||
msg = "Running createrepo for arch '%s'" % arch
|
||||
|
||||
compose.log_info("[BEGIN] %s", msg)
|
||||
@ -156,19 +171,6 @@ def _create_arch_repo(worker_thread, args, task_num):
|
||||
compose.log_info("[DONE ] %s", msg)
|
||||
|
||||
|
||||
def _reuse_arch_repo(worker_thread, args, task_num):
|
||||
"""Reuse a single pkgset repo for given arch."""
|
||||
compose, arch, _, paths, pkgset, _ = args
|
||||
repo_dir = compose.paths.work.pkgset_repo(pkgset.name, arch=arch)
|
||||
paths[arch] = repo_dir
|
||||
old_repo_dir = compose.paths.old_compose_path(repo_dir)
|
||||
msg = "Copying repodata for reuse: %s" % old_repo_dir
|
||||
|
||||
compose.log_info("[BEGIN] %s", msg)
|
||||
copy_all(old_repo_dir, repo_dir)
|
||||
compose.log_info("[DONE ] %s", msg)
|
||||
|
||||
|
||||
class MaterializedPackageSet(object):
|
||||
"""A wrapper for PkgsetBase object that represents the package set created
|
||||
as repos on the filesystem.
|
||||
|
@ -153,46 +153,24 @@ class TestCreateArchRepos(helpers.PungiTestCase):
|
||||
]
|
||||
)
|
||||
|
||||
@mock.patch("pungi.phases.pkgset.common._reuse_arch_repo")
|
||||
def test_call_reuse_arch_repo(self, mock_reuse):
|
||||
self.pkgset.reuse = "/path/to/old/global/repo"
|
||||
common.create_arch_repos(
|
||||
self.compose, self.prefix, self.paths, self.pkgset, None
|
||||
)
|
||||
mock_reuse.assert_has_calls(
|
||||
[
|
||||
mock.call(
|
||||
mock.ANY,
|
||||
(self.compose, "amd64", self.prefix, self.paths, self.pkgset, None),
|
||||
1,
|
||||
),
|
||||
mock.call(
|
||||
mock.ANY,
|
||||
(
|
||||
self.compose,
|
||||
"x86_64",
|
||||
self.prefix,
|
||||
self.paths,
|
||||
self.pkgset,
|
||||
None,
|
||||
),
|
||||
2,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
@mock.patch("pungi.phases.pkgset.common.os.path.isdir", return_value=True)
|
||||
@mock.patch("pungi.phases.pkgset.common.copy_all")
|
||||
def test_reuse_arch_repo(self, mock_copy_all):
|
||||
def test_reuse_arch_repo(self, mock_copy_all, mock_isdir):
|
||||
self.pkgset.reuse = "/path/to/old/global/repo"
|
||||
old_repo = "/path/to/old/repo"
|
||||
self.compose.paths.old_compose_path = mock.Mock(return_value=old_repo)
|
||||
common._reuse_arch_repo(
|
||||
mock.Mock(),
|
||||
(self.compose, "x86_64", self.prefix, self.paths, self.pkgset, None),
|
||||
1,
|
||||
common.create_arch_repos(
|
||||
self.compose, self.prefix, self.paths, self.pkgset, None
|
||||
)
|
||||
mock_copy_all.assert_called_once_with(
|
||||
old_repo, os.path.join(self.compose.topdir, "work/x86_64/repo/foo")
|
||||
mock_copy_all.assert_has_calls(
|
||||
[
|
||||
mock.call(
|
||||
old_repo, os.path.join(self.compose.topdir, "work/amd64/repo/foo")
|
||||
),
|
||||
mock.call(
|
||||
old_repo, os.path.join(self.compose.topdir, "work/x86_64/repo/foo")
|
||||
),
|
||||
]
|
||||
)
|
||||
self.compose.log_info.assert_has_calls(
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user