← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/overrides-init into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/overrides-init into lp:launchpad with lp:~wgrant/launchpad/overrides-cross-archs as a prerequisite.

Commit message:
OverridePolicy-specific arguments to calculate(Source|Binary)Overrides are now __init__ arguments instead.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1073755 in Launchpad itself: "package overrides functionality is inconsistently implemented"
  https://bugs.launchpad.net/launchpad/+bug/1073755

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/overrides-init/+merge/227659

We want to be able to easily compose fallback chains of policies, so the various custom arguments (any_arch, include_deleted) to the override methods must go. OverridePolicy-specific arguments to calculate(Source|Binary)Overrides are now __init__ arguments instead.

I also added tests for include_deleted, since there weren't any before.
-- 
https://code.launchpad.net/~wgrant/launchpad/overrides-init/+merge/227659
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/overrides-init into lp:launchpad.
=== modified file 'lib/lp/soyuz/adapters/overrides.py'
--- lib/lp/soyuz/adapters/overrides.py	2014-07-22 05:57:19 +0000
+++ lib/lp/soyuz/adapters/overrides.py	2014-07-22 05:57:19 +0000
@@ -187,15 +187,18 @@
 
     implements(IOverridePolicy)
 
-    def __init__(self, phased_update_percentage=None):
+    def __init__(self, archive, distroseries, pocket,
+                 phased_update_percentage=None):
         super(BaseOverridePolicy, self).__init__()
+        self.archive = archive
+        self.distroseries = distroseries
+        self.pocket = pocket
         self.phased_update_percentage = phased_update_percentage
 
-    def calculateSourceOverrides(self, archive, distroseries, pocket, sources):
+    def calculateSourceOverrides(self, sources):
         raise NotImplementedError()
 
-    def calculateBinaryOverrides(self, archive, distroseries, pocket,
-                                 binaries):
+    def calculateBinaryOverrides(self, binaries):
         raise NotImplementedError()
 
 
