Merge lp:~wgrant/launchpad/archive-debug-archive into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: not available
Proposed branch: lp:~wgrant/launchpad/archive-debug-archive
Merge into: lp:launchpad
Diff against target: 151 lines
4 files modified
lib/lp/soyuz/interfaces/archive.py (+3/-0)
lib/lp/soyuz/model/archive.py (+9/-0)
lib/lp/soyuz/model/queue.py (+6/-10)
lib/lp/soyuz/tests/test_archive.py (+53/-1)
To merge this branch: bzr merge lp:~wgrant/launchpad/archive-debug-archive
Reviewer Review Type Date Requested Status
Eleanor Berger (community) Approve
Review via email: mp+13949@code.launchpad.net
To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

= Summary =

For my ddebs-in-soyuz work, I need to be able to identify an archive's corresponding debug archive in many places. This is currently only done in lp.soyuz.model.queue.

== Proposed fix ==

Factor the calculation out into a property: IArchive.debug_archive.

== Pre-implementation notes ==

None.

== Implementation details ==

Nothing special.

== Tests ==

Added new tests in lp.soyuz.tests.test_archive.TestCorrespondingDebugArchive, for each possible situation.

bin/test -vvt TestCorrespondingDebugArchive

== Demo and Q/A ==

This is purely a refactor; there is no functional change.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/soyuz/interfaces/archive.py
  lib/lp/soyuz/model/archive.py
  lib/lp/soyuz/model/queue.py
  lib/lp/soyuz/tests/test_archive.py

== Pylint notices ==

lib/lp/soyuz/interfaces/archive.py
    40: [F0401] Unable to import 'lazr.enum' (No module named enum)
    53: [F0401] Unable to import 'lazr.restful.declarations' (No module named restful)
    59: [F0401] Unable to import 'lazr.restful.fields' (No module named restful)

lib/lp/soyuz/model/archive.py
    14: [F0401] Unable to import 'lazr.lifecycle.event' (No module named lifecycle)

lib/lp/soyuz/model/queue.py
    547: [C0301] Line too long (93/78)
    562: [C0301] Line too long (80/78)

Revision history for this message
Eleanor Berger (intellectronica) wrote :

