launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #17201
[Merge] lp:~wgrant/launchpad/overrides-fallback into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/overrides-fallback into lp:launchpad with lp:~wgrant/launchpad/overrides-copies as a prerequisite.
Commit message:
Replace UbuntuOverridePolicy with a generalised FallbackOverridePolicy.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/overrides-fallback/+merge/227866
Replace UbuntuOverridePolicy with a generalised FallbackOverridePolicy. It's initialised with a sequence of policies and runs them in order to fill in the missing overrides, as UbuntuOverridePolicy did with just FromExistingOverridePolicy and UnknownOverridePolicy.
Archive.getOverridePolicy preserves exactly the behaviour it had before. It'll soon get more complicated to replace archiveuploader's per-ArchivePurpose rules.
--
https://code.launchpad.net/~wgrant/launchpad/overrides-fallback/+merge/227866
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/overrides-fallback into lp:launchpad.
=== modified file 'lib/lp/soyuz/adapters/overrides.py'
--- lib/lp/soyuz/adapters/overrides.py 2014-07-23 06:31:23 +0000
+++ lib/lp/soyuz/adapters/overrides.py 2014-07-23 06:31:24 +0000
@@ -7,11 +7,11 @@
__all__ = [
'BinaryOverride',
+ 'FallbackOverridePolicy',
'FromExistingOverridePolicy',
'IBinaryOverride',
'ISourceOverride',
'SourceOverride',
- 'UbuntuOverridePolicy',
'UnknownOverridePolicy',
]
@@ -411,48 +411,34 @@
for binary_package_name, architecture_tag in binaries.keys())
-class UbuntuOverridePolicy(FromExistingOverridePolicy,
- UnknownOverridePolicy):
- """Override policy for Ubuntu.
+class FallbackOverridePolicy(BaseOverridePolicy):
+ """Override policy that fills things through a sequence of policies."""
- An override policy that incorporates both the existing policy and the
- unknown policy.
- """
+ def __init__(self, policies):
+ self.policies = policies
def calculateSourceOverrides(self, sources):
- total = set(sources.keys())
- existing_policy = FromExistingOverridePolicy(
- self.archive, self.distroseries, self.pocket,
- phased_update_percentage=self.phased_update_percentage,
- include_deleted=True)
- overrides = existing_policy.calculateSourceOverrides(sources)
- existing = set(overrides.keys())
- missing = total.difference(existing)
- if missing:
- unknown_policy = UnknownOverridePolicy(
- self.archive, self.distroseries, self.pocket,
- phased_update_percentage=self.phased_update_percentage)
- unknown = unknown_policy.calculateSourceOverrides(
+ overrides = {}
+ missing = set(sources.keys())
+ for policy in self.policies:
+ if not missing:
+ break
+ these_overrides = policy.calculateSourceOverrides(
dict((spn, sources[spn]) for spn in missing))
- overrides.update(unknown)
+ overrides.update(these_overrides)
+ missing -= set(these_overrides.keys())
return overrides
def calculateBinaryOverrides(self, binaries):
- total = set(binaries.keys())
- existing_policy = FromExistingOverridePolicy(
- self.archive, self.distroseries, self.pocket,
- phased_update_percentage=self.phased_update_percentage,
- include_deleted=True)
- overrides = existing_policy.calculateBinaryOverrides(binaries)
- existing = set(overrides.keys())
- missing = total.difference(existing)
- if missing:
- unknown_policy = UnknownOverridePolicy(
- self.archive, self.distroseries, self.pocket,
- phased_update_percentage=self.phased_update_percentage)
- unknown = unknown_policy.calculateBinaryOverrides(
+ overrides = {}
+ missing = set(binaries.keys())
+ for policy in self.policies:
+ if not missing:
+ break
+ these_overrides = policy.calculateBinaryOverrides(
dict((key, binaries[key]) for key in missing))
- overrides.update(unknown)
+ overrides.update(these_overrides)
+ missing -= set(these_overrides.keys())
return overrides
=== modified file 'lib/lp/soyuz/adapters/tests/test_overrides.py'
--- lib/lp/soyuz/adapters/tests/test_overrides.py 2014-07-23 06:31:23 +0000
+++ lib/lp/soyuz/adapters/tests/test_overrides.py 2014-07-23 06:31:24 +0000
@@ -11,9 +11,9 @@
from lp.services.database.sqlbase import flush_database_caches
from lp.soyuz.adapters.overrides import (
BinaryOverride,
+ FallbackOverridePolicy,
FromExistingOverridePolicy,
SourceOverride,
- UbuntuOverridePolicy,
UnknownOverridePolicy,
)
from lp.soyuz.enums import PackagePublishingStatus
@@ -457,13 +457,13 @@
self.assertEqual(expected, overrides)
-class TestUbuntuOverridePolicy(TestCaseWithFactory):
+class TestFallbackOverridePolicy(TestCaseWithFactory):
layer = ZopelessDatabaseLayer
- def test_ubuntu_override_policy_sources(self):
- # The Ubuntu policy incorporates both the existing and the unknown
- # policy.
+ def test_fallback_sources(self):
+ # The fallback policy runs through a sequence of policies until
+ # all overrides are fulfilled.
universe = getUtility(IComponentSet)['universe']
spns = [self.factory.makeSourcePackageName()]
expected = {spns[0]: SourceOverride(component=universe, new=True)}
@@ -480,8 +480,11 @@
version=spph.sourcepackagerelease.version, new=False))
spns.append(self.factory.makeSourcePackageName())
expected[spns[-1]] = SourceOverride(component=universe, new=True)
- policy = UbuntuOverridePolicy(
- distroseries.main_archive, distroseries, pocket)
+ policy = FallbackOverridePolicy([
+ FromExistingOverridePolicy(
+ distroseries.main_archive, distroseries, pocket),
+ UnknownOverridePolicy(
+ distroseries.main_archive, distroseries, pocket)])
overrides = policy.calculateSourceOverrides(
dict((spn, SourceOverride()) for spn in spns))
self.assertEqual(10, len(overrides))
@@ -520,8 +523,11 @@
expected[bpn, distroarchseries.architecturetag] = BinaryOverride(
component=universe, new=True)
distroseries.nominatedarchindep = distroarchseries
- policy = UbuntuOverridePolicy(
- distroseries.main_archive, distroseries, pocket)
+ policy = FallbackOverridePolicy([
+ FromExistingOverridePolicy(
+ distroseries.main_archive, distroseries, pocket),
+ UnknownOverridePolicy(
+ distroseries.main_archive, distroseries, pocket)])
overrides = policy.calculateBinaryOverrides(
dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
self.assertEqual(5, len(overrides))
@@ -556,9 +562,13 @@
expected[(bpn, distroarchseries.architecturetag)] = BinaryOverride(
component=universe, phased_update_percentage=50, new=True)
distroseries.nominatedarchindep = distroarchseries
- policy = UbuntuOverridePolicy(
- distroseries.main_archive, distroseries, pocket,
- phased_update_percentage=50)
+ policy = FallbackOverridePolicy([
+ FromExistingOverridePolicy(
+ distroseries.main_archive, distroseries, pocket,
+ phased_update_percentage=50),
+ UnknownOverridePolicy(
+ distroseries.main_archive, distroseries, pocket,
+ phased_update_percentage=50)])
overrides = policy.calculateBinaryOverrides(
dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
self.assertEqual(2, len(overrides))
=== modified file 'lib/lp/soyuz/configure.zcml'
--- lib/lp/soyuz/configure.zcml 2014-07-08 22:31:49 +0000
+++ lib/lp/soyuz/configure.zcml 2014-07-23 06:31:24 +0000
@@ -927,7 +927,7 @@
</class>
<!-- OverridePolicy -->
- <class class="lp.soyuz.adapters.overrides.UbuntuOverridePolicy">
+ <class class="lp.soyuz.adapters.overrides.FallbackOverridePolicy">
<allow interface="lp.soyuz.adapters.overrides.IOverridePolicy" />
</class>
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2014-07-23 06:31:23 +0000
+++ lib/lp/soyuz/model/archive.py 2014-07-23 06:31:24 +0000
@@ -2079,13 +2079,22 @@
phased_update_percentage=None):
"""See `IArchive`."""
# Circular imports.
- from lp.soyuz.adapters.overrides import UbuntuOverridePolicy
+ from lp.soyuz.adapters.overrides import (
+ FallbackOverridePolicy,
+ FromExistingOverridePolicy,
+ UnknownOverridePolicy,
+ )
# XXX StevenK: bug=785004 2011-05-19 Return PPAOverridePolicy() for
# a PPA that overrides the component/pocket to main/RELEASE.
if self.purpose in MAIN_ARCHIVE_PURPOSES:
- return UbuntuOverridePolicy(
- self, distroseries, pocket,
- phased_update_percentage=phased_update_percentage)
+ return FallbackOverridePolicy([
+ FromExistingOverridePolicy(
+ self, distroseries, pocket,
+ phased_update_percentage=phased_update_percentage,
+ include_deleted=True),
+ UnknownOverridePolicy(
+ self, distroseries, pocket,
+ phased_update_percentage=phased_update_percentage)])
return None
def removeCopyNotification(self, job_id):
Follow ups