@@ -208,6 +211,11 @@
     for the latest published binary publication.
     """
 
+    def __init__(self, *args, **kwargs):
+        self.any_arch = kwargs.pop('any_arch', False)
+        self.include_deleted = kwargs.pop('include_deleted', False)
+        super(FromExistingOverridePolicy, self).__init__(*args, **kwargs)
+
     def getExistingPublishingStatuses(self, include_deleted):
         status = [
             PackagePublishingStatus.PENDING,
@@ -217,8 +225,7 @@
             status.append(PackagePublishingStatus.DELETED)
         return status
 
-    def calculateSourceOverrides(self, archive, distroseries, pocket, sources,
-                                 include_deleted=False):
+    def calculateSourceOverrides(self, sources):
         def eager_load(rows):
             bulk.load(Component, (row[1] for row in rows))
             bulk.load(Section, (row[2] for row in rows))
@@ -226,9 +233,9 @@
         spns = sources.keys()
         store = IStore(SourcePackagePublishingHistory)
         other_conditions = []
-        if pocket is not None:
+        if self.pocket is not None:
             other_conditions.append(
-                SourcePackagePublishingHistory.pocket == pocket)
+                SourcePackagePublishingHistory.pocket == self.pocket)
         already_published = DecoratedResultSet(
             store.find(
                 (SourcePackagePublishingHistory.sourcepackagenameID,
@@ -237,11 +244,11 @@
                  SourcePackageRelease.version),
                 SourcePackageRelease.id ==
                     SourcePackagePublishingHistory.sourcepackagereleaseID,
-                SourcePackagePublishingHistory.archiveID == archive.id,
+                SourcePackagePublishingHistory.archiveID == self.archive.id,
                 SourcePackagePublishingHistory.distroseriesID ==
-                    distroseries.id,
+                    self.distroseries.id,
                 SourcePackagePublishingHistory.status.is_in(
-                    self.getExistingPublishingStatuses(include_deleted)),
+                    self.getExistingPublishingStatuses(self.include_deleted)),
                 SourcePackagePublishingHistory.sourcepackagenameID.is_in(
                     spn.id for spn in spns),
                 *other_conditions).order_by(
@@ -258,19 +265,17 @@
                 component=component, section=section, version=version))
             for (name, component, section, version) in already_published)
 
-    def calculateBinaryOverrides(self, archive, distroseries, pocket,
-                                 binaries, include_deleted=False,
-                                 any_arch=False):
+    def calculateBinaryOverrides(self, binaries):
         def eager_load(rows):
             bulk.load(Component, (row[2] for row in rows))
             bulk.load(Section, (row[3] for row in rows))
 
         store = IStore(BinaryPackagePublishingHistory)
         other_conditions = []
-        if not any_arch:
-            expanded = calculate_target_das(distroseries, binaries.keys())
+        if not self.any_arch:
+            expanded = calculate_target_das(self.distroseries, binaries.keys())
             candidates = [
-                make_package_condition(archive, das, bpn)
+                make_package_condition(self.archive, das, bpn)
                 for bpn, das in expanded if das is not None]
         else:
             candidates = []
@@ -281,15 +286,15 @@
                         bpn.id)
                 archtags.add(archtag)
             other_conditions.extend([
-                DistroArchSeries.distroseriesID == distroseries.id,
+                DistroArchSeries.distroseriesID == self.distroseries.id,
                 BinaryPackagePublishingHistory.distroarchseriesID ==
                     DistroArchSeries.id,
                 ])
         if len(candidates) == 0:
             return {}
-        if pocket is not None:
+        if self.pocket is not None:
             other_conditions.append(
-                BinaryPackagePublishingHistory.pocket == pocket)
+                BinaryPackagePublishingHistory.pocket == self.pocket)
         # Do not copy phased_update_percentage from existing publications;
         # it is too context-dependent to copy.
         already_published = DecoratedResultSet(
@@ -303,7 +308,7 @@
                 BinaryPackageRelease.id ==
                     BinaryPackagePublishingHistory.binarypackagereleaseID,
                 BinaryPackagePublishingHistory.status.is_in(
-                    self.getExistingPublishingStatuses(include_deleted)),
+                    self.getExistingPublishingStatuses(self.include_deleted)),
                 Or(*candidates),
                 *other_conditions).order_by(
                     BinaryPackagePublishingHistory.distroarchseriesID,
@@ -323,7 +328,7 @@
         for name, das, component, section, priority, ver in already_published:
             # These details can always fulfill their own archtag, and may
             # satisfy a None archtag if the DAS is nominatedarchindep.
-            if not any_arch:
+            if not self.any_arch:
                 matching_keys = [(name, das.architecturetag)]
                 if das == das.distroseries.nominatedarchindep:
                     matching_keys.append((name, None))
@@ -376,18 +381,17 @@
         else:
             return override_component_name
 
-    def calculateSourceOverrides(self, archive, distroseries, pocket, sources):
+    def calculateSourceOverrides(self, sources):
         return dict(
             (spn, SourceOverride(
                 component=(
-                    archive.default_component or
+                    self.archive.default_component or
                     UnknownOverridePolicy.getComponentOverride(
                         override.component, return_component=True))))
             for spn, override in sources.items())
 
-    def calculateBinaryOverrides(self, archive, distroseries, pocket,
-                                 binaries):
-        default_component = archive.default_component or getUtility(
+    def calculateBinaryOverrides(self, binaries):
+        default_component = self.archive.default_component or getUtility(
             IComponentSet)['universe']
         return dict(
             ((binary_package_name, architecture_tag), BinaryOverride(
@@ -404,30 +408,38 @@
     unknown policy.
     """
 
-    def calculateSourceOverrides(self, archive, distroseries, pocket, sources):
+    def calculateSourceOverrides(self, sources):
         total = set(sources.keys())
