Merge lp:~mwhudson/launchpad/remove-old-puller-xmlrpc-methods into lp:launchpad

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~mwhudson/launchpad/remove-old-puller-xmlrpc-methods
Merge into: lp:launchpad
Diff against target: 448 lines (+2/-306)
8 files modified
lib/lp/code/doc/xmlrpc-branch-puller.txt (+1/-16)
lib/lp/code/interfaces/branchpuller.py (+0/-6)
lib/lp/code/interfaces/codehosting.py (+0/-14)
lib/lp/code/model/branchpuller.py (+0/-22)
lib/lp/code/model/tests/test_branchpuller.py (+0/-82)
lib/lp/code/xmlrpc/codehosting.py (+1/-43)
lib/lp/code/xmlrpc/tests/test_codehosting.py (+0/-100)
lib/lp/codehosting/inmemory.py (+0/-23)
To merge this branch: bzr merge lp:~mwhudson/launchpad/remove-old-puller-xmlrpc-methods
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+20024@code.launchpad.net

Commit message

Remove some code to do with the 'old' way of scheduling branch pulling.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Just deleting some code we don't use any more.

Revision history for this message
Tim Penhey (thumper) wrote :

  merge approved

Yay for obsolete code removal.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/doc/xmlrpc-branch-puller.txt'
--- lib/lp/code/doc/xmlrpc-branch-puller.txt 2009-10-22 11:55:51 +0000
+++ lib/lp/code/doc/xmlrpc-branch-puller.txt 2010-02-24 02:03:16 +0000
@@ -28,19 +28,4 @@
28 True28 True
2929
30The IBranchPuller interface defines some methods, for which see the unit30The IBranchPuller interface defines some methods, for which see the unit
31tests. To allow a minimal test here, we call getBranchPullQueue,31tests.
32which will return an empty list.
33
34 >>> from lp.code.enums import BranchType
35 >>> branch_puller.getBranchPullQueue(BranchType.HOSTED.name)
36 []
37
38This remains true when it is accessed over XMLRPC.
39
40 >>> import xmlrpclib
41 >>> from canonical.functional import XMLRPCTestTransport
42 >>> puller = xmlrpclib.ServerProxy(
43 ... 'http://xmlrpc-private.launchpad.dev:8087/branch_puller',
44 ... transport=XMLRPCTestTransport())
45 >>> puller.getBranchPullQueue(BranchType.HOSTED.name)
46 []
4732
=== modified file 'lib/lp/code/interfaces/branchpuller.py'
--- lib/lp/code/interfaces/branchpuller.py 2009-06-30 16:56:07 +0000
+++ lib/lp/code/interfaces/branchpuller.py 2010-02-24 02:03:16 +0000
@@ -23,12 +23,6 @@
23 MIRROR_TIME_INCREMENT = Attribute(23 MIRROR_TIME_INCREMENT = Attribute(
24 "How frequently we mirror branches.")24 "How frequently we mirror branches.")
2525
26 def getPullQueue(branch_type):
27 """Return a queue of branches to mirror using the puller.
28
29 :param branch_type: A value from the `BranchType` enum.
30 """
31
32 def acquireBranchToPull():26 def acquireBranchToPull():
33 """Return a Branch to pull and mark it as mirror-started.27 """Return a Branch to pull and mark it as mirror-started.
3428
3529
=== modified file 'lib/lp/code/interfaces/codehosting.py'
--- lib/lp/code/interfaces/codehosting.py 2009-06-25 04:06:00 +0000
+++ lib/lp/code/interfaces/codehosting.py 2010-02-24 02:03:16 +0000
@@ -58,20 +58,6 @@
58 Published at 'branch_puller' on the private XML-RPC server.58 Published at 'branch_puller' on the private XML-RPC server.
59 """59 """
6060
61 def getBranchPullQueue(branch_type):
62 """Get the list of branches to be mirrored.
63
64 :param branch_type: One of 'HOSTED', 'MIRRORED', or 'IMPORTED'.
65
66 :raise UnknownBranchTypeError: if the branch type is unrecognized.
67
68 :returns: a list of (branch_id, pull_url, unique_name, default_branch)
69 4-tuples. branch_id is the database id of the branch, pull_url is
70 where to pull from, unique_name is the unique_name of the branch
71 and default_branch is the default stacked on branch for the
72 branch's target.
73 """
74
75 def acquireBranchToPull():61 def acquireBranchToPull():
76 """Return a Branch to pull and mark it as mirror-started.62 """Return a Branch to pull and mark it as mirror-started.
7763
7864
=== modified file 'lib/lp/code/model/branchpuller.py'
--- lib/lp/code/model/branchpuller.py 2009-08-04 05:14:32 +0000
+++ lib/lp/code/model/branchpuller.py 2010-02-24 02:03:16 +0000
@@ -9,17 +9,13 @@
99
10from datetime import timedelta10from datetime import timedelta
1111
12from storm.expr import LeftJoin, Join
13from zope.component import getUtility12from zope.component import getUtility
14from zope.interface import implements13from zope.interface import implements
1514
16from canonical.database.constants import UTC_NOW15from canonical.database.constants import UTC_NOW
17from lp.code.enums import BranchType16from lp.code.enums import BranchType
18from lp.code.model.branch import Branch17from lp.code.model.branch import Branch
19from lp.code.interfaces.branch import BranchTypeError
20from lp.code.interfaces.branchpuller import IBranchPuller18from lp.code.interfaces.branchpuller import IBranchPuller
21from lp.registry.model.person import Owner
22from lp.registry.model.product import Product
23from canonical.launchpad.webapp.interfaces import (19from canonical.launchpad.webapp.interfaces import (
24 IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)20 IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
2521
@@ -32,24 +28,6 @@
32 MAXIMUM_MIRROR_FAILURES = 528 MAXIMUM_MIRROR_FAILURES = 5
33 MIRROR_TIME_INCREMENT = timedelta(hours=6)29 MIRROR_TIME_INCREMENT = timedelta(hours=6)
3430
35 def getPullQueue(self, branch_type):
36 """See `IBranchPuller`."""
37 if branch_type == BranchType.REMOTE:
38 raise BranchTypeError("No pull queue for REMOTE branches.")
39 store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
40 # Prejoin on owner and product to preserve existing behaviour.
41 # XXX: JonathanLange 2009-03-22 spec=package-branches: This prejoin is
42 # inappropriate in the face of package branches.
43 prejoin = store.using(
44 Branch,
45 LeftJoin(Product, Branch.product == Product.id),
46 Join(Owner, Branch.owner == Owner.id))
47 return prejoin.find(
48 Branch,
49 Branch.branch_type == branch_type,
50 Branch.next_mirror_time <= UTC_NOW).order_by(
51 Branch.next_mirror_time)
52
53 def acquireBranchToPull(self):31 def acquireBranchToPull(self):
54 """See `IBranchPuller`."""32 """See `IBranchPuller`."""
55 store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)33 store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
5634
=== modified file 'lib/lp/code/model/tests/test_branchpuller.py'
--- lib/lp/code/model/tests/test_branchpuller.py 2009-09-28 23:51:54 +0000
+++ lib/lp/code/model/tests/test_branchpuller.py 2010-02-24 02:03:16 +0000
@@ -17,7 +17,6 @@
17from canonical.database.constants import UTC_NOW17from canonical.database.constants import UTC_NOW
18from canonical.testing.layers import DatabaseFunctionalLayer18from canonical.testing.layers import DatabaseFunctionalLayer
19from lp.code.enums import BranchType19from lp.code.enums import BranchType
20from lp.code.interfaces.branch import BranchTypeError
21from lp.code.interfaces.branchpuller import IBranchPuller20from lp.code.interfaces.branchpuller import IBranchPuller
22from lp.testing import TestCaseWithFactory, login_person21from lp.testing import TestCaseWithFactory, login_person
2322
@@ -78,37 +77,6 @@
78 branch.requestMirror()77 branch.requestMirror()
79 self.assertEqual(UTC_NOW, branch.next_mirror_time)78 self.assertEqual(UTC_NOW, branch.next_mirror_time)
8079
81 def test_requestMirrorDuringPull(self):
82 """Branches can have mirrors requested while they are being mirrored.
83 If so, they should not be removed from the pull queue when the mirror
84 is complete.
85 """
86 # We run these in separate transactions so as to have the times set to
87 # different values. This is closer to what happens in production.
88 branch = self.makeAnyBranch()
89 branch.startMirroring()
90 self.assertEqual(
91 [], list(self.branch_puller.getPullQueue(branch.branch_type)))
92 branch.requestMirror()
93 self.assertEqual(
94 [branch],
95 list(self.branch_puller.getPullQueue(branch.branch_type)))
96 branch.mirrorComplete('rev1')
97 self.assertEqual(
98 [branch],
99 list(self.branch_puller.getPullQueue(branch.branch_type)))
100
101 def test_startMirroringRemovesFromPullQueue(self):
102 # Starting a mirror removes the branch from the pull queue.
103 branch = self.makeAnyBranch()
104 branch.requestMirror()
105 self.assertEqual(
106 set([branch]),
107 set(self.branch_puller.getPullQueue(branch.branch_type)))
108 branch.startMirroring()
109 self.assertEqual(
110 set(), set(self.branch_puller.getPullQueue(branch.branch_type)))
111
112 def test_mirroringResetsMirrorRequest(self):80 def test_mirroringResetsMirrorRequest(self):
113 """Mirroring branches resets their mirror request times."""81 """Mirroring branches resets their mirror request times."""
114 branch = self.makeAnyBranch()82 branch = self.makeAnyBranch()
@@ -129,44 +97,6 @@
129 self.assertEqual(1, branch.mirror_failures)97 self.assertEqual(1, branch.mirror_failures)
130 self.assertEqual(None, branch.next_mirror_time)98 self.assertEqual(None, branch.next_mirror_time)
13199
132 def test_pullQueueEmpty(self):
133 """Branches with no next_mirror_time are not in the pull queue."""
134 branch = self.makeAnyBranch()
135 self.assertIs(None, branch.next_mirror_time)
136 self.assertEqual(
137 [], list(self.branch_puller.getPullQueue(self.branch_type)))
138
139 def test_pastNextMirrorTimeInQueue(self):
140 """Branches with next_mirror_time in the past are mirrored."""
141 transaction.begin()
142 branch = self.makeAnyBranch()
143 branch.requestMirror()
144 queue = self.branch_puller.getPullQueue(branch.branch_type)
145 self.assertEqual([branch], list(queue))
146
147 def test_futureNextMirrorTimeInQueue(self):
148 """Branches with next_mirror_time in the future are not mirrored."""
149 transaction.begin()
150 branch = removeSecurityProxy(self.makeAnyBranch())
151 tomorrow = self.getNow() + timedelta(1)
152 branch.next_mirror_time = tomorrow
153 branch.syncUpdate()
154 transaction.commit()
155 self.assertEqual(
156 [], list(self.branch_puller.getPullQueue(branch.branch_type)))
157
158 def test_pullQueueOrder(self):
159 """Pull queue has the oldest mirror request times first."""
160 branches = []
161 for i in range(3):
162 branch = removeSecurityProxy(self.makeAnyBranch())
163 branch.next_mirror_time = self.getNow() - timedelta(hours=i+1)
164 branch.sync()
165 branches.append(branch)
166 self.assertEqual(
167 list(reversed(branches)),
168 list(self.branch_puller.getPullQueue(self.branch_type)))
169
170100
171class TestMirroringForMirroredBranches(TestMirroringForHostedBranches):101class TestMirroringForMirroredBranches(TestMirroringForHostedBranches):
172102
@@ -231,18 +161,6 @@
231 branch_type = BranchType.IMPORTED161 branch_type = BranchType.IMPORTED
232162
233163
234class TestRemoteBranches(TestCaseWithFactory):
235
236 layer = DatabaseFunctionalLayer
237
238 def test_raises_branch_type_error(self):
239 # getPullQueue raises `BranchTypeError` if passed BranchType.REMOTE.
240 # It's impossible to mirror remote branches, so we shouldn't even try.
241 puller = getUtility(IBranchPuller)
242 self.assertRaises(
243 BranchTypeError, puller.getPullQueue, BranchType.REMOTE)
244
245
246class AcquireBranchToPullTests:164class AcquireBranchToPullTests:
247 """Tests for acquiring branches to pull.165 """Tests for acquiring branches to pull.
248166
249167
=== modified file 'lib/lp/code/xmlrpc/codehosting.py'
--- lib/lp/code/xmlrpc/codehosting.py 2009-11-23 22:39:21 +0000
+++ lib/lp/code/xmlrpc/codehosting.py 2010-02-24 02:03:16 +0000
@@ -12,7 +12,6 @@
1212
1313
14import datetime14import datetime
15import urllib
1615
17import pytz16import pytz
1817
@@ -25,8 +24,7 @@
2524
26from canonical.launchpad.ftests import login_person, logout25from canonical.launchpad.ftests import login_person, logout
27from lp.code.enums import BranchType26from lp.code.enums import BranchType
28from lp.code.interfaces.branch import (27from lp.code.interfaces.branch import BranchCreationException
29 BranchCreationException, UnknownBranchTypeError)
30from lp.code.interfaces.branchlookup import IBranchLookup28from lp.code.interfaces.branchlookup import IBranchLookup
31from lp.code.interfaces.branchnamespace import (29from lp.code.interfaces.branchnamespace import (
32 InvalidNamespace, lookup_branch_namespace, split_unique_name)30 InvalidNamespace, lookup_branch_namespace, split_unique_name)
@@ -56,46 +54,6 @@
5654
57 implements(IBranchPuller)55 implements(IBranchPuller)
5856
59 def _getBranchPullInfo(self, branch):
60 """Return information the branch puller needs to pull this branch.
61
62 This is outside of the IBranch interface so that the authserver can
63 access the information without logging in as a particular user.
64
65 :return: (id, url, unique_name, default_stacked_on_url), where 'id'
66 is the branch database ID, 'url' is the URL to pull from,
67 'unique_name' is the `unique_name` property and
68 'default_stacked_on_url' is the URL of the branch to stack on by
69 default (normally of the form '/~foo/bar/baz'). If there is no
70 default stacked-on branch, then it's ''.
71 """
72 branch = removeSecurityProxy(branch)
73 if branch.branch_type == BranchType.REMOTE:
74 raise AssertionError(
75 'Remote branches should never be in the pull queue.')
76 default_branch = branch.target.default_stacked_on_branch
77 if default_branch is None:
78 default_branch = ''
79 elif (branch.branch_type == BranchType.MIRRORED
80 and default_branch.private):
81 default_branch = ''
82 else:
83 default_branch = '/' + default_branch.unique_name
84 return (
85 branch.id, branch.getPullURL(), branch.unique_name,
86 default_branch)
87
88 def getBranchPullQueue(self, branch_type):
89 """See `IBranchPuller`."""
90 try:
91 branch_type = BranchType.items[branch_type]
92 except KeyError:
93 raise UnknownBranchTypeError(
94 'Unknown branch type: %r' % (branch_type,))
95 branches = getUtility(branchpuller.IBranchPuller).getPullQueue(
96 branch_type)
97 return [self._getBranchPullInfo(branch) for branch in branches]
98
99 def acquireBranchToPull(self):57 def acquireBranchToPull(self):
100 """See `IBranchPuller`."""58 """See `IBranchPuller`."""
101 branch = getUtility(branchpuller.IBranchPuller).acquireBranchToPull()59 branch = getUtility(branchpuller.IBranchPuller).acquireBranchToPull()
10260
=== modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py'
--- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-02-18 03:11:03 +0000
+++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-02-24 02:03:16 +0000
@@ -399,105 +399,6 @@
399 self.assertFaultEqual(faults.NoBranchWithID(branch_id), fault)399 self.assertFaultEqual(faults.NoBranchWithID(branch_id), fault)
400400
401401
402class BranchPullQueueTest(TestCaseWithFactory):
403 """Tests for the pull queue methods of `IBranchPuller`."""
404
405 def setUp(self):
406 super(BranchPullQueueTest, self).setUp()
407 frontend = self.frontend()
408 self.storage = frontend.getPullerEndpoint()
409 self.factory = frontend.getLaunchpadObjectFactory()
410
411 def assertBranchQueues(self, hosted, mirrored, imported):
412 expected_hosted = [
413 self.storage._getBranchPullInfo(branch) for branch in hosted]
414 expected_mirrored = [
415 self.storage._getBranchPullInfo(branch) for branch in mirrored]
416 expected_imported = [
417 self.storage._getBranchPullInfo(branch) for branch in imported]
418 self.assertEqual(
419 expected_hosted, self.storage.getBranchPullQueue('HOSTED'))
420 self.assertEqual(
421 expected_mirrored, self.storage.getBranchPullQueue('MIRRORED'))
422 self.assertEqual(
423 expected_imported, self.storage.getBranchPullQueue('IMPORTED'))
424
425 def test_pullQueuesEmpty(self):
426 """getBranchPullQueue returns an empty list when there are no branches
427 to pull.
428 """
429 self.assertBranchQueues([], [], [])
430
431 def makeBranchAndRequestMirror(self, branch_type):
432 """Make a branch of the given type and call requestMirror on it."""
433 branch = self.factory.makeAnyBranch(branch_type=branch_type)
434 branch.requestMirror()
435 # The pull queues contain branches that have next_mirror_time strictly
436 # in the past, but requestMirror sets this field to UTC_NOW, so we
437 # push the time back slightly here to get the branch to show up in the
438 # queue.
439 naked_branch = removeSecurityProxy(branch)
440 naked_branch.next_mirror_time -= datetime.timedelta(seconds=1)
441 return branch
442
443 def test_getBranchPullInfo_no_default_stacked_branch(self):
444 # If there's no default stacked branch for the project that a branch
445 # is on, then _getBranchPullInfo returns (id, url, unique_name, '').
446 branch = self.factory.makeAnyBranch()
447 info = self.storage._getBranchPullInfo(branch)
448 self.assertEqual(
449 (branch.id, branch.getPullURL(), branch.unique_name, ''), info)
450
451 def test_getBranchPullInfo_default_stacked_branch(self):
452 # If there's a default stacked branch for the project that a branch is
453 # on, then _getBranchPullInfo returns (id, url, unique_name,
454 # default_branch_unique_name).
455 product = self.factory.makeProduct()
456 default_branch = self.factory.enableDefaultStackingForProduct(product)
457 branch = self.factory.makeProductBranch(product=product)
458 info = self.storage._getBranchPullInfo(branch)
459 self.assertEqual(
460 (branch.id, branch.getPullURL(), branch.unique_name,
461 '/' + default_branch.unique_name), info)
462
463 def test_getBranchPullInfo_private_branch(self):
464 # We don't want to stack mirrored branches onto private branches:
465 # mirrored branches are public by their nature. Thus, if the default
466 # stacked-on branch for the project is private and the branch is
467 # MIRRORED then we don't include the default stacked-on branch's
468 # details in the tuple.
469 product = self.factory.makeProduct()
470 default_branch = self.factory.makeProductBranch(
471 product=product, private=True)
472 self.factory.enableDefaultStackingForProduct(product, default_branch)
473 mirrored_branch = self.factory.makeProductBranch(
474 branch_type=BranchType.MIRRORED, product=product)
475 info = self.storage._getBranchPullInfo(mirrored_branch)
476 self.assertEqual(
477 (mirrored_branch.id, mirrored_branch.getPullURL(),
478 mirrored_branch.unique_name, ''), info)
479
480 def test_getBranchPullInfo_junk(self):
481 # _getBranchPullInfo returns (id, url, unique_name, '') for junk
482 # branches.
483 branch = self.factory.makePersonalBranch()
484 info = self.storage._getBranchPullInfo(branch)
485 self.assertEqual(
486 (branch.id, branch.getPullURL(), branch.unique_name, ''), info)
487
488 def test_requestMirrorPutsBranchInQueue_hosted(self):
489 branch = self.makeBranchAndRequestMirror(BranchType.HOSTED)
490 self.assertBranchQueues([branch], [], [])
491
492 def test_requestMirrorPutsBranchInQueue_mirrored(self):
493 branch = self.makeBranchAndRequestMirror(BranchType.MIRRORED)
494 self.assertBranchQueues([], [branch], [])
495
496 def test_requestMirrorPutsBranchInQueue_imported(self):
497 branch = self.makeBranchAndRequestMirror(BranchType.IMPORTED)
498 self.assertBranchQueues([], [], [branch])
499
500
501class AcquireBranchToPullTestsViaEndpoint(TestCaseWithFactory,402class AcquireBranchToPullTestsViaEndpoint(TestCaseWithFactory,
502 AcquireBranchToPullTests):403 AcquireBranchToPullTests):
503 """Tests for `acquireBranchToPull` method of `IBranchPuller`."""404 """Tests for `acquireBranchToPull` method of `IBranchPuller`."""
@@ -1175,7 +1076,6 @@
1175 suite = unittest.TestSuite()1076 suite = unittest.TestSuite()
1176 puller_tests = unittest.TestSuite(1077 puller_tests = unittest.TestSuite(
1177 [loader.loadTestsFromTestCase(BranchPullerTest),1078 [loader.loadTestsFromTestCase(BranchPullerTest),
1178 loader.loadTestsFromTestCase(BranchPullQueueTest),
1179 loader.loadTestsFromTestCase(AcquireBranchToPullTestsViaEndpoint),1079 loader.loadTestsFromTestCase(AcquireBranchToPullTestsViaEndpoint),
1180 loader.loadTestsFromTestCase(BranchFileSystemTest),1080 loader.loadTestsFromTestCase(BranchFileSystemTest),
1181 ])1081 ])
11821082
=== modified file 'lib/lp/codehosting/inmemory.py'
--- lib/lp/codehosting/inmemory.py 2010-02-19 03:06:12 +0000
+++ lib/lp/codehosting/inmemory.py 2010-02-24 02:03:16 +0000
@@ -442,29 +442,6 @@
442 self._branch_set = branch_set442 self._branch_set = branch_set
443 self._script_activity_set = script_activity_set443 self._script_activity_set = script_activity_set
444444
445 def _getBranchPullInfo(self, branch):
446 default_branch = ''
447 if branch.product is not None:
448 series = branch.product.development_focus
449 user_branch = series.branch
450 if (user_branch is not None
451 and not (
452 user_branch.private
453 and branch.branch_type == BranchType.MIRRORED)):
454 default_branch = '/' + user_branch.unique_name
455 return (
456 branch.id, branch.getPullURL(), branch.unique_name,
457 default_branch)
458
459 def getBranchPullQueue(self, branch_type):
460 queue = []
461 branch_type = BranchType.items[branch_type]
462 for branch in self._branch_set:
463 if (branch.branch_type == branch_type
464 and branch.next_mirror_time < UTC_NOW):
465 queue.append(self._getBranchPullInfo(branch))
466 return queue
467
468 def acquireBranchToPull(self):445 def acquireBranchToPull(self):
469 branches = sorted(446 branches = sorted(
470 [branch for branch in self._branch_set447 [branch for branch in self._branch_set