Merge lp:~mwhudson/launchpad/remove-old-puller-xmlrpc-methods into lp:launchpad
- remove-old-puller-xmlrpc-methods
- Merge into devel
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 | ||||
Related bugs: |
|
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.
Description of the change
To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote : | # |
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
1 | === modified file 'lib/lp/code/doc/xmlrpc-branch-puller.txt' | |||
2 | --- lib/lp/code/doc/xmlrpc-branch-puller.txt 2009-10-22 11:55:51 +0000 | |||
3 | +++ lib/lp/code/doc/xmlrpc-branch-puller.txt 2010-02-24 02:03:16 +0000 | |||
4 | @@ -28,19 +28,4 @@ | |||
5 | 28 | True | 28 | True |
6 | 29 | 29 | ||
7 | 30 | The IBranchPuller interface defines some methods, for which see the unit | 30 | The IBranchPuller interface defines some methods, for which see the unit |
24 | 31 | tests. To allow a minimal test here, we call getBranchPullQueue, | 31 | tests. |
9 | 32 | which will return an empty list. | ||
10 | 33 | |||
11 | 34 | >>> from lp.code.enums import BranchType | ||
12 | 35 | >>> branch_puller.getBranchPullQueue(BranchType.HOSTED.name) | ||
13 | 36 | [] | ||
14 | 37 | |||
15 | 38 | This remains true when it is accessed over XMLRPC. | ||
16 | 39 | |||
17 | 40 | >>> import xmlrpclib | ||
18 | 41 | >>> from canonical.functional import XMLRPCTestTransport | ||
19 | 42 | >>> puller = xmlrpclib.ServerProxy( | ||
20 | 43 | ... 'http://xmlrpc-private.launchpad.dev:8087/branch_puller', | ||
21 | 44 | ... transport=XMLRPCTestTransport()) | ||
22 | 45 | >>> puller.getBranchPullQueue(BranchType.HOSTED.name) | ||
23 | 46 | [] | ||
25 | 47 | 32 | ||
26 | === modified file 'lib/lp/code/interfaces/branchpuller.py' | |||
27 | --- lib/lp/code/interfaces/branchpuller.py 2009-06-30 16:56:07 +0000 | |||
28 | +++ lib/lp/code/interfaces/branchpuller.py 2010-02-24 02:03:16 +0000 | |||
29 | @@ -23,12 +23,6 @@ | |||
30 | 23 | MIRROR_TIME_INCREMENT = Attribute( | 23 | MIRROR_TIME_INCREMENT = Attribute( |
31 | 24 | "How frequently we mirror branches.") | 24 | "How frequently we mirror branches.") |
32 | 25 | 25 | ||
33 | 26 | def getPullQueue(branch_type): | ||
34 | 27 | """Return a queue of branches to mirror using the puller. | ||
35 | 28 | |||
36 | 29 | :param branch_type: A value from the `BranchType` enum. | ||
37 | 30 | """ | ||
38 | 31 | |||
39 | 32 | def acquireBranchToPull(): | 26 | def acquireBranchToPull(): |
40 | 33 | """Return a Branch to pull and mark it as mirror-started. | 27 | """Return a Branch to pull and mark it as mirror-started. |
41 | 34 | 28 | ||
42 | 35 | 29 | ||
43 | === modified file 'lib/lp/code/interfaces/codehosting.py' | |||
44 | --- lib/lp/code/interfaces/codehosting.py 2009-06-25 04:06:00 +0000 | |||
45 | +++ lib/lp/code/interfaces/codehosting.py 2010-02-24 02:03:16 +0000 | |||
46 | @@ -58,20 +58,6 @@ | |||
47 | 58 | Published at 'branch_puller' on the private XML-RPC server. | 58 | Published at 'branch_puller' on the private XML-RPC server. |
48 | 59 | """ | 59 | """ |
49 | 60 | 60 | ||
50 | 61 | def getBranchPullQueue(branch_type): | ||
51 | 62 | """Get the list of branches to be mirrored. | ||
52 | 63 | |||
53 | 64 | :param branch_type: One of 'HOSTED', 'MIRRORED', or 'IMPORTED'. | ||
54 | 65 | |||
55 | 66 | :raise UnknownBranchTypeError: if the branch type is unrecognized. | ||
56 | 67 | |||
57 | 68 | :returns: a list of (branch_id, pull_url, unique_name, default_branch) | ||
58 | 69 | 4-tuples. branch_id is the database id of the branch, pull_url is | ||
59 | 70 | where to pull from, unique_name is the unique_name of the branch | ||
60 | 71 | and default_branch is the default stacked on branch for the | ||
61 | 72 | branch's target. | ||
62 | 73 | """ | ||
63 | 74 | |||
64 | 75 | def acquireBranchToPull(): | 61 | def acquireBranchToPull(): |
65 | 76 | """Return a Branch to pull and mark it as mirror-started. | 62 | """Return a Branch to pull and mark it as mirror-started. |
66 | 77 | 63 | ||
67 | 78 | 64 | ||
68 | === modified file 'lib/lp/code/model/branchpuller.py' | |||
69 | --- lib/lp/code/model/branchpuller.py 2009-08-04 05:14:32 +0000 | |||
70 | +++ lib/lp/code/model/branchpuller.py 2010-02-24 02:03:16 +0000 | |||
71 | @@ -9,17 +9,13 @@ | |||
72 | 9 | 9 | ||
73 | 10 | from datetime import timedelta | 10 | from datetime import timedelta |
74 | 11 | 11 | ||
75 | 12 | from storm.expr import LeftJoin, Join | ||
76 | 13 | from zope.component import getUtility | 12 | from zope.component import getUtility |
77 | 14 | from zope.interface import implements | 13 | from zope.interface import implements |
78 | 15 | 14 | ||
79 | 16 | from canonical.database.constants import UTC_NOW | 15 | from canonical.database.constants import UTC_NOW |
80 | 17 | from lp.code.enums import BranchType | 16 | from lp.code.enums import BranchType |
81 | 18 | from lp.code.model.branch import Branch | 17 | from lp.code.model.branch import Branch |
82 | 19 | from lp.code.interfaces.branch import BranchTypeError | ||
83 | 20 | from lp.code.interfaces.branchpuller import IBranchPuller | 18 | from lp.code.interfaces.branchpuller import IBranchPuller |
84 | 21 | from lp.registry.model.person import Owner | ||
85 | 22 | from lp.registry.model.product import Product | ||
86 | 23 | from canonical.launchpad.webapp.interfaces import ( | 19 | from canonical.launchpad.webapp.interfaces import ( |
87 | 24 | IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR) | 20 | IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR) |
88 | 25 | 21 | ||
89 | @@ -32,24 +28,6 @@ | |||
90 | 32 | MAXIMUM_MIRROR_FAILURES = 5 | 28 | MAXIMUM_MIRROR_FAILURES = 5 |
91 | 33 | MIRROR_TIME_INCREMENT = timedelta(hours=6) | 29 | MIRROR_TIME_INCREMENT = timedelta(hours=6) |
92 | 34 | 30 | ||
93 | 35 | def getPullQueue(self, branch_type): | ||
94 | 36 | """See `IBranchPuller`.""" | ||
95 | 37 | if branch_type == BranchType.REMOTE: | ||
96 | 38 | raise BranchTypeError("No pull queue for REMOTE branches.") | ||
97 | 39 | store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) | ||
98 | 40 | # Prejoin on owner and product to preserve existing behaviour. | ||
99 | 41 | # XXX: JonathanLange 2009-03-22 spec=package-branches: This prejoin is | ||
100 | 42 | # inappropriate in the face of package branches. | ||
101 | 43 | prejoin = store.using( | ||
102 | 44 | Branch, | ||
103 | 45 | LeftJoin(Product, Branch.product == Product.id), | ||
104 | 46 | Join(Owner, Branch.owner == Owner.id)) | ||
105 | 47 | return prejoin.find( | ||
106 | 48 | Branch, | ||
107 | 49 | Branch.branch_type == branch_type, | ||
108 | 50 | Branch.next_mirror_time <= UTC_NOW).order_by( | ||
109 | 51 | Branch.next_mirror_time) | ||
110 | 52 | |||
111 | 53 | def acquireBranchToPull(self): | 31 | def acquireBranchToPull(self): |
112 | 54 | """See `IBranchPuller`.""" | 32 | """See `IBranchPuller`.""" |
113 | 55 | store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) | 33 | store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
114 | 56 | 34 | ||
115 | === modified file 'lib/lp/code/model/tests/test_branchpuller.py' | |||
116 | --- lib/lp/code/model/tests/test_branchpuller.py 2009-09-28 23:51:54 +0000 | |||
117 | +++ lib/lp/code/model/tests/test_branchpuller.py 2010-02-24 02:03:16 +0000 | |||
118 | @@ -17,7 +17,6 @@ | |||
119 | 17 | from canonical.database.constants import UTC_NOW | 17 | from canonical.database.constants import UTC_NOW |
120 | 18 | from canonical.testing.layers import DatabaseFunctionalLayer | 18 | from canonical.testing.layers import DatabaseFunctionalLayer |
121 | 19 | from lp.code.enums import BranchType | 19 | from lp.code.enums import BranchType |
122 | 20 | from lp.code.interfaces.branch import BranchTypeError | ||
123 | 21 | from lp.code.interfaces.branchpuller import IBranchPuller | 20 | from lp.code.interfaces.branchpuller import IBranchPuller |
124 | 22 | from lp.testing import TestCaseWithFactory, login_person | 21 | from lp.testing import TestCaseWithFactory, login_person |
125 | 23 | 22 | ||
126 | @@ -78,37 +77,6 @@ | |||
127 | 78 | branch.requestMirror() | 77 | branch.requestMirror() |
128 | 79 | self.assertEqual(UTC_NOW, branch.next_mirror_time) | 78 | self.assertEqual(UTC_NOW, branch.next_mirror_time) |
129 | 80 | 79 | ||
130 | 81 | def test_requestMirrorDuringPull(self): | ||
131 | 82 | """Branches can have mirrors requested while they are being mirrored. | ||
132 | 83 | If so, they should not be removed from the pull queue when the mirror | ||
133 | 84 | is complete. | ||
134 | 85 | """ | ||
135 | 86 | # We run these in separate transactions so as to have the times set to | ||
136 | 87 | # different values. This is closer to what happens in production. | ||
137 | 88 | branch = self.makeAnyBranch() | ||
138 | 89 | branch.startMirroring() | ||
139 | 90 | self.assertEqual( | ||
140 | 91 | [], list(self.branch_puller.getPullQueue(branch.branch_type))) | ||
141 | 92 | branch.requestMirror() | ||
142 | 93 | self.assertEqual( | ||
143 | 94 | [branch], | ||
144 | 95 | list(self.branch_puller.getPullQueue(branch.branch_type))) | ||
145 | 96 | branch.mirrorComplete('rev1') | ||
146 | 97 | self.assertEqual( | ||
147 | 98 | [branch], | ||
148 | 99 | list(self.branch_puller.getPullQueue(branch.branch_type))) | ||
149 | 100 | |||
150 | 101 | def test_startMirroringRemovesFromPullQueue(self): | ||
151 | 102 | # Starting a mirror removes the branch from the pull queue. | ||
152 | 103 | branch = self.makeAnyBranch() | ||
153 | 104 | branch.requestMirror() | ||
154 | 105 | self.assertEqual( | ||
155 | 106 | set([branch]), | ||
156 | 107 | set(self.branch_puller.getPullQueue(branch.branch_type))) | ||
157 | 108 | branch.startMirroring() | ||
158 | 109 | self.assertEqual( | ||
159 | 110 | set(), set(self.branch_puller.getPullQueue(branch.branch_type))) | ||
160 | 111 | |||
161 | 112 | def test_mirroringResetsMirrorRequest(self): | 80 | def test_mirroringResetsMirrorRequest(self): |
162 | 113 | """Mirroring branches resets their mirror request times.""" | 81 | """Mirroring branches resets their mirror request times.""" |
163 | 114 | branch = self.makeAnyBranch() | 82 | branch = self.makeAnyBranch() |
164 | @@ -129,44 +97,6 @@ | |||
165 | 129 | self.assertEqual(1, branch.mirror_failures) | 97 | self.assertEqual(1, branch.mirror_failures) |
166 | 130 | self.assertEqual(None, branch.next_mirror_time) | 98 | self.assertEqual(None, branch.next_mirror_time) |
167 | 131 | 99 | ||
168 | 132 | def test_pullQueueEmpty(self): | ||
169 | 133 | """Branches with no next_mirror_time are not in the pull queue.""" | ||
170 | 134 | branch = self.makeAnyBranch() | ||
171 | 135 | self.assertIs(None, branch.next_mirror_time) | ||
172 | 136 | self.assertEqual( | ||
173 | 137 | [], list(self.branch_puller.getPullQueue(self.branch_type))) | ||
174 | 138 | |||
175 | 139 | def test_pastNextMirrorTimeInQueue(self): | ||
176 | 140 | """Branches with next_mirror_time in the past are mirrored.""" | ||
177 | 141 | transaction.begin() | ||
178 | 142 | branch = self.makeAnyBranch() | ||
179 | 143 | branch.requestMirror() | ||
180 | 144 | queue = self.branch_puller.getPullQueue(branch.branch_type) | ||
181 | 145 | self.assertEqual([branch], list(queue)) | ||
182 | 146 | |||
183 | 147 | def test_futureNextMirrorTimeInQueue(self): | ||
184 | 148 | """Branches with next_mirror_time in the future are not mirrored.""" | ||
185 | 149 | transaction.begin() | ||
186 | 150 | branch = removeSecurityProxy(self.makeAnyBranch()) | ||
187 | 151 | tomorrow = self.getNow() + timedelta(1) | ||
188 | 152 | branch.next_mirror_time = tomorrow | ||
189 | 153 | branch.syncUpdate() | ||
190 | 154 | transaction.commit() | ||
191 | 155 | self.assertEqual( | ||
192 | 156 | [], list(self.branch_puller.getPullQueue(branch.branch_type))) | ||
193 | 157 | |||
194 | 158 | def test_pullQueueOrder(self): | ||
195 | 159 | """Pull queue has the oldest mirror request times first.""" | ||
196 | 160 | branches = [] | ||
197 | 161 | for i in range(3): | ||
198 | 162 | branch = removeSecurityProxy(self.makeAnyBranch()) | ||
199 | 163 | branch.next_mirror_time = self.getNow() - timedelta(hours=i+1) | ||
200 | 164 | branch.sync() | ||
201 | 165 | branches.append(branch) | ||
202 | 166 | self.assertEqual( | ||
203 | 167 | list(reversed(branches)), | ||
204 | 168 | list(self.branch_puller.getPullQueue(self.branch_type))) | ||
205 | 169 | |||
206 | 170 | 100 | ||
207 | 171 | class TestMirroringForMirroredBranches(TestMirroringForHostedBranches): | 101 | class TestMirroringForMirroredBranches(TestMirroringForHostedBranches): |
208 | 172 | 102 | ||
209 | @@ -231,18 +161,6 @@ | |||
210 | 231 | branch_type = BranchType.IMPORTED | 161 | branch_type = BranchType.IMPORTED |
211 | 232 | 162 | ||
212 | 233 | 163 | ||
213 | 234 | class TestRemoteBranches(TestCaseWithFactory): | ||
214 | 235 | |||
215 | 236 | layer = DatabaseFunctionalLayer | ||
216 | 237 | |||
217 | 238 | def test_raises_branch_type_error(self): | ||
218 | 239 | # getPullQueue raises `BranchTypeError` if passed BranchType.REMOTE. | ||
219 | 240 | # It's impossible to mirror remote branches, so we shouldn't even try. | ||
220 | 241 | puller = getUtility(IBranchPuller) | ||
221 | 242 | self.assertRaises( | ||
222 | 243 | BranchTypeError, puller.getPullQueue, BranchType.REMOTE) | ||
223 | 244 | |||
224 | 245 | |||
225 | 246 | class AcquireBranchToPullTests: | 164 | class AcquireBranchToPullTests: |
226 | 247 | """Tests for acquiring branches to pull. | 165 | """Tests for acquiring branches to pull. |
227 | 248 | 166 | ||
228 | 249 | 167 | ||
229 | === modified file 'lib/lp/code/xmlrpc/codehosting.py' | |||
230 | --- lib/lp/code/xmlrpc/codehosting.py 2009-11-23 22:39:21 +0000 | |||
231 | +++ lib/lp/code/xmlrpc/codehosting.py 2010-02-24 02:03:16 +0000 | |||
232 | @@ -12,7 +12,6 @@ | |||
233 | 12 | 12 | ||
234 | 13 | 13 | ||
235 | 14 | import datetime | 14 | import datetime |
236 | 15 | import urllib | ||
237 | 16 | 15 | ||
238 | 17 | import pytz | 16 | import pytz |
239 | 18 | 17 | ||
240 | @@ -25,8 +24,7 @@ | |||
241 | 25 | 24 | ||
242 | 26 | from canonical.launchpad.ftests import login_person, logout | 25 | from canonical.launchpad.ftests import login_person, logout |
243 | 27 | from lp.code.enums import BranchType | 26 | from lp.code.enums import BranchType |
246 | 28 | from lp.code.interfaces.branch import ( | 27 | from lp.code.interfaces.branch import BranchCreationException |
245 | 29 | BranchCreationException, UnknownBranchTypeError) | ||
247 | 30 | from lp.code.interfaces.branchlookup import IBranchLookup | 28 | from lp.code.interfaces.branchlookup import IBranchLookup |
248 | 31 | from lp.code.interfaces.branchnamespace import ( | 29 | from lp.code.interfaces.branchnamespace import ( |
249 | 32 | InvalidNamespace, lookup_branch_namespace, split_unique_name) | 30 | InvalidNamespace, lookup_branch_namespace, split_unique_name) |
250 | @@ -56,46 +54,6 @@ | |||
251 | 56 | 54 | ||
252 | 57 | implements(IBranchPuller) | 55 | implements(IBranchPuller) |
253 | 58 | 56 | ||
254 | 59 | def _getBranchPullInfo(self, branch): | ||
255 | 60 | """Return information the branch puller needs to pull this branch. | ||
256 | 61 | |||
257 | 62 | This is outside of the IBranch interface so that the authserver can | ||
258 | 63 | access the information without logging in as a particular user. | ||
259 | 64 | |||
260 | 65 | :return: (id, url, unique_name, default_stacked_on_url), where 'id' | ||
261 | 66 | is the branch database ID, 'url' is the URL to pull from, | ||
262 | 67 | 'unique_name' is the `unique_name` property and | ||
263 | 68 | 'default_stacked_on_url' is the URL of the branch to stack on by | ||
264 | 69 | default (normally of the form '/~foo/bar/baz'). If there is no | ||
265 | 70 | default stacked-on branch, then it's ''. | ||
266 | 71 | """ | ||
267 | 72 | branch = removeSecurityProxy(branch) | ||
268 | 73 | if branch.branch_type == BranchType.REMOTE: | ||
269 | 74 | raise AssertionError( | ||
270 | 75 | 'Remote branches should never be in the pull queue.') | ||
271 | 76 | default_branch = branch.target.default_stacked_on_branch | ||
272 | 77 | if default_branch is None: | ||
273 | 78 | default_branch = '' | ||
274 | 79 | elif (branch.branch_type == BranchType.MIRRORED | ||
275 | 80 | and default_branch.private): | ||
276 | 81 | default_branch = '' | ||
277 | 82 | else: | ||
278 | 83 | default_branch = '/' + default_branch.unique_name | ||
279 | 84 | return ( | ||
280 | 85 | branch.id, branch.getPullURL(), branch.unique_name, | ||
281 | 86 | default_branch) | ||
282 | 87 | |||
283 | 88 | def getBranchPullQueue(self, branch_type): | ||
284 | 89 | """See `IBranchPuller`.""" | ||
285 | 90 | try: | ||
286 | 91 | branch_type = BranchType.items[branch_type] | ||
287 | 92 | except KeyError: | ||
288 | 93 | raise UnknownBranchTypeError( | ||
289 | 94 | 'Unknown branch type: %r' % (branch_type,)) | ||
290 | 95 | branches = getUtility(branchpuller.IBranchPuller).getPullQueue( | ||
291 | 96 | branch_type) | ||
292 | 97 | return [self._getBranchPullInfo(branch) for branch in branches] | ||
293 | 98 | |||
294 | 99 | def acquireBranchToPull(self): | 57 | def acquireBranchToPull(self): |
295 | 100 | """See `IBranchPuller`.""" | 58 | """See `IBranchPuller`.""" |
296 | 101 | branch = getUtility(branchpuller.IBranchPuller).acquireBranchToPull() | 59 | branch = getUtility(branchpuller.IBranchPuller).acquireBranchToPull() |
297 | 102 | 60 | ||
298 | === modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py' | |||
299 | --- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-02-18 03:11:03 +0000 | |||
300 | +++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-02-24 02:03:16 +0000 | |||
301 | @@ -399,105 +399,6 @@ | |||
302 | 399 | self.assertFaultEqual(faults.NoBranchWithID(branch_id), fault) | 399 | self.assertFaultEqual(faults.NoBranchWithID(branch_id), fault) |
303 | 400 | 400 | ||
304 | 401 | 401 | ||
305 | 402 | class BranchPullQueueTest(TestCaseWithFactory): | ||
306 | 403 | """Tests for the pull queue methods of `IBranchPuller`.""" | ||
307 | 404 | |||
308 | 405 | def setUp(self): | ||
309 | 406 | super(BranchPullQueueTest, self).setUp() | ||
310 | 407 | frontend = self.frontend() | ||
311 | 408 | self.storage = frontend.getPullerEndpoint() | ||
312 | 409 | self.factory = frontend.getLaunchpadObjectFactory() | ||
313 | 410 | |||
314 | 411 | def assertBranchQueues(self, hosted, mirrored, imported): | ||
315 | 412 | expected_hosted = [ | ||
316 | 413 | self.storage._getBranchPullInfo(branch) for branch in hosted] | ||
317 | 414 | expected_mirrored = [ | ||
318 | 415 | self.storage._getBranchPullInfo(branch) for branch in mirrored] | ||
319 | 416 | expected_imported = [ | ||
320 | 417 | self.storage._getBranchPullInfo(branch) for branch in imported] | ||
321 | 418 | self.assertEqual( | ||
322 | 419 | expected_hosted, self.storage.getBranchPullQueue('HOSTED')) | ||
323 | 420 | self.assertEqual( | ||
324 | 421 | expected_mirrored, self.storage.getBranchPullQueue('MIRRORED')) | ||
325 | 422 | self.assertEqual( | ||
326 | 423 | expected_imported, self.storage.getBranchPullQueue('IMPORTED')) | ||
327 | 424 | |||
328 | 425 | def test_pullQueuesEmpty(self): | ||
329 | 426 | """getBranchPullQueue returns an empty list when there are no branches | ||
330 | 427 | to pull. | ||
331 | 428 | """ | ||
332 | 429 | self.assertBranchQueues([], [], []) | ||
333 | 430 | |||
334 | 431 | def makeBranchAndRequestMirror(self, branch_type): | ||
335 | 432 | """Make a branch of the given type and call requestMirror on it.""" | ||
336 | 433 | branch = self.factory.makeAnyBranch(branch_type=branch_type) | ||
337 | 434 | branch.requestMirror() | ||
338 | 435 | # The pull queues contain branches that have next_mirror_time strictly | ||
339 | 436 | # in the past, but requestMirror sets this field to UTC_NOW, so we | ||
340 | 437 | # push the time back slightly here to get the branch to show up in the | ||
341 | 438 | # queue. | ||
342 | 439 | naked_branch = removeSecurityProxy(branch) | ||
343 | 440 | naked_branch.next_mirror_time -= datetime.timedelta(seconds=1) | ||
344 | 441 | return branch | ||
345 | 442 | |||
346 | 443 | def test_getBranchPullInfo_no_default_stacked_branch(self): | ||
347 | 444 | # If there's no default stacked branch for the project that a branch | ||
348 | 445 | # is on, then _getBranchPullInfo returns (id, url, unique_name, ''). | ||
349 | 446 | branch = self.factory.makeAnyBranch() | ||
350 | 447 | info = self.storage._getBranchPullInfo(branch) | ||
351 | 448 | self.assertEqual( | ||
352 | 449 | (branch.id, branch.getPullURL(), branch.unique_name, ''), info) | ||
353 | 450 | |||
354 | 451 | def test_getBranchPullInfo_default_stacked_branch(self): | ||
355 | 452 | # If there's a default stacked branch for the project that a branch is | ||
356 | 453 | # on, then _getBranchPullInfo returns (id, url, unique_name, | ||
357 | 454 | # default_branch_unique_name). | ||
358 | 455 | product = self.factory.makeProduct() | ||
359 | 456 | default_branch = self.factory.enableDefaultStackingForProduct(product) | ||
360 | 457 | branch = self.factory.makeProductBranch(product=product) | ||
361 | 458 | info = self.storage._getBranchPullInfo(branch) | ||
362 | 459 | self.assertEqual( | ||
363 | 460 | (branch.id, branch.getPullURL(), branch.unique_name, | ||
364 | 461 | '/' + default_branch.unique_name), info) | ||
365 | 462 | |||
366 | 463 | def test_getBranchPullInfo_private_branch(self): | ||
367 | 464 | # We don't want to stack mirrored branches onto private branches: | ||
368 | 465 | # mirrored branches are public by their nature. Thus, if the default | ||
369 | 466 | # stacked-on branch for the project is private and the branch is | ||
370 | 467 | # MIRRORED then we don't include the default stacked-on branch's | ||
371 | 468 | # details in the tuple. | ||
372 | 469 | product = self.factory.makeProduct() | ||
373 | 470 | default_branch = self.factory.makeProductBranch( | ||
374 | 471 | product=product, private=True) | ||
375 | 472 | self.factory.enableDefaultStackingForProduct(product, default_branch) | ||
376 | 473 | mirrored_branch = self.factory.makeProductBranch( | ||
377 | 474 | branch_type=BranchType.MIRRORED, product=product) | ||
378 | 475 | info = self.storage._getBranchPullInfo(mirrored_branch) | ||
379 | 476 | self.assertEqual( | ||
380 | 477 | (mirrored_branch.id, mirrored_branch.getPullURL(), | ||
381 | 478 | mirrored_branch.unique_name, ''), info) | ||
382 | 479 | |||
383 | 480 | def test_getBranchPullInfo_junk(self): | ||
384 | 481 | # _getBranchPullInfo returns (id, url, unique_name, '') for junk | ||
385 | 482 | # branches. | ||
386 | 483 | branch = self.factory.makePersonalBranch() | ||
387 | 484 | info = self.storage._getBranchPullInfo(branch) | ||
388 | 485 | self.assertEqual( | ||
389 | 486 | (branch.id, branch.getPullURL(), branch.unique_name, ''), info) | ||
390 | 487 | |||
391 | 488 | def test_requestMirrorPutsBranchInQueue_hosted(self): | ||
392 | 489 | branch = self.makeBranchAndRequestMirror(BranchType.HOSTED) | ||
393 | 490 | self.assertBranchQueues([branch], [], []) | ||
394 | 491 | |||
395 | 492 | def test_requestMirrorPutsBranchInQueue_mirrored(self): | ||
396 | 493 | branch = self.makeBranchAndRequestMirror(BranchType.MIRRORED) | ||
397 | 494 | self.assertBranchQueues([], [branch], []) | ||
398 | 495 | |||
399 | 496 | def test_requestMirrorPutsBranchInQueue_imported(self): | ||
400 | 497 | branch = self.makeBranchAndRequestMirror(BranchType.IMPORTED) | ||
401 | 498 | self.assertBranchQueues([], [], [branch]) | ||
402 | 499 | |||
403 | 500 | |||
404 | 501 | class AcquireBranchToPullTestsViaEndpoint(TestCaseWithFactory, | 402 | class AcquireBranchToPullTestsViaEndpoint(TestCaseWithFactory, |
405 | 502 | AcquireBranchToPullTests): | 403 | AcquireBranchToPullTests): |
406 | 503 | """Tests for `acquireBranchToPull` method of `IBranchPuller`.""" | 404 | """Tests for `acquireBranchToPull` method of `IBranchPuller`.""" |
407 | @@ -1175,7 +1076,6 @@ | |||
408 | 1175 | suite = unittest.TestSuite() | 1076 | suite = unittest.TestSuite() |
409 | 1176 | puller_tests = unittest.TestSuite( | 1077 | puller_tests = unittest.TestSuite( |
410 | 1177 | [loader.loadTestsFromTestCase(BranchPullerTest), | 1078 | [loader.loadTestsFromTestCase(BranchPullerTest), |
411 | 1178 | loader.loadTestsFromTestCase(BranchPullQueueTest), | ||
412 | 1179 | loader.loadTestsFromTestCase(AcquireBranchToPullTestsViaEndpoint), | 1079 | loader.loadTestsFromTestCase(AcquireBranchToPullTestsViaEndpoint), |
413 | 1180 | loader.loadTestsFromTestCase(BranchFileSystemTest), | 1080 | loader.loadTestsFromTestCase(BranchFileSystemTest), |
414 | 1181 | ]) | 1081 | ]) |
415 | 1182 | 1082 | ||
416 | === modified file 'lib/lp/codehosting/inmemory.py' | |||
417 | --- lib/lp/codehosting/inmemory.py 2010-02-19 03:06:12 +0000 | |||
418 | +++ lib/lp/codehosting/inmemory.py 2010-02-24 02:03:16 +0000 | |||
419 | @@ -442,29 +442,6 @@ | |||
420 | 442 | self._branch_set = branch_set | 442 | self._branch_set = branch_set |
421 | 443 | self._script_activity_set = script_activity_set | 443 | self._script_activity_set = script_activity_set |
422 | 444 | 444 | ||
423 | 445 | def _getBranchPullInfo(self, branch): | ||
424 | 446 | default_branch = '' | ||
425 | 447 | if branch.product is not None: | ||
426 | 448 | series = branch.product.development_focus | ||
427 | 449 | user_branch = series.branch | ||
428 | 450 | if (user_branch is not None | ||
429 | 451 | and not ( | ||
430 | 452 | user_branch.private | ||
431 | 453 | and branch.branch_type == BranchType.MIRRORED)): | ||
432 | 454 | default_branch = '/' + user_branch.unique_name | ||
433 | 455 | return ( | ||
434 | 456 | branch.id, branch.getPullURL(), branch.unique_name, | ||
435 | 457 | default_branch) | ||
436 | 458 | |||
437 | 459 | def getBranchPullQueue(self, branch_type): | ||
438 | 460 | queue = [] | ||
439 | 461 | branch_type = BranchType.items[branch_type] | ||
440 | 462 | for branch in self._branch_set: | ||
441 | 463 | if (branch.branch_type == branch_type | ||
442 | 464 | and branch.next_mirror_time < UTC_NOW): | ||
443 | 465 | queue.append(self._getBranchPullInfo(branch)) | ||
444 | 466 | return queue | ||
445 | 467 | |||
446 | 468 | def acquireBranchToPull(self): | 445 | def acquireBranchToPull(self): |
447 | 469 | branches = sorted( | 446 | branches = sorted( |
448 | 470 | [branch for branch in self._branch_set | 447 | [branch for branch in self._branch_set |
Just deleting some code we don't use any more.