-        overrides = FromExistingOverridePolicy.calculateSourceOverrides(
-            self, archive, distroseries, pocket, sources, include_deleted=True)
+        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 = UnknownOverridePolicy.calculateSourceOverrides(
-                self, archive, distroseries, pocket,
+            unknown_policy = UnknownOverridePolicy(
+                self.archive, self.distroseries, self.pocket,
+                phased_update_percentage=self.phased_update_percentage)
+            unknown = unknown_policy.calculateSourceOverrides(
                 dict((spn, sources[spn]) for spn in missing))
             overrides.update(unknown)
         return overrides
 
-    def calculateBinaryOverrides(self, archive, distroseries, pocket,
-                                 binaries):
+    def calculateBinaryOverrides(self, binaries):
         total = set(binaries.keys())
-        overrides = FromExistingOverridePolicy.calculateBinaryOverrides(
-            self, archive, distroseries, pocket, binaries,
+        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 = UnknownOverridePolicy.calculateBinaryOverrides(
-                self, archive, distroseries, pocket,
+            unknown_policy = UnknownOverridePolicy(
+                self.archive, self.distroseries, self.pocket,
+                phased_update_percentage=self.phased_update_percentage)
+            unknown = unknown_policy.calculateBinaryOverrides(
                 dict((key, binaries[key]) for key in missing))
             overrides.update(unknown)
         return overrides

=== modified file 'lib/lp/soyuz/adapters/tests/test_overrides.py'
--- lib/lp/soyuz/adapters/tests/test_overrides.py	2014-07-22 05:57:19 +0000
+++ lib/lp/soyuz/adapters/tests/test_overrides.py	2014-07-22 05:57:19 +0000
@@ -34,9 +34,9 @@
         # When the spn is published in the given archive/distroseries, the
         # overrides for that archive/distroseries are returned.
         spph = self.factory.makeSourcePackagePublishingHistory()
-        policy = FromExistingOverridePolicy()
+        policy = FromExistingOverridePolicy(
+            spph.distroseries.main_archive, spph.distroseries, spph.pocket)
         overrides = policy.calculateSourceOverrides(
-            spph.distroseries.main_archive, spph.distroseries, spph.pocket,
             {spph.sourcepackagerelease.sourcepackagename: SourceOverride()})
         expected = {
             spph.sourcepackagerelease.sourcepackagename: SourceOverride(
@@ -49,22 +49,22 @@
         # are made.
         spn = self.factory.makeSourcePackageName()
         distroseries = self.factory.makeDistroSeries()
-        policy = FromExistingOverridePolicy()
         self.factory.makeSourcePackagePublishingHistory(
             archive=distroseries.main_archive, distroseries=distroseries,
             pocket=PackagePublishingPocket.RELEASE, sourcepackagename=spn)
-        overrides = policy.calculateSourceOverrides(
+        overrides = FromExistingOverridePolicy(
             distroseries.main_archive, distroseries,
-            PackagePublishingPocket.PROPOSED,
+            PackagePublishingPocket.PROPOSED).calculateSourceOverrides(
             {spn: SourceOverride()})
         self.assertEqual(0, len(overrides))
-        overrides = policy.calculateSourceOverrides(
+        overrides = FromExistingOverridePolicy(
             distroseries.main_archive, distroseries,
-            PackagePublishingPocket.RELEASE,
+            PackagePublishingPocket.RELEASE).calculateSourceOverrides(
             {spn: SourceOverride()})
         self.assertEqual(1, len(overrides))
-        overrides = policy.calculateSourceOverrides(
-            distroseries.main_archive, distroseries, None,
+        overrides = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries,
+            None).calculateSourceOverrides(
             {spn: SourceOverride()})
         self.assertEqual(1, len(overrides))
 
@@ -83,14 +83,54 @@
             sourcepackagename=spn)
         spph = self.factory.makeSourcePackagePublishingHistory(
             sourcepackagerelease=spr, distroseries=distroseries)
-        policy = FromExistingOverridePolicy()
-        overrides = policy.calculateSourceOverrides(
-            spph.distroseries.main_archive, spph.distroseries, spph.pocket,
-            {spn: SourceOverride(spn)})
-        self.assertEqual(
-            {spn: SourceOverride(
-                component=spph.component, section=spph.section,
-                version=spph.sourcepackagerelease.version)},
+        overrides = FromExistingOverridePolicy(
+            spph.distroseries.main_archive, spph.distroseries,
+            spph.pocket).calculateSourceOverrides(
+            {spn: SourceOverride(spn)})
+        self.assertEqual(
+            {spn: SourceOverride(
+                component=spph.component, section=spph.section,
+                version=spph.sourcepackagerelease.version)},
+            overrides)
+
+    def test_source_overrides_can_include_deleted(self):
+        # include_deleted=True causes Deleted publications to be
+        # considered too.
+        spn = self.factory.makeSourcePackageName()
+        distroseries = self.factory.makeDistroSeries()
+        spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)
+        spph = self.factory.makeSourcePackagePublishingHistory(
+            archive=distroseries.main_archive, distroseries=distroseries,
+            sourcepackagerelease=spr, status=PackagePublishingStatus.PUBLISHED)
+        deleted_spr = self.factory.makeSourcePackageRelease(
+            sourcepackagename=spn)
+        deleted_spph = self.factory.makeSourcePackagePublishingHistory(
+            archive=distroseries.main_archive, distroseries=distroseries,
+            sourcepackagerelease=deleted_spr,
+            status=PackagePublishingStatus.DELETED, pocket=spph.pocket)
+
+        # With include_deleted=False only the Published ancestry is
+        # found.
+        overrides = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries,
+            spph.pocket).calculateSourceOverrides(
+            {spn: SourceOverride(spn)})
+        self.assertEqual(
+            {spn: SourceOverride(
+                component=spph.component, section=spph.section,
+                version=spph.sourcepackagerelease.version)},
+            overrides)
+
+        # But with include_deleted=True the newer Deleted publication is
+        # used.
+        overrides = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries,
+            spph.pocket, include_deleted=True).calculateSourceOverrides(
+            {spn: SourceOverride(spn)})
+        self.assertEqual(
+            {spn: SourceOverride(
+                component=deleted_spph.component, section=deleted_spph.section,
+                version=deleted_spph.sourcepackagerelease.version)},
             overrides)
 
     def test_source_overrides_constant_query_count(self):
@@ -107,12 +147,12 @@
         flush_database_caches()
         distroseries.main_archive
         bulk.reload(spns)
-        policy = FromExistingOverridePolicy()
+        policy = FromExistingOverridePolicy(
+            spph.distroseries.main_archive, spph.distroseries, spph.pocket)
         with StormStatementRecorder() as recorder:
             policy.calculateSourceOverrides(
-                spph.distroseries.main_archive, spph.distroseries,
-                spph.pocket, dict((spn, SourceOverride()) for spn in spns))
-        self.assertThat(recorder, HasQueryCount(Equals(4)))
+                dict((spn, SourceOverride()) for spn in spns))
+        self.assertThat(recorder, HasQueryCount(Equals(3)))
 
     def test_no_binary_overrides(self):
         # if the given binary is not published in the given distroarchseries,
@@ -122,9 +162,9 @@
         distroseries.nominatedarchindep = das
         bpn = self.factory.makeBinaryPackageName()
         pocket = self.factory.getAnyPocket()
-        policy = FromExistingOverridePolicy()
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, pocket,
             {(bpn, None): BinaryOverride()})
         self.assertEqual({}, overrides)
 
@@ -140,9 +180,9 @@
             archive=distroseries.main_archive, pocket=bpph1.pocket,
             distroarchseries=self.factory.makeDistroArchSeries(distroseries))
         distroseries.nominatedarchindep = bpph1.distroarchseries
-        policy = FromExistingOverridePolicy()
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, bpph1.pocket)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, bpph1.pocket,
             {(bpph1.binarypackagerelease.binarypackagename,
               bpph1.distroarchseries.architecturetag): BinaryOverride(),
              (bpph2.binarypackagerelease.binarypackagename,
@@ -180,20 +220,21 @@
         self.factory.makeBinaryPackagePublishingHistory(
             archive=distroseries.main_archive, distroarchseries=das,
             pocket=PackagePublishingPocket.RELEASE, binarypackagename=bpn)
-        policy = FromExistingOverridePolicy()
-
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries,
+            PackagePublishingPocket.PROPOSED)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries,
-            PackagePublishingPocket.PROPOSED,
             {(bpn, das.architecturetag): BinaryOverride()})
         self.assertEqual(0, len(overrides))
