gather: Honor package whitelist

Basically everything not on the list is excluded. This has to be applied
before we filter only the latest versions (otherwise we could lose
packages that are on the whitelist).

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-03-07 13:42:09 +01:00
parent 41d0139b39
commit a03a46a078
3 changed files with 88 additions and 7 deletions

View File

@ -125,6 +125,7 @@ def main(persistdir, cachedir):
gather_opts.multilib_whitelist = ksparser.handler.multilib_whitelist
gather_opts.prepopulate = ksparser.handler.prepopulate
gather_opts.fulltree_excludes = ksparser.handler.fulltree_excludes
gather_opts.package_whitelist = ksparser.handler.package_whitelist
g = Gather(dnf_obj, gather_opts)

View File

@ -69,6 +69,8 @@ class GatherOptions(pungi.common.OptionsBase):
# lookaside repos; packages will be flagged accordingly
self.lookaside_repos = []
self.package_whitelist = set()
self.merge_options(**kwargs)
@ -363,14 +365,29 @@ class Gather(GatherBase):
self.logger.debug("EXCLUDED by %s: %s", pattern, [str(p) for p in pkgs])
self.dnf._sack.add_excludes(pkgs)
all_queues = ['q_binary_packages', 'q_native_binary_packages',
'q_multilib_binary_packages', 'q_noarch_binary_packages',
'q_source_packages', 'q_native_debug_packages',
'q_multilib_debug_packages']
if self.opts.package_whitelist:
with Profiler("Gather._apply_excludes():apply-package-whitelist'"):
to_keep = []
for pattern in self.opts.package_whitelist:
nvra = parse_nvra(pattern)
nvra.pop('src')
try:
nvra['epoch'] = int(nvra.pop('epoch'))
except ValueError:
pass
to_keep.extend(self._query.filter(**nvra).run())
for queue in all_queues:
setattr(self, queue, getattr(self, queue).filter(pkg=to_keep).latest().apply())
with Profiler("Gather._apply_excludes():exclude-queries"):
self._filter_queue('q_binary_packages', exclude)
self._filter_queue('q_native_binary_packages', exclude)
self._filter_queue('q_multilib_binary_packages', exclude)
self._filter_queue('q_noarch_binary_packages', exclude)
self._filter_queue('q_source_packages', exclude)
self._filter_queue('q_native_debug_packages', exclude)
self._filter_queue('q_multilib_debug_packages', exclude)
for queue in all_queues:
self._filter_queue(queue, exclude)
@Profiler("Gather.add_initial_packages()")
def add_initial_packages(self, pattern_list):

View File

@ -1846,8 +1846,71 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase):
def test_bash_older(self):
pass
def test_whitelist_old_version(self):
# There are two version of dummy-bash in the package set; let's
# whitelist only the older one and its dependencies.
packages = [
"dummy-bash",
]
package_whitelist = [
"dummy-basesystem-10.0-6.noarch",
"dummy-basesystem-10.0-6.src",
"dummy-bash-debuginfo-4.2.37-5.x86_64",
"dummy-bash-4.2.37-5.x86_64",
"dummy-bash-4.2.37-5.src",
"dummy-filesystem-4.2.37-6.x86_64",
"dummy-filesystem-4.2.37-6.src",
"dummy-glibc-common-2.14-5.x86_64",
"dummy-glibc-debuginfo-common-2.14-5.x86_64",
"dummy-glibc-debuginfo-2.14-5.x86_64",
"dummy-glibc-2.14-5.x86_64",
"dummy-glibc-2.14-5.src",
]
pkg_map = self.go(packages, None, greedy="none", package_whitelist=package_whitelist)
self.assertNotIn("dummy-bash-4.2.37-5.i686.rpm", pkg_map["rpm"])
self.assertNotIn("dummy-bash-4.2.37-6.i686.rpm", pkg_map["rpm"])
self.assertNotIn("dummy-bash-4.2.37-6.x86_64.rpm", pkg_map["rpm"])
self.assertItemsEqual(pkg_map["rpm"], [
"dummy-basesystem-10.0-6.noarch.rpm",
"dummy-bash-4.2.37-5.x86_64.rpm",
"dummy-filesystem-4.2.37-6.x86_64.rpm",
"dummy-glibc-2.14-5.x86_64.rpm",
"dummy-glibc-common-2.14-5.x86_64.rpm",
])
self.assertItemsEqual(pkg_map["srpm"], [
"dummy-basesystem-10.0-6.src.rpm",
"dummy-bash-4.2.37-5.src.rpm",
"dummy-filesystem-4.2.37-6.src.rpm",
"dummy-glibc-2.14-5.src.rpm",
])
self.assertItemsEqual(pkg_map["debuginfo"], [
"dummy-bash-debuginfo-4.2.37-5.x86_64.rpm",
"dummy-glibc-debuginfo-2.14-5.x86_64.rpm",
"dummy-glibc-debuginfo-common-2.14-5.x86_64.rpm",
])
def test_firefox_selfhosting_with_krb5_lookaside(self):
super(DNFDepsolvingTestCase, self).test_firefox_selfhosting_with_krb5_lookaside()
self.assertFlags("dummy-krb5-devel-1.10-5.x86_64", [PkgFlag.lookaside])
self.assertFlags("dummy-krb5-1.10-5.src", [PkgFlag.lookaside])
self.assertFlags("dummy-krb5-debuginfo-1.10-5.x86_64", [PkgFlag.lookaside])
def test_package_whitelist(self):
packages = ['*']
whitelist = [
'dummy-bash-4.2.37-6.x86_64',
'dummy-bash-4.2.37-6.src',
]
pkg_map = self.go(packages, None, package_whitelist=whitelist)
self.assertItemsEqual(pkg_map["rpm"], [
'dummy-bash-4.2.37-6.x86_64.rpm',
])
self.assertItemsEqual(pkg_map["srpm"], [
'dummy-bash-4.2.37-6.src.rpm',
])
self.assertItemsEqual(pkg_map["debuginfo"], [
])