2017-03-31 06:57:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
|
|
|
|
|
|
|
from pungi.phases.gather.methods import method_deps as deps
|
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class TestWritePungiConfig(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestWritePungiConfig, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
2019-08-01 15:01:16 +00:00
|
|
|
self.package_sets = self._make_pkgset_phase(["p1"]).package_sets
|
2017-03-31 06:57:28 +00:00
|
|
|
|
|
|
|
def assertWritten(self, PungiWrapper, **kwargs):
|
|
|
|
wrapper = PungiWrapper.return_value
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(wrapper.mock_calls, [mock.call.write_kickstart(**kwargs)])
|
2017-03-31 06:57:28 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper")
|
2017-03-31 06:57:28 +00:00
|
|
|
def test_correct(self, PungiWrapper):
|
2020-01-22 10:02:22 +00:00
|
|
|
pkgs = [("pkg1", None), ("pkg2", "x86_64")]
|
|
|
|
grps = ["grp1"]
|
|
|
|
filter = [("pkg3", None), ("pkg4", "x86_64")]
|
2017-03-31 06:57:28 +00:00
|
|
|
white = mock.Mock()
|
|
|
|
black = mock.Mock()
|
|
|
|
prepopulate = mock.Mock()
|
|
|
|
fulltree = mock.Mock()
|
2019-08-01 15:01:16 +00:00
|
|
|
deps.write_pungi_config(
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose,
|
|
|
|
"x86_64",
|
|
|
|
self.compose.variants["Server"],
|
|
|
|
pkgs,
|
|
|
|
grps,
|
|
|
|
filter,
|
|
|
|
white,
|
|
|
|
black,
|
|
|
|
prepopulate=prepopulate,
|
|
|
|
fulltree_excludes=fulltree,
|
2019-08-01 15:01:16 +00:00
|
|
|
package_sets=self.package_sets,
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertWritten(
|
|
|
|
PungiWrapper,
|
|
|
|
packages=["pkg1", "pkg2.x86_64"],
|
|
|
|
ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf",
|
|
|
|
lookaside_repos={},
|
|
|
|
multilib_whitelist=white,
|
|
|
|
multilib_blacklist=black,
|
|
|
|
groups=["grp1"],
|
|
|
|
prepopulate=prepopulate,
|
|
|
|
repos={
|
|
|
|
"pungi-repo-0": self.topdir + "/work/x86_64/repo/p1",
|
|
|
|
"comps-repo": self.topdir + "/work/x86_64/comps_repo_Server",
|
|
|
|
},
|
|
|
|
exclude_packages=["pkg3", "pkg4.x86_64"],
|
|
|
|
fulltree_excludes=fulltree,
|
|
|
|
)
|
2017-03-31 06:57:28 +00:00
|
|
|
|
2019-07-02 08:09:20 +00:00
|
|
|
@mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper")
|
|
|
|
def test_duplicated_package_name(self, PungiWrapper):
|
|
|
|
pkgs = [("pkg1", None), ("pkg1", "x86_64")]
|
|
|
|
grps = []
|
|
|
|
filter = [("pkg2", None), ("pkg2", "x86_64")]
|
|
|
|
white = mock.Mock()
|
|
|
|
black = mock.Mock()
|
|
|
|
prepopulate = mock.Mock()
|
|
|
|
fulltree = mock.Mock()
|
2019-08-01 15:01:16 +00:00
|
|
|
deps.write_pungi_config(
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose,
|
|
|
|
"x86_64",
|
|
|
|
self.compose.variants["Server"],
|
|
|
|
pkgs,
|
|
|
|
grps,
|
|
|
|
filter,
|
|
|
|
white,
|
|
|
|
black,
|
|
|
|
prepopulate=prepopulate,
|
|
|
|
fulltree_excludes=fulltree,
|
2019-08-01 15:01:16 +00:00
|
|
|
package_sets=self.package_sets,
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertWritten(
|
|
|
|
PungiWrapper,
|
|
|
|
packages=["pkg1", "pkg1.x86_64"],
|
|
|
|
ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf",
|
|
|
|
lookaside_repos={},
|
|
|
|
multilib_whitelist=white,
|
|
|
|
multilib_blacklist=black,
|
|
|
|
groups=[],
|
|
|
|
prepopulate=prepopulate,
|
|
|
|
repos={
|
|
|
|
"pungi-repo-0": self.topdir + "/work/x86_64/repo/p1",
|
|
|
|
"comps-repo": self.topdir + "/work/x86_64/comps_repo_Server",
|
|
|
|
},
|
|
|
|
exclude_packages=["pkg2", "pkg2.x86_64"],
|
|
|
|
fulltree_excludes=fulltree,
|
|
|
|
)
|
2019-07-02 08:09:20 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.gather.get_lookaside_repos")
|
|
|
|
@mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper")
|
2017-03-31 06:57:28 +00:00
|
|
|
def test_with_lookaside(self, PungiWrapper, glr):
|
2020-01-22 10:02:22 +00:00
|
|
|
glr.return_value = ["http://example.com/repo"]
|
|
|
|
pkgs = [("pkg1", None)]
|
2019-08-01 15:01:16 +00:00
|
|
|
deps.write_pungi_config(
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose,
|
|
|
|
"x86_64",
|
|
|
|
self.compose.variants["Server"],
|
|
|
|
pkgs,
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
2019-08-01 15:01:16 +00:00
|
|
|
package_sets=self.package_sets,
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertWritten(
|
|
|
|
PungiWrapper,
|
|
|
|
packages=["pkg1"],
|
|
|
|
ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf",
|
|
|
|
lookaside_repos={"lookaside-repo-0": "http://example.com/repo"},
|
|
|
|
multilib_whitelist=[],
|
|
|
|
multilib_blacklist=[],
|
|
|
|
groups=[],
|
|
|
|
prepopulate=None,
|
|
|
|
repos={
|
|
|
|
"pungi-repo-0": self.topdir + "/work/x86_64/repo/p1",
|
|
|
|
"comps-repo": self.topdir + "/work/x86_64/comps_repo_Server",
|
|
|
|
},
|
|
|
|
exclude_packages=[],
|
|
|
|
fulltree_excludes=None,
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
glr.call_args_list,
|
|
|
|
[mock.call(self.compose, "x86_64", self.compose.variants["Server"])],
|
|
|
|
)
|
2017-03-31 06:57:28 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper")
|
2017-03-31 06:57:28 +00:00
|
|
|
def test_without_input(self, PungiWrapper):
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
deps.write_pungi_config(
|
|
|
|
self.compose,
|
|
|
|
"x86_64",
|
|
|
|
self.compose.variants["Server"],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
)
|
2017-03-31 06:57:28 +00:00
|
|
|
self.assertEqual(
|
|
|
|
str(ctx.exception),
|
2020-02-06 07:09:32 +00:00
|
|
|
"No packages included in Server.x86_64 (no comps groups, no input packages, no prepopulate)", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2017-03-31 06:57:28 +00:00
|
|
|
self.assertEqual(PungiWrapper.return_value.mock_calls, [])
|
2019-10-18 07:39:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestRaiseOnInvalidSigkeys(helpers.PungiTestCase):
|
|
|
|
def test_raise_on_invalid_sigkeys(self):
|
|
|
|
pkgset = {
|
|
|
|
"global": mock.Mock(),
|
|
|
|
}
|
2020-01-22 10:02:22 +00:00
|
|
|
pkgset["global"].invalid_sigkey_rpms = [{"name": "pkg1"}]
|
|
|
|
pkgset["global"].raise_invalid_sigkeys_exception = mock.Mock(
|
|
|
|
side_effect=RuntimeError()
|
|
|
|
)
|
2019-10-18 07:39:54 +00:00
|
|
|
result = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"rpm": [{"path": "pkg1-1-1.el7"}],
|
2019-10-18 07:39:54 +00:00
|
|
|
}
|
|
|
|
with self.assertRaises(RuntimeError):
|
2020-01-22 10:02:22 +00:00
|
|
|
deps.raise_on_invalid_sigkeys("", "", [pkgset], result)
|
2019-12-16 03:07:53 +00:00
|
|
|
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
class TestCheckDeps(helpers.PungiTestCase):
|
2019-12-16 03:07:53 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestCheckDeps, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
self.arch = "x86_64"
|
|
|
|
self.variant = self.compose.variants["Server"]
|
2019-12-16 03:07:53 +00:00
|
|
|
|
|
|
|
def test_not_check_deps(self):
|
|
|
|
self.compose.conf["check_deps"] = False
|
|
|
|
self.assertIsNone(deps.check_deps(self.compose, self.arch, self.variant, {}))
|
|
|
|
|
|
|
|
def test_missing_deps(self):
|
|
|
|
self.compose.conf["check_deps"] = True
|
2020-01-22 10:02:22 +00:00
|
|
|
missing_deps = {"foo.noarch": set(["bar = 1.1"])}
|
2019-12-16 03:07:53 +00:00
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
deps.check_deps(self.compose, self.arch, self.variant, missing_deps)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(str(ctx.exception), "Unresolved dependencies detected")
|
2019-12-16 03:07:53 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.compose.log_error.call_args_list,
|
|
|
|
[
|
|
|
|
mock.call(
|
2020-02-06 07:09:32 +00:00
|
|
|
"Unresolved dependencies for %s.%s in package foo.noarch: ['bar = 1.1']" # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
% (self.variant, self.arch)
|
2019-12-16 03:07:53 +00:00
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
2019-12-16 03:07:53 +00:00
|
|
|
)
|