All good. Thanks for working on this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/interfaces/archive.py'
2--- lib/lp/soyuz/interfaces/archive.py 2009-10-12 17:10:54 +0000
3+++ lib/lp/soyuz/interfaces/archive.py 2009-10-26 12:00:37 +0000
4@@ -196,6 +196,9 @@
5 "The expanded list of archive dependencies. It includes the implicit "
6 "PRIMARY archive dependency for PPAs.")
7
8+ debug_archive = Attribute(
9+ "The archive into which debug binaries should be uploaded.")
10+
11 archive_url = Attribute("External archive URL.")
12
13 is_ppa = Attribute("True if this archive is a PPA.")
14
15=== modified file 'lib/lp/soyuz/model/archive.py'
16--- lib/lp/soyuz/model/archive.py 2009-10-13 16:50:00 +0000
17+++ lib/lp/soyuz/model/archive.py 2009-10-26 12:00:37 +0000
18@@ -254,6 +254,15 @@
19 return archives
20
21 @property
22+ def debug_archive(self):
23+ """See `IArchive`."""
24+ if self.purpose == ArchivePurpose.PRIMARY:
25+ return getUtility(IArchiveSet).getByDistroPurpose(
26+ self.distribution, ArchivePurpose.DEBUG)
27+ else:
28+ return self
29+
30+ @property
31 def archive_url(self):
32 """See `IArchive`."""
33 archive_postfixes = {
34
35=== modified file 'lib/lp/soyuz/model/queue.py'
36--- lib/lp/soyuz/model/queue.py 2009-10-15 13:17:49 +0000
37+++ lib/lp/soyuz/model/queue.py 2009-10-26 12:00:37 +0000
38@@ -45,8 +45,6 @@
39 from canonical.database.sqlbase import SQLBase, sqlvalues
40 from canonical.encoding import guess as guess_encoding, ascii_smash
41 from canonical.launchpad.helpers import get_email_template
42-from lp.soyuz.interfaces.archive import (
43- ArchivePurpose, IArchiveSet)
44 from lp.soyuz.interfaces.binarypackagerelease import (
45 BinaryPackageFormat)
46 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
47@@ -56,7 +54,7 @@
48 from lp.registry.interfaces.pocket import (
49 PackagePublishingPocket, pocketsuffix)
50 from lp.soyuz.interfaces.publishing import (
51- IPublishingSet, ISourcePackagePublishingHistory, PackagePublishingStatus)
52+ IPublishingSet, ISourcePackagePublishingHistory)
53 from lp.soyuz.interfaces.queue import (
54 IPackageUpload, IPackageUploadBuild, IPackageUploadCustom,
55 IPackageUploadQueue, IPackageUploadSource, IPackageUploadSet,
56@@ -1371,15 +1369,13 @@
57 archive = self.packageupload.archive
58 # DDEBs targeted to the PRIMARY archive are published in the
59 # corresponding DEBUG archive.
60- if (archive.purpose == ArchivePurpose.PRIMARY and
61- binary.binpackageformat == BinaryPackageFormat.DDEB):
62- distribution = self.packageupload.distroseries.distribution
63- archive = getUtility(IArchiveSet).getByDistroPurpose(
64- distribution, ArchivePurpose.DEBUG)
65- if archive is None:
66+ if binary.binpackageformat == BinaryPackageFormat.DDEB:
67+ debug_archive = archive.debug_archive
68+ if debug_archive is None:
69 raise QueueInconsistentStateError(
70 "Could not find the corresponding DEBUG archive "
71- "for %s" % (distribution.title))
72+ "for %s" % (archive.displayname))
73+ archive = debug_archive
74
75 for each_target_dar in target_dars:
76 bpph = getUtility(IPublishingSet).newBinaryPublication(
77
78=== modified file 'lib/lp/soyuz/tests/test_archive.py'
79--- lib/lp/soyuz/tests/test_archive.py 2009-09-30 15:04:46 +0000
80+++ lib/lp/soyuz/tests/test_archive.py 2009-10-26 12:00:37 +0000
81@@ -8,11 +8,13 @@
82 import unittest
83
84 from zope.component import getUtility
85+from zope.security.proxy import removeSecurityProxy
86
87 from canonical.testing import LaunchpadZopelessLayer
88
89 from lp.registry.interfaces.distribution import IDistributionSet
90-from lp.soyuz.interfaces.archive import IArchiveSet
91+from lp.registry.interfaces.person import IPersonSet
92+from lp.soyuz.interfaces.archive import IArchiveSet, ArchivePurpose
93 from lp.soyuz.interfaces.binarypackagerelease import BinaryPackageFormat
94 from lp.soyuz.interfaces.build import BuildStatus
95 from lp.soyuz.interfaces.publishing import PackagePublishingStatus
96@@ -330,5 +332,55 @@
97 self.failUnlessEqual(
98 self.sourcepackagereleases[0], result[0])
99
100+class TestCorrespondingDebugArchive(TestCaseWithFactory):
101+
102+ layer = LaunchpadZopelessLayer
103+
104+ def setUp(self):
105+ super(TestCorrespondingDebugArchive, self).setUp()
106+
107+ self.ubuntutest = getUtility(IDistributionSet)['ubuntutest']
108+
109+ # Create a debug archive, as there isn't one in the sample data.
110+ self.debug_archive = getUtility(IArchiveSet).new(
111+ purpose=ArchivePurpose.DEBUG,
112+ distribution=self.ubuntutest,
113+ owner=self.ubuntutest.owner)
114+
115+ # Retrieve sample data archives of each type.
116+ self.primary_archive = getUtility(IArchiveSet).getByDistroPurpose(
117+ self.ubuntutest, ArchivePurpose.PRIMARY)
118+ self.partner_archive = getUtility(IArchiveSet).getByDistroPurpose(
119+ self.ubuntutest, ArchivePurpose.PARTNER)
120+ self.copy_archive = getUtility(IArchiveSet).getByDistroPurpose(
121+ self.ubuntutest, ArchivePurpose.PARTNER)
122+ self.ppa = getUtility(IPersonSet).getByName('cprov').archive
123+
124+ def testPrimaryDebugArchiveIsDebug(self):
125+ self.assertEquals(
126+ self.primary_archive.debug_archive, self.debug_archive)
127+
128+ def testPartnerDebugArchiveIsSelf(self):
129+ self.assertEquals(
130+ self.partner_archive.debug_archive, self.partner_archive)
131+
132+ def testCopyDebugArchiveIsSelf(self):
133+ self.assertEquals(
134+ self.copy_archive.debug_archive, self.copy_archive)
135+
136+ def testDebugDebugArchiveIsSelf(self):
137+ self.assertEquals(
138+ self.debug_archive.debug_archive, self.debug_archive)
139+
140+ def testPPADebugArchiveIsSelf(self):
141+ self.assertEquals(self.ppa.debug_archive, self.ppa)
142+
143+ def testMissingPrimaryDebugArchiveIsNone(self):
144+ # Turn the DEBUG archive into a COPY archive to hide it.
145+ removeSecurityProxy(self.debug_archive).purpose = ArchivePurpose.COPY
146+
147+ self.assertIs(
148+ self.primary_archive.debug_archive, None)
149+
150 def test_suite():
151 return unittest.TestLoader().loadTestsFromName(__name__)