Merge lp:~stevenk/launchpad/destroy-pppd into lp:launchpad

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
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+172945@code.launchpad.net

Commit message

Destroy the process-pending-packagediffs cronjob, its tests, the model code it used, and the horses they rode in on.

Description of the change

Destroy the process-pending-packagediffs cronjob and friends, now it is no longer needed due to the switch to the job system.

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
=== removed file 'cronscripts/process-pending-packagediffs.py'
--- cronscripts/process-pending-packagediffs.py 2013-01-07 02:40:55 +0000
+++ cronscripts/process-pending-packagediffs.py 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1#!/usr/bin/python -S
2#
3# Copyright 2009 Canonical Ltd. This software is licensed under the
4# GNU Affero General Public License version 3 (see the file LICENSE).
5
6"""Process pending PackageDiffs.
7
8Process a optionally limited set of pending PackageDiffs.
9
10By default it process up to 50 diffs each run, which is enough to catch
11up on 1 hour of uploads (on average).
12
13However users might benefit for more frequently runs since the diff ETA
14relative to the upload will be shorter.
15
16The cycle time needs to be balanced with the run time to produce the shortest
17diff ETA and to not overlap much, for instance, if it has to diff monster
18sources like openoffice or firefox.
19
20Experiments with the cycle time will be safe enough and won't sink the host
21performance, since the lock file is exclusive.
22"""
23
24__metaclass__ = type
25
26import _pythonpath
27
28from lp.services.config import config
29from lp.soyuz.scripts.packagediff import ProcessPendingPackageDiffs
30
31
32if __name__ == '__main__':
33 script = ProcessPendingPackageDiffs(
34 'process-pending-packagediffs', dbuser=config.uploader.dbuser)
35 script.lock_and_run()
360
=== modified file 'lib/lp/soyuz/doc/package-diff.txt'
--- lib/lp/soyuz/doc/package-diff.txt 2013-01-08 07:54:50 +0000
+++ lib/lp/soyuz/doc/package-diff.txt 2013-07-31 00:41:29 +0000
@@ -117,8 +117,7 @@
117Before starting let's enable the universe component and add the i386117Before starting let's enable the universe component and add the i386
118chroot in hoary in order to be able to accept the NEW packages.118chroot in hoary in order to be able to accept the NEW packages.
119119
120 >>> from lp.soyuz.model.component import (120 >>> from lp.soyuz.model.component import ComponentSelection
121 ... ComponentSelection)
122 >>> from lp.services.librarian.model import LibraryFileAlias121 >>> from lp.services.librarian.model import LibraryFileAlias
123 >>> from lp.soyuz.interfaces.component import IComponentSet122 >>> from lp.soyuz.interfaces.component import IComponentSet
124123
@@ -154,8 +153,7 @@
154153
155 >>> packager.buildUpstream()154 >>> packager.buildUpstream()
156 >>> packager.buildSource(signed=False)155 >>> packager.buildSource(signed=False)
157 >>> biscuit_one_pub = packager.uploadSourceVersion(156 >>> biscuit_one_pub = packager.uploadSourceVersion('1.0-1', policy='sync')
158 ... '1.0-1', policy='sync')
159157
160 >>> len(biscuit_one_pub.sourcepackagerelease.package_diffs)158 >>> len(biscuit_one_pub.sourcepackagerelease.package_diffs)
161 0159 0
@@ -436,29 +434,6 @@
436 biscuit diff from 1.0-1 to 1.0-8 True -6434 biscuit diff from 1.0-1 to 1.0-8 True -6
437 pmount diff from 0.1-1 to 0.1-2 False -7435 pmount diff from 0.1-1 to 0.1-2 False -7
438436
439Or only the PackageDiffs not yet fullfilled.
440
441 >>> print_diffs(packagediff_set.getPendingDiffs())
442 pmount diff from 0.1-1 to 0.1-2 False 0
443 biscuit diff from 1.0-8 to 1.0-9 False 2
444 biscuit diff from 1.0-8 to 1.0-12 False 3
445 biscuit diff from 1.0-9 to 1.0-10 False 4
446 biscuit diff from 1.0-8 to 1.0-11 False 5
447 biscuit diff from 1.0-8 (in Ubuntu) to 1.0-2 False 6
448 biscuit diff from 1.0-2 to 1.0-3 False 7
449
450Note that the iteration over all PackageDiffs is sorted by descending
451database ID, i.e. newest first, and getPendingDiffs() results are
452ordered by ascending database IDs, oldest first.
453
454getPendingDiffs() results can optionally be limited.
455
456 >>> packagediff_set.getPendingDiffs().count()
457 7
458
459 >>> packagediff_set.getPendingDiffs(limit=2).count()
460 2
461
462All package diffs targeting a set of source package releases can also437All package diffs targeting a set of source package releases can also
463be requested. The results are ordered by the source package release438be requested. The results are ordered by the source package release
464ID:439ID:
465440
=== modified file 'lib/lp/soyuz/interfaces/packagediff.py'
--- lib/lp/soyuz/interfaces/packagediff.py 2013-01-07 02:40:55 +0000
+++ lib/lp/soyuz/interfaces/packagediff.py 2013-07-31 00:41:29 +0000
@@ -92,14 +92,6 @@
92 def get(diff_id):92 def get(diff_id):
93 """Retrieve a `PackageDiff` for the given id."""93 """Retrieve a `PackageDiff` for the given id."""
9494
95 def getPendingDiffs(limit=None):
96 """Return all pending `PackageDiff` records.
97
98 :param limit: optional results limitation.
99
100 :return a `SelectResult` ordered by id respecting the given limit.
101 """
102
103 def getDiffsToReleases(sprs, preload_for_display=False):95 def getDiffsToReleases(sprs, preload_for_display=False):
104 """Return all diffs that targetting a set of source package releases.96 """Return all diffs that targetting a set of source package releases.
10597
10698
=== modified file 'lib/lp/soyuz/model/packagediff.py'
--- lib/lp/soyuz/model/packagediff.py 2013-07-25 12:39:54 +0000
+++ lib/lp/soyuz/model/packagediff.py 2013-07-31 00:41:29 +0000
@@ -264,12 +264,6 @@
264 """See `IPackageDiffSet`."""264 """See `IPackageDiffSet`."""
265 return PackageDiff.get(diff_id)265 return PackageDiff.get(diff_id)
266266
267 def getPendingDiffs(self, limit=None):
268 return IStore(PackageDiff).find(
269 PackageDiff,
270 PackageDiff.status == PackageDiffStatus.PENDING).order_by(
271 PackageDiff.id).config(limit=limit)
272
273 def getDiffsToReleases(self, sprs, preload_for_display=False):267 def getDiffsToReleases(self, sprs, preload_for_display=False):
274 """See `IPackageDiffSet`."""268 """See `IPackageDiffSet`."""
275 from lp.registry.model.distribution import Distribution269 from lp.registry.model.distribution import Distribution
276270
=== removed file 'lib/lp/soyuz/scripts/packagediff.py'
--- lib/lp/soyuz/scripts/packagediff.py 2010-08-20 20:31:18 +0000
+++ lib/lp/soyuz/scripts/packagediff.py 1970-01-01 00:00:00 +0000
@@ -1,62 +0,0 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""PackageDiff cronscript class."""
5
6__metaclass__ = type
7
8__all__ = [
9 'ProcessPendingPackageDiffs',
10 ]
11
12from zope.component import getUtility
13
14from lp.services.scripts.base import (
15 LaunchpadCronScript,
16 LaunchpadScriptFailure,
17 )
18from lp.soyuz.interfaces.packagediff import IPackageDiffSet
19
20
21class ProcessPendingPackageDiffs(LaunchpadCronScript):
22
23 def add_my_options(self):
24 # 50 diffs seems to be more them enough to process all uploaded
25 # source packages for 1 hour (average upload rate) for ubuntu
26 # primary archive, security and PPAs in general.
27 self.parser.add_option(
28 "-l", "--limit", type="int", default=50,
29 help="Maximum number of requests to be processed in this run.")
30
31 self.parser.add_option(
32 "-n", "--dry-run",
33 dest="dryrun", action="store_true", default=False,
34 help="Whether or not to commit the transaction.")
35
36 def main(self):
37 """Process pending `PackageDiff` records.
38
39 Collect up to the maximum number of pending `PackageDiff` records
40 available and process them.
41
42 Processed diffs results are commited individually.
43 """
44 if self.args:
45 raise LaunchpadScriptFailure("Unhandled arguments %r" % self.args)
46
47 packagediff_set = getUtility(IPackageDiffSet)
48
49 pending_diffs = packagediff_set.getPendingDiffs(
50 limit=self.options.limit)
51 self.logger.debug(
52 'Considering %s diff requests' % pending_diffs.count())
53
54 # Iterate over all pending packagediffs.
55 for packagediff in pending_diffs:
56 self.logger.debug(
57 'Performing package diff for %s from %s' % (
58 packagediff.from_source.name, packagediff.title))
59 packagediff.performDiff()
60 if not self.options.dryrun:
61 self.logger.debug('Commiting the transaction.')
62 self.txn.commit()
630
=== removed file 'lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py'
--- lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py 2012-01-01 02:58:52 +0000
+++ lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py 1970-01-01 00:00:00 +0000
@@ -1,106 +0,0 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4__metaclass__ = type
5
6import os
7import subprocess
8import sys
9
10from lp.services.config import config
11from lp.services.log.logger import BufferLogger
12from lp.soyuz.scripts.packagediff import ProcessPendingPackageDiffs
13from lp.soyuz.tests.soyuz import TestPackageDiffsBase
14from lp.testing.layers import LaunchpadZopelessLayer
15
16
17class TestProcessPendingPackageDiffsScript(TestPackageDiffsBase):
18 """Test the process-pending-packagediffs.py script."""
19 layer = LaunchpadZopelessLayer
20 dbuser = config.uploader.dbuser
21
22 def runProcessPendingPackageDiffs(self, extra_args=None):
23 """Run process-pending-packagediffs.py.
24
25 Returns a tuple of the process's return code, stdout output and
26 stderr output."""
27 if extra_args is None:
28 extra_args = []
29 script = os.path.join(
30 config.root, "cronscripts", "process-pending-packagediffs.py")
31 args = [sys.executable, script]
32 args.extend(extra_args)
33 process = subprocess.Popen(
34 args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
35 stdout, stderr = process.communicate()
36 return (process.returncode, stdout, stderr)
37
38 def testSimpleScriptRun(self):
39 """Try a simple processing-pending-packagediffs.py run."""
40 returncode, out, err = self.runProcessPendingPackageDiffs()
41 if returncode != 0:
42 print "\nStdout:\n%s\nStderr\n%s\n" % (out, err)
43 self.assertEqual(0, returncode)
44
45 self.layer.txn.abort()
46
47 # The pending PackageDiff request was processed.
48 self.assertEqual(self.getPendingDiffs().count(), 0)
49
50 def getDiffProcessor(self, limit=None):
51 """Return a `ProcessPendingPackageDiffs` instance.
52
53 :param limit: if passed, it will be used as the 'limit' script
54 argument.
55
56 :return the initialized script object using `BufferLogger` and
57 the given parameters.
58 """
59 test_args = []
60 if limit is not None:
61 test_args.append('-l %s' % limit)
62
63 diff_processor = ProcessPendingPackageDiffs(
64 name='process-pending-packagediffs', test_args=test_args)
65 diff_processor.logger = BufferLogger()
66 diff_processor.txn = self.layer.txn
67 return diff_processor
68
69 def testSimpleRun(self):
70 """Simple run of the script class.
71
72 The only diff available is processed after its run.
73 """
74 # Setup a DiffProcessor.
75 diff_processor = self.getDiffProcessor()
76 diff_processor.main()
77
78 # The pending PackageDiff request was processed.
79 # See doc/package-diff.txt for more information.
80 pending_diffs = self.getPendingDiffs()
81 self.assertEqual(pending_diffs.count(), 0)
82
83 def testLimitedRun(self):
84 """Run the script with a limited scope.
85
86 Check if a limited run of the script only processes up to 'limit'
87 pending diff records and exits.
88 """
89 # Setup a DiffProcessor limited to one request per run.
90 diff_processor = self.getDiffProcessor(limit=1)
91
92 # Upload a new source version, so we have two pending PackageDiff
93 # records to process.
94 self.packager.buildVersion('1.0-3', changelog_text="biscuits")
95 self.packager.buildSource(include_orig=False)
96 self.packager.uploadSourceVersion('1.0-3', suite="warty-updates")
97 self.assertEqual(self.getPendingDiffs().count(), 2)
98
99 # The first processor run will process only one PackageDiff,
100 # the other will remain.
101 diff_processor.main()
102 self.assertEqual(self.getPendingDiffs().count(), 1)
103
104 # The next run process the remaining one.
105 diff_processor.main()
106 self.assertEqual(self.getPendingDiffs().count(), 0)
1070
=== modified file 'lib/lp/soyuz/stories/soyuz/xx-package-diff.txt'
--- lib/lp/soyuz/stories/soyuz/xx-package-diff.txt 2011-12-30 06:14:56 +0000
+++ lib/lp/soyuz/stories/soyuz/xx-package-diff.txt 2013-07-31 00:41:29 +0000
@@ -73,24 +73,13 @@
73 >>> diff_one = biscuit_one_pub.sourcepackagerelease.requestDiffTo(73 >>> diff_one = biscuit_one_pub.sourcepackagerelease.requestDiffTo(
74 ... requester=name16,74 ... requester=name16,
75 ... to_sourcepackagerelease=biscuit_two_pub.sourcepackagerelease)75 ... to_sourcepackagerelease=biscuit_two_pub.sourcepackagerelease)
76
77 >>> diff_two = biscuit_two_pub.sourcepackagerelease.requestDiffTo(76 >>> diff_two = biscuit_two_pub.sourcepackagerelease.requestDiffTo(
78 ... requester=name16,77 ... requester=name16,
79 ... to_sourcepackagerelease=biscuit_three_pub.sourcepackagerelease)78 ... to_sourcepackagerelease=biscuit_three_pub.sourcepackagerelease)
80
81 >>> diff_three = biscuit_three_pub.sourcepackagerelease.requestDiffTo(79 >>> diff_three = biscuit_three_pub.sourcepackagerelease.requestDiffTo(
82 ... requester=name16,80 ... requester=name16,
83 ... to_sourcepackagerelease=biscuit_four_pub.sourcepackagerelease)81 ... to_sourcepackagerelease=biscuit_four_pub.sourcepackagerelease)
8482
85 >>> from lp.soyuz.interfaces.packagediff import IPackageDiffSet
86 >>> diff_set = getUtility(IPackageDiffSet)
87 >>> diffs = list(diff_set.getPendingDiffs())
88 >>> for diff in diffs:
89 ... print diff.title
90 diff from 1.0-1 to 1.0-2
91 diff from 1.0-2 to 1.0-3
92 diff from 1.0-3 (in Ubuntu) to 1.0-4
93
94Perform some diffs in advance, the first diff in ubuntu and the diff83Perform some diffs in advance, the first diff in ubuntu and the diff
95in PPA will be performed, the second diff in ubuntu will be performed84in PPA will be performed, the second diff in ubuntu will be performed
96later.85later.
@@ -166,9 +155,7 @@
166the missing link is rendered.155the missing link is rendered.
167156
168 >>> login('foo.bar@canonical.com')157 >>> login('foo.bar@canonical.com')
169 >>> diff_set = getUtility(IPackageDiffSet)158 >>> perform_fake_diff(diff_two, 'biscuit_1.0-2_1.0-3.diff.gz')
170 >>> [diff] = diff_set.getPendingDiffs()
171 >>> perform_fake_diff(diff, 'biscuit_1.0-2_1.0-3.diff.gz')
172 >>> transaction.commit()159 >>> transaction.commit()
173 >>> logout()160 >>> logout()
174161
175162
=== modified file 'lib/lp/soyuz/tests/soyuz.py'
--- lib/lp/soyuz/tests/soyuz.py 2012-07-12 23:47:04 +0000
+++ lib/lp/soyuz/tests/soyuz.py 2013-07-31 00:41:29 +0000
@@ -7,36 +7,21 @@
77
8__all__ = [8__all__ = [
9 'SoyuzTestHelper',9 'SoyuzTestHelper',
10 'TestPackageDiffsBase',
11 ]10 ]
1211
13import unittest
14
15from zope.component import getUtility12from zope.component import getUtility
1613
17from lp.registry.interfaces.distribution import IDistributionSet14from lp.registry.interfaces.distribution import IDistributionSet
18from lp.registry.interfaces.person import IPersonSet15from lp.registry.interfaces.person import IPersonSet
19from lp.registry.interfaces.pocket import PackagePublishingPocket16from lp.registry.interfaces.pocket import PackagePublishingPocket
20from lp.services.config import config
21from lp.services.librarian.model import LibraryFileAlias
22from lp.soyuz.enums import PackagePublishingStatus17from lp.soyuz.enums import PackagePublishingStatus
23from lp.soyuz.interfaces.packagediff import IPackageDiffSet
24from lp.soyuz.model.publishing import (18from lp.soyuz.model.publishing import (
25 BinaryPackagePublishingHistory,19 BinaryPackagePublishingHistory,
26 SourcePackagePublishingHistory,20 SourcePackagePublishingHistory,
27 )21 )
28from lp.soyuz.tests.fakepackager import FakePackager
29from lp.testing.dbuser import dbuser
30from lp.testing.gpgkeys import import_public_test_keys
31from lp.testing.layers import LaunchpadZopelessLayer
32from lp.testing.sampledata import (22from lp.testing.sampledata import (
33 BUILDD_ADMIN_USERNAME,23 BUILDD_ADMIN_USERNAME,
34 CHROOT_LIBRARYFILEALIAS,
35 I386_ARCHITECTURE_NAME,
36 LAUNCHPAD_DBUSER_NAME,
37 UBUNTU_DISTRIBUTION_NAME,24 UBUNTU_DISTRIBUTION_NAME,
38 WARTY_DISTROSERIES_NAME,
39 WARTY_UPDATES_SUITE_NAME,
40 )25 )
4126
4227
@@ -137,69 +122,3 @@
137 Return True if the lists matches, otherwise False.122 Return True if the lists matches, otherwise False.
138 """123 """
139 return [p.id for p in expected] == [r.id for r in given]124 return [p.id for p in expected] == [r.id for r in given]
140
141
142class TestPackageDiffsBase(unittest.TestCase):
143 """Base class facilitating tests related to package diffs."""
144 layer = LaunchpadZopelessLayer
145 dbuser = config.uploader.dbuser
146
147 def setUp(self):
148 """Setup proper DB connection and contents for tests
149
150 Connect to the DB as the 'uploader' user (same user used in the
151 script), upload the test packages (see `uploadTestPackages`) and
152 commit the transaction.
153
154 Store the `FakePackager` object used in the test uploads as `packager`
155 so the tests can reuse it if necessary.
156 """
157 super(TestPackageDiffsBase, self).setUp()
158 with dbuser(LAUNCHPAD_DBUSER_NAME):
159 fake_chroot = LibraryFileAlias.get(CHROOT_LIBRARYFILEALIAS)
160 ubuntu = getUtility(IDistributionSet).getByName(
161 UBUNTU_DISTRIBUTION_NAME)
162 warty = ubuntu.getSeries(WARTY_DISTROSERIES_NAME)
163 warty[I386_ARCHITECTURE_NAME].addOrUpdateChroot(fake_chroot)
164
165 self.packager = self.uploadTestPackages()
166 self.layer.txn.commit()
167
168 def uploadTestPackages(self):
169 """Upload packages for testing `PackageDiff` generation script.
170
171 Upload zeca_1.0-1 and zeca_1.0-2 sources, so a `PackageDiff` between
172 them is created.
173
174 Assert there is not pending `PackageDiff` in the DB before uploading
175 the package and also assert that there is one after the uploads.
176
177 :return: the FakePackager object used to generate and upload the test,
178 packages, so the tests can upload subsequent version if necessary.
179 """
180 # No pending PackageDiff available in sampledata.
181 self.assertEqual(self.getPendingDiffs().count(), 0)
182
183 import_public_test_keys()
184 # Use FakePackager to upload a base package to ubuntu.
185 packager = FakePackager(
186 'zeca', '1.0', 'foo.bar@canonical.com-passwordless.sec')
187 packager.buildUpstream()
188 packager.buildSource()
189 packager.uploadSourceVersion('1.0-1', suite=WARTY_UPDATES_SUITE_NAME)
190
191 # Upload a new version of the source, so a PackageDiff can
192 # be created.
193 packager.buildVersion('1.0-2', changelog_text="cookies")
194 packager.buildSource(include_orig=False)
195 packager.uploadSourceVersion('1.0-2', suite=WARTY_UPDATES_SUITE_NAME)
196
197 # Check if there is exactly one pending PackageDiff record and
198 # It's the one we have just created.
199 self.assertEqual(self.getPendingDiffs().count(), 1)
200
201 return packager
202
203 def getPendingDiffs(self):
204 """Pending `PackageDiff` available."""
205 return getUtility(IPackageDiffSet).getPendingDiffs()
206125
=== modified file 'lib/lp/soyuz/tests/test_packagediff.py'
--- lib/lp/soyuz/tests/test_packagediff.py 2013-07-23 17:57:52 +0000
+++ lib/lp/soyuz/tests/test_packagediff.py 2013-07-31 00:41:29 +0000
@@ -6,7 +6,9 @@
6__metaclass__ = type6__metaclass__ = type
77
8from datetime import datetime8from datetime import datetime
9import os.path
910
11import transaction
10from zope.security.proxy import removeSecurityProxy12from zope.security.proxy import removeSecurityProxy
1113
12from lp.services.config import config14from lp.services.config import config
@@ -16,13 +18,44 @@
16from lp.services.job.model.job import Job18from lp.services.job.model.job import Job
17from lp.soyuz.enums import PackageDiffStatus19from lp.soyuz.enums import PackageDiffStatus
18from lp.soyuz.model.archive import Archive20from lp.soyuz.model.archive import Archive
19from lp.soyuz.tests.soyuz import TestPackageDiffsBase
20from lp.testing import TestCaseWithFactory21from lp.testing import TestCaseWithFactory
21from lp.testing.dbuser import dbuser22from lp.testing.dbuser import dbuser
22from lp.testing.layers import LaunchpadZopelessLayer23from lp.testing.layers import LaunchpadZopelessLayer
2324
2425
25class TestPackageDiffs(TestPackageDiffsBase, TestCaseWithFactory):26def create_proper_job(factory):
27 archive = factory.makeArchive()
28 foo_dash1 = factory.makeSourcePackageRelease(archive=archive)
29 foo_dash15 = factory.makeSourcePackageRelease(archive=archive)
30 suite_dir = 'lib/lp/archiveuploader/tests/data/suite'
31 files = {
32 '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir: None,
33 '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir: None,
34 '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir: None,
35 '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir: None,
36 '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir: None}
37 for name in files:
38 filename = os.path.split(name)[-1]
39 with open(name, 'r') as content:
40 files[name] = factory.makeLibraryFileAlias(
41 filename=filename, content=content.read())
42 transaction.commit()
43 dash1_files = (
44 '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir,
45 '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir,
46 '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir)
47 dash15_files = (
48 '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir,
49 '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir,
50 '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir)
51 for name in dash1_files:
52 foo_dash1.addFile(files[name])
53 for name in dash15_files:
54 foo_dash15.addFile(files[name])
55 return foo_dash1.requestDiffTo(factory.makePerson(), foo_dash15)
56
57
58class TestPackageDiffs(TestCaseWithFactory):
26 """Test package diffs."""59 """Test package diffs."""
27 layer = LaunchpadZopelessLayer60 layer = LaunchpadZopelessLayer
28 dbuser = config.uploader.dbuser61 dbuser = config.uploader.dbuser
@@ -30,7 +63,7 @@
30 def test_packagediff_working(self):63 def test_packagediff_working(self):
31 # Test the case where none of the files required for the diff are64 # Test the case where none of the files required for the diff are
32 # expired in the librarian and where everything works as expected.65 # expired in the librarian and where everything works as expected.
33 [diff] = self.getPendingDiffs()66 diff = create_proper_job(self.factory)
34 self.assertEqual(0, removeSecurityProxy(diff)._countDeletedLFAs())67 self.assertEqual(0, removeSecurityProxy(diff)._countDeletedLFAs())
35 diff.performDiff()68 diff.performDiff()
36 self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)69 self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)
@@ -39,11 +72,7 @@
39 """Expire the files associated with the given source package in the72 """Expire the files associated with the given source package in the
40 librarian."""73 librarian."""
41 assert expire or delete74 assert expire or delete
42 store = IStore(Archive)75 query = "UPDATE LibraryFileAlias lfa SET "
43 query = """
44 UPDATE LibraryFileAlias lfa
45 SET
46 """
47 if expire:76 if expire:
48 query += "expires = %s" % sqlvalues(datetime.utcnow())77 query += "expires = %s" % sqlvalues(datetime.utcnow())
49 if expire and delete:78 if expire and delete:
@@ -59,45 +88,36 @@
59 AND sprf.libraryfile = lfa.id88 AND sprf.libraryfile = lfa.id
60 """ % sqlvalues(source.id)89 """ % sqlvalues(source.id)
61 with dbuser('launchpad'):90 with dbuser('launchpad'):
62 store.execute(query)91 IStore(Archive).execute(query)
6392
64 def test_packagediff_with_expired_and_deleted_lfas(self):93 def test_packagediff_with_expired_and_deleted_lfas(self):
65 # Test the case where files required for the diff are expired *and*94 # Test the case where files required for the diff are expired *and*
66 # deleted in the librarian causing a package diff failure.95 # deleted in the librarian causing a package diff failure.
67 [diff] = self.getPendingDiffs()96 diff = create_proper_job(self.factory)
68 # Expire and delete the files associated with the 'from_source'
69 # package.
70 self.expireLFAsForSource(diff.from_source)97 self.expireLFAsForSource(diff.from_source)
71 # The helper method now finds 3 expired files.98 self.assertEqual(4, removeSecurityProxy(diff)._countDeletedLFAs())
72 self.assertEqual(3, removeSecurityProxy(diff)._countDeletedLFAs())
73 diff.performDiff()99 diff.performDiff()
74 # The diff fails due to the presence of expired files.
75 self.assertEqual(PackageDiffStatus.FAILED, diff.status)100 self.assertEqual(PackageDiffStatus.FAILED, diff.status)
76101
77 def test_packagediff_with_expired_but_not_deleted_lfas(self):102 def test_packagediff_with_expired_but_not_deleted_lfas(self):
78 # Test the case where files required for the diff are expired but103 # Test the case where files required for the diff are expired but
79 # not deleted in the librarian still allowing the package diff to be104 # not deleted in the librarian still allowing the package diff to be
80 # performed.105 # performed.
81 [diff] = self.getPendingDiffs()106 diff = create_proper_job(self.factory)
82 # Expire but don't delete the files associated with the 'from_source'107 # Expire but don't delete the files associated with the 'from_source'
83 # package.108 # package.
84 self.expireLFAsForSource(diff.from_source, expire=True, delete=False)109 self.expireLFAsForSource(diff.from_source, expire=True, delete=False)
85 # The helper method now finds no expired files.
86 self.assertEqual(0, removeSecurityProxy(diff)._countDeletedLFAs())110 self.assertEqual(0, removeSecurityProxy(diff)._countDeletedLFAs())
87 diff.performDiff()111 diff.performDiff()
88 # The diff succeeds as expected.
89 self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)112 self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)
90113
91 def test_packagediff_with_deleted_but_not_expired_lfas(self):114 def test_packagediff_with_deleted_but_not_expired_lfas(self):
92 # Test the case where files required for the diff have been115 # Test the case where files required for the diff have been
93 # deleted explicitly, not through expiry.116 # deleted explicitly, not through expiry.
94 [diff] = self.getPendingDiffs()117 diff = create_proper_job(self.factory)
95 # Delete the files associated with the 'from_source' package.
96 self.expireLFAsForSource(diff.from_source, expire=False, delete=True)118 self.expireLFAsForSource(diff.from_source, expire=False, delete=True)
97 # The helper method now finds 3 expired files.119 self.assertEqual(4, removeSecurityProxy(diff)._countDeletedLFAs())
98 self.assertEqual(3, removeSecurityProxy(diff)._countDeletedLFAs())
99 diff.performDiff()120 diff.performDiff()
100 # The diff fails due to the presence of expired files.
101 self.assertEqual(PackageDiffStatus.FAILED, diff.status)121 self.assertEqual(PackageDiffStatus.FAILED, diff.status)
102122
103 def test_packagediff_private_with_copied_spr(self):123 def test_packagediff_private_with_copied_spr(self):
@@ -128,7 +148,11 @@
128 self.assertFalse(diff.private)148 self.assertFalse(diff.private)
129149
130 def test_job_created(self):150 def test_job_created(self):
131 # The setup code already creates a packagediff.151 # Requesting a package diff creates a PackageDiffJob.
152 ppa = self.factory.makeArchive()
153 from_spr = self.factory.makeSourcePackageRelease(archive=ppa)
154 to_spr = self.factory.makeSourcePackageRelease(archive=ppa)
155 from_spr.requestDiffTo(ppa.owner, to_spr)
132 [job] = IStore(Job).find(156 [job] = IStore(Job).find(
133 Job, Job.base_job_type == JobType.GENERATE_PACKAGE_DIFF)157 Job, Job.base_job_type == JobType.GENERATE_PACKAGE_DIFF)
134 self.assertIsNot(None, job)158 self.assertIsNot(None, job)
135159
=== modified file 'lib/lp/soyuz/tests/test_packagediffjob.py'
--- lib/lp/soyuz/tests/test_packagediffjob.py 2013-07-23 17:57:52 +0000
+++ lib/lp/soyuz/tests/test_packagediffjob.py 2013-07-31 00:41:29 +0000
@@ -3,8 +3,6 @@
33
4__metaclass__ = type4__metaclass__ = type
55
6import os.path
7
8from testtools.content import text_content6from testtools.content import text_content
9import transaction7import transaction
10from zope.component import getUtility8from zope.component import getUtility
@@ -19,6 +17,7 @@
19 IPackageDiffJobSource,17 IPackageDiffJobSource,
20 )18 )
21from lp.soyuz.model.packagediffjob import PackageDiffJob19from lp.soyuz.model.packagediffjob import PackageDiffJob
20from lp.soyuz.tests.test_packagediff import create_proper_job
22from lp.services.features.testing import FeatureFixture21from lp.services.features.testing import FeatureFixture
23from lp.services.job.interfaces.job import JobStatus22from lp.services.job.interfaces.job import JobStatus
24from lp.testing import (23from lp.testing import (
@@ -34,38 +33,6 @@
34 )33 )
3534
3635
37def create_proper_job(factory):
38 archive = factory.makeArchive()
39 foo_dash1 = factory.makeSourcePackageRelease(archive=archive)
40 foo_dash15 = factory.makeSourcePackageRelease(archive=archive)
41 suite_dir = 'lib/lp/archiveuploader/tests/data/suite'
42 files = {
43 '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir: None,
44 '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir: None,
45 '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir: None,
46 '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir: None,
47 '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir: None}
48 for name in files:
49 filename = os.path.split(name)[-1]
50 with open(name, 'r') as content:
51 files[name] = factory.makeLibraryFileAlias(
52 filename=filename, content=content.read())
53 transaction.commit()
54 dash1_files = (
55 '%s/foo_1.0-1/foo_1.0-1.diff.gz' % suite_dir,
56 '%s/foo_1.0-1/foo_1.0-1.dsc' % suite_dir,
57 '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir)
58 dash15_files = (
59 '%s/foo_1.0-1/foo_1.0.orig.tar.gz' % suite_dir,
60 '%s/foo_1.0-1.5/foo_1.0-1.5.diff.gz' % suite_dir,
61 '%s/foo_1.0-1.5/foo_1.0-1.5.dsc' % suite_dir)
62 for name in dash1_files:
63 foo_dash1.addFile(files[name])
64 for name in dash15_files:
65 foo_dash15.addFile(files[name])
66 return foo_dash1.requestDiffTo(factory.makePerson(), foo_dash15)
67
68
69class TestPackageDiffJob(TestCaseWithFactory):36class TestPackageDiffJob(TestCaseWithFactory):
7037
71 layer = LaunchpadZopelessLayer38 layer = LaunchpadZopelessLayer