From 63329d48c3bc1c72a7bacd654a3ce6e93f6041e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 7 Mar 2018 12:35:33 +0100 Subject: [PATCH 05/12] Write package whitelist for each variant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we have a package set for the variant (which happens if there are modules), include a list of all NEVRAs in the pungi kickstart. This can be used to make sure only packages from correct tag get into the compose. If two packages with same name but different version get into the compose, this can help get even older version into a particular variant. Signed-off-by: Lubomír Sedlář --- pungi/ks.py | 15 +++++++++ pungi/phases/gather/methods/method_deps.py | 7 +++- pungi/wrappers/pungi.py | 51 +++++++++++------------------- tests/helpers.py | 1 + tests/test_gather_method_deps.py | 29 +++++++++++++++-- 5 files changed, 68 insertions(+), 35 deletions(-) diff --git a/pungi/ks.py b/pungi/ks.py index ecb8821f..517242aa 100644 --- a/pungi/ks.py +++ b/pungi/ks.py @@ -127,6 +127,19 @@ class PrepopulateSection(pykickstart.sections.Section): self.handler.prepopulate.add(line) +class PackageWhitelistSection(pykickstart.sections.Section): + sectionOpen = "%package-whitelist" + + def handleLine(self, line): + if not self.handler: + return + + (h, s, t) = line.partition('#') + line = h.rstrip() + + self.handler.package_whitelist.add(line) + + class KickstartParser(pykickstart.parser.KickstartParser): def setupSections(self): pykickstart.parser.KickstartParser.setupSections(self) @@ -134,6 +147,7 @@ class KickstartParser(pykickstart.parser.KickstartParser): self.registerSection(MultilibBlacklistSection(self.handler)) self.registerSection(MultilibWhitelistSection(self.handler)) self.registerSection(PrepopulateSection(self.handler)) + self.registerSection(PackageWhitelistSection(self.handler)) def get_packages(self, dnf_obj): packages = set() @@ -194,6 +208,7 @@ class PungiHandler(HandlerClass): self.multilib_blacklist = set() self.multilib_whitelist = set() self.prepopulate = set() + self.package_whitelist = set() def get_ksparser(ks_path=None): diff --git a/pungi/phases/gather/methods/method_deps.py b/pungi/phases/gather/methods/method_deps.py index 7c9e8fb6..d38343f3 100644 --- a/pungi/phases/gather/methods/method_deps.py +++ b/pungi/phases/gather/methods/method_deps.py @@ -88,12 +88,17 @@ def write_pungi_config(compose, arch, variant, packages, groups, filter_packages 'No packages included in %s.%s (no comps groups, no input packages, no prepopulate)' % (variant.uid, arch)) + package_whitelist = set() + if variant.pkgset: + for rpm_obj in variant.pkgset.rpms_by_arch.get(arch, []): + package_whitelist.add(rpm_obj.nevra) + pungi_wrapper.write_kickstart( ks_path=pungi_cfg, repos=repos, groups=groups, packages=packages_str, exclude_packages=filter_packages_str, lookaside_repos=lookaside_repos, fulltree_excludes=fulltree_excludes, multilib_whitelist=multilib_whitelist, multilib_blacklist=multilib_blacklist, - prepopulate=prepopulate) + prepopulate=prepopulate, package_whitelist=package_whitelist) def resolve_deps(compose, arch, variant, source_name=None): diff --git a/pungi/wrappers/pungi.py b/pungi/wrappers/pungi.py index 501d6f57..04110f47 100644 --- a/pungi/wrappers/pungi.py +++ b/pungi/wrappers/pungi.py @@ -32,9 +32,22 @@ UNRESOLVED_DEPENDENCY_RE = re.compile(r"^.*Unresolvable dependency (.+) in ([^ ] MISSING_COMPS_PACKAGE_RE = re.compile(r"^.*Could not find a match for (.+) in any configured repo") +def _write_ks_section(f, section, lines): + if lines: + f.write("\n%%%s\n" % section) + for i in sorted(lines): + f.write("%s\n" % i) + + f.write("%end\n") + + class PungiWrapper(object): - def write_kickstart(self, ks_path, repos, groups, packages, exclude_packages=None, comps_repo=None, lookaside_repos=None, fulltree_excludes=None, multilib_blacklist=None, multilib_whitelist=None, prepopulate=None): + def write_kickstart(self, ks_path, repos, groups, packages, + exclude_packages=None, comps_repo=None, + lookaside_repos=None, fulltree_excludes=None, + multilib_blacklist=None, multilib_whitelist=None, + prepopulate=None, package_whitelist=None): groups = groups or [] exclude_packages = exclude_packages or {} lookaside_repos = lookaside_repos or {} @@ -75,37 +88,11 @@ class PungiWrapper(object): kickstart.write("%end\n") - # %fulltree-excludes - if fulltree_excludes: - kickstart.write("\n") - kickstart.write("%fulltree-excludes\n") - for i in sorted(fulltree_excludes): - kickstart.write("%s\n" % i) - kickstart.write("%end\n") - - # %multilib-blacklist - if multilib_blacklist: - kickstart.write("\n") - kickstart.write("%multilib-blacklist\n") - for i in sorted(multilib_blacklist): - kickstart.write("%s\n" % i) - kickstart.write("%end\n") - - # %multilib-whitelist - if multilib_whitelist: - kickstart.write("\n") - kickstart.write("%multilib-whitelist\n") - for i in sorted(multilib_whitelist): - kickstart.write("%s\n" % i) - kickstart.write("%end\n") - - # %prepopulate - if prepopulate: - kickstart.write("\n") - kickstart.write("%prepopulate\n") - for i in sorted(prepopulate): - kickstart.write("%s\n" % i) - kickstart.write("%end\n") + _write_ks_section(kickstart, "fulltree-excludes", fulltree_excludes) + _write_ks_section(kickstart, "multilib-blacklist", multilib_blacklist) + _write_ks_section(kickstart, "multilib-whitelist", multilib_whitelist) + _write_ks_section(kickstart, "prepopulate", prepopulate) + _write_ks_section(kickstart, "package-whitelist", package_whitelist) kickstart.close() diff --git a/tests/helpers.py b/tests/helpers.py index f069635d..b82de42f 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -38,6 +38,7 @@ class MockVariant(mock.Mock): self.mmds = [] self.arch_mmds = {} self.variants = {} + self.pkgset = mock.Mock(rpms_by_arch={}) def __str__(self): return self.uid diff --git a/tests/test_gather_method_deps.py b/tests/test_gather_method_deps.py index bd93a185..31bf82b7 100644 --- a/tests/test_gather_method_deps.py +++ b/tests/test_gather_method_deps.py @@ -39,7 +39,7 @@ class TestWritePungiConfig(helpers.PungiTestCase): groups=['grp1'], prepopulate=prepopulate, repos={'pungi-repo': self.topdir + '/work/x86_64/repo'}, exclude_packages=['pkg3', 'pkg4.x86_64'], - fulltree_excludes=fulltree) + fulltree_excludes=fulltree, package_whitelist=set()) @mock.patch('pungi.phases.gather.get_lookaside_repos') @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') @@ -54,11 +54,36 @@ class TestWritePungiConfig(helpers.PungiTestCase): multilib_whitelist=[], multilib_blacklist=[], groups=[], prepopulate=None, repos={'pungi-repo': self.topdir + '/work/x86_64/repo'}, - exclude_packages=[], fulltree_excludes=None) + exclude_packages=[], fulltree_excludes=None, + package_whitelist=set()) 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_with_whitelist(self, PungiWrapper): + pkgs = [('pkg1', None), ('pkg2', 'x86_64')] + grps = ['grp1'] + filter = [('pkg3', None), ('pkg4', 'x86_64')] + self.compose.variants['Server'].pkgset.rpms_by_arch['x86_64'] = [ + mock.Mock(nevra='pkg-1.0.0-1') + ] + white = mock.Mock() + black = 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, + 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, + package_whitelist=set(['pkg-1.0.0-1'])) + + @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'], -- 2.13.6