diff --git a/pungi/phases/gather/methods/method_deps.py b/pungi/phases/gather/methods/method_deps.py index 6d1f8627..4306c7f5 100644 --- a/pungi/phases/gather/methods/method_deps.py +++ b/pungi/phases/gather/methods/method_deps.py @@ -37,13 +37,18 @@ class GatherMethodDeps(pungi.phases.gather.method.GatherMethodBase): # "debuginfo": [], # } - write_pungi_config(self.compose, arch, variant, packages, groups, filter_packages, multilib_whitelist, multilib_blacklist, package_set=package_sets[arch], fulltree_excludes=fulltree_excludes, prepopulate=prepopulate) + write_pungi_config(self.compose, arch, variant, packages, groups, filter_packages, + multilib_whitelist, multilib_blacklist, package_set=package_sets[arch], + fulltree_excludes=fulltree_excludes, prepopulate=prepopulate) result = resolve_deps(self.compose, arch, variant) check_deps(self.compose, arch, variant) return result -def write_pungi_config(compose, arch, variant, packages, groups, filter_packages, multilib_whitelist, multilib_blacklist, repos=None, comps_repo=None, package_set=None, fulltree_excludes=None, prepopulate=None): +def write_pungi_config(compose, arch, variant, packages, groups, filter_packages, + multilib_whitelist, multilib_blacklist, repos=None, + comps_repo=None, package_set=None, fulltree_excludes=None, + prepopulate=None): """write pungi config (kickstart) for arch/variant""" pungi_wrapper = PungiWrapper() pungi_cfg = compose.paths.work.pungi_conf(variant=variant, arch=arch) @@ -77,7 +82,17 @@ def write_pungi_config(compose, arch, variant, packages, groups, filter_packages else: filter_packages_str.append(pkg_name) - pungi_wrapper.write_kickstart(ks_path=pungi_cfg, repos=repos, groups=groups, packages=packages_str, exclude_packages=filter_packages_str, comps_repo=comps_repo, lookaside_repos=lookaside_repos, fulltree_excludes=fulltree_excludes, multilib_whitelist=multilib_whitelist, multilib_blacklist=multilib_blacklist, prepopulate=prepopulate) + if not groups and not packages_str and not prepopulate: + raise RuntimeError( + 'No packages included in %s.%s (no comps groups, no input packages, no prepopulate)' + % (variant.uid, arch)) + + pungi_wrapper.write_kickstart( + ks_path=pungi_cfg, repos=repos, groups=groups, packages=packages_str, + exclude_packages=filter_packages_str, comps_repo=comps_repo, + lookaside_repos=lookaside_repos, fulltree_excludes=fulltree_excludes, + multilib_whitelist=multilib_whitelist, multilib_blacklist=multilib_blacklist, + prepopulate=prepopulate) def resolve_deps(compose, arch, variant): diff --git a/tests/test_gather_method_deps.py b/tests/test_gather_method_deps.py new file mode 100644 index 00000000..ab97a1bb --- /dev/null +++ b/tests/test_gather_method_deps.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +import mock +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) + +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, {}) + self.compose.DEBUG = False + + def assertWritten(self, PungiWrapper, **kwargs): + wrapper = PungiWrapper.return_value + self.assertEqual(wrapper.mock_calls, + [mock.call.write_kickstart(**kwargs)]) + + @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') + def test_correct(self, PungiWrapper): + pkgs = [('pkg1', None), ('pkg2', 'x86_64')] + grps = ['grp1'] + filter = [('pkg3', None), ('pkg4', 'x86_64')] + white = mock.Mock() + black = mock.Mock() + comps_repo = mock.Mock() + prepopulate = mock.Mock() + fulltree = mock.Mock() + deps.write_pungi_config(self.compose, 'x86_64', self.compose.variants['Server'], + pkgs, grps, filter, white, black, comps_repo=comps_repo, + prepopulate=prepopulate, fulltree_excludes=fulltree) + 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': self.topdir + '/work/x86_64/repo'}, + exclude_packages=['pkg3', 'pkg4.x86_64'], + fulltree_excludes=fulltree, + comps_repo=comps_repo) + + @mock.patch('pungi.phases.gather.get_lookaside_repos') + @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') + def test_with_lookaside(self, PungiWrapper, glr): + glr.return_value = ['http://example.com/repo'] + pkgs = [('pkg1', None)] + deps.write_pungi_config(self.compose, 'x86_64', self.compose.variants['Server'], + pkgs, [], [], [], []) + 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': self.topdir + '/work/x86_64/repo'}, + exclude_packages=[], fulltree_excludes=None, comps_repo=None) + self.assertEqual(glr.call_args_list, + [mock.call(self.compose, 'x86_64', self.compose.variants['Server'])]) + + @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') + def test_without_input(self, PungiWrapper): + with self.assertRaises(RuntimeError) as ctx: + deps.write_pungi_config(self.compose, 'x86_64', self.compose.variants['Server'], + [], [], [], [], []) + self.assertEqual( + str(ctx.exception), + 'No packages included in Server.x86_64 (no comps groups, no input packages, no prepopulate)') + self.assertEqual(PungiWrapper.return_value.mock_calls, [])