-        overrides = policy.calculateBinaryOverrides(
+        policy = FromExistingOverridePolicy(
             distroseries.main_archive, distroseries,
-            PackagePublishingPocket.RELEASE,
+            PackagePublishingPocket.RELEASE)
+        overrides = policy.calculateBinaryOverrides(
             {(bpn, das.architecturetag): BinaryOverride()})
         self.assertEqual(1, len(overrides))
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, None)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, None,
             {(bpn, das.architecturetag): BinaryOverride()})
         self.assertEqual(1, len(overrides))
 
@@ -208,9 +249,9 @@
         distroseries.nominatedarchindep = das
         bpn = self.factory.makeBinaryPackageName()
         pocket = self.factory.getAnyPocket()
-        policy = FromExistingOverridePolicy()
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, pocket,
             {(bpn, 'i386'): BinaryOverride()})
         self.assertEqual({}, overrides)
 
@@ -233,29 +274,72 @@
         bpph_override = BinaryOverride(
             component=bpph.component, section=bpph.section,
             priority=bpph.priority, version=bpph.binarypackagerelease.version)
-        policy = FromExistingOverridePolicy()
 
         # With any_arch=False only amd64 is found.
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, pocket,
             {(bpn, 'i386'): BinaryOverride(),
              (bpn, 'amd64'): BinaryOverride(),
              (bpn, None): BinaryOverride()})
         self.assertEqual({(bpn, 'amd64'): bpph_override}, overrides)
 
         # But with any_arch=True we get the amd64 overrides everywhere.
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket, any_arch=True)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, pocket,
             {(bpn, 'i386'): BinaryOverride(),
              (bpn, 'amd64'): BinaryOverride(),
-             (bpn, None): BinaryOverride()},
-            any_arch=True)
+             (bpn, None): BinaryOverride()})
         self.assertEqual(
             {(bpn, 'i386'): bpph_override,
              (bpn, 'amd64'): bpph_override,
              (bpn, None): bpph_override},
             overrides)
 
