Merge lp:~stevenk/launchpad/populate-spph-pu into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 15303
Proposed branch: lp:~stevenk/launchpad/populate-spph-pu
Merge into: lp:launchpad
Diff against target: 307 lines (+75/-17)
9 files modified
lib/lp/_schema_circular_imports.py (+3/-1)
lib/lp/soyuz/interfaces/publishing.py (+15/-1)
lib/lp/soyuz/model/packagecopyjob.py (+1/-1)
lib/lp/soyuz/model/publishing.py (+9/-4)
lib/lp/soyuz/model/queue.py (+3/-2)
lib/lp/soyuz/scripts/packagecopier.py (+8/-5)
lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt (+1/-0)
lib/lp/soyuz/tests/test_packagecopyjob.py (+23/-1)
lib/lp/soyuz/tests/test_packageupload.py (+12/-2)
To merge this branch: bzr merge lp:~stevenk/launchpad/populate-spph-pu
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+105601@code.launchpad.net

Commit message

When calling newSourcePublication() from IPackageUpload.realiseUpload() or do_copy() via means of PCJs, set packageupload.

Description of the change

When calling newSourcePublication() from IPackageUpload.realiseUpload(), pass in the new packageupload parameter, so that we can grab the packageupload easily after the fact.
This will also set packageupload for publications that are copied via PCJs.

This can't land until 15-0 is applied on prod and merged into devel, but I thought I'd get it reviewed first.

I have drive-by'd a text fix in ISPPH's interface (and screwed up what diff thinks what was added, sigh), as well as fixing a strange in-test import.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

