Merge lp:~mwhudson/launchpad/no-hosted-area-server-catchup into lp:launchpad/db-devel
- no-hosted-area-server-catchup
- Merge into db-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/no-hosted-area-server-catchup |
Merge into: | lp:launchpad/db-devel |
Prerequisite: | lp:~mwhudson/launchpad/no-hosted-area-scanner-tests |
Diff against target: |
553 lines (+61/-173) 14 files modified
cronscripts/rosetta-branches.py (+2/-2) cronscripts/sendbranchmail.py (+2/-2) lib/lp/code/model/directbranchcommit.py (+2/-2) lib/lp/code/scripts/tests/test_sendbranchmail.py (+3/-3) lib/lp/codehosting/puller/tests/test_acceptance.py (+12/-19) lib/lp/codehosting/puller/tests/test_scheduler.py (+7/-5) lib/lp/codehosting/vfs/__init__.py (+2/-5) lib/lp/codehosting/vfs/branchfs.py (+2/-47) lib/lp/codehosting/vfs/tests/test_branchfs.py (+17/-3) lib/lp/codehosting/vfs/transport.py (+0/-20) lib/lp/testing/__init__.py (+0/-19) lib/lp/testing/factory.py (+2/-1) lib/lp/translations/tests/test_rosetta_branches_script.py (+2/-2) scripts/update-stacked-on.py (+8/-43) |
To merge this branch: | bzr merge lp:~mwhudson/launchpad/no-hosted-area-server-catchup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
Hi Tim,
This branch is mostly a cleanup, it removes all uses of get_puller_server or get_scanner_server and replaces them with get_rw_server or get_ro_server as appropriate.
There are also some clean ups and test fixes that really belong in a lower pipe -- I hope you'll forgive me for those.
Cheers,
mwh
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cronscripts/rosetta-branches.py' | |||
2 | --- cronscripts/rosetta-branches.py 2010-02-16 15:25:52 +0000 | |||
3 | +++ cronscripts/rosetta-branches.py 2010-04-27 02:24:09 +0000 | |||
4 | @@ -17,7 +17,7 @@ | |||
5 | 17 | from zope.component import getUtility | 17 | from zope.component import getUtility |
6 | 18 | 18 | ||
7 | 19 | from canonical.config import config | 19 | from canonical.config import config |
9 | 20 | from lp.codehosting.vfs.branchfs import get_scanner_server | 20 | from lp.codehosting.vfs.branchfs import get_ro_server |
10 | 21 | from lp.services.job.runner import JobRunner | 21 | from lp.services.job.runner import JobRunner |
11 | 22 | from lp.code.interfaces.branchjob import IRosettaUploadJobSource | 22 | from lp.code.interfaces.branchjob import IRosettaUploadJobSource |
12 | 23 | from lp.services.scripts.base import LaunchpadCronScript | 23 | from lp.services.scripts.base import LaunchpadCronScript |
13 | @@ -31,7 +31,7 @@ | |||
14 | 31 | globalErrorUtility.configure('rosettabranches') | 31 | globalErrorUtility.configure('rosettabranches') |
15 | 32 | runner = JobRunner.fromReady( | 32 | runner = JobRunner.fromReady( |
16 | 33 | getUtility(IRosettaUploadJobSource), self.logger) | 33 | getUtility(IRosettaUploadJobSource), self.logger) |
18 | 34 | server = get_scanner_server() | 34 | server = get_ro_server() |
19 | 35 | server.start_server() | 35 | server.start_server() |
20 | 36 | try: | 36 | try: |
21 | 37 | runner.runAll() | 37 | runner.runAll() |
22 | 38 | 38 | ||
23 | === modified file 'cronscripts/sendbranchmail.py' | |||
24 | --- cronscripts/sendbranchmail.py 2010-02-16 15:25:52 +0000 | |||
25 | +++ cronscripts/sendbranchmail.py 2010-04-27 02:24:09 +0000 | |||
26 | @@ -16,7 +16,7 @@ | |||
27 | 16 | from zope.component import getUtility | 16 | from zope.component import getUtility |
28 | 17 | 17 | ||
29 | 18 | from canonical.config import config | 18 | from canonical.config import config |
31 | 19 | from lp.codehosting.vfs import get_scanner_server | 19 | from lp.codehosting.vfs import get_ro_server |
32 | 20 | from lp.services.job.runner import JobRunner | 20 | from lp.services.job.runner import JobRunner |
33 | 21 | from lp.code.interfaces.branchjob import ( | 21 | from lp.code.interfaces.branchjob import ( |
34 | 22 | IRevisionMailJobSource, IRevisionsAddedJobSource) | 22 | IRevisionMailJobSource, IRevisionsAddedJobSource) |
35 | @@ -32,7 +32,7 @@ | |||
36 | 32 | jobs = list(getUtility(IRevisionMailJobSource).iterReady()) | 32 | jobs = list(getUtility(IRevisionMailJobSource).iterReady()) |
37 | 33 | jobs.extend(getUtility(IRevisionsAddedJobSource).iterReady()) | 33 | jobs.extend(getUtility(IRevisionsAddedJobSource).iterReady()) |
38 | 34 | runner = JobRunner(jobs, self.logger) | 34 | runner = JobRunner(jobs, self.logger) |
40 | 35 | server = get_scanner_server() | 35 | server = get_ro_server() |
41 | 36 | server.start_server() | 36 | server.start_server() |
42 | 37 | try: | 37 | try: |
43 | 38 | runner.runAll() | 38 | runner.runAll() |
44 | 39 | 39 | ||
45 | === modified file 'lib/lp/code/model/directbranchcommit.py' | |||
46 | --- lib/lp/code/model/directbranchcommit.py 2010-04-27 02:24:00 +0000 | |||
47 | +++ lib/lp/code/model/directbranchcommit.py 2010-04-27 02:24:09 +0000 | |||
48 | @@ -51,9 +51,9 @@ | |||
49 | 51 | """Create context for direct commit to branch. | 51 | """Create context for direct commit to branch. |
50 | 52 | 52 | ||
51 | 53 | Before constructing a `DirectBranchCommit`, set up a server that | 53 | Before constructing a `DirectBranchCommit`, set up a server that |
53 | 54 | allows write access to lp-hosted:/// URLs: | 54 | allows write access to lp-internal:/// URLs: |
54 | 55 | 55 | ||
56 | 56 | bzrserver = get_multi_server(write_hosted=True) | 56 | bzrserver = get_rw_server() |
57 | 57 | bzrserver.start_server() | 57 | bzrserver.start_server() |
58 | 58 | try: | 58 | try: |
59 | 59 | branchcommit = DirectBranchCommit(branch) | 59 | branchcommit = DirectBranchCommit(branch) |
60 | 60 | 60 | ||
61 | === modified file 'lib/lp/code/scripts/tests/test_sendbranchmail.py' | |||
62 | --- lib/lp/code/scripts/tests/test_sendbranchmail.py 2010-04-01 04:37:30 +0000 | |||
63 | +++ lib/lp/code/scripts/tests/test_sendbranchmail.py 2010-04-27 02:24:09 +0000 | |||
64 | @@ -23,7 +23,7 @@ | |||
65 | 23 | layer = ZopelessAppServerLayer | 23 | layer = ZopelessAppServerLayer |
66 | 24 | 24 | ||
67 | 25 | def createBranch(self): | 25 | def createBranch(self): |
69 | 26 | branch, tree = self.createMirroredBranchAndTree() | 26 | branch, tree = self.create_branch_and_tree() |
70 | 27 | branch.subscribe(branch.registrant, | 27 | branch.subscribe(branch.registrant, |
71 | 28 | BranchSubscriptionNotificationLevel.FULL, | 28 | BranchSubscriptionNotificationLevel.FULL, |
72 | 29 | BranchSubscriptionDiffSize.WHOLEDIFF, | 29 | BranchSubscriptionDiffSize.WHOLEDIFF, |
73 | @@ -36,7 +36,7 @@ | |||
74 | 36 | 36 | ||
75 | 37 | def test_sendbranchmail(self): | 37 | def test_sendbranchmail(self): |
76 | 38 | """Ensure sendbranchmail runs and sends email.""" | 38 | """Ensure sendbranchmail runs and sends email.""" |
78 | 39 | self.useTempBzrHome() | 39 | self.useBzrBranches() |
79 | 40 | branch, tree = self.createBranch() | 40 | branch, tree = self.createBranch() |
80 | 41 | RevisionMailJob.create( | 41 | RevisionMailJob.create( |
81 | 42 | branch, 1, 'from@example.org', 'body', True, 'foo') | 42 | branch, 1, 'from@example.org', 'body', True, 'foo') |
82 | @@ -68,7 +68,7 @@ | |||
83 | 68 | 68 | ||
84 | 69 | def test_revision_added_job(self): | 69 | def test_revision_added_job(self): |
85 | 70 | """RevisionsAddedJobs are run by sendbranchmail.""" | 70 | """RevisionsAddedJobs are run by sendbranchmail.""" |
87 | 71 | self.useTempBzrHome() | 71 | self.useBzrBranches() |
88 | 72 | branch, tree = self.createBranch() | 72 | branch, tree = self.createBranch() |
89 | 73 | tree.bzrdir.root_transport.put_bytes('foo', 'baz') | 73 | tree.bzrdir.root_transport.put_bytes('foo', 'baz') |
90 | 74 | tree.commit('Added foo.', rev_id='rev2') | 74 | tree.commit('Added foo.', rev_id='rev2') |
91 | 75 | 75 | ||
92 | === modified file 'lib/lp/codehosting/puller/tests/test_acceptance.py' | |||
93 | --- lib/lp/codehosting/puller/tests/test_acceptance.py 2010-04-27 02:24:00 +0000 | |||
94 | +++ lib/lp/codehosting/puller/tests/test_acceptance.py 2010-04-27 02:24:09 +0000 | |||
95 | @@ -7,22 +7,18 @@ | |||
96 | 7 | __all__ = [] | 7 | __all__ = [] |
97 | 8 | 8 | ||
98 | 9 | 9 | ||
99 | 10 | import datetime | ||
100 | 11 | import os | 10 | import os |
101 | 12 | from subprocess import PIPE, Popen | 11 | from subprocess import PIPE, Popen |
102 | 13 | import unittest | 12 | import unittest |
103 | 14 | 13 | ||
104 | 15 | import pytz | ||
105 | 16 | 14 | ||
106 | 17 | import transaction | 15 | import transaction |
107 | 18 | 16 | ||
108 | 19 | from bzrlib.branch import Branch | 17 | from bzrlib.branch import Branch |
109 | 20 | from bzrlib.bzrdir import BzrDir | 18 | from bzrlib.bzrdir import BzrDir |
110 | 21 | from bzrlib import errors | 19 | from bzrlib import errors |
111 | 22 | from bzrlib.transport import get_transport | ||
112 | 23 | from bzrlib.upgrade import upgrade | 20 | from bzrlib.upgrade import upgrade |
115 | 24 | from bzrlib.urlutils import ( | 21 | from bzrlib.urlutils import join as urljoin, local_path_from_url |
114 | 25 | join as urljoin, local_path_from_url, local_path_to_url) | ||
116 | 26 | from bzrlib.workingtree import WorkingTree | 22 | from bzrlib.workingtree import WorkingTree |
117 | 27 | 23 | ||
118 | 28 | from zope.component import getUtility | 24 | from zope.component import getUtility |
119 | @@ -30,7 +26,7 @@ | |||
120 | 30 | 26 | ||
121 | 31 | from lp.code.enums import BranchType | 27 | from lp.code.enums import BranchType |
122 | 32 | from lp.code.interfaces.branchtarget import IBranchTarget | 28 | from lp.code.interfaces.branchtarget import IBranchTarget |
124 | 33 | from lp.codehosting.vfs import branch_id_to_path, get_lp_server | 29 | from lp.codehosting.vfs import get_lp_server |
125 | 34 | from lp.codehosting.puller.tests import PullerBranchTestCase | 30 | from lp.codehosting.puller.tests import PullerBranchTestCase |
126 | 35 | from lp.codehosting.tests.helpers import LoomTestMixin | 31 | from lp.codehosting.tests.helpers import LoomTestMixin |
127 | 36 | from canonical.config import config | 32 | from canonical.config import config |
128 | @@ -56,8 +52,7 @@ | |||
129 | 56 | self.makeCleanDirectory( | 52 | self.makeCleanDirectory( |
130 | 57 | local_path_from_url(config.launchpad.bzr_imports_root_url)) | 53 | local_path_from_url(config.launchpad.bzr_imports_root_url)) |
131 | 58 | 54 | ||
134 | 59 | def assertMirrored(self, db_branch, source_branch, | 55 | def assertMirrored(self, db_branch, source_branch): |
133 | 60 | accessing_user=None): | ||
135 | 61 | """Assert that 'db_branch' was mirrored succesfully. | 56 | """Assert that 'db_branch' was mirrored succesfully. |
136 | 62 | 57 | ||
137 | 63 | This method checks that the fields on db_branch show that the branch | 58 | This method checks that the fields on db_branch show that the branch |
138 | @@ -73,8 +68,7 @@ | |||
139 | 73 | supplied create a fresh user for this -- but this won't work for a | 68 | supplied create a fresh user for this -- but this won't work for a |
140 | 74 | private branch. | 69 | private branch. |
141 | 75 | """ | 70 | """ |
144 | 76 | if accessing_user is None: | 71 | accessing_user = self.factory.makePerson() |
143 | 77 | accessing_user = self.factory.makePerson() | ||
145 | 78 | transaction.commit() | 72 | transaction.commit() |
146 | 79 | self.assertEqual(None, db_branch.mirror_status_message) | 73 | self.assertEqual(None, db_branch.mirror_status_message) |
147 | 80 | self.assertEqual( | 74 | self.assertEqual( |
148 | @@ -219,22 +213,21 @@ | |||
149 | 219 | (defaults to not). | 213 | (defaults to not). |
150 | 220 | :return: `IBranch`. | 214 | :return: `IBranch`. |
151 | 221 | """ | 215 | """ |
153 | 222 | # Make the branch. | 216 | # Make the branch in the database. |
154 | 223 | product = self.factory.makeProduct() | 217 | product = self.factory.makeProduct() |
155 | 224 | default_branch = self.factory.makeProductBranch( | 218 | default_branch = self.factory.makeProductBranch( |
156 | 225 | product=product, private=private) | 219 | product=product, private=private) |
159 | 226 | default_branch.last_mirrored = datetime.datetime.now(pytz.UTC) | 220 | transaction.commit() |
160 | 227 | # Make it the default stacked-on branch. | 221 | # Create the underlying bzr branch. |
161 | 222 | lp_server = self.getLPServerForUser(default_branch.owner) | ||
162 | 223 | BzrDir.create_branch_convenience( | ||
163 | 224 | lp_server.get_url() + default_branch.unique_name) | ||
164 | 225 | transaction.commit() | ||
165 | 226 | # Make it the default stacked-on branch for the product. | ||
166 | 228 | series = removeSecurityProxy(product.development_focus) | 227 | series = removeSecurityProxy(product.development_focus) |
167 | 229 | series.branch = default_branch | 228 | series.branch = default_branch |
168 | 230 | self.assertEqual( | 229 | self.assertEqual( |
169 | 231 | default_branch, IBranchTarget(product).default_stacked_on_branch) | 230 | default_branch, IBranchTarget(product).default_stacked_on_branch) |
170 | 232 | branch_location = urljoin( | ||
171 | 233 | local_path_to_url(config.codehosting.mirrored_branches_root), | ||
172 | 234 | branch_id_to_path(default_branch.id)) | ||
173 | 235 | get_transport(branch_location).create_prefix() | ||
174 | 236 | BzrDir.create_branch_convenience(branch_location) | ||
175 | 237 | transaction.commit() | ||
176 | 238 | return default_branch | 231 | return default_branch |
177 | 239 | 232 | ||
178 | 240 | def test_stack_mirrored_branch(self): | 233 | def test_stack_mirrored_branch(self): |
179 | 241 | 234 | ||
180 | === modified file 'lib/lp/codehosting/puller/tests/test_scheduler.py' | |||
181 | --- lib/lp/codehosting/puller/tests/test_scheduler.py 2010-04-27 02:24:00 +0000 | |||
182 | +++ lib/lp/codehosting/puller/tests/test_scheduler.py 2010-04-27 02:24:09 +0000 | |||
183 | @@ -28,6 +28,7 @@ | |||
184 | 28 | from canonical.launchpad.webapp import errorlog | 28 | from canonical.launchpad.webapp import errorlog |
185 | 29 | from canonical.testing import ( | 29 | from canonical.testing import ( |
186 | 30 | reset_logging, TwistedLayer, TwistedAppServerLayer) | 30 | reset_logging, TwistedLayer, TwistedAppServerLayer) |
187 | 31 | from lp.code.interfaces.codehosting import LAUNCHPAD_SERVICES | ||
188 | 31 | from lp.codehosting.puller import get_lock_id_for_branch_id, scheduler | 32 | from lp.codehosting.puller import get_lock_id_for_branch_id, scheduler |
189 | 32 | from lp.codehosting.puller.tests import PullerBranchTestCase | 33 | from lp.codehosting.puller.tests import PullerBranchTestCase |
190 | 33 | from lp.codehosting.puller.worker import ( | 34 | from lp.codehosting.puller.worker import ( |
191 | @@ -454,9 +455,9 @@ | |||
192 | 454 | 455 | ||
193 | 455 | def checkMirrorCompleted(ignored): | 456 | def checkMirrorCompleted(ignored): |
194 | 456 | self.assertEqual( | 457 | self.assertEqual( |
198 | 457 | [('branchChanged', self.arbitrary_branch_id, stacked_on_url, | 458 | [('branchChanged', LAUNCHPAD_SERVICES, |
199 | 458 | revid_after, control_string, branch_string, | 459 | self.arbitrary_branch_id, stacked_on_url, revid_after, |
200 | 459 | repository_string)], | 460 | control_string, branch_string, repository_string)], |
201 | 460 | self.status_client.calls) | 461 | self.status_client.calls) |
202 | 461 | return deferred.addCallback(checkMirrorCompleted) | 462 | return deferred.addCallback(checkMirrorCompleted) |
203 | 462 | 463 | ||
204 | @@ -680,8 +681,9 @@ | |||
205 | 680 | repository_string = \ | 681 | repository_string = \ |
206 | 681 | default_format.repository_format.get_format_string() | 682 | default_format.repository_format.get_format_string() |
207 | 682 | self.assertEqual( | 683 | self.assertEqual( |
210 | 683 | [('branchChanged', self.db_branch.id, '', revision_id, | 684 | [('branchChanged', LAUNCHPAD_SERVICES, self.db_branch.id, '', |
211 | 684 | control_string, branch_string, repository_string)], | 685 | revision_id, control_string, branch_string, |
212 | 686 | repository_string)], | ||
213 | 685 | self.client.calls) | 687 | self.client.calls) |
214 | 686 | return ignored | 688 | return ignored |
215 | 687 | deferred.addCallback(check_authserver_called) | 689 | deferred.addCallback(check_authserver_called) |
216 | 688 | 690 | ||
217 | === modified file 'lib/lp/codehosting/vfs/__init__.py' | |||
218 | --- lib/lp/codehosting/vfs/__init__.py 2010-04-27 02:24:00 +0000 | |||
219 | +++ lib/lp/codehosting/vfs/__init__.py 2010-04-27 02:24:09 +0000 | |||
220 | @@ -9,17 +9,14 @@ | |||
221 | 9 | 'branch_id_to_path', | 9 | 'branch_id_to_path', |
222 | 10 | 'BranchFileSystemClient', | 10 | 'BranchFileSystemClient', |
223 | 11 | 'get_lp_server', | 11 | 'get_lp_server', |
224 | 12 | 'get_multi_server', | ||
225 | 13 | 'get_ro_server', | 12 | 'get_ro_server', |
226 | 14 | 'get_rw_server', | 13 | 'get_rw_server', |
227 | 15 | 'get_scanner_server', | ||
228 | 16 | 'LaunchpadServer', | 14 | 'LaunchpadServer', |
229 | 17 | 'make_branch_mirrorer', | 15 | 'make_branch_mirrorer', |
230 | 18 | ] | 16 | ] |
231 | 19 | 17 | ||
232 | 20 | from lp.codehosting.vfs.branchfs import ( | 18 | from lp.codehosting.vfs.branchfs import ( |
236 | 21 | AsyncLaunchpadTransport, branch_id_to_path, get_lp_server, | 19 | AsyncLaunchpadTransport, LaunchpadServer, branch_id_to_path, |
237 | 22 | get_multi_server, get_ro_server, get_rw_server, get_scanner_server, | 20 | get_lp_server, get_ro_server, get_rw_server, make_branch_mirrorer) |
235 | 23 | LaunchpadServer, make_branch_mirrorer) | ||
238 | 24 | from lp.codehosting.vfs.branchfsclient import ( | 21 | from lp.codehosting.vfs.branchfsclient import ( |
239 | 25 | BlockingProxy,BranchFileSystemClient) | 22 | BlockingProxy,BranchFileSystemClient) |
240 | 26 | 23 | ||
241 | === modified file 'lib/lp/codehosting/vfs/branchfs.py' | |||
242 | --- lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:24:00 +0000 | |||
243 | +++ lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:24:09 +0000 | |||
244 | @@ -54,10 +54,8 @@ | |||
245 | 54 | 'BranchPolicy', | 54 | 'BranchPolicy', |
246 | 55 | 'DirectDatabaseLaunchpadServer', | 55 | 'DirectDatabaseLaunchpadServer', |
247 | 56 | 'get_lp_server', | 56 | 'get_lp_server', |
248 | 57 | 'get_multi_server', | ||
249 | 58 | 'get_ro_server', | 57 | 'get_ro_server', |
250 | 59 | 'get_rw_server', | 58 | 'get_rw_server', |
251 | 60 | 'get_scanner_server', | ||
252 | 61 | 'make_branch_mirrorer', | 59 | 'make_branch_mirrorer', |
253 | 62 | 'LaunchpadInternalServer', | 60 | 'LaunchpadInternalServer', |
254 | 63 | 'LaunchpadServer', | 61 | 'LaunchpadServer', |
255 | @@ -88,8 +86,8 @@ | |||
256 | 88 | from lp.codehosting.vfs.branchfsclient import ( | 86 | from lp.codehosting.vfs.branchfsclient import ( |
257 | 89 | BlockingProxy, BranchFileSystemClient) | 87 | BlockingProxy, BranchFileSystemClient) |
258 | 90 | from lp.codehosting.vfs.transport import ( | 88 | from lp.codehosting.vfs.transport import ( |
261 | 91 | AsyncVirtualServer, AsyncVirtualTransport, _MultiServer, | 89 | AsyncVirtualServer, AsyncVirtualTransport, TranslationError, |
262 | 92 | get_chrooted_transport, get_readonly_transport, TranslationError) | 90 | get_chrooted_transport, get_readonly_transport) |
263 | 93 | from canonical.config import config | 91 | from canonical.config import config |
264 | 94 | from canonical.launchpad.xmlrpc import faults | 92 | from canonical.launchpad.xmlrpc import faults |
265 | 95 | from lp.code.enums import BranchType | 93 | from lp.code.enums import BranchType |
266 | @@ -177,7 +175,6 @@ | |||
267 | 177 | return LaunchpadInternalServer( | 175 | return LaunchpadInternalServer( |
268 | 178 | 'lp-internal:///', codehosting_endpoint, branch_transport) | 176 | 'lp-internal:///', codehosting_endpoint, branch_transport) |
269 | 179 | 177 | ||
270 | 180 | get_scanner_server = get_ro_server | ||
271 | 181 | 178 | ||
272 | 182 | def get_rw_server(direct_database=False): | 179 | def get_rw_server(direct_database=False): |
273 | 183 | """Get a server that can write to the Launchpad branch vfs. | 180 | """Get a server that can write to the Launchpad branch vfs. |
274 | @@ -200,48 +197,6 @@ | |||
275 | 200 | 'lp-internal:///', codehosting_endpoint, transport) | 197 | 'lp-internal:///', codehosting_endpoint, transport) |
276 | 201 | 198 | ||
277 | 202 | 199 | ||
278 | 203 | def get_multi_server(write_hosted=False, write_mirrored=False, | ||
279 | 204 | direct_database=False): | ||
280 | 205 | """Get a server with access to both mirrored and hosted areas. | ||
281 | 206 | |||
282 | 207 | The server wraps up two `LaunchpadInternalServer`s or | ||
283 | 208 | `DirectDatabaseLaunchpadServer`s. One server points to the hosted branch | ||
284 | 209 | area and the other points to the mirrored area. | ||
285 | 210 | |||
286 | 211 | Write permision defaults to False, but can be overridden. | ||
287 | 212 | |||
288 | 213 | :param write_hosted: if True, lp-hosted URLs are writeable. Otherwise, | ||
289 | 214 | they are read-only. | ||
290 | 215 | :param write_mirrored: if True, lp-mirrored URLs are writeable. | ||
291 | 216 | Otherwise, they are read-only. | ||
292 | 217 | |||
293 | 218 | :param direct_database: if True, use a server implementation that talks | ||
294 | 219 | directly to the database. If False, the default, use a server | ||
295 | 220 | implementation that talks to the internal XML-RPC server. | ||
296 | 221 | """ | ||
297 | 222 | # XXX 2010-04-20, MichaelHudson: this function will disappear in a later | ||
298 | 223 | # pipe. | ||
299 | 224 | hosted_transport = get_chrooted_transport( | ||
300 | 225 | config.codehosting.mirrored_branches_root, mkdir=True) | ||
301 | 226 | if not write_hosted: | ||
302 | 227 | hosted_transport = get_readonly_transport(hosted_transport) | ||
303 | 228 | mirrored_transport = get_chrooted_transport( | ||
304 | 229 | config.codehosting.mirrored_branches_root, mkdir=True) | ||
305 | 230 | if not write_mirrored: | ||
306 | 231 | mirrored_transport = get_readonly_transport(mirrored_transport) | ||
307 | 232 | if direct_database: | ||
308 | 233 | make_server = DirectDatabaseLaunchpadServer | ||
309 | 234 | else: | ||
310 | 235 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) | ||
311 | 236 | codehosting_endpoint = BlockingProxy(proxy) | ||
312 | 237 | def make_server(scheme, transport): | ||
313 | 238 | return LaunchpadInternalServer( | ||
314 | 239 | scheme, codehosting_endpoint, transport) | ||
315 | 240 | hosted_server = make_server('lp-hosted:///', hosted_transport) | ||
316 | 241 | mirrored_server = make_server('lp-mirrored:///', mirrored_transport) | ||
317 | 242 | return _MultiServer(hosted_server, mirrored_server) | ||
318 | 243 | |||
319 | 244 | |||
320 | 245 | class ITransportDispatch(Interface): | 200 | class ITransportDispatch(Interface): |
321 | 246 | """Turns descriptions of transports into transports.""" | 201 | """Turns descriptions of transports into transports.""" |
322 | 247 | 202 | ||
323 | 248 | 203 | ||
324 | === modified file 'lib/lp/codehosting/vfs/tests/test_branchfs.py' | |||
325 | --- lib/lp/codehosting/vfs/tests/test_branchfs.py 2010-04-27 02:24:00 +0000 | |||
326 | +++ lib/lp/codehosting/vfs/tests/test_branchfs.py 2010-04-27 02:24:09 +0000 | |||
327 | @@ -826,11 +826,12 @@ | |||
328 | 826 | self.backing_transport = MemoryTransport() | 826 | self.backing_transport = MemoryTransport() |
329 | 827 | self.disable_directory_isolation() | 827 | self.disable_directory_isolation() |
330 | 828 | 828 | ||
332 | 829 | def _replacement_branchChanged(self, branch_id, stacked_on_url, | 829 | def _replacement_branchChanged(self, user_id, branch_id, stacked_on_url, |
333 | 830 | last_revision, *format_strings): | 830 | last_revision, *format_strings): |
334 | 831 | self._branch_changed_log.append(dict( | 831 | self._branch_changed_log.append(dict( |
337 | 832 | branch_id=branch_id, stacked_on_url=stacked_on_url, | 832 | user_id=user_id, branch_id=branch_id, |
338 | 833 | last_revision=last_revision, format_strings=format_strings)) | 833 | stacked_on_url=stacked_on_url, last_revision=last_revision, |
339 | 834 | format_strings=format_strings)) | ||
340 | 834 | 835 | ||
341 | 835 | def get_server(self): | 836 | def get_server(self): |
342 | 836 | if self._server is None: | 837 | if self._server is None: |
343 | @@ -862,6 +863,19 @@ | |||
344 | 862 | branch.unlock() | 863 | branch.unlock() |
345 | 863 | self.assertEqual(1, len(self._branch_changed_log)) | 864 | self.assertEqual(1, len(self._branch_changed_log)) |
346 | 864 | 865 | ||
347 | 866 | def test_branch_unlock_reports_users_id(self): | ||
348 | 867 | # Unlocking a branch calls branchChanged on the branch filesystem | ||
349 | 868 | # endpoint with the logged in user's id. | ||
350 | 869 | db_branch = self.factory.makeAnyBranch( | ||
351 | 870 | branch_type=BranchType.HOSTED, owner=self.requester) | ||
352 | 871 | branch = self.make_branch(db_branch.unique_name) | ||
353 | 872 | del self._branch_changed_log[:] | ||
354 | 873 | branch.lock_write() | ||
355 | 874 | branch.unlock() | ||
356 | 875 | self.assertEqual(1, len(self._branch_changed_log)) | ||
357 | 876 | self.assertEqual( | ||
358 | 877 | self.requester.id, self._branch_changed_log[0]['user_id']) | ||
359 | 878 | |||
360 | 865 | def test_branch_unlock_reports_stacked_on_url(self): | 879 | def test_branch_unlock_reports_stacked_on_url(self): |
361 | 866 | # Unlocking a branch reports the stacked on URL to the branch | 880 | # Unlocking a branch reports the stacked on URL to the branch |
362 | 867 | # filesystem endpoint. | 881 | # filesystem endpoint. |
363 | 868 | 882 | ||
364 | === modified file 'lib/lp/codehosting/vfs/transport.py' | |||
365 | --- lib/lp/codehosting/vfs/transport.py 2010-03-19 10:43:51 +0000 | |||
366 | +++ lib/lp/codehosting/vfs/transport.py 2010-04-27 02:24:09 +0000 | |||
367 | @@ -16,7 +16,6 @@ | |||
368 | 16 | 'AsyncVirtualTransport', | 16 | 'AsyncVirtualTransport', |
369 | 17 | 'get_chrooted_transport', | 17 | 'get_chrooted_transport', |
370 | 18 | 'get_readonly_transport', | 18 | 'get_readonly_transport', |
371 | 19 | '_MultiServer', | ||
372 | 20 | 'SynchronousAdapter', | 19 | 'SynchronousAdapter', |
373 | 21 | 'TranslationError', | 20 | 'TranslationError', |
374 | 22 | ] | 21 | ] |
375 | @@ -69,25 +68,6 @@ | |||
376 | 69 | return get_transport('readonly+' + transport.base) | 68 | return get_transport('readonly+' + transport.base) |
377 | 70 | 69 | ||
378 | 71 | 70 | ||
379 | 72 | class _MultiServer(Server): | ||
380 | 73 | """Server that wraps around multiple servers.""" | ||
381 | 74 | |||
382 | 75 | def __init__(self, *servers): | ||
383 | 76 | self._servers = servers | ||
384 | 77 | |||
385 | 78 | def start_server(self): | ||
386 | 79 | for server in self._servers: | ||
387 | 80 | server.start_server() | ||
388 | 81 | |||
389 | 82 | def destroy(self): | ||
390 | 83 | for server in reversed(self._servers): | ||
391 | 84 | server.destroy() | ||
392 | 85 | |||
393 | 86 | def stop_server(self): | ||
394 | 87 | for server in reversed(self._servers): | ||
395 | 88 | server.stop_server() | ||
396 | 89 | |||
397 | 90 | |||
398 | 91 | class AsyncVirtualTransport(Transport): | 71 | class AsyncVirtualTransport(Transport): |
399 | 92 | """A transport for a virtual file system. | 72 | """A transport for a virtual file system. |
400 | 93 | 73 | ||
401 | 94 | 74 | ||
402 | === modified file 'lib/lp/testing/__init__.py' | |||
403 | --- lib/lp/testing/__init__.py 2010-04-27 02:24:00 +0000 | |||
404 | +++ lib/lp/testing/__init__.py 2010-04-27 02:24:09 +0000 | |||
405 | @@ -499,25 +499,6 @@ | |||
406 | 499 | get_transport(base).create_prefix() | 499 | get_transport(base).create_prefix() |
407 | 500 | return os.path.join(base, branch_id_to_path(branch.id)) | 500 | return os.path.join(base, branch_id_to_path(branch.id)) |
408 | 501 | 501 | ||
409 | 502 | def createMirroredBranchAndTree(self): | ||
410 | 503 | """Create a database branch, bzr branch and bzr checkout. | ||
411 | 504 | |||
412 | 505 | This always uses the configured mirrored area, ignoring whatever | ||
413 | 506 | server might be providing lp-mirrored: urls. | ||
414 | 507 | |||
415 | 508 | Unlike normal codehosting operation, the working tree is stored in the | ||
416 | 509 | branch directory. | ||
417 | 510 | |||
418 | 511 | The branch and tree files are automatically deleted at the end of the | ||
419 | 512 | test. | ||
420 | 513 | |||
421 | 514 | :return: a `Branch` and a workingtree. | ||
422 | 515 | """ | ||
423 | 516 | db_branch = self.factory.makeAnyBranch() | ||
424 | 517 | bzr_branch = self.createBranchAtURL(self.getBranchPath( | ||
425 | 518 | db_branch, config.codehosting.internal_branch_by_id_root)) | ||
426 | 519 | return db_branch, bzr_branch.bzrdir.open_workingtree() | ||
427 | 520 | |||
428 | 521 | def useTempBzrHome(self): | 502 | def useTempBzrHome(self): |
429 | 522 | self.useTempDir() | 503 | self.useTempDir() |
430 | 523 | # Avoid leaking local user configuration into tests. | 504 | # Avoid leaking local user configuration into tests. |
431 | 524 | 505 | ||
432 | === modified file 'lib/lp/testing/factory.py' | |||
433 | --- lib/lp/testing/factory.py 2010-04-27 02:24:00 +0000 | |||
434 | +++ lib/lp/testing/factory.py 2010-04-27 02:24:09 +0000 | |||
435 | @@ -1058,7 +1058,8 @@ | |||
436 | 1058 | parent = revision | 1058 | parent = revision |
437 | 1059 | parent_ids = [parent.revision_id] | 1059 | parent_ids = [parent.revision_id] |
438 | 1060 | branch.startMirroring() | 1060 | branch.startMirroring() |
440 | 1061 | branch.mirrorComplete(parent.revision_id) | 1061 | removeSecurityProxy(branch).branchChanged( |
441 | 1062 | '', parent.revision_id, None, None, None) | ||
442 | 1062 | branch.updateScannedDetails(parent, sequence) | 1063 | branch.updateScannedDetails(parent, sequence) |
443 | 1063 | 1064 | ||
444 | 1064 | def makeBranchRevision(self, branch, revision_id, sequence=None): | 1065 | def makeBranchRevision(self, branch, revision_id, sequence=None): |
445 | 1065 | 1066 | ||
446 | === modified file 'lib/lp/translations/tests/test_rosetta_branches_script.py' | |||
447 | --- lib/lp/translations/tests/test_rosetta_branches_script.py 2009-09-03 20:29:25 +0000 | |||
448 | +++ lib/lp/translations/tests/test_rosetta_branches_script.py 2010-04-27 02:24:09 +0000 | |||
449 | @@ -38,9 +38,9 @@ | |||
450 | 38 | queue.remove(entry) | 38 | queue.remove(entry) |
451 | 39 | 39 | ||
452 | 40 | def _setup_series_branch(self, pot_path): | 40 | def _setup_series_branch(self, pot_path): |
454 | 41 | self.useTempBzrHome() | 41 | self.useBzrBranches() |
455 | 42 | pot_content = self.factory.getUniqueString() | 42 | pot_content = self.factory.getUniqueString() |
457 | 43 | branch, tree = self.createMirroredBranchAndTree() | 43 | branch, tree = self.create_branch_and_tree() |
458 | 44 | tree.bzrdir.root_transport.put_bytes(pot_path, pot_content) | 44 | tree.bzrdir.root_transport.put_bytes(pot_path, pot_content) |
459 | 45 | tree.add(pot_path) | 45 | tree.add(pot_path) |
460 | 46 | revision_id = tree.commit("first commit") | 46 | revision_id = tree.commit("first commit") |
461 | 47 | 47 | ||
462 | === modified file 'scripts/update-stacked-on.py' | |||
463 | --- scripts/update-stacked-on.py 2010-04-27 02:24:00 +0000 | |||
464 | +++ scripts/update-stacked-on.py 2010-04-27 02:24:09 +0000 | |||
465 | @@ -22,50 +22,16 @@ | |||
466 | 22 | 22 | ||
467 | 23 | import _pythonpath | 23 | import _pythonpath |
468 | 24 | import sys | 24 | import sys |
469 | 25 | import xmlrpclib | ||
470 | 26 | 25 | ||
471 | 27 | from bzrlib.bzrdir import BzrDir | 26 | from bzrlib.bzrdir import BzrDir |
472 | 28 | from bzrlib.config import TransportConfig | 27 | from bzrlib.config import TransportConfig |
473 | 29 | from bzrlib import errors | 28 | from bzrlib import errors |
474 | 30 | 29 | ||
479 | 31 | from lp.codehosting.vfs.branchfs import LaunchpadInternalServer | 30 | from lp.codehosting.vfs import get_rw_server, get_ro_server |
476 | 32 | from lp.codehosting.vfs import BlockingProxy | ||
477 | 33 | from lp.codehosting.vfs.transport import ( | ||
478 | 34 | get_chrooted_transport, get_readonly_transport, _MultiServer) | ||
480 | 35 | from lp.codehosting.bzrutils import get_branch_stacked_on_url | 31 | from lp.codehosting.bzrutils import get_branch_stacked_on_url |
481 | 36 | from canonical.config import config | ||
482 | 37 | from lp.services.scripts.base import LaunchpadScript | 32 | from lp.services.scripts.base import LaunchpadScript |
483 | 38 | 33 | ||
484 | 39 | 34 | ||
485 | 40 | def get_server(read_only): | ||
486 | 41 | """Get a server that can write to both hosted and mirrored areas.""" | ||
487 | 42 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) | ||
488 | 43 | authserver = BlockingProxy(proxy) | ||
489 | 44 | hosted_transport = get_chrooted_transport( | ||
490 | 45 | config.codehosting.hosted_branches_root) | ||
491 | 46 | if read_only: | ||
492 | 47 | hosted_transport = get_readonly_transport(hosted_transport) | ||
493 | 48 | mirrored_transport = get_chrooted_transport( | ||
494 | 49 | config.codehosting.mirrored_branches_root) | ||
495 | 50 | if read_only: | ||
496 | 51 | mirrored_transport = get_readonly_transport(mirrored_transport) | ||
497 | 52 | hosted_server = LaunchpadInternalServer( | ||
498 | 53 | 'lp-hosted:///', authserver, hosted_transport) | ||
499 | 54 | mirrored_server = LaunchpadInternalServer( | ||
500 | 55 | 'lp-mirrored:///', authserver, mirrored_transport) | ||
501 | 56 | return _MultiServer(hosted_server, mirrored_server) | ||
502 | 57 | |||
503 | 58 | |||
504 | 59 | def get_hosted_url(unique_name): | ||
505 | 60 | """Return the hosted URL for the branch with 'unique_name'.""" | ||
506 | 61 | return 'lp-hosted:///%s' % unique_name | ||
507 | 62 | |||
508 | 63 | |||
509 | 64 | def get_mirrored_url(unique_name): | ||
510 | 65 | """Return the mirrored URL for the branch with 'unique_name'.""" | ||
511 | 66 | return 'lp-mirrored:///%s' % unique_name | ||
512 | 67 | |||
513 | 68 | |||
514 | 69 | def set_branch_stacked_on_url(bzrdir, stacked_on_url): | 35 | def set_branch_stacked_on_url(bzrdir, stacked_on_url): |
515 | 70 | """Set the stacked_on_location for the branch at 'bzrdir'. | 36 | """Set the stacked_on_location for the branch at 'bzrdir'. |
516 | 71 | 37 | ||
517 | @@ -93,7 +59,10 @@ | |||
518 | 93 | "motions.")) | 59 | "motions.")) |
519 | 94 | 60 | ||
520 | 95 | def main(self): | 61 | def main(self): |
522 | 96 | server = get_server(self.options.dry_run) | 62 | if self.options.dry_run: |
523 | 63 | server = get_ro_server() | ||
524 | 64 | else: | ||
525 | 65 | server = get_rw_server() | ||
526 | 97 | server.start_server() | 66 | server.start_server() |
527 | 98 | if self.options.dry_run: | 67 | if self.options.dry_run: |
528 | 99 | self.logger.debug('Running read-only') | 68 | self.logger.debug('Running read-only') |
529 | @@ -109,8 +78,7 @@ | |||
530 | 109 | 78 | ||
531 | 110 | :param branch_id: The database ID of the branch. This is only used for | 79 | :param branch_id: The database ID of the branch. This is only used for |
532 | 111 | logging. | 80 | logging. |
535 | 112 | :param bzr_branch_url: The URL of the Bazaar branch. Normally this is | 81 | :param bzr_branch_url: The lp-internal:/// URL of the Bazaar branch. |
534 | 113 | of the form lp-mirrored:/// or lp-hosted:///. | ||
536 | 114 | :param stacked_on_location: The location to store in the branch's | 82 | :param stacked_on_location: The location to store in the branch's |
537 | 115 | stacked_on_location configuration variable. | 83 | stacked_on_location configuration variable. |
538 | 116 | """ | 84 | """ |
539 | @@ -165,12 +133,9 @@ | |||
540 | 165 | (branch_id, branch_type, unique_name, | 133 | (branch_id, branch_type, unique_name, |
541 | 166 | stacked_on_name) = branch_info | 134 | stacked_on_name) = branch_info |
542 | 167 | stacked_on_location = '/' + stacked_on_name | 135 | stacked_on_location = '/' + stacked_on_name |
543 | 168 | if branch_type == 'HOSTED': | ||
544 | 169 | self.updateStackedOn( | ||
545 | 170 | branch_id, get_hosted_url(unique_name), | ||
546 | 171 | stacked_on_location) | ||
547 | 172 | self.updateStackedOn( | 136 | self.updateStackedOn( |
549 | 173 | branch_id, get_mirrored_url(unique_name), stacked_on_location) | 137 | branch_id, 'lp-internal:///' + unique_name, |
550 | 138 | stacked_on_location) | ||
551 | 174 | 139 | ||
552 | 175 | 140 | ||
553 | 176 | if __name__ == '__main__': | 141 | if __name__ == '__main__': |
This is all good.