+    def test_binary_overrides_can_include_deleted(self):
+        # calculateBinaryOverrides can be asked to include Deleted
+        # publications.
+        distroseries = self.factory.makeDistroSeries()
+        das = self.factory.makeDistroArchSeries(
+            architecturetag='amd64',
+            distroseries=distroseries)
+        bpn = self.factory.makeBinaryPackageName()
+        pocket = self.factory.getAnyPocket()
+        bpph = self.factory.makeBinaryPackagePublishingHistory(
+            archive=distroseries.main_archive, distroarchseries=das,
+            pocket=pocket, binarypackagename=bpn, architecturespecific=True,
+            status=PackagePublishingStatus.PUBLISHED)
+        deleted_bpph = self.factory.makeBinaryPackagePublishingHistory(
+            archive=distroseries.main_archive, distroarchseries=das,
+            pocket=pocket, binarypackagename=bpn, architecturespecific=True,
+            status=PackagePublishingStatus.DELETED)
+
+        # With include_deleted=False the Published pub is found.
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
+        overrides = policy.calculateBinaryOverrides(
+            {(bpn, 'amd64'): BinaryOverride()})
+        self.assertEqual(
+            {(bpn, 'amd64'): BinaryOverride(
+                component=bpph.component, section=bpph.section,
+                priority=bpph.priority,
+                version=bpph.binarypackagerelease.version)},
+            overrides)
+
+        # But with include_deleted=True we get the newer Deleted pub instead.
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket,
+            include_deleted=True)
+        overrides = policy.calculateBinaryOverrides(
+            {(bpn, 'amd64'): BinaryOverride()})
+        self.assertEqual(
+            {(bpn, 'amd64'): BinaryOverride(
+                component=deleted_bpph.component, section=deleted_bpph.section,
+                priority=deleted_bpph.priority,
+                version=deleted_bpph.binarypackagerelease.version)},
+            overrides)
+
     def test_binary_overrides_constant_query_count(self):
         # The query count is constant, no matter how many bpn-das pairs are
         # checked.
