2019-08-02 08:30:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2022-11-11 13:32:00 +00:00
|
|
|
from unittest import mock
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
2019-08-02 08:30:09 +00:00
|
|
|
|
2019-10-02 07:40:18 +00:00
|
|
|
from pungi.module_util import Modulemd
|
2019-08-02 08:30:09 +00:00
|
|
|
from pungi.phases.pkgset import common
|
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class MockCreateRepo(object):
|
|
|
|
def __init__(self, createrepo_c):
|
|
|
|
self.createrepo_c = createrepo_c
|
|
|
|
|
|
|
|
def get_createrepo_cmd(self, path_prefix, outputdir, pkglist, **kwargs):
|
|
|
|
return (path_prefix, outputdir, pkglist)
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.init.run_in_threads", new=helpers.fake_run_in_threads)
|
|
|
|
@mock.patch("pungi.phases.pkgset.common.CreaterepoWrapper", new=MockCreateRepo)
|
|
|
|
@mock.patch("pungi.phases.pkgset.common.run")
|
|
|
|
class TestMaterializedPkgsetCreate(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestMaterializedPkgsetCreate, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
self.prefix = "/prefix"
|
|
|
|
self.pkgset = self._make_pkgset("foo")
|
|
|
|
self.subsets = {}
|
|
|
|
|
|
|
|
def _mk_call(self, arch, name):
|
|
|
|
pkglist = "%s.%s.conf" % (arch, name)
|
|
|
|
logfile = "arch_repo.%s.%s.log" % (name, arch)
|
|
|
|
return mock.call(
|
|
|
|
(
|
|
|
|
self.prefix,
|
|
|
|
os.path.join(self.topdir, "work", arch, "repo", name),
|
|
|
|
os.path.join(self.topdir, "work", arch, "package_list", pkglist),
|
|
|
|
),
|
|
|
|
logfile=os.path.join(self.topdir, "logs", arch, logfile),
|
|
|
|
show_cmd=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
def _make_pkgset(self, name):
|
|
|
|
pkgset = mock.Mock()
|
|
|
|
pkgset.name = name
|
2020-02-25 03:02:39 +00:00
|
|
|
pkgset.reuse = None
|
2019-08-02 08:30:09 +00:00
|
|
|
|
2022-09-22 14:17:53 +00:00
|
|
|
def mock_subset(primary, arch_list, **kwargs):
|
2019-08-02 08:30:09 +00:00
|
|
|
self.subsets[primary] = mock.Mock()
|
|
|
|
return self.subsets[primary]
|
|
|
|
|
|
|
|
pkgset.subset.side_effect = mock_subset
|
|
|
|
return pkgset
|
|
|
|
|
|
|
|
def _mk_paths(self, name, arches):
|
|
|
|
paths = {"global": os.path.join(self.topdir, "work/global/repo", name)}
|
|
|
|
for arch in arches:
|
|
|
|
paths[arch] = os.path.join(self.topdir, "work", arch, "repo", name)
|
|
|
|
return paths
|
|
|
|
|
|
|
|
def test_run(self, mock_run):
|
|
|
|
result = common.MaterializedPackageSet.create(
|
|
|
|
self.compose, self.pkgset, self.prefix
|
|
|
|
)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, result.package_sets.keys(), ["global", "amd64", "x86_64"]
|
|
|
|
)
|
2019-08-02 08:30:09 +00:00
|
|
|
self.assertEqual(result["global"], self.pkgset)
|
|
|
|
self.assertEqual(result["x86_64"], self.subsets["x86_64"])
|
|
|
|
self.assertEqual(result["amd64"], self.subsets["amd64"])
|
|
|
|
|
|
|
|
self.pkgset.subset.assert_any_call(
|
2022-09-22 14:17:53 +00:00
|
|
|
"x86_64",
|
|
|
|
["x86_64", "noarch", "src"],
|
|
|
|
exclusive_noarch=True,
|
|
|
|
inherit_to_noarch=True,
|
2019-08-02 08:30:09 +00:00
|
|
|
)
|
|
|
|
self.pkgset.subset.assert_any_call(
|
2022-09-22 14:17:53 +00:00
|
|
|
"amd64",
|
|
|
|
["amd64", "x86_64", "noarch", "src"],
|
|
|
|
exclusive_noarch=True,
|
|
|
|
inherit_to_noarch=True,
|
2019-08-02 08:30:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for arch, pkgset in result.package_sets.items():
|
|
|
|
pkgset.save_file_list.assed_any_call(
|
|
|
|
os.path.join(
|
|
|
|
self.topdir, "work", arch, "package_list", arch + ".foo.conf"
|
|
|
|
),
|
|
|
|
remove_path_prefix=self.prefix,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(result.paths, self._mk_paths("foo", ["amd64", "x86_64"]))
|
|
|
|
|
|
|
|
mock_run.assert_has_calls(
|
|
|
|
[self._mk_call(arch, "foo") for arch in ["global", "amd64", "x86_64"]],
|
|
|
|
any_order=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
@helpers.unittest.skipUnless(Modulemd, "Skipping tests, no module support")
|
|
|
|
@mock.patch("pungi.phases.pkgset.common.collect_module_defaults")
|
2022-04-27 13:31:14 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.common.collect_module_obsoletes")
|
2019-08-02 08:30:09 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.common.add_modular_metadata")
|
2022-04-27 13:31:14 +00:00
|
|
|
def test_run_with_modulemd(self, amm, cmo, cmd, mock_run):
|
|
|
|
# Test Index for cmo
|
|
|
|
mod_index = Modulemd.ModuleIndex.new()
|
|
|
|
mmdobs = Modulemd.Obsoletes.new(
|
|
|
|
1, 10993435, "mod_name", "mod_stream", "testmsg"
|
|
|
|
)
|
|
|
|
mmdobs.set_obsoleted_by("mod_name", "mod_name_2")
|
|
|
|
mod_index.add_obsoletes(mmdobs)
|
|
|
|
cmo.return_value = mod_index
|
|
|
|
|
|
|
|
mmd = {
|
|
|
|
"x86_64": [
|
|
|
|
Modulemd.ModuleStream.new(
|
|
|
|
Modulemd.ModuleStreamVersionEnum.TWO, "mod_name", "stream_name"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
}
|
2019-08-02 08:30:09 +00:00
|
|
|
common.MaterializedPackageSet.create(
|
|
|
|
self.compose, self.pkgset, self.prefix, mmd=mmd
|
|
|
|
)
|
|
|
|
cmd.assert_called_once_with(
|
|
|
|
os.path.join(self.topdir, "work/global/module_defaults"),
|
2022-04-27 13:31:14 +00:00
|
|
|
{"mod_name"},
|
2019-09-18 12:47:30 +00:00
|
|
|
overrides_dir=None,
|
2019-08-02 08:30:09 +00:00
|
|
|
)
|
2022-04-27 13:31:14 +00:00
|
|
|
|
|
|
|
cmo.assert_called_once()
|
|
|
|
cmd.assert_called_once()
|
|
|
|
amm.assert_called_once()
|
|
|
|
|
|
|
|
self.assertEqual(
|
2022-11-08 10:47:14 +00:00
|
|
|
amm.mock_calls[0][1][1], os.path.join(self.topdir, "work/x86_64/repo/foo")
|
2022-04-27 13:31:14 +00:00
|
|
|
)
|
2022-11-08 10:47:14 +00:00
|
|
|
self.assertIsInstance(amm.mock_calls[0][1][2], Modulemd.ModuleIndex)
|
|
|
|
self.assertIsNotNone(amm.mock_calls[0][1][2].get_module("mod_name"))
|
2022-04-27 13:31:14 +00:00
|
|
|
# Check if proper Index is used by add_modular_metadata
|
|
|
|
self.assertIsNotNone(
|
2022-11-08 10:47:14 +00:00
|
|
|
amm.mock_calls[0][1][2].get_module("mod_name").get_obsoletes()
|
2022-04-27 13:31:14 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-11-08 10:47:14 +00:00
|
|
|
amm.mock_calls[0][1][3],
|
2019-08-02 08:30:09 +00:00
|
|
|
os.path.join(self.topdir, "logs/x86_64/arch_repo_modulemd.foo.x86_64.log"),
|
|
|
|
)
|
2020-03-25 09:02:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCreateArchRepos(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestCreateArchRepos, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
self.prefix = "/prefix"
|
|
|
|
self.paths = {}
|
|
|
|
self.pkgset = mock.Mock()
|
|
|
|
self.pkgset.reuse = None
|
|
|
|
self.pkgset.name = "foo"
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.pkgset.common._create_arch_repo")
|
|
|
|
def test_call_create_arch_repo(self, mock_create):
|
|
|
|
common.create_arch_repos(
|
|
|
|
self.compose, self.prefix, self.paths, self.pkgset, None
|
|
|
|
)
|
|
|
|
mock_create.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,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-07-07 03:00:10 +00:00
|
|
|
@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, mock_isdir):
|
2020-03-25 09:02:25 +00:00
|
|
|
self.pkgset.reuse = "/path/to/old/global/repo"
|
2020-07-07 03:00:10 +00:00
|
|
|
old_repo = "/path/to/old/repo"
|
|
|
|
self.compose.paths.old_compose_path = mock.Mock(return_value=old_repo)
|
2020-03-25 09:02:25 +00:00
|
|
|
common.create_arch_repos(
|
|
|
|
self.compose, self.prefix, self.paths, self.pkgset, None
|
|
|
|
)
|
2020-07-07 03:00:10 +00:00
|
|
|
mock_copy_all.assert_has_calls(
|
2020-03-25 09:02:25 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
2020-07-07 03:00:10 +00:00
|
|
|
old_repo, os.path.join(self.compose.topdir, "work/amd64/repo/foo")
|
2020-03-25 09:02:25 +00:00
|
|
|
),
|
|
|
|
mock.call(
|
2020-07-07 03:00:10 +00:00
|
|
|
old_repo, os.path.join(self.compose.topdir, "work/x86_64/repo/foo")
|
2020-03-25 09:02:25 +00:00
|
|
|
),
|
2020-07-08 06:26:59 +00:00
|
|
|
],
|
|
|
|
any_order=True,
|
2020-03-25 09:02:25 +00:00
|
|
|
)
|
|
|
|
self.compose.log_info.assert_has_calls(
|
|
|
|
[
|
|
|
|
mock.call("[BEGIN] %s", "Copying repodata for reuse: %s" % old_repo),
|
|
|
|
mock.call("[DONE ] %s", "Copying repodata for reuse: %s" % old_repo),
|
|
|
|
]
|
|
|
|
)
|