Merge lp:~wgrant/launchpad/dont-overrideFromAncestry into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16609
Proposed branch: lp:~wgrant/launchpad/dont-overrideFromAncestry
Merge into: lp:launchpad
Diff against target: 573 lines (+11/-461)
5 files modified
lib/lp/soyuz/doc/publishing.txt (+0/-114)
lib/lp/soyuz/interfaces/publishing.py (+0/-56)
lib/lp/soyuz/model/publishing.py (+0/-86)
lib/lp/soyuz/scripts/packagecopier.py (+11/-9)
lib/lp/soyuz/tests/test_publishing.py (+0/-196)
To merge this branch: bzr merge lp:~wgrant/launchpad/dont-overrideFromAncestry
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+162933@code.launchpad.net

Commit message

Drop overrideFromAncestry, getNearestAncestor, and getAncestry.

Description of the change

Stop calling overrideFromAncestry and getNearestAncestor in do_copy. overrideFromAncestry is redundant with the modern overrides in _do_direct_copy, and getNearestAncestor can be replaced with getPublishedSources. Those two methods and getAncestry can then go away, saving a lot of code.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
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/soyuz/doc/publishing.txt'
2--- lib/lp/soyuz/doc/publishing.txt 2013-03-12 01:07:49 +0000
3+++ lib/lp/soyuz/doc/publishing.txt 2013-05-08 06:29:28 +0000
4@@ -1756,117 +1756,3 @@
5 ... [firefox_source_pub.id, foo_pub.id],
6 ... archive=ubuntu.main_archive)
7 >>> print_build_summaries(build_summaries)
8-
9-
10-IPublishing ancestry lookup and override
11-========================================
12-
13-`IPublishing` is implemented by both kinds of package publications we
14-have `SourcePackagePublishingHistory` and
15-`BinaryPackagePublishingHistory`.
16-
17-This interface allows, among other features, easy ancestry lookup and
18-pre-publication overrides via:
19-
20- * getAncestry
21- * overrideFromAncestry
22-
23- # Setup a publishing scenario for illustrating ancestry lookup.
24- >>> ubuntu_source_ancestry = test_publisher.getPubSource(
25- ... sourcename='testing', version='1.0',
26- ... architecturehintlist='i386', component='multiverse',
27- ... status=PackagePublishingStatus.PUBLISHED)
28- >>> ubuntu_binary_ancestry = test_publisher.getPubBinaries(
29- ... binaryname='testing-bin', pub_source=ubuntu_source_ancestry,
30- ... status=PackagePublishingStatus.PUBLISHED)[0]
31- >>> ppa_source_ancestry = test_publisher.getPubSource(
32- ... sourcename='testing', version='1.1', component='main',
33- ... architecturehintlist='i386', archive=cprov.archive,
34- ... status=PackagePublishingStatus.PUBLISHED)
35- >>> ppa_binary_ancestry = test_publisher.getPubBinaries(
36- ... binaryname='testing-bin', pub_source=ppa_source_ancestry,
37- ... status=PackagePublishingStatus.PUBLISHED)[0]
38- >>> test_source = test_publisher.getPubSource(
39- ... sourcename='testing', version='2.0', component='universe',
40- ... architecturehintlist='i386')
41- >>> test_binary = test_publisher.getPubBinaries(
42- ... binaryname='testing-bin', pub_source=test_source)[0]
43-
44-We will create a helper function to inspect ancestries. It simply pass
45-any given keyword argument to 'test_source' and 'test_binary'
46-getAncestry() method.
47-
48- >>> def print_ancestries(**kwargs):
49- ... def print_displayname(pub):
50- ... if pub is not None:
51- ... print pub.displayname
52- ... else:
53- ... print pub
54- ... print_displayname(test_source.getAncestry(**kwargs))
55- ... print_displayname(test_binary.getAncestry(**kwargs))
56-
57-The 'test_source' and 'test_binary' ancestries in the same context,
58-i.e. ubuntu primary archive.
59-
60- >>> print_ancestries()
61- testing 1.0 in breezy-autotest
62- testing-bin 1.0 in breezy-autotest i386
63-
64-Call sites may quickly adjust the context where the ancestries are
65-looked up.
66-
67- >>> print_ancestries(archive=cprov.archive)
68- testing 1.1 in breezy-autotest
69- testing-bin 1.1 in breezy-autotest i386
70-
71- >>> print_ancestries(distroseries=test_source.distroseries)
72- testing 1.0 in breezy-autotest
73- testing-bin 1.0 in breezy-autotest i386
74-
75- >>> print_ancestries(pocket=test_source.pocket)
76- testing 1.0 in breezy-autotest
77- testing-bin 1.0 in breezy-autotest i386
78-
79-The default 'status' filter is set to PUBLISHED ancestries, however
80-call sites may decide differently.
81-
82- >>> print_ancestries(status=PackagePublishingStatus.PUBLISHED)
83- testing 1.0 in breezy-autotest
84- testing-bin 1.0 in breezy-autotest i386
85-
86-On the lack of ancestry, None is returned.
87-
88- >>> from lp.soyuz.interfaces.publishing import (
89- ... inactive_publishing_status)
90- >>> print_ancestries(status=inactive_publishing_status)
91- None
92- None
93-
94-`overrideFromAncestry` operates directly on top of the default
95-behavior of `getAncestry`. It looks up the most recent ancestry for a
96-publication and override it in place. If there is no previous publication
97-then the package's component is used.
98-
99- >>> print test_source.component.name
100- universe
101-
102- >>> test_source.overrideFromAncestry()
103- >>> print test_source.component.name
104- multiverse
105-
106-It works in the same way for binaries.
107-
108- >>> multiverse = getUtility(IComponentSet)['multiverse']
109- >>> test_binary.binarypackagerelease.component = multiverse
110-
111- >>> print test_binary.component.name
112- universe
113-
114- >>> copied_binary = test_binary.copyTo(
115- ... hoary_test, test_source.pocket, archive=test_binary.archive)[0]
116- >>> print copied_binary.component.name
117- universe
118-
119- >>> copied_binary.overrideFromAncestry()
120- >>> print copied_binary.component.name
121- multiverse
122
123=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
124--- lib/lp/soyuz/interfaces/publishing.py 2013-05-03 00:07:30 +0000
125+++ lib/lp/soyuz/interfaces/publishing.py 2013-05-08 06:29:28 +0000
126@@ -221,34 +221,6 @@
127 `IBinaryPackagePublishingHistory`.
128 """
129
130- def getAncestry(archive=None, distroseries=None, pocket=None,
131- status=None):
132- """Return the most recent publication of the same source or binary.
133-
134- If a suitable ancestry could not be found, None is returned.
135-
136- It optionally accepts parameters for adjusting the publishing
137- context, if not given they default to the current context.
138-
139- :param archive: optional `IArchive`, defaults to the context archive.
140- :param distroseries: optional `IDistroSeries`, defaults to the
141- context distroseries.
142- :param pocket: optional `PackagePublishingPocket`, defaults to any
143- pocket.
144- :param status: optional `PackagePublishingStatus` or a collection of
145- them, defaults to `PackagePublishingStatus.PUBLISHED`
146- """
147-
148- def overrideFromAncestry():
149- """Set the right published component from publishing ancestry.
150-
151- Start with the publishing records and fall back to the original
152- uploaded package if necessary.
153-
154- :raise: AssertionError if the context publishing record is not in
155- PENDING status.
156- """
157-
158
159 class IPublishingEdit(Interface):
160 """Base interface for writeable Publishing classes."""
161@@ -1343,34 +1315,6 @@
162 the source_package_pub, allowing the use of the cached results.
163 """
164
165- def getNearestAncestor(
166- package_name, archive, distroseries, pocket=None, status=None,
167- binary=False):
168- """Return the ancestor of the given parkage in a particular archive.
169-
170- :param package_name: The package name for which we are checking for
171- an ancestor.
172- :type package_name: ``string``
173- :param archive: The archive in which we are looking for an ancestor.
174- :type archive: `IArchive`
175- :param distroseries: The particular series in which we are looking for
176- an ancestor.
177- :type distroseries: `IDistroSeries`
178- :param pocket: An optional pocket to restrict the search.
179- :type pocket: `PackagePublishingPocket`.
180- :param status: An optional status defaulting to PUBLISHED if not
181- provided.
182- :type status: `PackagePublishingStatus`
183- :param binary: An optional argument to look for a binary ancestor
184- instead of the default source.
185- :type binary: ``Boolean``
186-
187- :return: The most recent publishing history for the given
188- arguments.
189- :rtype: `ISourcePackagePublishingHistory` or
190- `IBinaryPackagePublishingHistory` or None.
191- """
192-
193 active_publishing_status = (
194 PackagePublishingStatus.PENDING,
195 PackagePublishingStatus.PUBLISHED,
196
197=== modified file 'lib/lp/soyuz/model/publishing.py'
198--- lib/lp/soyuz/model/publishing.py 2013-05-04 00:37:58 +0000
199+++ lib/lp/soyuz/model/publishing.py 2013-05-08 06:29:28 +0000
200@@ -847,41 +847,6 @@
201 return getUtility(
202 IPublishingSet).getBuildStatusSummaryForSourcePublication(self)
203
204- def getAncestry(self, archive=None, distroseries=None, pocket=None,
205- status=None):
206- """See `ISourcePackagePublishingHistory`."""
207- if archive is None:
208- archive = self.archive
209- if distroseries is None:
210- distroseries = self.distroseries
211-
212- return getUtility(IPublishingSet).getNearestAncestor(
213- self.source_package_name, archive, distroseries, pocket,
214- status)
215-
216- def overrideFromAncestry(self):
217- """See `ISourcePackagePublishingHistory`."""
218- # We don't want to use changeOverride here because it creates a
219- # new publishing record. This code can be only executed for pending
220- # publishing records.
221- assert self.status == PackagePublishingStatus.PENDING, (
222- "Cannot override published records.")
223-
224- # If there is published ancestry, use its component, otherwise
225- # use the original upload component. Since PPAs only use main,
226- # we don't need to check the ancestry.
227- if not self.archive.is_ppa:
228- ancestry = self.getAncestry()
229- if ancestry is not None:
230- component = ancestry.component
231- else:
232- component = self.sourcepackagerelease.component
233-
234- self.component = component
235-
236- assert self.component in (
237- self.archive.getComponentsForSeries(self.distroseries))
238-
239 def sourceFileUrls(self):
240 """See `ISourcePackagePublishingHistory`."""
241 source_urls = proxied_urls(
242@@ -1280,36 +1245,6 @@
243 return getUtility(IPublishingSet).copyBinariesTo(
244 [self], distroseries, pocket, archive)
245
246- def getAncestry(self, archive=None, distroseries=None, pocket=None,
247- status=None):
248- """See `IBinaryPackagePublishingHistory`."""
249- if archive is None:
250- archive = self.archive
251- if distroseries is None:
252- distroseries = self.distroarchseries.distroseries
253-
254- return getUtility(IPublishingSet).getNearestAncestor(
255- self.binary_package_name, archive, distroseries, pocket,
256- status, binary=True)
257-
258- def overrideFromAncestry(self):
259- """See `IBinaryPackagePublishingHistory`."""
260- # We don't want to use changeOverride here because it creates a
261- # new publishing record. This code can be only executed for pending
262- # publishing records.
263- assert self.status == PackagePublishingStatus.PENDING, (
264- "Cannot override published records.")
265-
266- # If there is an ancestry, use its component, otherwise use the
267- # original upload component.
268- ancestry = self.getAncestry()
269- if ancestry is not None:
270- component = ancestry.component
271- else:
272- component = self.binarypackagerelease.component
273-
274- self.component = component
275-
276 def _getDownloadCountClauses(self, start_date=None, end_date=None):
277 clauses = [
278 BinaryPackageReleaseDownloadCount.archive == self.archive,
279@@ -2109,27 +2044,6 @@
280 BinaryPackagePublishingHistory, bpph_ids, removed_by,
281 removal_comment=removal_comment)
282
283- def getNearestAncestor(
284- self, package_name, archive, distroseries, pocket=None,
285- status=None, binary=False):
286- """See `IPublishingSet`."""
287- if status is None:
288- status = PackagePublishingStatus.PUBLISHED
289-
290- if binary:
291- ancestries = archive.getAllPublishedBinaries(
292- name=package_name, exact_match=True, pocket=pocket,
293- status=status, distroarchseries=distroseries.architectures)
294- else:
295- ancestries = archive.getPublishedSources(
296- name=package_name, exact_match=True, pocket=pocket,
297- status=status, distroseries=distroseries)
298-
299- try:
300- return ancestries[0]
301- except IndexError:
302- return None
303-
304
305 def get_current_source_releases(context_sourcepackagenames, archive_ids_func,
306 package_clause_func, extra_clauses, key_col):
307
308=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
309--- lib/lp/soyuz/scripts/packagecopier.py 2013-04-17 23:19:35 +0000
310+++ lib/lp/soyuz/scripts/packagecopier.py 2013-05-08 06:29:28 +0000
311@@ -38,6 +38,7 @@
312 from lp.soyuz.interfaces.queue import IPackageUploadCustom
313 from lp.soyuz.scripts.custom_uploads_copier import CustomUploadsCopier
314
315+
316 # XXX cprov 2009-06-12: this function should be incorporated in
317 # IPublishing.
318 def update_files_privacy(pub_record):
319@@ -181,7 +182,7 @@
320 # implementations of ancestry lookup:
321 # NascentUpload.getSourceAncestry,
322 # PackageUploadSource.getSourceAncestryForDiffs, and
323- # PublishingSet.getNearestAncestor, none of which is obviously
324+ # Archive.getPublishedSources, none of which is obviously
325 # correct here. Instead of adding a fourth, we should consolidate
326 # these.
327 ancestries = archive.getPublishedSources(
328@@ -476,8 +477,10 @@
329 # published in the destination archive.
330 self._checkArchiveConflicts(source, series)
331
332- ancestry = source.getAncestry(
333- self.archive, series, pocket, status=active_publishing_status)
334+ ancestry = self.archive.getPublishedSources(
335+ name=source.source_package_name, exact_match=True,
336+ distroseries=series, pocket=pocket,
337+ status=active_publishing_status).first()
338 if ancestry is not None:
339 ancestry_version = ancestry.sourcepackagerelease.version
340 copy_version = source.sourcepackagerelease.version
341@@ -633,13 +636,12 @@
342 announce_from_person=announce_from_person,
343 previous_version=old_version)
344 if not archive.private and has_restricted_files(source):
345- # Fix copies by overriding them according to the current
346- # ancestry and unrestrict files with privacy mismatch. We must
347- # do this *after* calling notify (which only actually sends mail
348- # on commit), because otherwise the new changelog LFA won't be
349- # visible without a commit, which may not be safe here.
350+ # Fix copies by unrestricting files with privacy mismatch.
351+ # We must do this *after* calling notify (which only
352+ # actually sends mail on commit), because otherwise the new
353+ # changelog LFA won't be visible without a commit, which may
354+ # not be safe here.
355 for pub_record in sub_copies:
356- pub_record.overrideFromAncestry()
357 for changed_file in update_files_privacy(pub_record):
358 if logger is not None:
359 logger.info("Made %s public" % changed_file.filename)
360
361=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
362--- lib/lp/soyuz/tests/test_publishing.py 2013-05-04 00:37:58 +0000
363+++ lib/lp/soyuz/tests/test_publishing.py 2013-05-08 06:29:28 +0000
364@@ -31,9 +31,7 @@
365 from lp.services.database.constants import UTC_NOW
366 from lp.services.librarian.interfaces import ILibraryFileAliasSet
367 from lp.services.log.logger import DevNullLogger
368-from lp.soyuz.adapters.overrides import UnknownOverridePolicy
369 from lp.soyuz.enums import (
370- ArchivePurpose,
371 BinaryPackageFormat,
372 PackageUploadStatus,
373 )
374@@ -803,200 +801,6 @@
375 shutil.rmtree(test_temp_dir)
376
377
378-class OverrideFromAncestryTestCase(TestCaseWithFactory):
379- """Test `IPublishing.overrideFromAncestry`.
380-
381- When called from a `SourcePackagePublishingHistory` or a
382- `BinaryPackagePublishingHistory` it sets the object target component
383- according to its ancestry if available or falls back to the component
384- it was originally uploaded to.
385- """
386- layer = LaunchpadZopelessLayer
387-
388- def setUp(self):
389- TestCaseWithFactory.setUp(self)
390- self.test_publisher = SoyuzTestPublisher()
391- self.test_publisher.prepareBreezyAutotest()
392-
393- def test_overrideFromAncestry_only_works_for_pending_records(self):
394- # overrideFromAncestry only accepts PENDING publishing records.
395- source = self.test_publisher.getPubSource()
396-
397- forbidden_status = [
398- item
399- for item in PackagePublishingStatus.items
400- if item is not PackagePublishingStatus.PENDING]
401-
402- for status in forbidden_status:
403- source.status = status
404- self.layer.commit()
405- self.assertRaisesWithContent(
406- AssertionError,
407- 'Cannot override published records.',
408- source.overrideFromAncestry)
409-
410- def makeSource(self):
411- """Return a 'source' publication.
412-
413- It's pending publication with binaries in a brand new PPA
414- and in 'main' component.
415- """
416- test_archive = self.factory.makeArchive(
417- distribution=self.test_publisher.ubuntutest,
418- purpose=ArchivePurpose.PPA)
419- source = self.test_publisher.getPubSource(archive=test_archive)
420- self.test_publisher.getPubBinaries(pub_source=source)
421- return source
422-
423- def copyAndCheck(self, pub_record, series, component_name):
424- """Copy and check if overrideFromAncestry is working as expected.
425-
426- The copied publishing record is targeted to the same component
427- as its source, but override_from_ancestry changes it to follow
428- the ancestry or fallback to the SPR/BPR original component.
429- """
430- copied = pub_record.copyTo(
431- series, pub_record.pocket, series.main_archive)
432-
433- # Cope with heterogeneous results from copyTo().
434- try:
435- copies = tuple(copied)
436- except TypeError:
437- copies = (copied, )
438-
439- for copy in copies:
440- self.assertEqual(pub_record.component, copy.component)
441- copy.overrideFromAncestry()
442- self.layer.commit()
443- self.assertEqual("universe", copy.component.name)
444-
445- def test_overrideFromAncestry_fallback_to_source_component(self):
446- # overrideFromAncestry on the lack of ancestry, falls back to the
447- # component the source was originally uploaded to.
448- source = self.makeSource()
449-
450- # Adjust the source package release original component.
451- universe = getUtility(IComponentSet)['universe']
452- source.sourcepackagerelease.component = universe
453-
454- self.copyAndCheck(source, source.distroseries, 'universe')
455-
456- def test_overrideFromAncestry_fallback_to_binary_component(self):
457- # overrideFromAncestry on the lack of ancestry, falls back to the
458- # component the binary was originally uploaded to.
459- binary = self.makeSource().getPublishedBinaries()[0]
460-
461- # Adjust the binary package release original component.
462- universe = getUtility(IComponentSet)['universe']
463- removeSecurityProxy(binary.binarypackagerelease).component = universe
464-
465- self.copyAndCheck(
466- binary, binary.distroarchseries.distroseries, 'universe')
467-
468- def test_overrideFromAncestry_follow_ancestry_source_component(self):
469- # overrideFromAncestry finds and uses the component of the most
470- # recent PUBLISHED publication of the same name in the same
471- #location.
472- source = self.makeSource()
473-
474- # Create a published ancestry source in the copy destination
475- # targeted to 'universe' and also 2 other noise source
476- # publications, a pending source target to 'restricted' and
477- # a published, but older, one target to 'multiverse'.
478- self.test_publisher.getPubSource(component='restricted')
479-
480- self.test_publisher.getPubSource(
481- component='multiverse', status=PackagePublishingStatus.PUBLISHED)
482-
483- self.test_publisher.getPubSource(
484- component='universe', status=PackagePublishingStatus.PUBLISHED)
485-
486- # Overridden copy it targeted to 'universe'.
487- self.copyAndCheck(source, source.distroseries, 'universe')
488-
489- def test_overrideFromAncestry_follow_ancestry_binary_component(self):
490- # overrideFromAncestry finds and uses the component of the most
491- # recent published publication of the same name in the same
492- # location.
493- binary = self.makeSource().getPublishedBinaries()[0]
494-
495- # Create a published ancestry binary in the copy destination
496- # targeted to 'universe'.
497- restricted_source = self.test_publisher.getPubSource(
498- component='restricted')
499- self.test_publisher.getPubBinaries(pub_source=restricted_source)
500-
501- multiverse_source = self.test_publisher.getPubSource(
502- component='multiverse')
503- self.test_publisher.getPubBinaries(
504- pub_source=multiverse_source,
505- status=PackagePublishingStatus.PUBLISHED)
506-
507- ancestry_source = self.test_publisher.getPubSource(
508- component='universe')
509- self.test_publisher.getPubBinaries(
510- pub_source=ancestry_source,
511- status=PackagePublishingStatus.PUBLISHED)
512-
513- # Overridden copy it targeted to 'universe'.
514- self.copyAndCheck(
515- binary, binary.distroarchseries.distroseries, 'universe')
516-
517- def test_ppa_override_no_ancestry(self):
518- # Test a PPA publication with no ancestry is 'main'
519- ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
520- spr = self.factory.makeSourcePackageRelease()
521- spph = self.factory.makeSourcePackagePublishingHistory(
522- sourcepackagerelease=spr, archive=ppa)
523- spph.overrideFromAncestry()
524- self.assertEqual("main", spph.component.name)
525-
526- def test_ppa_override_with_ancestry(self):
527- # Test a PPA publication with ancestry
528- ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
529- spr = self.factory.makeSourcePackageRelease()
530- # We don't reference the first spph so it doesn't get a name.
531- self.factory.makeSourcePackagePublishingHistory(
532- sourcepackagerelease=spr, archive=ppa)
533- spph2 = self.factory.makeSourcePackagePublishingHistory(
534- sourcepackagerelease=spr, archive=ppa)
535- spph2.overrideFromAncestry()
536- self.assertEqual("main", spph2.component.name)
537-
538- def test_copyTo_with_overrides(self):
539- # Specifying overrides with copyTo should result in the new
540- # publication having those overrides.
541- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
542- target_archive = self.factory.makeArchive(
543- purpose=ArchivePurpose.PRIMARY)
544- main_component = getUtility(IComponentSet)['main']
545- spph = self.factory.makeSourcePackagePublishingHistory(
546- archive=archive, component=main_component)
547- name = spph.sourcepackagerelease.sourcepackagename
548-
549- # Roll with default overrides to reduce the setup.
550- policy = UnknownOverridePolicy()
551- overrides = policy.calculateSourceOverrides(
552- target_archive, None, None, [name])
553- [override] = overrides
554-
555- copy = spph.copyTo(
556- spph.distroseries, spph.pocket, target_archive, override)
557-
558- # The component is overridden to the default.
559- self.assertEqual('universe', copy.component.name)
560- # Section has no default so it comes from the old publication.
561- self.assertEqual(spph.section, copy.section)
562-
563- def test_copyTo_sets_ancestor(self):
564- # SPPH's ancestor get's populated when a spph is copied over.
565- target_archive = self.factory.makeArchive()
566- spph = self.factory.makeSourcePackagePublishingHistory()
567- copy = spph.copyTo(spph.distroseries, spph.pocket, target_archive)
568-
569- self.assertEqual(spph, copy.ancestor)
570-
571-
572 class BuildRecordCreationTests(TestNativePublishingBase):
573 """Test the creation of build records."""
574