@@ -272,10 +356,10 @@
         flush_database_caches()
         distroseries.main_archive
         bulk.reload(bpn[0] for bpn in bpns)
-        policy = FromExistingOverridePolicy()
+        policy = FromExistingOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
         with StormStatementRecorder() as recorder:
             policy.calculateBinaryOverrides(
-                distroseries.main_archive, distroseries, pocket,
                 dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
         self.assertThat(recorder, HasQueryCount(Equals(4)))
 
@@ -316,9 +400,10 @@
             self.factory.makeComponent(component)
         distroseries = self.factory.makeDistroSeries()
         spns = [self.factory.makeSourcePackageName() for i in range(3)]
-        overrides = UnknownOverridePolicy().calculateSourceOverrides(
+        policy = UnknownOverridePolicy(
             distroseries.main_archive, distroseries,
-            PackagePublishingPocket.RELEASE,
+            PackagePublishingPocket.RELEASE)
+        overrides = policy.calculateSourceOverrides(
             dict(
                 (spn, SourceOverride(
                     component=getUtility(IComponentSet)[component]))
@@ -338,9 +423,10 @@
             self.factory.makeComponent(component)
         distroseries = self.factory.makeDistroSeries()
         spns = [self.factory.makeSourcePackageName() for i in range(3)]
-        overrides = UnknownOverridePolicy().calculateSourceOverrides(
+        policy = UnknownOverridePolicy(
             self.factory.makeArchive(distribution=distroseries.distribution),
-            distroseries, PackagePublishingPocket.RELEASE,
+            distroseries, PackagePublishingPocket.RELEASE)
+        overrides = policy.calculateSourceOverrides(
             dict(
                 (spn, SourceOverride(
                     component=getUtility(IComponentSet)[component]))
@@ -358,9 +444,9 @@
         bpph = self.factory.makeBinaryPackagePublishingHistory()
         distroseries = bpph.distroarchseries.distroseries
         distroseries.nominatedarchindep = bpph.distroarchseries
-        policy = UnknownOverridePolicy()
+        policy = UnknownOverridePolicy(
+            distroseries.main_archive, distroseries, bpph.pocket)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, bpph.pocket,
             {(bpph.binarypackagerelease.binarypackagename, None):
                 BinaryOverride()})
         universe = getUtility(IComponentSet)['universe']
@@ -393,9 +479,9 @@
                     version=spph.sourcepackagerelease.version))
         spns.append(self.factory.makeSourcePackageName())
         expected[spns[-1]] = SourceOverride(component=universe)
-        policy = UbuntuOverridePolicy()
+        policy = UbuntuOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
         overrides = policy.calculateSourceOverrides(
-            distroseries.main_archive, distroseries, pocket,
             dict((spn, SourceOverride()) for spn in spns))
         self.assertEqual(10, len(overrides))
         self.assertEqual(expected, overrides)
@@ -433,9 +519,9 @@
             expected[bpn, distroarchseries.architecturetag] = BinaryOverride(
                 component=universe)
         distroseries.nominatedarchindep = distroarchseries
-        policy = UbuntuOverridePolicy()
+        policy = UbuntuOverridePolicy(
+            distroseries.main_archive, distroseries, pocket)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, pocket,
             dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
         self.assertEqual(5, len(overrides))
         self.assertEqual(expected, overrides)
@@ -469,9 +555,10 @@
         expected[(bpn, distroarchseries.architecturetag)] = BinaryOverride(
             component=universe, phased_update_percentage=50)
         distroseries.nominatedarchindep = distroarchseries
-        policy = UbuntuOverridePolicy(phased_update_percentage=50)
+        policy = UbuntuOverridePolicy(
+            distroseries.main_archive, distroseries, pocket,
+            phased_update_percentage=50)
         overrides = policy.calculateBinaryOverrides(
-            distroseries.main_archive, distroseries, pocket,
             dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
         self.assertEqual(2, len(overrides))
         self.assertEqual(expected, overrides)

=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py	2014-07-15 02:12:04 +0000
+++ lib/lp/soyuz/interfaces/archive.py	2014-07-22 05:57:19 +0000
@@ -1058,7 +1058,7 @@
     def getPockets():
         """Return iterable containing valid pocket names for this archive."""
 
-    def getOverridePolicy(phased_update_percentage=None):
+    def getOverridePolicy(distroseries, pocket, phased_update_percentage=None):
         """Returns an instantiated `IOverridePolicy` for the archive."""
 
     buildd_secret = TextLine(

=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2014-07-15 02:12:04 +0000
+++ lib/lp/soyuz/model/archive.py	2014-07-22 05:57:19 +0000
@@ -2075,7 +2075,8 @@
         # understandiung EnumItems.
         return list(PackagePublishingPocket.items)
 
-    def getOverridePolicy(self, phased_update_percentage=None):
+    def getOverridePolicy(self, distroseries, pocket,
+                          phased_update_percentage=None):
         """See `IArchive`."""
         # Circular imports.
         from lp.soyuz.adapters.overrides import UbuntuOverridePolicy
@@ -2083,6 +2084,7 @@
         # 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 None
 

=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
--- lib/lp/soyuz/model/packagecopyjob.py	2014-07-22 05:57:19 +0000
+++ lib/lp/soyuz/model/packagecopyjob.py	2014-07-22 05:57:19 +0000
@@ -518,9 +518,9 @@
         # This helper will only return if it's safe to carry on with the
         # copy, otherwise it raises SuspendJobException to tell the job
         # runner to suspend the job.
-        override_policy = FromExistingOverridePolicy()
+        override_policy = FromExistingOverridePolicy(
+            self.target_archive, self.target_distroseries, None)
         ancestry = override_policy.calculateSourceOverrides(
-            self.target_archive, self.target_distroseries, None,
             {source_name: SourceOverride()})
 
         copy_policy = self.getPolicyImplementation()
@@ -528,8 +528,9 @@
         if len(ancestry) == 0:
             # We need to get the default overrides and put them in the
             # metadata.
-            defaults = UnknownOverridePolicy().calculateSourceOverrides(
-                self.target_archive, self.target_distroseries, None,
+            default_policy = UnknownOverridePolicy(
+                self.target_archive, self.target_distroseries, None)
+            defaults = default_policy.calculateSourceOverrides(
                 {source_name: SourceOverride(component=source_component)})
             self.addSourceOverride(defaults[source_name])
             if auto_approve:

=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2014-07-22 05:57:19 +0000
+++ lib/lp/soyuz/model/publishing.py	2014-07-22 05:57:19 +0000
@@ -1478,7 +1478,6 @@
                     bpph.distroarchseries.architecturetag)] = bpph
             with_overrides = {}
             overrides = policy.calculateBinaryOverrides(
-                archive, distroseries, None,
                 dict(
                     ((bpn, archtag), BinaryOverride())
                     for bpn, archtag in bpn_archtag.keys()))

=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py	2014-07-22 05:57:19 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py	2014-07-22 05:57:19 +0000
@@ -713,7 +713,7 @@
         status=active_publishing_status,
         distroseries=series, pocket=pocket)
     policy = archive.getOverridePolicy(
-        phased_update_percentage=phased_update_percentage)
+        series, None, phased_update_percentage=phased_update_percentage)
     if source_in_destination.is_empty():
         # If no manual overrides were specified and the archive has an
         # override policy then use that policy to get overrides.
@@ -721,7 +721,6 @@
             # Only one override can be returned so take the first
             # element of the returned list.
             overrides = policy.calculateSourceOverrides(
-                archive, series, None,
                 {source.sourcepackagerelease.sourcepackagename:
                     SourceOverride()})
             # Only one override can be returned so take the first


Follow ups