Merge lp:~wgrant/launchpad/dont-overrideFromAncestry into lp:launchpad
- dont-overrideFromAncestry
- Merge into devel
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Steve Kowalik (community) | code | Approve | |
Review via email: mp+162933@code.launchpad.net |
Commit message
Drop overrideFromAnc
Description of the change
Stop calling overrideFromAnc
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 | 1756 | ... [firefox_source_pub.id, foo_pub.id], | 1756 | ... [firefox_source_pub.id, foo_pub.id], |
6 | 1757 | ... archive=ubuntu.main_archive) | 1757 | ... archive=ubuntu.main_archive) |
7 | 1758 | >>> print_build_summaries(build_summaries) | 1758 | >>> print_build_summaries(build_summaries) |
8 | 1759 | |||
9 | 1760 | |||
10 | 1761 | IPublishing ancestry lookup and override | ||
11 | 1762 | ======================================== | ||
12 | 1763 | |||
13 | 1764 | `IPublishing` is implemented by both kinds of package publications we | ||
14 | 1765 | have `SourcePackagePublishingHistory` and | ||
15 | 1766 | `BinaryPackagePublishingHistory`. | ||
16 | 1767 | |||
17 | 1768 | This interface allows, among other features, easy ancestry lookup and | ||
18 | 1769 | pre-publication overrides via: | ||
19 | 1770 | |||
20 | 1771 | * getAncestry | ||
21 | 1772 | * overrideFromAncestry | ||
22 | 1773 | |||
23 | 1774 | # Setup a publishing scenario for illustrating ancestry lookup. | ||
24 | 1775 | >>> ubuntu_source_ancestry = test_publisher.getPubSource( | ||
25 | 1776 | ... sourcename='testing', version='1.0', | ||
26 | 1777 | ... architecturehintlist='i386', component='multiverse', | ||
27 | 1778 | ... status=PackagePublishingStatus.PUBLISHED) | ||
28 | 1779 | >>> ubuntu_binary_ancestry = test_publisher.getPubBinaries( | ||
29 | 1780 | ... binaryname='testing-bin', pub_source=ubuntu_source_ancestry, | ||
30 | 1781 | ... status=PackagePublishingStatus.PUBLISHED)[0] | ||
31 | 1782 | >>> ppa_source_ancestry = test_publisher.getPubSource( | ||
32 | 1783 | ... sourcename='testing', version='1.1', component='main', | ||
33 | 1784 | ... architecturehintlist='i386', archive=cprov.archive, | ||
34 | 1785 | ... status=PackagePublishingStatus.PUBLISHED) | ||
35 | 1786 | >>> ppa_binary_ancestry = test_publisher.getPubBinaries( | ||
36 | 1787 | ... binaryname='testing-bin', pub_source=ppa_source_ancestry, | ||
37 | 1788 | ... status=PackagePublishingStatus.PUBLISHED)[0] | ||
38 | 1789 | >>> test_source = test_publisher.getPubSource( | ||
39 | 1790 | ... sourcename='testing', version='2.0', component='universe', | ||
40 | 1791 | ... architecturehintlist='i386') | ||
41 | 1792 | >>> test_binary = test_publisher.getPubBinaries( | ||
42 | 1793 | ... binaryname='testing-bin', pub_source=test_source)[0] | ||
43 | 1794 | |||
44 | 1795 | We will create a helper function to inspect ancestries. It simply pass | ||
45 | 1796 | any given keyword argument to 'test_source' and 'test_binary' | ||
46 | 1797 | getAncestry() method. | ||
47 | 1798 | |||
48 | 1799 | >>> def print_ancestries(**kwargs): | ||
49 | 1800 | ... def print_displayname(pub): | ||
50 | 1801 | ... if pub is not None: | ||
51 | 1802 | ... print pub.displayname | ||
52 | 1803 | ... else: | ||
53 | 1804 | ... print pub | ||
54 | 1805 | ... print_displayname(test_source.getAncestry(**kwargs)) | ||
55 | 1806 | ... print_displayname(test_binary.getAncestry(**kwargs)) | ||
56 | 1807 | |||
57 | 1808 | The 'test_source' and 'test_binary' ancestries in the same context, | ||
58 | 1809 | i.e. ubuntu primary archive. | ||
59 | 1810 | |||
60 | 1811 | >>> print_ancestries() | ||
61 | 1812 | testing 1.0 in breezy-autotest | ||
62 | 1813 | testing-bin 1.0 in breezy-autotest i386 | ||
63 | 1814 | |||
64 | 1815 | Call sites may quickly adjust the context where the ancestries are | ||
65 | 1816 | looked up. | ||
66 | 1817 | |||
67 | 1818 | >>> print_ancestries(archive=cprov.archive) | ||
68 | 1819 | testing 1.1 in breezy-autotest | ||
69 | 1820 | testing-bin 1.1 in breezy-autotest i386 | ||
70 | 1821 | |||
71 | 1822 | >>> print_ancestries(distroseries=test_source.distroseries) | ||
72 | 1823 | testing 1.0 in breezy-autotest | ||
73 | 1824 | testing-bin 1.0 in breezy-autotest i386 | ||
74 | 1825 | |||
75 | 1826 | >>> print_ancestries(pocket=test_source.pocket) | ||
76 | 1827 | testing 1.0 in breezy-autotest | ||
77 | 1828 | testing-bin 1.0 in breezy-autotest i386 | ||
78 | 1829 | |||
79 | 1830 | The default 'status' filter is set to PUBLISHED ancestries, however | ||
80 | 1831 | call sites may decide differently. | ||
81 | 1832 | |||
82 | 1833 | >>> print_ancestries(status=PackagePublishingStatus.PUBLISHED) | ||
83 | 1834 | testing 1.0 in breezy-autotest | ||
84 | 1835 | testing-bin 1.0 in breezy-autotest i386 | ||
85 | 1836 | |||
86 | 1837 | On the lack of ancestry, None is returned. | ||
87 | 1838 | |||
88 | 1839 | >>> from lp.soyuz.interfaces.publishing import ( | ||
89 | 1840 | ... inactive_publishing_status) | ||
90 | 1841 | >>> print_ancestries(status=inactive_publishing_status) | ||
91 | 1842 | None | ||
92 | 1843 | None | ||
93 | 1844 | |||
94 | 1845 | `overrideFromAncestry` operates directly on top of the default | ||
95 | 1846 | behavior of `getAncestry`. It looks up the most recent ancestry for a | ||
96 | 1847 | publication and override it in place. If there is no previous publication | ||
97 | 1848 | then the package's component is used. | ||
98 | 1849 | |||
99 | 1850 | >>> print test_source.component.name | ||
100 | 1851 | universe | ||
101 | 1852 | |||
102 | 1853 | >>> test_source.overrideFromAncestry() | ||
103 | 1854 | >>> print test_source.component.name | ||
104 | 1855 | multiverse | ||
105 | 1856 | |||
106 | 1857 | It works in the same way for binaries. | ||
107 | 1858 | |||
108 | 1859 | >>> multiverse = getUtility(IComponentSet)['multiverse'] | ||
109 | 1860 | >>> test_binary.binarypackagerelease.component = multiverse | ||
110 | 1861 | |||
111 | 1862 | >>> print test_binary.component.name | ||
112 | 1863 | universe | ||
113 | 1864 | |||
114 | 1865 | >>> copied_binary = test_binary.copyTo( | ||
115 | 1866 | ... hoary_test, test_source.pocket, archive=test_binary.archive)[0] | ||
116 | 1867 | >>> print copied_binary.component.name | ||
117 | 1868 | universe | ||
118 | 1869 | |||
119 | 1870 | >>> copied_binary.overrideFromAncestry() | ||
120 | 1871 | >>> print copied_binary.component.name | ||
121 | 1872 | multiverse | ||
122 | 1873 | 1759 | ||
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 | 221 | `IBinaryPackagePublishingHistory`. | 221 | `IBinaryPackagePublishingHistory`. |
128 | 222 | """ | 222 | """ |
129 | 223 | 223 | ||
130 | 224 | def getAncestry(archive=None, distroseries=None, pocket=None, | ||
131 | 225 | status=None): | ||
132 | 226 | """Return the most recent publication of the same source or binary. | ||
133 | 227 | |||
134 | 228 | If a suitable ancestry could not be found, None is returned. | ||
135 | 229 | |||
136 | 230 | It optionally accepts parameters for adjusting the publishing | ||
137 | 231 | context, if not given they default to the current context. | ||
138 | 232 | |||
139 | 233 | :param archive: optional `IArchive`, defaults to the context archive. | ||
140 | 234 | :param distroseries: optional `IDistroSeries`, defaults to the | ||
141 | 235 | context distroseries. | ||
142 | 236 | :param pocket: optional `PackagePublishingPocket`, defaults to any | ||
143 | 237 | pocket. | ||
144 | 238 | :param status: optional `PackagePublishingStatus` or a collection of | ||
145 | 239 | them, defaults to `PackagePublishingStatus.PUBLISHED` | ||
146 | 240 | """ | ||
147 | 241 | |||
148 | 242 | def overrideFromAncestry(): | ||
149 | 243 | """Set the right published component from publishing ancestry. | ||
150 | 244 | |||
151 | 245 | Start with the publishing records and fall back to the original | ||
152 | 246 | uploaded package if necessary. | ||
153 | 247 | |||
154 | 248 | :raise: AssertionError if the context publishing record is not in | ||
155 | 249 | PENDING status. | ||
156 | 250 | """ | ||
157 | 251 | |||
158 | 252 | 224 | ||
159 | 253 | class IPublishingEdit(Interface): | 225 | class IPublishingEdit(Interface): |
160 | 254 | """Base interface for writeable Publishing classes.""" | 226 | """Base interface for writeable Publishing classes.""" |
161 | @@ -1343,34 +1315,6 @@ | |||
162 | 1343 | the source_package_pub, allowing the use of the cached results. | 1315 | the source_package_pub, allowing the use of the cached results. |
163 | 1344 | """ | 1316 | """ |
164 | 1345 | 1317 | ||
165 | 1346 | def getNearestAncestor( | ||
166 | 1347 | package_name, archive, distroseries, pocket=None, status=None, | ||
167 | 1348 | binary=False): | ||
168 | 1349 | """Return the ancestor of the given parkage in a particular archive. | ||
169 | 1350 | |||
170 | 1351 | :param package_name: The package name for which we are checking for | ||
171 | 1352 | an ancestor. | ||
172 | 1353 | :type package_name: ``string`` | ||
173 | 1354 | :param archive: The archive in which we are looking for an ancestor. | ||
174 | 1355 | :type archive: `IArchive` | ||
175 | 1356 | :param distroseries: The particular series in which we are looking for | ||
176 | 1357 | an ancestor. | ||
177 | 1358 | :type distroseries: `IDistroSeries` | ||
178 | 1359 | :param pocket: An optional pocket to restrict the search. | ||
179 | 1360 | :type pocket: `PackagePublishingPocket`. | ||
180 | 1361 | :param status: An optional status defaulting to PUBLISHED if not | ||
181 | 1362 | provided. | ||
182 | 1363 | :type status: `PackagePublishingStatus` | ||
183 | 1364 | :param binary: An optional argument to look for a binary ancestor | ||
184 | 1365 | instead of the default source. | ||
185 | 1366 | :type binary: ``Boolean`` | ||
186 | 1367 | |||
187 | 1368 | :return: The most recent publishing history for the given | ||
188 | 1369 | arguments. | ||
189 | 1370 | :rtype: `ISourcePackagePublishingHistory` or | ||
190 | 1371 | `IBinaryPackagePublishingHistory` or None. | ||
191 | 1372 | """ | ||
192 | 1373 | |||
193 | 1374 | active_publishing_status = ( | 1318 | active_publishing_status = ( |
194 | 1375 | PackagePublishingStatus.PENDING, | 1319 | PackagePublishingStatus.PENDING, |
195 | 1376 | PackagePublishingStatus.PUBLISHED, | 1320 | PackagePublishingStatus.PUBLISHED, |
196 | 1377 | 1321 | ||
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 | 847 | return getUtility( | 847 | return getUtility( |
202 | 848 | IPublishingSet).getBuildStatusSummaryForSourcePublication(self) | 848 | IPublishingSet).getBuildStatusSummaryForSourcePublication(self) |
203 | 849 | 849 | ||
204 | 850 | def getAncestry(self, archive=None, distroseries=None, pocket=None, | ||
205 | 851 | status=None): | ||
206 | 852 | """See `ISourcePackagePublishingHistory`.""" | ||
207 | 853 | if archive is None: | ||
208 | 854 | archive = self.archive | ||
209 | 855 | if distroseries is None: | ||
210 | 856 | distroseries = self.distroseries | ||
211 | 857 | |||
212 | 858 | return getUtility(IPublishingSet).getNearestAncestor( | ||
213 | 859 | self.source_package_name, archive, distroseries, pocket, | ||
214 | 860 | status) | ||
215 | 861 | |||
216 | 862 | def overrideFromAncestry(self): | ||
217 | 863 | """See `ISourcePackagePublishingHistory`.""" | ||
218 | 864 | # We don't want to use changeOverride here because it creates a | ||
219 | 865 | # new publishing record. This code can be only executed for pending | ||
220 | 866 | # publishing records. | ||
221 | 867 | assert self.status == PackagePublishingStatus.PENDING, ( | ||
222 | 868 | "Cannot override published records.") | ||
223 | 869 | |||
224 | 870 | # If there is published ancestry, use its component, otherwise | ||
225 | 871 | # use the original upload component. Since PPAs only use main, | ||
226 | 872 | # we don't need to check the ancestry. | ||
227 | 873 | if not self.archive.is_ppa: | ||
228 | 874 | ancestry = self.getAncestry() | ||
229 | 875 | if ancestry is not None: | ||
230 | 876 | component = ancestry.component | ||
231 | 877 | else: | ||
232 | 878 | component = self.sourcepackagerelease.component | ||
233 | 879 | |||
234 | 880 | self.component = component | ||
235 | 881 | |||
236 | 882 | assert self.component in ( | ||
237 | 883 | self.archive.getComponentsForSeries(self.distroseries)) | ||
238 | 884 | |||
239 | 885 | def sourceFileUrls(self): | 850 | def sourceFileUrls(self): |
240 | 886 | """See `ISourcePackagePublishingHistory`.""" | 851 | """See `ISourcePackagePublishingHistory`.""" |
241 | 887 | source_urls = proxied_urls( | 852 | source_urls = proxied_urls( |
242 | @@ -1280,36 +1245,6 @@ | |||
243 | 1280 | return getUtility(IPublishingSet).copyBinariesTo( | 1245 | return getUtility(IPublishingSet).copyBinariesTo( |
244 | 1281 | [self], distroseries, pocket, archive) | 1246 | [self], distroseries, pocket, archive) |
245 | 1282 | 1247 | ||
246 | 1283 | def getAncestry(self, archive=None, distroseries=None, pocket=None, | ||
247 | 1284 | status=None): | ||
248 | 1285 | """See `IBinaryPackagePublishingHistory`.""" | ||
249 | 1286 | if archive is None: | ||
250 | 1287 | archive = self.archive | ||
251 | 1288 | if distroseries is None: | ||
252 | 1289 | distroseries = self.distroarchseries.distroseries | ||
253 | 1290 | |||
254 | 1291 | return getUtility(IPublishingSet).getNearestAncestor( | ||
255 | 1292 | self.binary_package_name, archive, distroseries, pocket, | ||
256 | 1293 | status, binary=True) | ||
257 | 1294 | |||
258 | 1295 | def overrideFromAncestry(self): | ||
259 | 1296 | """See `IBinaryPackagePublishingHistory`.""" | ||
260 | 1297 | # We don't want to use changeOverride here because it creates a | ||
261 | 1298 | # new publishing record. This code can be only executed for pending | ||
262 | 1299 | # publishing records. | ||
263 | 1300 | assert self.status == PackagePublishingStatus.PENDING, ( | ||
264 | 1301 | "Cannot override published records.") | ||
265 | 1302 | |||
266 | 1303 | # If there is an ancestry, use its component, otherwise use the | ||
267 | 1304 | # original upload component. | ||
268 | 1305 | ancestry = self.getAncestry() | ||
269 | 1306 | if ancestry is not None: | ||
270 | 1307 | component = ancestry.component | ||
271 | 1308 | else: | ||
272 | 1309 | component = self.binarypackagerelease.component | ||
273 | 1310 | |||
274 | 1311 | self.component = component | ||
275 | 1312 | |||
276 | 1313 | def _getDownloadCountClauses(self, start_date=None, end_date=None): | 1248 | def _getDownloadCountClauses(self, start_date=None, end_date=None): |
277 | 1314 | clauses = [ | 1249 | clauses = [ |
278 | 1315 | BinaryPackageReleaseDownloadCount.archive == self.archive, | 1250 | BinaryPackageReleaseDownloadCount.archive == self.archive, |
279 | @@ -2109,27 +2044,6 @@ | |||
280 | 2109 | BinaryPackagePublishingHistory, bpph_ids, removed_by, | 2044 | BinaryPackagePublishingHistory, bpph_ids, removed_by, |
281 | 2110 | removal_comment=removal_comment) | 2045 | removal_comment=removal_comment) |
282 | 2111 | 2046 | ||
283 | 2112 | def getNearestAncestor( | ||
284 | 2113 | self, package_name, archive, distroseries, pocket=None, | ||
285 | 2114 | status=None, binary=False): | ||
286 | 2115 | """See `IPublishingSet`.""" | ||
287 | 2116 | if status is None: | ||
288 | 2117 | status = PackagePublishingStatus.PUBLISHED | ||
289 | 2118 | |||
290 | 2119 | if binary: | ||
291 | 2120 | ancestries = archive.getAllPublishedBinaries( | ||
292 | 2121 | name=package_name, exact_match=True, pocket=pocket, | ||
293 | 2122 | status=status, distroarchseries=distroseries.architectures) | ||
294 | 2123 | else: | ||
295 | 2124 | ancestries = archive.getPublishedSources( | ||
296 | 2125 | name=package_name, exact_match=True, pocket=pocket, | ||
297 | 2126 | status=status, distroseries=distroseries) | ||
298 | 2127 | |||
299 | 2128 | try: | ||
300 | 2129 | return ancestries[0] | ||
301 | 2130 | except IndexError: | ||
302 | 2131 | return None | ||
303 | 2132 | |||
304 | 2133 | 2047 | ||
305 | 2134 | def get_current_source_releases(context_sourcepackagenames, archive_ids_func, | 2048 | def get_current_source_releases(context_sourcepackagenames, archive_ids_func, |
306 | 2135 | package_clause_func, extra_clauses, key_col): | 2049 | package_clause_func, extra_clauses, key_col): |
307 | 2136 | 2050 | ||
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 | 38 | from lp.soyuz.interfaces.queue import IPackageUploadCustom | 38 | from lp.soyuz.interfaces.queue import IPackageUploadCustom |
313 | 39 | from lp.soyuz.scripts.custom_uploads_copier import CustomUploadsCopier | 39 | from lp.soyuz.scripts.custom_uploads_copier import CustomUploadsCopier |
314 | 40 | 40 | ||
315 | 41 | |||
316 | 41 | # XXX cprov 2009-06-12: this function should be incorporated in | 42 | # XXX cprov 2009-06-12: this function should be incorporated in |
317 | 42 | # IPublishing. | 43 | # IPublishing. |
318 | 43 | def update_files_privacy(pub_record): | 44 | def update_files_privacy(pub_record): |
319 | @@ -181,7 +182,7 @@ | |||
320 | 181 | # implementations of ancestry lookup: | 182 | # implementations of ancestry lookup: |
321 | 182 | # NascentUpload.getSourceAncestry, | 183 | # NascentUpload.getSourceAncestry, |
322 | 183 | # PackageUploadSource.getSourceAncestryForDiffs, and | 184 | # PackageUploadSource.getSourceAncestryForDiffs, and |
324 | 184 | # PublishingSet.getNearestAncestor, none of which is obviously | 185 | # Archive.getPublishedSources, none of which is obviously |
325 | 185 | # correct here. Instead of adding a fourth, we should consolidate | 186 | # correct here. Instead of adding a fourth, we should consolidate |
326 | 186 | # these. | 187 | # these. |
327 | 187 | ancestries = archive.getPublishedSources( | 188 | ancestries = archive.getPublishedSources( |
328 | @@ -476,8 +477,10 @@ | |||
329 | 476 | # published in the destination archive. | 477 | # published in the destination archive. |
330 | 477 | self._checkArchiveConflicts(source, series) | 478 | self._checkArchiveConflicts(source, series) |
331 | 478 | 479 | ||
334 | 479 | ancestry = source.getAncestry( | 480 | ancestry = self.archive.getPublishedSources( |
335 | 480 | self.archive, series, pocket, status=active_publishing_status) | 481 | name=source.source_package_name, exact_match=True, |
336 | 482 | distroseries=series, pocket=pocket, | ||
337 | 483 | status=active_publishing_status).first() | ||
338 | 481 | if ancestry is not None: | 484 | if ancestry is not None: |
339 | 482 | ancestry_version = ancestry.sourcepackagerelease.version | 485 | ancestry_version = ancestry.sourcepackagerelease.version |
340 | 483 | copy_version = source.sourcepackagerelease.version | 486 | copy_version = source.sourcepackagerelease.version |
341 | @@ -633,13 +636,12 @@ | |||
342 | 633 | announce_from_person=announce_from_person, | 636 | announce_from_person=announce_from_person, |
343 | 634 | previous_version=old_version) | 637 | previous_version=old_version) |
344 | 635 | if not archive.private and has_restricted_files(source): | 638 | if not archive.private and has_restricted_files(source): |
350 | 636 | # Fix copies by overriding them according to the current | 639 | # Fix copies by unrestricting files with privacy mismatch. |
351 | 637 | # ancestry and unrestrict files with privacy mismatch. We must | 640 | # We must do this *after* calling notify (which only |
352 | 638 | # do this *after* calling notify (which only actually sends mail | 641 | # actually sends mail on commit), because otherwise the new |
353 | 639 | # on commit), because otherwise the new changelog LFA won't be | 642 | # changelog LFA won't be visible without a commit, which may |
354 | 640 | # visible without a commit, which may not be safe here. | 643 | # not be safe here. |
355 | 641 | for pub_record in sub_copies: | 644 | for pub_record in sub_copies: |
356 | 642 | pub_record.overrideFromAncestry() | ||
357 | 643 | for changed_file in update_files_privacy(pub_record): | 645 | for changed_file in update_files_privacy(pub_record): |
358 | 644 | if logger is not None: | 646 | if logger is not None: |
359 | 645 | logger.info("Made %s public" % changed_file.filename) | 647 | logger.info("Made %s public" % changed_file.filename) |
360 | 646 | 648 | ||
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 | 31 | from lp.services.database.constants import UTC_NOW | 31 | from lp.services.database.constants import UTC_NOW |
366 | 32 | from lp.services.librarian.interfaces import ILibraryFileAliasSet | 32 | from lp.services.librarian.interfaces import ILibraryFileAliasSet |
367 | 33 | from lp.services.log.logger import DevNullLogger | 33 | from lp.services.log.logger import DevNullLogger |
368 | 34 | from lp.soyuz.adapters.overrides import UnknownOverridePolicy | ||
369 | 35 | from lp.soyuz.enums import ( | 34 | from lp.soyuz.enums import ( |
370 | 36 | ArchivePurpose, | ||
371 | 37 | BinaryPackageFormat, | 35 | BinaryPackageFormat, |
372 | 38 | PackageUploadStatus, | 36 | PackageUploadStatus, |
373 | 39 | ) | 37 | ) |
374 | @@ -803,200 +801,6 @@ | |||
375 | 803 | shutil.rmtree(test_temp_dir) | 801 | shutil.rmtree(test_temp_dir) |
376 | 804 | 802 | ||
377 | 805 | 803 | ||
378 | 806 | class OverrideFromAncestryTestCase(TestCaseWithFactory): | ||
379 | 807 | """Test `IPublishing.overrideFromAncestry`. | ||
380 | 808 | |||
381 | 809 | When called from a `SourcePackagePublishingHistory` or a | ||
382 | 810 | `BinaryPackagePublishingHistory` it sets the object target component | ||
383 | 811 | according to its ancestry if available or falls back to the component | ||
384 | 812 | it was originally uploaded to. | ||
385 | 813 | """ | ||
386 | 814 | layer = LaunchpadZopelessLayer | ||
387 | 815 | |||
388 | 816 | def setUp(self): | ||
389 | 817 | TestCaseWithFactory.setUp(self) | ||
390 | 818 | self.test_publisher = SoyuzTestPublisher() | ||
391 | 819 | self.test_publisher.prepareBreezyAutotest() | ||
392 | 820 | |||
393 | 821 | def test_overrideFromAncestry_only_works_for_pending_records(self): | ||
394 | 822 | # overrideFromAncestry only accepts PENDING publishing records. | ||
395 | 823 | source = self.test_publisher.getPubSource() | ||
396 | 824 | |||
397 | 825 | forbidden_status = [ | ||
398 | 826 | item | ||
399 | 827 | for item in PackagePublishingStatus.items | ||
400 | 828 | if item is not PackagePublishingStatus.PENDING] | ||
401 | 829 | |||
402 | 830 | for status in forbidden_status: | ||
403 | 831 | source.status = status | ||
404 | 832 | self.layer.commit() | ||
405 | 833 | self.assertRaisesWithContent( | ||
406 | 834 | AssertionError, | ||
407 | 835 | 'Cannot override published records.', | ||
408 | 836 | source.overrideFromAncestry) | ||
409 | 837 | |||
410 | 838 | def makeSource(self): | ||
411 | 839 | """Return a 'source' publication. | ||
412 | 840 | |||
413 | 841 | It's pending publication with binaries in a brand new PPA | ||
414 | 842 | and in 'main' component. | ||
415 | 843 | """ | ||
416 | 844 | test_archive = self.factory.makeArchive( | ||
417 | 845 | distribution=self.test_publisher.ubuntutest, | ||
418 | 846 | purpose=ArchivePurpose.PPA) | ||
419 | 847 | source = self.test_publisher.getPubSource(archive=test_archive) | ||
420 | 848 | self.test_publisher.getPubBinaries(pub_source=source) | ||
421 | 849 | return source | ||
422 | 850 | |||
423 | 851 | def copyAndCheck(self, pub_record, series, component_name): | ||
424 | 852 | """Copy and check if overrideFromAncestry is working as expected. | ||
425 | 853 | |||
426 | 854 | The copied publishing record is targeted to the same component | ||
427 | 855 | as its source, but override_from_ancestry changes it to follow | ||
428 | 856 | the ancestry or fallback to the SPR/BPR original component. | ||
429 | 857 | """ | ||
430 | 858 | copied = pub_record.copyTo( | ||
431 | 859 | series, pub_record.pocket, series.main_archive) | ||
432 | 860 | |||
433 | 861 | # Cope with heterogeneous results from copyTo(). | ||
434 | 862 | try: | ||
435 | 863 | copies = tuple(copied) | ||
436 | 864 | except TypeError: | ||
437 | 865 | copies = (copied, ) | ||
438 | 866 | |||
439 | 867 | for copy in copies: | ||
440 | 868 | self.assertEqual(pub_record.component, copy.component) | ||
441 | 869 | copy.overrideFromAncestry() | ||
442 | 870 | self.layer.commit() | ||
443 | 871 | self.assertEqual("universe", copy.component.name) | ||
444 | 872 | |||
445 | 873 | def test_overrideFromAncestry_fallback_to_source_component(self): | ||
446 | 874 | # overrideFromAncestry on the lack of ancestry, falls back to the | ||
447 | 875 | # component the source was originally uploaded to. | ||
448 | 876 | source = self.makeSource() | ||
449 | 877 | |||
450 | 878 | # Adjust the source package release original component. | ||
451 | 879 | universe = getUtility(IComponentSet)['universe'] | ||
452 | 880 | source.sourcepackagerelease.component = universe | ||
453 | 881 | |||
454 | 882 | self.copyAndCheck(source, source.distroseries, 'universe') | ||
455 | 883 | |||
456 | 884 | def test_overrideFromAncestry_fallback_to_binary_component(self): | ||
457 | 885 | # overrideFromAncestry on the lack of ancestry, falls back to the | ||
458 | 886 | # component the binary was originally uploaded to. | ||
459 | 887 | binary = self.makeSource().getPublishedBinaries()[0] | ||
460 | 888 | |||
461 | 889 | # Adjust the binary package release original component. | ||
462 | 890 | universe = getUtility(IComponentSet)['universe'] | ||
463 | 891 | removeSecurityProxy(binary.binarypackagerelease).component = universe | ||
464 | 892 | |||
465 | 893 | self.copyAndCheck( | ||
466 | 894 | binary, binary.distroarchseries.distroseries, 'universe') | ||
467 | 895 | |||
468 | 896 | def test_overrideFromAncestry_follow_ancestry_source_component(self): | ||
469 | 897 | # overrideFromAncestry finds and uses the component of the most | ||
470 | 898 | # recent PUBLISHED publication of the same name in the same | ||
471 | 899 | #location. | ||
472 | 900 | source = self.makeSource() | ||
473 | 901 | |||
474 | 902 | # Create a published ancestry source in the copy destination | ||
475 | 903 | # targeted to 'universe' and also 2 other noise source | ||
476 | 904 | # publications, a pending source target to 'restricted' and | ||
477 | 905 | # a published, but older, one target to 'multiverse'. | ||
478 | 906 | self.test_publisher.getPubSource(component='restricted') | ||
479 | 907 | |||
480 | 908 | self.test_publisher.getPubSource( | ||
481 | 909 | component='multiverse', status=PackagePublishingStatus.PUBLISHED) | ||
482 | 910 | |||
483 | 911 | self.test_publisher.getPubSource( | ||
484 | 912 | component='universe', status=PackagePublishingStatus.PUBLISHED) | ||
485 | 913 | |||
486 | 914 | # Overridden copy it targeted to 'universe'. | ||
487 | 915 | self.copyAndCheck(source, source.distroseries, 'universe') | ||
488 | 916 | |||
489 | 917 | def test_overrideFromAncestry_follow_ancestry_binary_component(self): | ||
490 | 918 | # overrideFromAncestry finds and uses the component of the most | ||
491 | 919 | # recent published publication of the same name in the same | ||
492 | 920 | # location. | ||
493 | 921 | binary = self.makeSource().getPublishedBinaries()[0] | ||
494 | 922 | |||
495 | 923 | # Create a published ancestry binary in the copy destination | ||
496 | 924 | # targeted to 'universe'. | ||
497 | 925 | restricted_source = self.test_publisher.getPubSource( | ||
498 | 926 | component='restricted') | ||
499 | 927 | self.test_publisher.getPubBinaries(pub_source=restricted_source) | ||
500 | 928 | |||
501 | 929 | multiverse_source = self.test_publisher.getPubSource( | ||
502 | 930 | component='multiverse') | ||
503 | 931 | self.test_publisher.getPubBinaries( | ||
504 | 932 | pub_source=multiverse_source, | ||
505 | 933 | status=PackagePublishingStatus.PUBLISHED) | ||
506 | 934 | |||
507 | 935 | ancestry_source = self.test_publisher.getPubSource( | ||
508 | 936 | component='universe') | ||
509 | 937 | self.test_publisher.getPubBinaries( | ||
510 | 938 | pub_source=ancestry_source, | ||
511 | 939 | status=PackagePublishingStatus.PUBLISHED) | ||
512 | 940 | |||
513 | 941 | # Overridden copy it targeted to 'universe'. | ||
514 | 942 | self.copyAndCheck( | ||
515 | 943 | binary, binary.distroarchseries.distroseries, 'universe') | ||
516 | 944 | |||
517 | 945 | def test_ppa_override_no_ancestry(self): | ||
518 | 946 | # Test a PPA publication with no ancestry is 'main' | ||
519 | 947 | ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA) | ||
520 | 948 | spr = self.factory.makeSourcePackageRelease() | ||
521 | 949 | spph = self.factory.makeSourcePackagePublishingHistory( | ||
522 | 950 | sourcepackagerelease=spr, archive=ppa) | ||
523 | 951 | spph.overrideFromAncestry() | ||
524 | 952 | self.assertEqual("main", spph.component.name) | ||
525 | 953 | |||
526 | 954 | def test_ppa_override_with_ancestry(self): | ||
527 | 955 | # Test a PPA publication with ancestry | ||
528 | 956 | ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA) | ||
529 | 957 | spr = self.factory.makeSourcePackageRelease() | ||
530 | 958 | # We don't reference the first spph so it doesn't get a name. | ||
531 | 959 | self.factory.makeSourcePackagePublishingHistory( | ||
532 | 960 | sourcepackagerelease=spr, archive=ppa) | ||
533 | 961 | spph2 = self.factory.makeSourcePackagePublishingHistory( | ||
534 | 962 | sourcepackagerelease=spr, archive=ppa) | ||
535 | 963 | spph2.overrideFromAncestry() | ||
536 | 964 | self.assertEqual("main", spph2.component.name) | ||
537 | 965 | |||
538 | 966 | def test_copyTo_with_overrides(self): | ||
539 | 967 | # Specifying overrides with copyTo should result in the new | ||
540 | 968 | # publication having those overrides. | ||
541 | 969 | archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY) | ||
542 | 970 | target_archive = self.factory.makeArchive( | ||
543 | 971 | purpose=ArchivePurpose.PRIMARY) | ||
544 | 972 | main_component = getUtility(IComponentSet)['main'] | ||
545 | 973 | spph = self.factory.makeSourcePackagePublishingHistory( | ||
546 | 974 | archive=archive, component=main_component) | ||
547 | 975 | name = spph.sourcepackagerelease.sourcepackagename | ||
548 | 976 | |||
549 | 977 | # Roll with default overrides to reduce the setup. | ||
550 | 978 | policy = UnknownOverridePolicy() | ||
551 | 979 | overrides = policy.calculateSourceOverrides( | ||
552 | 980 | target_archive, None, None, [name]) | ||
553 | 981 | [override] = overrides | ||
554 | 982 | |||
555 | 983 | copy = spph.copyTo( | ||
556 | 984 | spph.distroseries, spph.pocket, target_archive, override) | ||
557 | 985 | |||
558 | 986 | # The component is overridden to the default. | ||
559 | 987 | self.assertEqual('universe', copy.component.name) | ||
560 | 988 | # Section has no default so it comes from the old publication. | ||
561 | 989 | self.assertEqual(spph.section, copy.section) | ||
562 | 990 | |||
563 | 991 | def test_copyTo_sets_ancestor(self): | ||
564 | 992 | # SPPH's ancestor get's populated when a spph is copied over. | ||
565 | 993 | target_archive = self.factory.makeArchive() | ||
566 | 994 | spph = self.factory.makeSourcePackagePublishingHistory() | ||
567 | 995 | copy = spph.copyTo(spph.distroseries, spph.pocket, target_archive) | ||
568 | 996 | |||
569 | 997 | self.assertEqual(spph, copy.ancestor) | ||
570 | 998 | |||
571 | 999 | |||
572 | 1000 | class BuildRecordCreationTests(TestNativePublishingBase): | 804 | class BuildRecordCreationTests(TestNativePublishingBase): |
573 | 1001 | """Test the creation of build records.""" | 805 | """Test the creation of build records.""" |
574 | 1002 | 806 |