I think 'pu' is ambiguous. Is there a better name like 'package_upload' that will make this code easier to read?

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/_schema_circular_imports.py'
2--- lib/lp/_schema_circular_imports.py 2012-05-01 10:20:07 +0000
3+++ lib/lp/_schema_circular_imports.py 2012-05-24 22:36:21 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Update the interface schema values due to circular imports.
10@@ -370,6 +370,8 @@
11 patch_reference_property(
12 ISourcePackagePublishingHistory, 'ancestor',
13 ISourcePackagePublishingHistory)
14+patch_reference_property(
15+ ISourcePackagePublishingHistory, 'packageupload', IPackageUpload)
16
17 # IArchive apocalypse.
18 patch_reference_property(IArchive, 'distribution', IDistribution)
19
20=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
21--- lib/lp/soyuz/interfaces/publishing.py 2012-04-16 15:48:58 +0000
22+++ lib/lp/soyuz/interfaces/publishing.py 2012-05-24 22:36:21 +0000
23@@ -499,7 +499,17 @@
24 Reference(
25 IPerson,
26 title=_('Publication sponsor'),
27- description=_('The IPerson who sponsored the creation of'
28+ description=_('The IPerson who sponsored the creation of '
29+ 'this publication.'),
30+ required=False, readonly=True
31+ ))
32+
33+ packageupload = exported(
34+ Reference(
35+ # Really IPackageUpload, fixed in _schema_circular_imports.
36+ Interface,
37+ title=_('Package upload'),
38+ description=_('The Package Upload that caused the creation of '
39 'this publication.'),
40 required=False, readonly=True
41 ))
42@@ -637,6 +647,8 @@
43 `IOverridePolicy`.
44 :param creator: the `IPerson` to use as the creator for the copied
45 publication.
46+ :param packageupload: The `IPackageUpload` that caused this
47+ publication to be created.
48
49 :return: a `ISourcePackagePublishingHistory` record representing the
50 source in the destination location.
51@@ -1023,6 +1035,8 @@
52 sourcepackagerelease's creator will be used.
53 :param sponsor: An optional `IPerson` indicating the sponsor of this
54 publication.
55+ :param packageupload: An optional `IPackageUpload` that caused this
56+ publication to be created.
57
58 datecreated will be UTC_NOW.
59 status will be PackagePublishingStatus.PENDING
60
61=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
62--- lib/lp/soyuz/model/packagecopyjob.py 2012-04-25 20:40:04 +0000
63+++ lib/lp/soyuz/model/packagecopyjob.py 2012-05-24 22:36:21 +0000
64@@ -552,7 +552,7 @@
65 include_binaries=self.include_binaries, check_permissions=True,
66 person=self.requester, overrides=[override],
67 send_email=send_email, announce_from_person=self.requester,
68- sponsored=self.sponsored)
69+ sponsored=self.sponsored, packageupload=pu)
70
71 # Add a PackageDiff for this new upload if it has ancestry.
72 if ancestry is not None:
73
74=== modified file 'lib/lp/soyuz/model/publishing.py'
75--- lib/lp/soyuz/model/publishing.py 2012-02-24 03:47:44 +0000
76+++ lib/lp/soyuz/model/publishing.py 2012-05-24 22:36:21 +0000
77@@ -457,6 +457,8 @@
78 sponsor = ForeignKey(
79 dbName='sponsor', foreignKey='Person',
80 storm_validator=validate_public_person, notNull=False, default=None)
81+ packageupload = ForeignKey(
82+ dbName='packageupload', foreignKey='PackageUpload', default=None)
83
84 @property
85 def package_creator(self):
86@@ -817,7 +819,8 @@
87 archive=current.archive)
88
89 def copyTo(self, distroseries, pocket, archive, override=None,
90- create_dsd_job=True, creator=None, sponsor=None):
91+ create_dsd_job=True, creator=None, sponsor=None,
92+ packageupload=None):
93 """See `ISourcePackagePublishingHistory`."""
94 component = self.component
95 section = self.section
96@@ -836,7 +839,8 @@
97 ancestor=self,
98 create_dsd_job=create_dsd_job,
99 creator=creator,
100- sponsor=sponsor)
101+ sponsor=sponsor,
102+ packageupload=packageupload)
103
104 def getStatusSummaryForBuilds(self):
105 """See `ISourcePackagePublishingHistory`."""
106@@ -1502,7 +1506,7 @@
107 def newSourcePublication(self, archive, sourcepackagerelease,
108 distroseries, component, section, pocket,
109 ancestor=None, create_dsd_job=True,
110- creator=None, sponsor=None):
111+ creator=None, sponsor=None, packageupload=None):
112 """See `IPublishingSet`."""
113 # Avoid circular import.
114 from lp.registry.model.distributionsourcepackage import (
115@@ -1520,7 +1524,8 @@
116 datecreated=UTC_NOW,
117 ancestor=ancestor,
118 creator=creator,
119- sponsor=sponsor)
120+ sponsor=sponsor,
121+ packageupload=packageupload)
122 DistributionSourcePackage.ensure(pub)
123
124 if create_dsd_job:
125
126=== modified file 'lib/lp/soyuz/model/queue.py'
127--- lib/lp/soyuz/model/queue.py 2012-01-05 14:05:10 +0000
128+++ lib/lp/soyuz/model/queue.py 2012-05-24 22:36:21 +0000
129@@ -1,4 +1,4 @@
130-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
131+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
132 # GNU Affero General Public License version 3 (see the file LICENSE).
133
134 # pylint: disable-msg=E0611,W0212
135@@ -1215,7 +1215,8 @@
136 distroseries=self.packageupload.distroseries,
137 component=self.sourcepackagerelease.component,
138 section=self.sourcepackagerelease.section,
139- pocket=self.packageupload.pocket)
140+ pocket=self.packageupload.pocket,
141+ packageupload=self.packageupload)
142
143
144 class PackageUploadCustom(SQLBase):
145
146=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
147--- lib/lp/soyuz/scripts/packagecopier.py 2012-02-21 22:46:28 +0000
148+++ lib/lp/soyuz/scripts/packagecopier.py 2012-05-24 22:36:21 +0000
149@@ -533,7 +533,7 @@
150 allow_delayed_copies=True, person=None, check_permissions=True,
151 overrides=None, send_email=False, strict_binaries=True,
152 close_bugs=True, create_dsd_job=True, announce_from_person=None,
153- sponsored=None):
154+ sponsored=None, packageupload=None):
155 """Perform the complete copy of the given sources incrementally.
156
157 Verifies if each copy can be performed using `CopyChecker` and
158@@ -579,7 +579,8 @@
159 being sponsored for this copy. May be None, but if present will
160 affect the "From:" address on notifications and the creator of the
161 publishing record will be set to this person.
162-
163+ :param packageupload: The `IPackageUpload` that caused this publication
164+ to be created.
165
166 :raise CannotCopy when one or more copies were not allowed. The error
167 will contain the reason why each copy was denied.
168@@ -661,7 +662,7 @@
169 include_binaries, override, close_bugs=close_bugs,
170 create_dsd_job=create_dsd_job,
171 close_bugs_since_version=old_version, creator=creator,
172- sponsor=sponsor)
173+ sponsor=sponsor, packageupload=packageupload)
174 if send_email:
175 notify(
176 person, source.sourcepackagerelease, [], [], archive,
177@@ -678,7 +679,7 @@
178 def _do_direct_copy(source, archive, series, pocket, include_binaries,
179 override=None, close_bugs=True, create_dsd_job=True,
180 close_bugs_since_version=None, creator=None,
181- sponsor=None):
182+ sponsor=None, packageupload=None):
183 """Copy publishing records to another location.
184
185 Copy each item of the given list of `SourcePackagePublishingHistory`
186@@ -706,6 +707,8 @@
187 for bugs to close. See `close_bugs_for_sourcepackagerelease`.
188 :param creator: the requester `IPerson`.
189 :param sponsor: the sponsor `IPerson`, if this copy is being sponsored.
190+ :param packageupload: The `IPackageUpload` that caused this publication
191+ to be created.
192
193 :return: a list of `ISourcePackagePublishingHistory` and
194 `BinaryPackagePublishingHistory` corresponding to the copied
195@@ -736,7 +739,7 @@
196 override = overrides[0]
197 source_copy = source.copyTo(
198 series, pocket, archive, override, create_dsd_job=create_dsd_job,
199- creator=creator, sponsor=sponsor)
200+ creator=creator, sponsor=sponsor, packageupload=packageupload)
201 if close_bugs:
202 close_bugs_for_sourcepublication(
203 source_copy, close_bugs_since_version)
204
205=== modified file 'lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt'
206--- lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt 2012-01-31 01:19:45 +0000
207+++ lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt 2012-05-24 22:36:21 +0000
208@@ -129,6 +129,7 @@
209 package_creator_link: u'http://.../beta/~name16'
210 package_maintainer_link: u'http://.../beta/~name16'
211 package_signer_link: u'http://.../beta/~name16'
212+ packageupload_link: None
213 pocket: u'Release'
214 removal_comment: None
215 removed_by_link: None
216
217=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
218--- lib/lp/soyuz/tests/test_packagecopyjob.py 2012-04-26 15:25:13 +0000
219+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2012-05-24 22:36:21 +0000
220@@ -355,6 +355,24 @@
221
222 self.assertEqual(1, naked_job.reportFailure.call_count)
223
224+ def test_copy_with_packageupload(self):
225+ # When a PCJ with a PackageUpload gets processed, the resulting
226+ # publication is linked to the PackageUpload.
227+ spn = self.factory.getUniqueString()
228+ pcj = self.createCopyJob(spn, 'universe', 'web', '1.0-1', True)
229+ pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
230+ [pcj.id]).one()
231+ pu.acceptFromQueue()
232+ owner = pcj.target_archive.owner
233+ switch_dbuser("launchpad_main")
234+ with person_logged_in(owner):
235+ pcj.target_archive.newComponentUploader(
236+ pcj.requester, 'universe')
237+ self.runJob(pcj)
238+ new_publication = pcj.target_archive.getPublishedSources(
239+ name=spn).one()
240+ self.assertEqual(new_publication.packageupload, pu)
241+
242 def test_target_ppa_non_release_pocket(self):
243 # When copying to a PPA archive the target must be the release pocket.
244 distroseries = self.factory.makeDistroSeries()
245@@ -812,7 +830,8 @@
246 # UnknownOverridePolicy policy.
247 self.assertEqual('universe', pcj.metadata['component_override'])
248
249- def createCopyJob(self, sourcename, component, section, version):
250+ def createCopyJob(self, sourcename, component, section, version,
251+ return_job=False):
252 # Helper method to create a package copy job for a package with
253 # the given sourcename, component, section and version.
254 publisher = SoyuzTestPublisher()
255@@ -846,6 +865,9 @@
256
257 # Run the job so it gains a PackageUpload.
258 self.assertRaises(SuspendJobException, self.runJob, job)
259+ job.suspend()
260+ if return_job:
261+ return job
262 pcj = removeSecurityProxy(job).context
263 return pcj
264
265
266=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
267--- lib/lp/soyuz/tests/test_packageupload.py 2012-01-20 15:42:44 +0000
268+++ lib/lp/soyuz/tests/test_packageupload.py 2012-05-24 22:36:21 +0000
269@@ -1,4 +1,4 @@
270-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
271+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
272 # GNU Affero General Public License version 3 (see the file LICENSE).
273
274 """Test Build features."""
275@@ -35,6 +35,7 @@
276 QueueInconsistentStateError,
277 )
278 from lp.soyuz.interfaces.section import ISectionSet
279+from lp.soyuz.model.packagecopyjob import IPackageCopyJobSource
280 from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
281 from lp.testing import TestCaseWithFactory
282 from lp.testing.dbuser import switch_dbuser
283@@ -363,6 +364,16 @@
284 self.assertEqual(spr.sourcepackagename.name, upload.package_name)
285 self.assertEqual(spr.version, upload.package_version)
286
287+ def test_publish_sets_packageupload(self):
288+ # Publishing a PackageUploadSource will pass itself to the source
289+ # publication that was created.
290+ upload = self.factory.makeSourcePackageUpload()
291+ self.factory.makeComponentSelection(
292+ upload.distroseries, upload.sourcepackagerelease.component)
293+ upload.setAccepted()
294+ [spph] = upload.realiseUpload()
295+ self.assertEqual(spph.packageupload, upload)
296+
297
298 class TestPackageUploadWithPackageCopyJob(TestCaseWithFactory):
299
300@@ -371,7 +382,6 @@
301
302 def makeUploadWithPackageCopyJob(self, sourcepackagename=None):
303 """Create a `PackageUpload` plus attached `PlainPackageCopyJob`."""
304- from lp.soyuz.model.packagecopyjob import IPackageCopyJobSource
305 upload = self.factory.makeCopyJobPackageUpload(
306 sourcepackagename=sourcepackagename)
307 return upload, getUtility(IPackageCopyJobSource).wrap(