Merge lp:~stevenk/launchpad/destroy-pppd into lp:launchpad
- destroy-pppd
- Merge into devel
Proposed by
Steve Kowalik
Status: | Merged |
---|---|
Approved by: | William Grant |
Approved revision: | no longer in the source branch. |
Merged at revision: | 16719 |
Proposed branch: | lp:~stevenk/launchpad/destroy-pppd |
Merge into: | lp:launchpad |
Prerequisite: | lp:~stevenk/launchpad/packagediff-job |
Diff against target: |
666 lines (+52/-397) 10 files modified
cronscripts/process-pending-packagediffs.py (+0/-35) lib/lp/soyuz/doc/package-diff.txt (+2/-27) lib/lp/soyuz/interfaces/packagediff.py (+0/-8) lib/lp/soyuz/model/packagediff.py (+0/-6) lib/lp/soyuz/scripts/packagediff.py (+0/-62) lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py (+0/-106) lib/lp/soyuz/stories/soyuz/xx-package-diff.txt (+1/-14) lib/lp/soyuz/tests/soyuz.py (+0/-81) lib/lp/soyuz/tests/test_packagediff.py (+48/-24) lib/lp/soyuz/tests/test_packagediffjob.py (+1/-34) |
To merge this branch: | bzr merge lp:~stevenk/launchpad/destroy-pppd |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email: mp+172945@code.launchpad.net |
Commit message
Destroy the process-
Description of the change
Destroy the process-
To post a comment you must log in.
Revision history for this message
William Grant (wgrant) : | # |
review:
Approve
(code)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'cronscripts/process-pending-packagediffs.py' |
2 | --- cronscripts/process-pending-packagediffs.py 2013-01-07 02:40:55 +0000 |
3 | +++ cronscripts/process-pending-packagediffs.py 1970-01-01 00:00:00 +0000 |
4 | @@ -1,35 +0,0 @@ |
5 | -#!/usr/bin/python -S |
6 | -# |
7 | -# Copyright 2009 Canonical Ltd. This software is licensed under the |
8 | -# GNU Affero General Public License version 3 (see the file LICENSE). |
9 | - |
10 | -"""Process pending PackageDiffs. |
11 | - |
12 | -Process a optionally limited set of pending PackageDiffs. |
13 | - |
14 | -By default it process up to 50 diffs each run, which is enough to catch |
15 | -up on 1 hour of uploads (on average). |
16 | - |
17 | -However users might benefit for more frequently runs since the diff ETA |
18 | -relative to the upload will be shorter. |
19 | - |
20 | -The cycle time needs to be balanced with the run time to produce the shortest |
21 | -diff ETA and to not overlap much, for instance, if it has to diff monster |
22 | -sources like openoffice or firefox. |
23 | - |
24 | -Experiments with the cycle time will be safe enough and won't sink the host |
25 | -performance, since the lock file is exclusive. |
26 | -""" |
27 | - |
28 | -__metaclass__ = type |
29 | - |
30 | -import _pythonpath |
31 | - |
32 | -from lp.services.config import config |
33 | -from lp.soyuz.scripts.packagediff import ProcessPendingPackageDiffs |
34 | - |
35 | - |
36 | -if __name__ == '__main__': |
37 | - script = ProcessPendingPackageDiffs( |
38 | - 'process-pending-packagediffs', dbuser=config.uploader.dbuser) |
39 | - script.lock_and_run() |
40 | |
41 | === modified file 'lib/lp/soyuz/doc/package-diff.txt' |
42 | --- lib/lp/soyuz/doc/package-diff.txt 2013-01-08 07:54:50 +0000 |
43 | +++ lib/lp/soyuz/doc/package-diff.txt 2013-07-31 00:41:29 +0000 |
44 | @@ -117,8 +117,7 @@ |
45 | Before starting let's enable the universe component and add the i386 |
46 | chroot in hoary in order to be able to accept the NEW packages. |
47 | |
48 | - >>> from lp.soyuz.model.component import ( |
49 | - ... ComponentSelection) |
50 | + >>> from lp.soyuz.model.component import ComponentSelection |
51 | >>> from lp.services.librarian.model import LibraryFileAlias |
52 | >>> from lp.soyuz.interfaces.component import IComponentSet |
53 | |
54 | @@ -154,8 +153,7 @@ |
55 | |
56 | >>> packager.buildUpstream() |
57 | >>> packager.buildSource(signed=False) |
58 | - >>> biscuit_one_pub = packager.uploadSourceVersion( |
59 | - ... '1.0-1', policy='sync') |
60 | + >>> biscuit_one_pub = packager.uploadSourceVersion('1.0-1', policy='sync') |
61 | |
62 | >>> len(biscuit_one_pub.sourcepackagerelease.package_diffs) |
63 | 0 |
64 | @@ -436,29 +434,6 @@ |
65 | biscuit diff from 1.0-1 to 1.0-8 True -6 |
66 | pmount diff from 0.1-1 to 0.1-2 False -7 |
67 | |
68 | -Or only the PackageDiffs not yet fullfilled. |
69 | - |
70 | - >>> print_diffs(packagediff_set.getPendingDiffs()) |
71 | - pmount diff from 0.1-1 to 0.1-2 False 0 |
72 | - biscuit diff from 1.0-8 to 1.0-9 False 2 |
73 | - biscuit diff from 1.0-8 to 1.0-12 False 3 |
74 | - biscuit diff from 1.0-9 to 1.0-10 False 4 |
75 | - biscuit diff from 1.0-8 to 1.0-11 False 5 |
76 | - biscuit diff from 1.0-8 (in Ubuntu) to 1.0-2 False 6 |
77 | - biscuit diff from 1.0-2 to 1.0-3 False 7 |
78 | - |
79 | -Note that the iteration over all PackageDiffs is sorted by descending |
80 | -database ID, i.e. newest first, and getPendingDiffs() results are |
81 | -ordered by ascending database IDs, oldest first. |
82 | - |
83 | -getPendingDiffs() results can optionally be limited. |
84 | - |
85 | - >>> packagediff_set.getPendingDiffs().count() |
86 | - 7 |
87 | - |
88 | - >>> packagediff_set.getPendingDiffs(limit=2).count() |
89 | - 2 |
90 | - |
91 | All package diffs targeting a set of source package releases can also |
92 | be requested. The results are ordered by the source package release |
93 | ID: |
94 | |
95 | === modified file 'lib/lp/soyuz/interfaces/packagediff.py' |
96 | --- lib/lp/soyuz/interfaces/packagediff.py 2013-01-07 02:40:55 +0000 |
97 | +++ lib/lp/soyuz/interfaces/packagediff.py 2013-07-31 00:41:29 +0000 |
98 | @@ -92,14 +92,6 @@ |
99 | def get(diff_id): |
100 | """Retrieve a `PackageDiff` for the given id.""" |
101 | |
102 | - def getPendingDiffs(limit=None): |
103 | - """Return all pending `PackageDiff` records. |
104 | - |
105 | - :param limit: optional results limitation. |
106 | - |
107 | - :return a `SelectResult` ordered by id respecting the given limit. |
108 | - """ |
109 | - |
110 | def getDiffsToReleases(sprs, preload_for_display=False): |
111 | """Return all diffs that targetting a set of source package releases. |
112 | |
113 | |
114 | === modified file 'lib/lp/soyuz/model/packagediff.py' |
115 | --- lib/lp/soyuz/model/packagediff.py 2013-07-25 12:39:54 +0000 |
116 | +++ lib/lp/soyuz/model/packagediff.py 2013-07-31 00:41:29 +0000 |
117 | @@ -264,12 +264,6 @@ |
118 | """See `IPackageDiffSet`.""" |
119 | return PackageDiff.get(diff_id) |
120 | |
121 | - def getPendingDiffs(self, limit=None): |
122 | - return IStore(PackageDiff).find( |
123 | - PackageDiff, |
124 | - PackageDiff.status == PackageDiffStatus.PENDING).order_by( |
125 | - PackageDiff.id).config(limit=limit) |
126 | - |
127 | def getDiffsToReleases(self, sprs, preload_for_display=False): |
128 | """See `IPackageDiffSet`.""" |
129 | from lp.registry.model.distribution import Distribution |
130 | |
131 | === removed file 'lib/lp/soyuz/scripts/packagediff.py' |
132 | --- lib/lp/soyuz/scripts/packagediff.py 2010-08-20 20:31:18 +0000 |
133 | +++ lib/lp/soyuz/scripts/packagediff.py 1970-01-01 00:00:00 +0000 |
134 | @@ -1,62 +0,0 @@ |
135 | -# Copyright 2009 Canonical Ltd. This software is licensed under the |
136 | -# GNU Affero General Public License version 3 (see the file LICENSE). |
137 | - |
138 | -"""PackageDiff cronscript class.""" |
139 | - |
140 | -__metaclass__ = type |
141 | - |
142 | -__all__ = [ |
143 | - 'ProcessPendingPackageDiffs', |
144 | - ] |
145 | - |
146 | -from zope.component import getUtility |
147 | - |
148 | -from lp.services.scripts.base import ( |
149 | - LaunchpadCronScript, |
150 | - LaunchpadScriptFailure, |
151 | - ) |
152 | -from lp.soyuz.interfaces.packagediff import IPackageDiffSet |
153 | - |
154 | - |
155 | -class ProcessPendingPackageDiffs(LaunchpadCronScript): |
156 | - |
157 | - def add_my_options(self): |
158 | - # 50 diffs seems to be more them enough to process all uploaded |
159 | - # source packages for 1 hour (average upload rate) for ubuntu |
160 | - # primary archive, security and PPAs in general. |
161 | - self.parser.add_option( |
162 | - "-l", "--limit", type="int", default=50, |
163 | - help="Maximum number of requests to be processed in this run.") |
164 | - |
165 | - self.parser.add_option( |
166 | - "-n", "--dry-run", |
167 | - dest="dryrun", action="store_true", default=False, |
168 | - help="Whether or not to commit the transaction.") |
169 | - |
170 | - def main(self): |
171 | - """Process pending `PackageDiff` records. |
172 | - |
173 | - Collect up to the maximum number of pending `PackageDiff` records |
174 | - available and process them. |
175 | - |
176 | - Processed diffs results are commited individually. |
177 | - """ |
178 | - if self.args: |
179 | - raise LaunchpadScriptFailure("Unhandled arguments %r" % self.args) |
180 | - |
181 | - packagediff_set = getUtility(IPackageDiffSet) |
182 | - |
183 | - pending_diffs = packagediff_set.getPendingDiffs( |
184 | - limit=self.options.limit) |
185 | - self.logger.debug( |
186 | - 'Considering %s diff requests' % pending_diffs.count()) |
187 | - |
188 | - # Iterate over all pending packagediffs. |
189 | - for packagediff in pending_diffs: |
190 | - self.logger.debug( |
191 | - 'Performing package diff for %s from %s' % ( |
192 | - packagediff.from_source.name, packagediff.title)) |
193 | - packagediff.performDiff() |
194 | - if not self.options.dryrun: |
195 | - self.logger.debug('Commiting the transaction.') |
196 | - self.txn.commit() |
197 | |
198 | === removed file 'lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py' |
199 | --- lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py 2012-01-01 02:58:52 +0000 |
200 | +++ lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py 1970-01-01 00:00:00 +0000 |
201 | @@ -1,106 +0,0 @@ |
202 | -# Copyright 2009-2010 Canonical Ltd. This software is licensed under the |
203 | -# GNU Affero General Public License version 3 (see the file LICENSE). |
204 | - |
205 | -__metaclass__ = type |
206 | - |
207 | -import os |
208 | -import subprocess |
209 | -import sys |
210 | - |
211 | -from lp.services.config import config |
212 | -from lp.services.log.logger import BufferLogger |
213 | -from lp.soyuz.scripts.packagediff import ProcessPendingPackageDiffs |
214 | -from lp.soyuz.tests.soyuz import TestPackageDiffsBase |
215 | -from lp.testing.layers import LaunchpadZopelessLayer |
216 | - |
217 | - |
218 | -class TestProcessPendingPackageDiffsScript(TestPackageDiffsBase): |
219 | - """Test the process-pending-packagediffs.py script.""" |
220 | - layer = LaunchpadZopelessLayer |
221 | - dbuser = config.uploader.dbuser |
222 | - |
223 | - def runProcessPendingPackageDiffs(self, extra_args=None): |
224 | - """Run process-pending-packagediffs.py. |
225 | - |
226 | - Returns a tuple of the process's return code, stdout output and |
227 | - stderr output.""" |
228 | - if extra_args is None: |
229 | - extra_args = [] |
230 | - script = os.path.join( |
231 | - config.root, "cronscripts", "process-pending-packagediffs.py") |
232 | - args = [sys.executable, script] |
233 | - args.extend(extra_args) |
234 | - process = subprocess.Popen( |
235 | - args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
236 | - stdout, stderr = process.communicate() |
237 | - return (process.returncode, stdout, stderr) |
238 | - |
239 | - def testSimpleScriptRun(self): |
240 | - """Try a simple processing-pending-packagediffs.py run.""" |
241 | - returncode, out, err = self.runProcessPendingPackageDiffs() |
242 | - if returncode != 0: |
243 | - print "\nStdout:\n%s\nStderr\n%s\n" % (out, err) |
244 | - self.assertEqual(0, returncode) |
245 | - |
246 | - self.layer.txn.abort() |
247 | - |
248 | - # The pending PackageDiff request was processed. |
249 | - self.assertEqual(self.getPendingDiffs().count(), 0) |
250 | - |
251 | - def getDiffProcessor(self, limit=None): |
252 | - """Return a `ProcessPendingPackageDiffs` instance. |
253 | - |
254 | - :param limit: if passed, it will be used as the 'limit' script |
255 | - argument. |
256 | - |
257 | - :return the initialized script object using `BufferLogger` and |
258 | - the given parameters. |
259 | - """ |
260 | - test_args = [] |
261 | - if limit is not None: |
262 | - test_args.append('-l %s' % limit) |
263 | - |
264 | - diff_processor = ProcessPendingPackageDiffs( |
265 | - name='process-pending-packagediffs', test_args=test_args) |
266 | - diff_processor.logger = BufferLogger() |
267 | - diff_processor.txn = self.layer.txn |
268 | - return diff_processor |
269 | - |
270 | - def testSimpleRun(self): |
271 | - """Simple run of the script class. |
272 | - |
273 | - The only diff available is processed after its run. |
274 | - """ |
275 | - # Setup a DiffProcessor. |
276 | - diff_processor = self.getDiffProcessor() |
277 | - diff_processor.main() |
278 | - |
279 | - # The pending PackageDiff request was processed. |
280 | - # See doc/package-diff.txt for more information. |
281 | - pending_diffs = self.getPendingDiffs() |
282 | - self.assertEqual(pending_diffs.count(), 0) |
283 | - |
284 | - def testLimitedRun(self): |
285 | - """Run the script with a limited scope. |
286 | - |
287 | - Check if a limited run of the script only processes up to 'limit' |
288 | - pending diff records and exits. |
289 | - """ |
290 | - # Setup a DiffProcessor limited to one request per run. |
291 | - diff_processor = self.getDiffProcessor(limit=1) |
292 | - |
293 | - # Upload a new source version, so we have two pending PackageDiff |
294 | - # records to process. |
295 | - self.packager.buildVersion('1.0-3', changelog_text="biscuits") |
296 | - self.packager.buildSource(include_orig=False) |
297 | - self.packager.uploadSourceVersion('1.0-3', suite="warty-updates") |
298 | - self.assertEqual(self.getPendingDiffs().count(), 2) |
299 | - |
300 | - # The first processor run will process only one PackageDiff, |
301 | - # the other will remain. |
302 | - diff_processor.main() |
303 | - self.assertEqual(self.getPendingDiffs().count(), 1) |
304 | - |
305 | - # The next run process the remaining one. |
306 | - diff_processor.main() |
307 | - self.assertEqual(self.getPendingDiffs().count(), 0) |
308 | |
309 | === modified file 'lib/lp/soyuz/stories/soyuz/xx-package-diff.txt' |
310 | --- lib/lp/soyuz/stories/soyuz/xx-package-diff.txt 2011-12-30 06:14:56 +0000 |
311 | +++ lib/lp/soyuz/stories/soyuz/xx-package-diff.txt 2013-07-31 00:41:29 +0000 |
312 | @@ -73,24 +73,13 @@ |
313 | >>> diff_one = biscuit_one_pub.sourcepackagerelease.requestDiffTo( |
314 | ... requester=name16, |
315 | ... to_sourcepackagerelease=biscuit_two_pub.sourcepackagerelease) |
316 | - |
317 | >>> diff_two = biscuit_two_pub.sourcepackagerelease.requestDiffTo( |
318 | ... requester=name16, |
319 | ... to_sourcepackagerelease=biscuit_three_pub.sourcepackagerelease) |
320 | - |
321 | >>> diff_three = biscuit_three_pub.sourcepackagerelease.requestDiffTo( |
322 | ... requester=name16, |
323 | ... to_sourcepackagerelease=biscuit_four_pub.sourcepackagerelease) |
324 | |
325 | - >>> from lp.soyuz.interfaces.packagediff import IPackageDiffSet |
326 | - >>> diff_set = getUtility(IPackageDiffSet) |
327 | - >>> diffs = list(diff_set.getPendingDiffs()) |
328 | - >>> for diff in diffs: |
329 | - ... print diff.title |
330 | - diff from 1.0-1 to 1.0-2 |
331 | - diff from 1.0-2 to 1.0-3 |
332 | - diff from 1.0-3 (in Ubuntu) to 1.0-4 |
333 | - |
334 | Perform some diffs in advance, the first diff in ubuntu and the diff |
335 | in PPA will be performed, the second diff in ubuntu will be performed |
336 | later. |
337 | @@ -166,9 +155,7 @@ |
338 | the missing link is rendered. |
339 | |
340 | >>> login('foo.bar@canonical.com') |
341 | - >>> diff_set = getUtility(IPackageDiffSet) |
342 | - >>> [diff] = diff_set.getPendingDiffs() |
343 | - >>> perform_fake_diff(diff, 'biscuit_1.0-2_1.0-3.diff.gz') |
344 | + >>> perform_fake_diff(diff_two, 'biscuit_1.0-2_1.0-3.diff.gz') |
345 | >>> transaction.commit() |
346 | >>> logout() |
347 | |
348 | |
349 | === modified file 'lib/lp/soyuz/tests/soyuz.py' |
350 | --- lib/lp/soyuz/tests/soyuz.py 2012-07-12 23:47:04 +0000 |
351 | +++ lib/lp/soyuz/tests/soyuz.py 2013-07-31 00:41:29 +0000 |
352 | @@ -7,36 +7,21 @@ |
353 | |
354 | __all__ = [ |
355 | 'SoyuzTestHelper', |
356 | - 'TestPackageDiffsBase', |
357 | ] |
358 | |
359 | -import unittest |
360 | - |
361 | from zope.component import getUtility |
362 | |
363 | from lp.registry.interfaces.distribution import IDistributionSet |
364 | from lp.registry.interfaces.person import IPersonSet |
365 | from lp.registry.interfaces.pocket import PackagePublishingPocket |
366 | -from lp.services.config import config |
367 | -from lp.services.librarian.model import LibraryFileAlias |
368 | from lp.soyuz.enums import PackagePublishingStatus |
369 | -from lp.soyuz.interfaces.packagediff import IPackageDiffSet |
370 | from lp.soyuz.model.publishing import ( |
371 | BinaryPackagePublishingHistory, |
372 | SourcePackagePublishingHistory, |
373 | ) |
374 | -from lp.soyuz.tests.fakepackager import FakePackager |
375 | -from lp.testing.dbuser import dbuser |
376 | -from lp.testing.gpgkeys import import_public_test_keys |
377 | -from lp.testing.layers import LaunchpadZopelessLayer |
378 | from lp.testing.sampledata import ( |
379 | BUILDD_ADMIN_USERNAME, |
380 | - CHROOT_LIBRARYFILEALIAS, |
381 | - I386_ARCHITECTURE_NAME, |
382 | - LAUNCHPAD_DBUSER_NAME, |
383 | UBUNTU_DISTRIBUTION_NAME, |
384 | - WARTY_DISTROSERIES_NAME, |
385 | - WARTY_UPDATES_SUITE_NAME, |
386 | ) |
387 | |
388 | |
389 | @@ -137,69 +122,3 @@ |
390 | Return True if the lists matches, otherwise False. |
391 | """ |
392 | return [p.id for p in expected] == [r.id for r in given] |
393 | - |
394 | - |
395 | -class TestPackageDiffsBase(unittest.TestCase): |
396 | - """Base class facilitating tests related to package diffs.""" |
397 | - layer = LaunchpadZopelessLayer |
398 | - dbuser = config.uploader.dbuser |
399 | - |
400 | - def setUp(self): |
401 | - """Setup proper DB connection and contents for tests |
402 | - |
403 | - Connect to the DB as the 'uploader' user (same user used in the |
404 | - script), upload the test packages (see `uploadTestPackages`) and |
405 | - commit the transaction. |
406 | - |
407 | - Store the `FakePackager` object used in the test uploads as `packager` |
408 | - so the tests can reuse it if necessary. |
409 | - """ |
410 | - super(TestPackageDiffsBase, self).setUp() |
411 | - with dbuser(LAUNCHPAD_DBUSER_NAME): |
412 | - fake_chroot = LibraryFileAlias.get(CHROOT_LIBRARYFILEALIAS) |
413 | - ubuntu = getUtility(IDistributionSet).getByName( |
414 | - UBUNTU_DISTRIBUTION_NAME) |
415 | - warty = ubuntu.getSeries(WARTY_DISTROSERIES_NAME) |
416 | - warty[I386_ARCHITECTURE_NAME].addOrUpdateChroot(fake_chroot) |
417 | - |
418 | - self.packager = self.uploadTestPackages() |
419 | - self.layer.txn.commit() |
420 | - |
421 | - def uploadTestPackages(self): |
422 | - """Upload packages for testing `PackageDiff` generation script. |
423 | - |
424 | - Upload zeca_1.0-1 and zeca_1.0-2 sources, so a `PackageDiff` between |
425 | - them is created. |
426 | - |
427 | - Assert there is not pending `PackageDiff` in the DB before uploading |
428 | - the package and also assert that there is one after the uploads. |
429 | - |
430 | - :return: the FakePackager object used to generate and upload the test, |
431 | - packages, so the tests can upload subsequent version if necessary. |
432 | - """ |
433 | - # No pending PackageDiff available in sampledata. |
434 | - self.assertEqual(self.getPendingDiffs().count(), 0) |
435 | - |
436 | - import_public_test_keys() |
437 | - # Use FakePackager to upload a base package to ubuntu. |
438 | - packager = FakePackager( |
439 | - 'zeca', '1.0', 'foo.bar@canonical.com-passwordless.sec') |
440 | - packager.buildUpstream() |
441 | - packager.buildSource() |
442 | - packager.uploadSourceVersion('1.0-1', suite=WARTY_UPDATES_SUITE_NAME) |
443 | - |
444 | - # Upload a new version of the source, so a PackageDiff can |
445 | - # be created. |
446 | - packager.buildVersion('1.0-2', changelog_text="cookies") |
447 | - packager.buildSource(include_orig=False) |
448 | - packager.uploadSourceVersion('1.0-2', suite=WARTY_UPDATES_SUITE_NAME) |
449 | - |
450 | - # Check if there is exactly one pending PackageDiff record and |
451 | - # It's the one we have just created. |
452 | - self.assertEqual(self.getPendingDiffs().count(), 1) |
453 | - |
454 | - return packager |
455 | - |
456 | - def getPendingDiffs(self): |
457 | - """Pending `PackageDiff` available.""" |
458 | - return getUtility(IPackageDiffSet).getPendingDiffs() |
459 | |
460 | === modified file 'lib/lp/soyuz/tests/test_packagediff.py' |
461 | --- lib/lp/soyuz/tests/test_packagediff.py 2013-07-23 17:57:52 +0000 |
462 | +++ lib/lp/soyuz/tests/test_packagediff.py 2013-07-31 00:41:29 +0000 |
463 | @@ -6,7 +6,9 @@ |
464 | __metaclass__ = type |
465 | |
466 | from datetime import datetime |
467 | +import os.path |
468 | |
469 | +import transaction |
470 | from zope.security.proxy import removeSecurityProxy |
471 | |
472 | from lp.services.config import config |
473 | @@ -16,13 +18,44 @@ |
474 | from lp.services.job.model.job import Job |
475 | from lp.soyuz.enums import PackageDiffStatus |
476 | from lp.soyuz.model.archive import Archive |
477 | -from lp.soyuz.tests.soyuz import TestPackageDiffsBase |
478 | from lp.testing import TestCaseWithFactory |
479 | from lp.testing.dbuser import dbuser |
480 | from lp.testing.layers import LaunchpadZopelessLayer |
481 | |
482 | |
483 | -class TestPackageDiffs(TestPackageDiffsBase, TestCaseWithFactory): |
484 | +def create_proper_job(factory): |
485 | + archive = factory.makeArchive() |
486 | + foo_dash1 = factory.makeSourcePackageRelease(archive=archive) |
487 | + foo_dash15 = factory.makeSourcePackageRelease(archive=archive) |
488 | + suite_dir = 'lib/lp/archiveuploader/tests/data/suite' |
489 | + files = { |
490 | + '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir: None, |
491 | + '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir: None, |
492 | + '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir: None, |
493 | + '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir: None, |
494 | + '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir: None} |
495 | + for name in files: |
496 | + filename = os.path.split(name)[-1] |
497 | + with open(name, 'r') as content: |
498 | + files[name] = factory.makeLibraryFileAlias( |
499 | + filename=filename, content=content.read()) |
500 | + transaction.commit() |
501 | + dash1_files = ( |
502 | + '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir, |
503 | + '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir, |
504 | + '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir) |
505 | + dash15_files = ( |
506 | + '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir, |
507 | + '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir, |
508 | + '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir) |
509 | + for name in dash1_files: |
510 | + foo_dash1.addFile(files[name]) |
511 | + for name in dash15_files: |
512 | + foo_dash15.addFile(files[name]) |
513 | + return foo_dash1.requestDiffTo(factory.makePerson(), foo_dash15) |
514 | + |
515 | + |
516 | +class TestPackageDiffs(TestCaseWithFactory): |
517 | """Test package diffs.""" |
518 | layer = LaunchpadZopelessLayer |
519 | dbuser = config.uploader.dbuser |
520 | @@ -30,7 +63,7 @@ |
521 | def test_packagediff_working(self): |
522 | # Test the case where none of the files required for the diff are |
523 | # expired in the librarian and where everything works as expected. |
524 | - [diff] = self.getPendingDiffs() |
525 | + diff = create_proper_job(self.factory) |
526 | self.assertEqual(0, removeSecurityProxy(diff)._countDeletedLFAs()) |
527 | diff.performDiff() |
528 | self.assertEqual(PackageDiffStatus.COMPLETED, diff.status) |
529 | @@ -39,11 +72,7 @@ |
530 | """Expire the files associated with the given source package in the |
531 | librarian.""" |
532 | assert expire or delete |
533 | - store = IStore(Archive) |
534 | - query = """ |
535 | - UPDATE LibraryFileAlias lfa |
536 | - SET |
537 | - """ |
538 | + query = "UPDATE LibraryFileAlias lfa SET " |
539 | if expire: |
540 | query += "expires = %s" % sqlvalues(datetime.utcnow()) |
541 | if expire and delete: |
542 | @@ -59,45 +88,36 @@ |
543 | AND sprf.libraryfile = lfa.id |
544 | """ % sqlvalues(source.id) |
545 | with dbuser('launchpad'): |
546 | - store.execute(query) |
547 | + IStore(Archive).execute(query) |
548 | |
549 | def test_packagediff_with_expired_and_deleted_lfas(self): |
550 | # Test the case where files required for the diff are expired *and* |
551 | # deleted in the librarian causing a package diff failure. |
552 | - [diff] = self.getPendingDiffs() |
553 | - # Expire and delete the files associated with the 'from_source' |
554 | - # package. |
555 | + diff = create_proper_job(self.factory) |
556 | self.expireLFAsForSource(diff.from_source) |
557 | - # The helper method now finds 3 expired files. |
558 | - self.assertEqual(3, removeSecurityProxy(diff)._countDeletedLFAs()) |
559 | + self.assertEqual(4, removeSecurityProxy(diff)._countDeletedLFAs()) |
560 | diff.performDiff() |
561 | - # The diff fails due to the presence of expired files. |
562 | self.assertEqual(PackageDiffStatus.FAILED, diff.status) |
563 | |
564 | def test_packagediff_with_expired_but_not_deleted_lfas(self): |
565 | # Test the case where files required for the diff are expired but |
566 | # not deleted in the librarian still allowing the package diff to be |
567 | # performed. |
568 | - [diff] = self.getPendingDiffs() |
569 | + diff = create_proper_job(self.factory) |
570 | # Expire but don't delete the files associated with the 'from_source' |
571 | # package. |
572 | self.expireLFAsForSource(diff.from_source, expire=True, delete=False) |
573 | - # The helper method now finds no expired files. |
574 | self.assertEqual(0, removeSecurityProxy(diff)._countDeletedLFAs()) |
575 | diff.performDiff() |
576 | - # The diff succeeds as expected. |
577 | self.assertEqual(PackageDiffStatus.COMPLETED, diff.status) |
578 | |
579 | def test_packagediff_with_deleted_but_not_expired_lfas(self): |
580 | # Test the case where files required for the diff have been |
581 | # deleted explicitly, not through expiry. |
582 | - [diff] = self.getPendingDiffs() |
583 | - # Delete the files associated with the 'from_source' package. |
584 | + diff = create_proper_job(self.factory) |
585 | self.expireLFAsForSource(diff.from_source, expire=False, delete=True) |
586 | - # The helper method now finds 3 expired files. |
587 | - self.assertEqual(3, removeSecurityProxy(diff)._countDeletedLFAs()) |
588 | + self.assertEqual(4, removeSecurityProxy(diff)._countDeletedLFAs()) |
589 | diff.performDiff() |
590 | - # The diff fails due to the presence of expired files. |
591 | self.assertEqual(PackageDiffStatus.FAILED, diff.status) |
592 | |
593 | def test_packagediff_private_with_copied_spr(self): |
594 | @@ -128,7 +148,11 @@ |
595 | self.assertFalse(diff.private) |
596 | |
597 | def test_job_created(self): |
598 | - # The setup code already creates a packagediff. |
599 | + # Requesting a package diff creates a PackageDiffJob. |
600 | + ppa = self.factory.makeArchive() |
601 | + from_spr = self.factory.makeSourcePackageRelease(archive=ppa) |
602 | + to_spr = self.factory.makeSourcePackageRelease(archive=ppa) |
603 | + from_spr.requestDiffTo(ppa.owner, to_spr) |
604 | [job] = IStore(Job).find( |
605 | Job, Job.base_job_type == JobType.GENERATE_PACKAGE_DIFF) |
606 | self.assertIsNot(None, job) |
607 | |
608 | === modified file 'lib/lp/soyuz/tests/test_packagediffjob.py' |
609 | --- lib/lp/soyuz/tests/test_packagediffjob.py 2013-07-23 17:57:52 +0000 |
610 | +++ lib/lp/soyuz/tests/test_packagediffjob.py 2013-07-31 00:41:29 +0000 |
611 | @@ -3,8 +3,6 @@ |
612 | |
613 | __metaclass__ = type |
614 | |
615 | -import os.path |
616 | - |
617 | from testtools.content import text_content |
618 | import transaction |
619 | from zope.component import getUtility |
620 | @@ -19,6 +17,7 @@ |
621 | IPackageDiffJobSource, |
622 | ) |
623 | from lp.soyuz.model.packagediffjob import PackageDiffJob |
624 | +from lp.soyuz.tests.test_packagediff import create_proper_job |
625 | from lp.services.features.testing import FeatureFixture |
626 | from lp.services.job.interfaces.job import JobStatus |
627 | from lp.testing import ( |
628 | @@ -34,38 +33,6 @@ |
629 | ) |
630 | |
631 | |
632 | -def create_proper_job(factory): |
633 | - archive = factory.makeArchive() |
634 | - foo_dash1 = factory.makeSourcePackageRelease(archive=archive) |
635 | - foo_dash15 = factory.makeSourcePackageRelease(archive=archive) |
636 | - suite_dir = 'lib/lp/archiveuploader/tests/data/suite' |
637 | - files = { |
638 | - '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir: None, |
639 | - '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir: None, |
640 | - '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir: None, |
641 | - '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir: None, |
642 | - '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir: None} |
643 | - for name in files: |
644 | - filename = os.path.split(name)[-1] |
645 | - with open(name, 'r') as content: |
646 | - files[name] = factory.makeLibraryFileAlias( |
647 | - filename=filename, content=content.read()) |
648 | - transaction.commit() |
649 | - dash1_files = ( |
650 | - '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir, |
651 | - '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir, |
652 | - '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir) |
653 | - dash15_files = ( |
654 | - '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir, |
655 | - '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir, |
656 | - '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir) |
657 | - for name in dash1_files: |
658 | - foo_dash1.addFile(files[name]) |
659 | - for name in dash15_files: |
660 | - foo_dash15.addFile(files[name]) |
661 | - return foo_dash1.requestDiffTo(factory.makePerson(), foo_dash15) |
662 | - |
663 | - |
664 | class TestPackageDiffJob(TestCaseWithFactory): |
665 | |
666 | layer = LaunchpadZopelessLayer |