launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #17202
[Merge] lp:~wgrant/launchpad/overrides-actually into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/overrides-actually into lp:launchpad with lp:~wgrant/launchpad/overrides-fallback as a prerequisite.
Commit message:
Provide an Archive.getOverridePolicy implementation for each ArchivePurpose. packagecopier override behaviour now matches archiveuploader except that binaries don't yet inherit their source component.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/overrides-actually/+merge/227913
Provide an Archive.getOverridePolicy implementation for each ArchivePurpose. packagecopier override behaviour now matches archiveuploader except that binaries don't yet inherit their source component.
--
https://code.launchpad.net/~wgrant/launchpad/overrides-actually/+merge/227913
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/overrides-actually into lp:launchpad.
=== modified file 'lib/lp/soyuz/adapters/overrides.py'
--- lib/lp/soyuz/adapters/overrides.py 2014-07-23 13:21:35 +0000
+++ lib/lp/soyuz/adapters/overrides.py 2014-07-23 13:21:35 +0000
@@ -7,6 +7,7 @@
__all__ = [
'BinaryOverride',
+ 'ConstantOverridePolicy',
'FallbackOverridePolicy',
'FromExistingOverridePolicy',
'IBinaryOverride',
@@ -394,16 +395,13 @@
def calculateSourceOverrides(self, sources):
return dict(
(spn, SourceOverride(
- component=(
- self.archive.default_component or
- UnknownOverridePolicy.getComponentOverride(
- override.component, return_component=True)),
+ component=UnknownOverridePolicy.getComponentOverride(
+ override.component, return_component=True),
new=True))
for spn, override in sources.items())
def calculateBinaryOverrides(self, binaries):
- default_component = self.archive.default_component or getUtility(
- IComponentSet)['universe']
+ default_component = getUtility(IComponentSet)['universe']
return dict(
((binary_package_name, architecture_tag), BinaryOverride(
component=default_component, new=True,
@@ -411,6 +409,32 @@
for binary_package_name, architecture_tag in binaries.keys())
+class ConstantOverridePolicy(BaseOverridePolicy):
+ """Override policy that returns constant values."""
+
+ def __init__(self, component=None, section=None, priority=None,
+ phased_update_percentage=None, new=None):
+ self.component = component
+ self.section = section
+ self.priority = priority
+ self.phased_update_percentage = phased_update_percentage
+ self.new = new
+
+ def calculateSourceOverrides(self, sources):
+ return dict(
+ (key, SourceOverride(
+ component=self.component, section=self.section,
+ new=self.new)) for key in sources.keys())
+
+ def calculateBinaryOverrides(self, binaries):
+ return dict(
+ (key, BinaryOverride(
+ component=self.component, section=self.section,
+ priority=self.priority,
+ phased_update_percentage=self.phased_update_percentage,
+ new=self.new)) for key in binaries.keys())
+
+
class FallbackOverridePolicy(BaseOverridePolicy):
"""Override policy that fills things through a sequence of policies."""
=== modified file 'lib/lp/soyuz/adapters/tests/test_overrides.py'
--- lib/lp/soyuz/adapters/tests/test_overrides.py 2014-07-23 13:21:35 +0000
+++ lib/lp/soyuz/adapters/tests/test_overrides.py 2014-07-23 13:21:35 +0000
@@ -11,12 +11,16 @@
from lp.services.database.sqlbase import flush_database_caches
from lp.soyuz.adapters.overrides import (
BinaryOverride,
+ ConstantOverridePolicy,
FallbackOverridePolicy,
FromExistingOverridePolicy,
SourceOverride,
UnknownOverridePolicy,
)
-from lp.soyuz.enums import PackagePublishingStatus
+from lp.soyuz.enums import (
+ PackagePublishingPriority,
+ PackagePublishingStatus,
+ )
from lp.soyuz.interfaces.component import IComponentSet
from lp.testing import (
StormStatementRecorder,
@@ -417,28 +421,6 @@
zip(spns, ('universe', 'multiverse', 'multiverse')))
self.assertEqual(expected, overrides)
- def test_unknown_sources_ppa(self):
- # The unknown policy overrides everything to the archive's
- # default component, if it has one.
- for component in ('contrib', 'non-free'):
- self.factory.makeComponent(component)
- distroseries = self.factory.makeDistroSeries()
- spns = [self.factory.makeSourcePackageName() for i in range(3)]
- policy = UnknownOverridePolicy(
- self.factory.makeArchive(distribution=distroseries.distribution),
- distroseries, PackagePublishingPocket.RELEASE)
- overrides = policy.calculateSourceOverrides(
- dict(
- (spn, SourceOverride(
- component=getUtility(IComponentSet)[component]))
- for spn, component in
- zip(spns, ('main', 'contrib', 'non-free'))))
- expected = dict(
- (spn, SourceOverride(
- component=getUtility(IComponentSet)[component], new=True))
- for spn, component in zip(spns, ('main', 'main', 'main')))
- self.assertEqual(expected, overrides)
-
def test_unknown_binaries(self):
# If the unknown policy is used, it does no checks, just returns the
# defaults.
@@ -457,6 +439,45 @@
self.assertEqual(expected, overrides)
+class TestConstantOverridePolicy(TestCaseWithFactory):
+
+ layer = ZopelessDatabaseLayer
+
+ def test_sources(self):
+ policy = ConstantOverridePolicy(
+ component=self.factory.makeComponent(),
+ section=self.factory.makeSection(),
+ phased_update_percentage=50, new=True)
+ spn = self.factory.makeSourcePackageName()
+ self.assertEqual(
+ {spn: SourceOverride(
+ component=policy.component, section=policy.section,
+ new=True)},
+ policy.calculateSourceOverrides(
+ {spn: SourceOverride(
+ component=self.factory.makeComponent(),
+ section=self.factory.makeSection(), new=False)}))
+
+ def test_binary(self):
+ policy = ConstantOverridePolicy(
+ component=self.factory.makeComponent(),
+ section=self.factory.makeSection(),
+ priority=PackagePublishingPriority.EXTRA,
+ phased_update_percentage=50, new=True)
+ bpn = self.factory.makeBinaryPackageName()
+ self.assertEqual(
+ {(bpn, None): BinaryOverride(
+ component=policy.component, section=policy.section,
+ priority=policy.priority, phased_update_percentage=50,
+ new=True)},
+ policy.calculateBinaryOverrides(
+ {(bpn, None): BinaryOverride(
+ component=self.factory.makeComponent(),
+ section=self.factory.makeSection(),
+ priority=PackagePublishingPriority.REQUIRED,
+ phased_update_percentage=90, new=False)}))
+
+
class TestFallbackOverridePolicy(TestCaseWithFactory):
layer = ZopelessDatabaseLayer
=== modified file 'lib/lp/soyuz/configure.zcml'
--- lib/lp/soyuz/configure.zcml 2014-07-23 13:21:35 +0000
+++ lib/lp/soyuz/configure.zcml 2014-07-23 13:21:35 +0000
@@ -930,6 +930,9 @@
<class class="lp.soyuz.adapters.overrides.FallbackOverridePolicy">
<allow interface="lp.soyuz.adapters.overrides.IOverridePolicy" />
</class>
+ <class class="lp.soyuz.adapters.overrides.ConstantOverridePolicy">
+ <allow interface="lp.soyuz.adapters.overrides.IOverridePolicy" />
+ </class>
<class
class="lp.soyuz.model.reporting.LatestPersonSourcePackageReleaseCache">
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2014-07-23 13:21:35 +0000
+++ lib/lp/soyuz/model/archive.py 2014-07-23 13:21:35 +0000
@@ -2080,22 +2080,47 @@
"""See `IArchive`."""
# Circular imports.
from lp.soyuz.adapters.overrides import (
+ ConstantOverridePolicy,
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:
+ if self.is_primary:
return FallbackOverridePolicy([
FromExistingOverridePolicy(
- self, distroseries, pocket,
+ self, distroseries, None,
phased_update_percentage=phased_update_percentage,
include_deleted=True),
+ FromExistingOverridePolicy(
+ self, distroseries, None,
+ phased_update_percentage=phased_update_percentage,
+ include_deleted=True, any_arch=True),
UnknownOverridePolicy(
self, distroseries, pocket,
phased_update_percentage=phased_update_percentage)])
- return None
+ elif self.is_partner:
+ return FallbackOverridePolicy([
+ FromExistingOverridePolicy(
+ self, distroseries, None,
+ phased_update_percentage=phased_update_percentage,
+ include_deleted=True),
+ FromExistingOverridePolicy(
+ self, distroseries, None,
+ phased_update_percentage=phased_update_percentage,
+ include_deleted=True, any_arch=True),
+ ConstantOverridePolicy(
+ component=getUtility(IComponentSet)['partner'],
+ phased_update_percentage=phased_update_percentage,
+ new=True)])
+ elif self.is_ppa:
+ return ConstantOverridePolicy(
+ component=getUtility(IComponentSet)['main'])
+ elif self.is_copy:
+ return self.distribution.main_archive.getOverridePolicy(
+ distroseries, pocket,
+ phased_update_percentage=phased_update_percentage)
+ raise AssertionError(
+ "No IOverridePolicy for purpose %r" % self.purpose)
def removeCopyNotification(self, job_id):
"""See `IArchive`."""
=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
--- lib/lp/soyuz/model/packagecopyjob.py 2014-07-23 13:21:35 +0000
+++ lib/lp/soyuz/model/packagecopyjob.py 2014-07-23 13:21:35 +0000
@@ -518,10 +518,11 @@
# copy, otherwise it raises SuspendJobException to tell the job
# runner to suspend the job.
override_policy = self.target_archive.getOverridePolicy(
- self.target_distroseries, None)
+ self.target_distroseries, self.target_pocket)
if override_policy is None:
override_policy = UnknownOverridePolicy(
- self.target_archive, self.target_distroseries, None)
+ self.target_archive, self.target_distroseries,
+ self.target_pocket)
overrides = override_policy.calculateSourceOverrides(
{source_name: SourceOverride(component=source_component)})
override = overrides[source_name]
=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py 2014-07-23 13:21:35 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py 2014-07-23 13:21:35 +0000
@@ -713,7 +713,7 @@
status=active_publishing_status,
distroseries=series, pocket=pocket)
policy = archive.getOverridePolicy(
- series, None, phased_update_percentage=phased_update_percentage)
+ series, pocket, 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.
=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py 2014-07-08 23:52:59 +0000
+++ lib/lp/soyuz/tests/test_archive.py 2014-07-23 13:21:35 +0000
@@ -47,6 +47,10 @@
from lp.soyuz.adapters.archivedependencies import (
get_sources_list_for_building,
)
+from lp.soyuz.adapters.overrides import (
+ BinaryOverride,
+ SourceOverride,
+ )
from lp.soyuz.enums import (
ArchivePermissionType,
ArchivePurpose,
@@ -92,6 +96,7 @@
from lp.soyuz.model.component import ComponentSelection
from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
from lp.testing import (
+ admin_logged_in,
ANONYMOUS,
celebrity_logged_in,
login,
@@ -3272,3 +3277,270 @@
e = self.assertRaises(
Unauthorized, getattr, archive, "getBuildSummariesForSourceIds")
self.assertEqual("launchpad.View", e.args[2])
+
+
+class TestArchiveGetOverridePolicy(TestCaseWithFactory):
+ """Tests for Archive.getOverridePolicy.
+
+ These are just integration tests. The underlying policies are tested
+ in lp.soyuz.adapters.tests.test_overrides.
+ """
+
+ layer = DatabaseFunctionalLayer
+
+ def setUp(self):
+ super(TestArchiveGetOverridePolicy, self).setUp()
+ self.series = self.factory.makeDistroSeries()
+ with admin_logged_in():
+ self.series.nominatedarchindep = self.amd64 = (
+ self.factory.makeDistroArchSeries(
+ distroseries=self.series, architecturetag='amd64'))
+ self.armhf = self.factory.makeDistroArchSeries(
+ distroseries=self.series, architecturetag='armhf')
+ self.main = getUtility(IComponentSet)['main']
+ self.universe = getUtility(IComponentSet)['universe']
+ self.multiverse = getUtility(IComponentSet)['multiverse']
+ self.non_free = getUtility(IComponentSet).ensure('non-free')
+ self.partner = getUtility(IComponentSet)['partner']
+
+ def prepareBinaries(self, archive, bpn):
+ amd64_bpph = self.factory.makeBinaryPackagePublishingHistory(
+ binarypackagename=bpn,
+ archive=archive, distroarchseries=self.amd64,
+ pocket=PackagePublishingPocket.UPDATES, architecturespecific=True)
+ armhf_bpph = self.factory.makeBinaryPackagePublishingHistory(
+ binarypackagename=bpn,
+ archive=archive, distroarchseries=self.armhf,
+ pocket=PackagePublishingPocket.UPDATES, architecturespecific=True)
+ amd64_override = BinaryOverride(
+ component=amd64_bpph.component, section=amd64_bpph.section,
+ priority=amd64_bpph.priority,
+ version=amd64_bpph.binarypackagerelease.version, new=False)
+ armhf_override = BinaryOverride(
+ component=armhf_bpph.component, section=armhf_bpph.section,
+ priority=armhf_bpph.priority,
+ version=armhf_bpph.binarypackagerelease.version, new=False)
+ return (amd64_override, armhf_override)
+
+ def test_primary_sources(self):
+ spph = self.factory.makeSourcePackagePublishingHistory(
+ archive=self.series.main_archive, distroseries=self.series,
+ pocket=PackagePublishingPocket.UPDATES)
+ policy = self.series.main_archive.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ existing_spn = spph.sourcepackagerelease.sourcepackagename
+ main_spn = self.factory.makeSourcePackageName()
+ non_free_spn = self.factory.makeSourcePackageName()
+
+ # Packages with an existing publication in any pocket return
+ # that publication's overrides. Otherwise they're new, with a
+ # default component mapped from their original component.
+ self.assertEqual(
+ {existing_spn: SourceOverride(
+ component=spph.component, section=spph.section,
+ version=spph.sourcepackagerelease.version, new=False),
+ main_spn: SourceOverride(component=self.universe, new=True),
+ non_free_spn: SourceOverride(component=self.multiverse, new=True),
+ },
+ policy.calculateSourceOverrides(
+ {existing_spn: SourceOverride(component=self.non_free),
+ main_spn: SourceOverride(component=self.main),
+ non_free_spn: SourceOverride(component=self.non_free),
+ }))
+
+ def test_primary_binaries(self):
+ existing_bpn = self.factory.makeBinaryPackageName()
+ other_bpn = self.factory.makeBinaryPackageName()
+ amd64_override, armhf_override = self.prepareBinaries(
+ self.series.main_archive, existing_bpn)
+ policy = self.series.main_archive.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ # Packages with an existing publication in any pocket of any DAS
+ # with a matching archtag, or nominatedarchindep if the archtag
+ # is None, return that publication's overrides. Otherwise
+ # they're new, with a default component mapped from their
+ # original component.
+ self.assertEqual(
+ {(existing_bpn, 'amd64'): amd64_override,
+ (existing_bpn, None): amd64_override,
+ (existing_bpn, 'i386'): armhf_override,
+ (other_bpn, 'amd64'): BinaryOverride(
+ component=self.universe, new=True),
+ },
+ policy.calculateBinaryOverrides(
+ {(existing_bpn, 'amd64'): BinaryOverride(component=self.main),
+ (existing_bpn, None): BinaryOverride(component=self.main),
+ (existing_bpn, 'i386'): BinaryOverride(component=self.main),
+ (other_bpn, 'amd64'): BinaryOverride(component=self.main),
+ }))
+
+ def test_ppa_sources(self):
+ ppa = self.factory.makeArchive(
+ distribution=self.series.distribution,
+ purpose=ArchivePurpose.PPA)
+ spph = self.factory.makeSourcePackagePublishingHistory(
+ archive=ppa, distroseries=self.series)
+ policy = ppa.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ existing_spn = spph.sourcepackagerelease.sourcepackagename
+ main_spn = self.factory.makeSourcePackageName()
+ non_free_spn = self.factory.makeSourcePackageName()
+
+ # PPA packages are always overridden to main, with no
+ # examination of existing publications or assertions about
+ # newness.
+ self.assertEqual(
+ {existing_spn: SourceOverride(component=self.main),
+ main_spn: SourceOverride(component=self.main),
+ non_free_spn: SourceOverride(component=self.main),
+ },
+ policy.calculateSourceOverrides(
+ {existing_spn: SourceOverride(component=self.non_free),
+ main_spn: SourceOverride(component=self.main),
+ non_free_spn: SourceOverride(component=self.non_free),
+ }))
+
+ def test_ppa_binaries(self):
+ ppa = self.factory.makeArchive(
+ distribution=self.series.distribution,
+ purpose=ArchivePurpose.PPA)
+ existing_bpn = self.factory.makeBinaryPackageName()
+ other_bpn = self.factory.makeBinaryPackageName()
+ amd64_override, armhf_override = self.prepareBinaries(
+ ppa, existing_bpn)
+ policy = ppa.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ # PPA packages are always overridden to main, with no
+ # examination of existing publications or assertions about
+ # newness.
+ self.assertEqual(
+ {(existing_bpn, 'amd64'): BinaryOverride(component=self.main),
+ (existing_bpn, None): BinaryOverride(component=self.main),
+ (existing_bpn, 'i386'): BinaryOverride(component=self.main),
+ (other_bpn, 'amd64'): BinaryOverride(component=self.main),
+ },
+ policy.calculateBinaryOverrides(
+ {(existing_bpn, 'amd64'): BinaryOverride(component=self.main),
+ (existing_bpn, None): BinaryOverride(component=self.main),
+ (existing_bpn, 'i386'): BinaryOverride(component=self.main),
+ (other_bpn, 'amd64'): BinaryOverride(component=self.non_free),
+ }))
+
+ def test_partner_sources(self):
+ partner = self.factory.makeArchive(
+ distribution=self.series.distribution,
+ purpose=ArchivePurpose.PARTNER)
+ spph = self.factory.makeSourcePackagePublishingHistory(
+ archive=partner, distroseries=self.series,
+ pocket=PackagePublishingPocket.RELEASE)
+ policy = partner.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ existing_spn = spph.sourcepackagerelease.sourcepackagename
+ universe_spn = self.factory.makeSourcePackageName()
+
+ # Packages with an existing publication in any pocket return
+ # that publication's overrides. Otherwise they're new, with a
+ # default component of partner.
+ self.assertEqual(
+ {existing_spn: SourceOverride(
+ component=spph.component, section=spph.section,
+ version=spph.sourcepackagerelease.version, new=False),
+ universe_spn: SourceOverride(component=self.partner, new=True),
+ },
+ policy.calculateSourceOverrides(
+ {existing_spn: SourceOverride(component=self.non_free),
+ universe_spn: SourceOverride(component=self.universe),
+ }))
+
+ def test_partner_binaries(self):
+ partner = self.factory.makeArchive(
+ distribution=self.series.distribution,
+ purpose=ArchivePurpose.PARTNER)
+ existing_bpn = self.factory.makeBinaryPackageName()
+ other_bpn = self.factory.makeBinaryPackageName()
+ amd64_override, armhf_override = self.prepareBinaries(
+ partner, existing_bpn)
+ policy = partner.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ # Packages with an existing publication in any pocket of any DAS
+ # with a matching archtag, or nominatedarchindep if the archtag
+ # is None, return that publication's overrides. Otherwise
+ # they're new, with a default component of partner.
+ self.assertEqual(
+ {(existing_bpn, 'amd64'): amd64_override,
+ (existing_bpn, None): amd64_override,
+ (existing_bpn, 'i386'): armhf_override,
+ (other_bpn, 'amd64'): BinaryOverride(
+ component=self.partner, new=True),
+ },
+ policy.calculateBinaryOverrides(
+ {(existing_bpn, 'amd64'): BinaryOverride(component=self.main),
+ (existing_bpn, None): BinaryOverride(component=self.main),
+ (existing_bpn, 'i386'): BinaryOverride(component=self.main),
+ (other_bpn, 'amd64'): BinaryOverride(component=self.non_free),
+ }))
+
+ def test_copy_sources(self):
+ copy = self.factory.makeArchive(
+ distribution=self.series.distribution, purpose=ArchivePurpose.COPY)
+ spph = self.factory.makeSourcePackagePublishingHistory(
+ archive=self.series.main_archive, distroseries=self.series,
+ pocket=PackagePublishingPocket.UPDATES)
+ policy = copy.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ existing_spn = spph.sourcepackagerelease.sourcepackagename
+ main_spn = self.factory.makeSourcePackageName()
+ non_free_spn = self.factory.makeSourcePackageName()
+
+ # Packages with an existing publication in any pocket in the
+ # copy archive's distribution's primary archive return that
+ # publication's overrides. Otherwise they're new, with a default
+ # component mapped from their original component.
+ self.assertEqual(
+ {existing_spn: SourceOverride(
+ component=spph.component, section=spph.section,
+ version=spph.sourcepackagerelease.version, new=False),
+ main_spn: SourceOverride(component=self.universe, new=True),
+ non_free_spn: SourceOverride(component=self.multiverse, new=True),
+ },
+ policy.calculateSourceOverrides(
+ {existing_spn: SourceOverride(component=self.non_free),
+ main_spn: SourceOverride(component=self.main),
+ non_free_spn: SourceOverride(component=self.non_free),
+ }))
+
+ def test_copy_binaries(self):
+ existing_bpn = self.factory.makeBinaryPackageName()
+ other_bpn = self.factory.makeBinaryPackageName()
+ amd64_override, armhf_override = self.prepareBinaries(
+ self.series.main_archive, existing_bpn)
+ copy = self.factory.makeArchive(
+ distribution=self.series.distribution, purpose=ArchivePurpose.COPY)
+ policy = copy.getOverridePolicy(
+ self.series, PackagePublishingPocket.RELEASE)
+
+ # Packages with an existing publication in any pocket of any DAS
+ # with a matching archtag, or nominatedarchindep if the archtag
+ # is None, in the copy archive's distribution's main archive
+ # return that publication's overrides. Otherwise they're new,
+ # with a default component mapped from their original component.
+ self.assertEqual(
+ {(existing_bpn, 'amd64'): amd64_override,
+ (existing_bpn, None): amd64_override,
+ (existing_bpn, 'i386'): armhf_override,
+ (other_bpn, 'amd64'): BinaryOverride(
+ component=self.universe, new=True),
+ },
+ policy.calculateBinaryOverrides(
+ {(existing_bpn, 'amd64'): BinaryOverride(component=self.main),
+ (existing_bpn, None): BinaryOverride(component=self.main),
+ (existing_bpn, 'i386'): BinaryOverride(component=self.main),
+ (other_bpn, 'amd64'): BinaryOverride(component=self.main),
+ }))
Follow ups