autopkgtests: Move some common code into a function

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 6 years ago
parent ccc1c25f61
commit fce1fe5c27
No known key found for this signature in database
GPG Key ID: A65B78DBE67C7AAC

@ -85,6 +85,14 @@ class Suite(object):
"""
return pkg_id in self._all_binaries_in_suite
def which_of_these_are_in_the_suite(self, pkgs):
"""Iterate over all packages that are in the suite
:param pkgs: An iterable of package ids
:return: An iterable of package ids that are in the suite
"""
yield from (x for x in pkgs if x in self._all_binaries_in_suite)
class TargetSuite(Suite):
@ -110,6 +118,14 @@ class TargetSuite(Suite):
"""
return self.inst_tester.is_pkg_in_the_suite(pkg_id)
def which_of_these_are_in_the_suite(self, pkgs):
"""Iterate over all packages that are in the suite
:param pkgs: An iterable of package ids
:return: An iterable of package ids that are in the suite
"""
yield from self.inst_tester.which_of_these_are_in_the_suite(pkgs)
def is_installable(self, pkg_id):
"""Determine whether the given package can be installed in the suite

@ -106,6 +106,14 @@ class InstallabilityTester(object):
"""
return pkg_id in self._suite_contents
def which_of_these_are_in_the_suite(self, pkgs):
"""Iterate over all packages that are in the suite
:param pkgs: An iterable of package ids
:return: An iterable of package ids that are in the suite
"""
yield from (x for x in pkgs if x in self._suite_contents)
def add_binary(self, pkg_id):
"""Add a binary package to the suite

@ -73,6 +73,15 @@ def srchash(src):
return src[0]
def added_pkgs_compared_to_target_suite(package_ids, target_suite, *, invert=False):
if invert:
pkgs_ids_to_ignore = package_ids - set(target_suite.which_of_these_are_in_the_suite(package_ids))
names_ignored = {p.package_name for p in pkgs_ids_to_ignore}
else:
names_ignored = {p.package_name for p in target_suite.which_of_these_are_in_the_suite(package_ids)}
yield from (p for p in package_ids if p.package_name not in names_ignored)
class AutopkgtestPolicy(BasePolicy):
"""autopkgtest regression policy for source migrations
@ -514,19 +523,10 @@ class AutopkgtestPolicy(BasePolicy):
# will also show up, but they are already properly
# installed. Nevermind.
depends = pkg_universe.dependencies_of(binary)
names_testing = set()
names_unstable = set()
# depends is a frozenset{frozenset{BinaryPackageId, ..}}
for deps_of_bin in depends:
for dep in deps_of_bin:
if target_suite.is_pkg_in_the_suite(dep):
names_testing.add(dep.package_name)
else:
names_unstable.add(dep.package_name)
for name in names_unstable - names_testing:
for deps_of_bin in depends:
# We'll figure out which version later
bin_new.update(d for d in deps_of_bin if d.package_name == name)
# We'll figure out which version later
bin_new.update(added_pkgs_compared_to_target_suite(deps_of_bin, target_suite))
# Check if the package breaks/conflicts anything. We might
# be adding slightly too many source packages due to the
@ -537,16 +537,8 @@ class AutopkgtestPolicy(BasePolicy):
for binary in bin_triggers:
# broken is a frozenset{BinaryPackageId, ..}
broken = pkg_universe.negative_dependencies_of(binary)
names_testing = set()
names_unstable = set()
for broken_bin in broken:
if target_suite.is_pkg_in_the_suite(broken_bin):
names_testing.add(broken_bin.package_name)
else:
names_unstable.add(broken_bin.package_name)
for name in names_testing - names_unstable:
# We'll figure out which version later
bin_broken.update(b for b in broken if b.package_name == name)
# We'll figure out which version later
bin_broken.update(added_pkgs_compared_to_target_suite(broken, target_suite, invert=True))
bin_triggers.update(bin_broken)
triggers = set()

Loading…
Cancel
Save