Merge lp:~mwhudson/launchpad/no-hosted-area-one-codehosting-endpoint into lp:launchpad
- no-hosted-area-one-codehosting-endpoint
- Merge into devel
Proposed by
Michael Hudson-Doyle
Status: | Merged |
---|---|
Approved by: | Michael Hudson-Doyle |
Approved revision: | no longer in the source branch. |
Merged at revision: | 10828 |
Proposed branch: | lp:~mwhudson/launchpad/no-hosted-area-one-codehosting-endpoint |
Merge into: | lp:launchpad |
Prerequisite: | lp:~mwhudson/launchpad/no-hosted-area-puller |
Diff against target: |
2294 lines (+436/-531) 28 files modified
bzrplugins/lpserve.py (+4/-4) configs/development/launchpad-lazr.conf (+1/-2) cronscripts/supermirror-pull.py (+1/-1) lib/canonical/config/schema-lazr.conf (+7/-9) lib/canonical/launchpad/interfaces/launchpad.py (+1/-3) lib/canonical/launchpad/systemhomes.py (+6/-14) lib/canonical/launchpad/xmlrpc/application.py (+4/-10) lib/canonical/launchpad/xmlrpc/configure.zcml (+9/-22) lib/lp/code/doc/xmlrpc-branch-filesystem.txt (+0/-31) lib/lp/code/doc/xmlrpc-branch-puller.txt (+0/-31) lib/lp/code/doc/xmlrpc-codehosting.txt (+32/-0) lib/lp/code/interfaces/codehosting.py (+10/-23) lib/lp/code/xmlrpc/codehosting.py (+58/-64) lib/lp/code/xmlrpc/tests/test_codehosting.py (+174/-184) lib/lp/codehosting/inmemory.py (+15/-29) lib/lp/codehosting/puller/scheduler.py (+9/-9) lib/lp/codehosting/puller/tests/test_scheduler.py (+7/-6) lib/lp/codehosting/sftp.py (+2/-1) lib/lp/codehosting/sshserver/daemon.py (+11/-11) lib/lp/codehosting/tests/test_acceptance.py (+3/-2) lib/lp/codehosting/tests/test_sftp.py (+3/-3) lib/lp/codehosting/vfs/branchfs.py (+40/-36) lib/lp/codehosting/vfs/branchfsclient.py (+17/-14) lib/lp/codehosting/vfs/tests/test_branchfs.py (+18/-18) lib/lp/codehosting/vfs/tests/test_branchfsclient.py (+1/-1) lib/lp/codehosting/vfs/tests/test_filesystem.py (+1/-1) lib/lp/codehosting/vfs/tests/test_transport.py (+1/-1) scripts/update-stacked-on.py (+1/-1) |
To merge this branch: | bzr merge lp:~mwhudson/launchpad/no-hosted-area-one-codehosting-endpoint |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Review via email: mp+23730@code.launchpad.net |
Commit message
Description of the change
Hi yet again Tim,
This large and EXTREMELY BORING branch combines the two codehosting api endpoints we currently have -- IBranchPuller and IBranchFileSystem -- into one -- ICodehostingAPI -- so that the puller can call the branchChanged method that is currently on IBranchPuller.
Cheers,
mwh
PS: it's very boring.
To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote : | # |
There is still an XML-RPC interface called IAuthServer. It's not a great name, but it's not a terrible name either.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote : | # |
It's not too terrible a name for the endpoint that implements authentication. It's a bit silly for all the other ones :-)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bzrplugins/lpserve.py' | |||
2 | --- bzrplugins/lpserve.py 2010-04-27 02:11:16 +0000 | |||
3 | +++ bzrplugins/lpserve.py 2010-04-27 02:11:35 +0000 | |||
4 | @@ -45,9 +45,9 @@ | |||
5 | 45 | Option('mirror-directory', | 45 | Option('mirror-directory', |
6 | 46 | help='serve branches from this directory. Defaults to ' | 46 | help='serve branches from this directory. Defaults to ' |
7 | 47 | 'config.codehosting.mirrored_branches_root.'), | 47 | 'config.codehosting.mirrored_branches_root.'), |
9 | 48 | Option('branchfs-endpoint', | 48 | Option('codehosting-endpoint', |
10 | 49 | help='the url of the internal XML-RPC server. Defaults to ' | 49 | help='the url of the internal XML-RPC server. Defaults to ' |
12 | 50 | 'config.codehosting.branchfs_endpoint.', | 50 | 'config.codehosting.codehosting_endpoint.', |
13 | 51 | type=unicode), | 51 | type=unicode), |
14 | 52 | ] | 52 | ] |
15 | 53 | 53 | ||
16 | @@ -86,7 +86,7 @@ | |||
17 | 86 | ui.ui_factory = old_factory | 86 | ui.ui_factory = old_factory |
18 | 87 | 87 | ||
19 | 88 | def run(self, user_id, port=None, branch_directory=None, | 88 | def run(self, user_id, port=None, branch_directory=None, |
21 | 89 | branchfs_endpoint_url=None, inet=False): | 89 | codehosting_endpoint_url=None, inet=False): |
22 | 90 | from lp.codehosting.bzrutils import install_oops_handler | 90 | from lp.codehosting.bzrutils import install_oops_handler |
23 | 91 | from lp.codehosting.vfs import get_lp_server, hooks | 91 | from lp.codehosting.vfs import get_lp_server, hooks |
24 | 92 | install_oops_handler(user_id) | 92 | install_oops_handler(user_id) |
25 | @@ -94,7 +94,7 @@ | |||
26 | 94 | resource.setrlimit(resource.RLIMIT_AS, (four_gig, four_gig)) | 94 | resource.setrlimit(resource.RLIMIT_AS, (four_gig, four_gig)) |
27 | 95 | seen_new_branch = hooks.SetProcTitleHook() | 95 | seen_new_branch = hooks.SetProcTitleHook() |
28 | 96 | lp_server = get_lp_server( | 96 | lp_server = get_lp_server( |
30 | 97 | int(user_id), branchfs_endpoint_url, branch_directory, | 97 | int(user_id), codehosting_endpoint_url, branch_directory, |
31 | 98 | seen_new_branch.seen) | 98 | seen_new_branch.seen) |
32 | 99 | lp_server.start_server() | 99 | lp_server.start_server() |
33 | 100 | 100 | ||
34 | 101 | 101 | ||
35 | === modified file 'configs/development/launchpad-lazr.conf' | |||
36 | --- configs/development/launchpad-lazr.conf 2010-04-27 02:11:16 +0000 | |||
37 | +++ configs/development/launchpad-lazr.conf 2010-04-27 02:11:35 +0000 | |||
38 | @@ -52,8 +52,7 @@ | |||
39 | 52 | [codehosting] | 52 | [codehosting] |
40 | 53 | launch: True | 53 | launch: True |
41 | 54 | authentication_endpoint: http://xmlrpc-private.launchpad.dev:8087/authserver | 54 | authentication_endpoint: http://xmlrpc-private.launchpad.dev:8087/authserver |
44 | 55 | branchfs_endpoint: http://xmlrpc-private.launchpad.dev:8087/branchfilesystem | 55 | codehosting_endpoint: http://xmlrpc-private.launchpad.dev:8087/codehosting |
43 | 56 | branch_puller_endpoint: http://xmlrpc-private.launchpad.dev:8087/branch_puller | ||
45 | 57 | supermirror_root: http://bazaar.launchpad.dev/ | 56 | supermirror_root: http://bazaar.launchpad.dev/ |
46 | 58 | hosted_branches_root: /var/tmp/bazaar.launchpad.dev/push-branches/ | 57 | hosted_branches_root: /var/tmp/bazaar.launchpad.dev/push-branches/ |
47 | 59 | codebrowse_root: http://bazaar.launchpad.dev/ | 58 | codebrowse_root: http://bazaar.launchpad.dev/ |
48 | 60 | 59 | ||
49 | === modified file 'cronscripts/supermirror-pull.py' | |||
50 | --- cronscripts/supermirror-pull.py 2010-03-25 18:06:39 +0000 | |||
51 | +++ cronscripts/supermirror-pull.py 2010-04-27 02:11:35 +0000 | |||
52 | @@ -44,7 +44,7 @@ | |||
53 | 44 | parser.error("Unhandled arguments %s" % repr(arguments)) | 44 | parser.error("Unhandled arguments %s" % repr(arguments)) |
54 | 45 | log = set_up_logging_for_script(options, 'supermirror_puller') | 45 | log = set_up_logging_for_script(options, 'supermirror_puller') |
55 | 46 | manager = scheduler.JobScheduler( | 46 | manager = scheduler.JobScheduler( |
57 | 47 | LoggingProxy(config.codehosting.branch_puller_endpoint, log), log, | 47 | LoggingProxy(config.codehosting.codehosting_endpoint, log), log, |
58 | 48 | options.branch_type) | 48 | options.branch_type) |
59 | 49 | 49 | ||
60 | 50 | reactor.callWhenRunning(run_mirror, log, manager) | 50 | reactor.callWhenRunning(run_mirror, log, manager) |
61 | 51 | 51 | ||
62 | === modified file 'lib/canonical/config/schema-lazr.conf' | |||
63 | --- lib/canonical/config/schema-lazr.conf 2010-04-27 02:11:16 +0000 | |||
64 | +++ lib/canonical/config/schema-lazr.conf 2010-04-27 02:11:35 +0000 | |||
65 | @@ -289,19 +289,17 @@ | |||
66 | 289 | # datatype: string | 289 | # datatype: string |
67 | 290 | authentication_endpoint: none | 290 | authentication_endpoint: none |
68 | 291 | 291 | ||
74 | 292 | # The URL of the XML-RPC endpoint used to provide the data that drives the | 292 | # Obsolete. |
70 | 293 | # virtual file systems used by the code hosting service. This should | ||
71 | 294 | # implement IBranchFileSystem. | ||
72 | 295 | # | ||
73 | 296 | # datatype: string | ||
75 | 297 | branchfs_endpoint: none | 293 | branchfs_endpoint: none |
76 | 298 | 294 | ||
81 | 299 | # The URL of the XML-RPC endpoint that provides the interface from the | 295 | # Obsolete. |
78 | 300 | # puller to the rest of Launchpad. This should implement IPullerAPI. | ||
79 | 301 | # | ||
80 | 302 | # datatype: string | ||
82 | 303 | branch_puller_endpoint: none | 296 | branch_puller_endpoint: none |
83 | 304 | 297 | ||
84 | 298 | # The URL of the XML-RPC endpoint that implements ICodehostingAPI. | ||
85 | 299 | # | ||
86 | 300 | # datatype: string | ||
87 | 301 | codehosting_endpoint: none | ||
88 | 302 | |||
89 | 305 | # See [error_reports]. | 303 | # See [error_reports]. |
90 | 306 | oops_prefix: none | 304 | oops_prefix: none |
91 | 307 | 305 | ||
92 | 308 | 306 | ||
93 | === added directory 'lib/canonical/launchpad/apidoc' | |||
94 | === modified file 'lib/canonical/launchpad/interfaces/launchpad.py' | |||
95 | --- lib/canonical/launchpad/interfaces/launchpad.py 2010-04-19 14:47:49 +0000 | |||
96 | +++ lib/canonical/launchpad/interfaces/launchpad.py 2010-04-27 02:11:35 +0000 | |||
97 | @@ -292,9 +292,7 @@ | |||
98 | 292 | 292 | ||
99 | 293 | codeimportscheduler = Attribute("""Code import scheduler end point.""") | 293 | codeimportscheduler = Attribute("""Code import scheduler end point.""") |
100 | 294 | 294 | ||
104 | 295 | branch_puller = Attribute("""Branch puller end point.""") | 295 | codehosting = Attribute("""Codehosting end point.""") |
102 | 296 | |||
103 | 297 | branchfilesystem = Attribute("""The branch filesystem end point.""") | ||
105 | 298 | 296 | ||
106 | 299 | mailinglists = Attribute("""Mailing list XML-RPC end point.""") | 297 | mailinglists = Attribute("""Mailing list XML-RPC end point.""") |
107 | 300 | 298 | ||
108 | 301 | 299 | ||
109 | === modified file 'lib/canonical/launchpad/systemhomes.py' | |||
110 | --- lib/canonical/launchpad/systemhomes.py 2010-04-05 16:06:06 +0000 | |||
111 | +++ lib/canonical/launchpad/systemhomes.py 2010-04-27 02:11:35 +0000 | |||
112 | @@ -42,8 +42,7 @@ | |||
113 | 42 | from canonical.launchpad.webapp.interfaces import ICanonicalUrlData | 42 | from canonical.launchpad.webapp.interfaces import ICanonicalUrlData |
114 | 43 | from lp.bugs.interfaces.bug import ( | 43 | from lp.bugs.interfaces.bug import ( |
115 | 44 | CreateBugParams, IBugSet, InvalidBugTargetType) | 44 | CreateBugParams, IBugSet, InvalidBugTargetType) |
118 | 45 | from lp.code.interfaces.codehosting import ( | 45 | from lp.code.interfaces.codehosting import ICodehostingApplication |
117 | 46 | IBranchFileSystemApplication, IBranchPullerApplication) | ||
119 | 47 | from lp.code.interfaces.codeimportscheduler import ( | 46 | from lp.code.interfaces.codeimportscheduler import ( |
120 | 48 | ICodeImportSchedulerApplication) | 47 | ICodeImportSchedulerApplication) |
121 | 49 | from lp.registry.interfaces.product import IProduct | 48 | from lp.registry.interfaces.product import IProduct |
122 | @@ -61,18 +60,11 @@ | |||
123 | 61 | title = "Auth Server" | 60 | title = "Auth Server" |
124 | 62 | 61 | ||
125 | 63 | 62 | ||
138 | 64 | class BranchFileSystemApplication: | 63 | class CodehostingApplication: |
139 | 65 | """BranchFileSystem End-Point.""" | 64 | """Codehosting End-Point.""" |
140 | 66 | implements(IBranchFileSystemApplication) | 65 | implements(ICodehostingApplication) |
141 | 67 | 66 | ||
142 | 68 | title = "Branch File System" | 67 | title = "Codehosting API" |
131 | 69 | |||
132 | 70 | |||
133 | 71 | class BranchPullerApplication: | ||
134 | 72 | """BranchPuller End-Point.""" | ||
135 | 73 | implements(IBranchPullerApplication) | ||
136 | 74 | |||
137 | 75 | title = "Puller API" | ||
143 | 76 | 68 | ||
144 | 77 | 69 | ||
145 | 78 | class CodeImportSchedulerApplication: | 70 | class CodeImportSchedulerApplication: |
146 | 79 | 71 | ||
147 | === modified file 'lib/canonical/launchpad/xmlrpc/application.py' | |||
148 | --- lib/canonical/launchpad/xmlrpc/application.py 2009-06-25 05:30:52 +0000 | |||
149 | +++ lib/canonical/launchpad/xmlrpc/application.py 2010-04-27 02:11:35 +0000 | |||
150 | @@ -24,8 +24,7 @@ | |||
151 | 24 | IAuthServerApplication, ILaunchBag, | 24 | IAuthServerApplication, ILaunchBag, |
152 | 25 | IMailingListApplication, IPrivateApplication, | 25 | IMailingListApplication, IPrivateApplication, |
153 | 26 | IPrivateMaloneApplication) | 26 | IPrivateMaloneApplication) |
156 | 27 | from lp.code.interfaces.codehosting import ( | 27 | from lp.code.interfaces.codehosting import ICodehostingApplication |
155 | 28 | IBranchFileSystemApplication, IBranchPullerApplication) | ||
157 | 29 | from lp.code.interfaces.codeimportscheduler import ( | 28 | from lp.code.interfaces.codeimportscheduler import ( |
158 | 30 | ICodeImportSchedulerApplication) | 29 | ICodeImportSchedulerApplication) |
159 | 31 | from canonical.launchpad.webapp import LaunchpadXMLRPCView | 30 | from canonical.launchpad.webapp import LaunchpadXMLRPCView |
160 | @@ -45,14 +44,9 @@ | |||
161 | 45 | return getUtility(IAuthServerApplication) | 44 | return getUtility(IAuthServerApplication) |
162 | 46 | 45 | ||
163 | 47 | @property | 46 | @property |
172 | 48 | def branch_puller(self): | 47 | def codehosting(self): |
173 | 49 | """See `IPrivateApplication`.""" | 48 | """See `IPrivateApplication`.""" |
174 | 50 | return getUtility(IBranchPullerApplication) | 49 | return getUtility(ICodehostingApplication) |
167 | 51 | |||
168 | 52 | @property | ||
169 | 53 | def branchfilesystem(self): | ||
170 | 54 | """See `IPrivateApplication`.""" | ||
171 | 55 | return getUtility(IBranchFileSystemApplication) | ||
175 | 56 | 50 | ||
176 | 57 | @property | 51 | @property |
177 | 58 | def codeimportscheduler(self): | 52 | def codeimportscheduler(self): |
178 | 59 | 53 | ||
179 | === modified file 'lib/canonical/launchpad/xmlrpc/configure.zcml' | |||
180 | --- lib/canonical/launchpad/xmlrpc/configure.zcml 2009-07-13 18:15:02 +0000 | |||
181 | +++ lib/canonical/launchpad/xmlrpc/configure.zcml 2010-04-27 02:11:35 +0000 | |||
182 | @@ -28,28 +28,15 @@ | |||
183 | 28 | /> | 28 | /> |
184 | 29 | 29 | ||
185 | 30 | <securedutility | 30 | <securedutility |
208 | 31 | class="canonical.launchpad.systemhomes.BranchPullerApplication" | 31 | class="canonical.launchpad.systemhomes.CodehostingApplication" |
209 | 32 | provides="lp.code.interfaces.codehosting.IBranchPullerApplication"> | 32 | provides="lp.code.interfaces.codehosting.ICodehostingApplication"> |
210 | 33 | <allow interface="lp.code.interfaces.codehosting.IBranchPullerApplication"/> | 33 | <allow interface="lp.code.interfaces.codehosting.ICodehostingApplication"/> |
211 | 34 | </securedutility> | 34 | </securedutility> |
212 | 35 | 35 | ||
213 | 36 | <xmlrpc:view | 36 | <xmlrpc:view |
214 | 37 | for="lp.code.interfaces.codehosting.IBranchPullerApplication" | 37 | for="lp.code.interfaces.codehosting.ICodehostingApplication" |
215 | 38 | interface="lp.code.interfaces.codehosting.IBranchPuller" | 38 | interface="lp.code.interfaces.codehosting.ICodehostingAPI" |
216 | 39 | class="lp.code.xmlrpc.codehosting.BranchPuller" | 39 | class="lp.code.xmlrpc.codehosting.CodehostingAPI" |
195 | 40 | permission="zope.Public" | ||
196 | 41 | /> | ||
197 | 42 | |||
198 | 43 | <securedutility | ||
199 | 44 | class="canonical.launchpad.systemhomes.BranchFileSystemApplication" | ||
200 | 45 | provides="lp.code.interfaces.codehosting.IBranchFileSystemApplication"> | ||
201 | 46 | <allow interface="lp.code.interfaces.codehosting.IBranchFileSystemApplication"/> | ||
202 | 47 | </securedutility> | ||
203 | 48 | |||
204 | 49 | <xmlrpc:view | ||
205 | 50 | for="lp.code.interfaces.codehosting.IBranchFileSystemApplication" | ||
206 | 51 | interface="lp.code.interfaces.codehosting.IBranchFileSystem" | ||
207 | 52 | class="lp.code.xmlrpc.codehosting.BranchFileSystem" | ||
217 | 53 | permission="zope.Public" | 40 | permission="zope.Public" |
218 | 54 | /> | 41 | /> |
219 | 55 | 42 | ||
220 | 56 | 43 | ||
221 | === removed file 'lib/lp/code/doc/xmlrpc-branch-filesystem.txt' | |||
222 | --- lib/lp/code/doc/xmlrpc-branch-filesystem.txt 2009-10-22 11:55:51 +0000 | |||
223 | +++ lib/lp/code/doc/xmlrpc-branch-filesystem.txt 1970-01-01 00:00:00 +0000 | |||
224 | @@ -1,31 +0,0 @@ | |||
225 | 1 | = The BranchFileSystem application = | ||
226 | 2 | |||
227 | 3 | The branch file system application is an XMLRPC service that provides | ||
228 | 4 | data for the virtual filesystems used by the codehosting service. It | ||
229 | 5 | is available as the branchfilesystem attribute of our private XMLRPC | ||
230 | 6 | instance. | ||
231 | 7 | |||
232 | 8 | >>> from canonical.launchpad.interfaces import ( | ||
233 | 9 | ... IPrivateApplication) | ||
234 | 10 | >>> from lp.code.interfaces.codehosting import ( | ||
235 | 11 | ... IBranchFileSystemApplication) | ||
236 | 12 | >>> from canonical.launchpad.webapp.testing import verifyObject | ||
237 | 13 | |||
238 | 14 | >>> private_root = getUtility(IPrivateApplication) | ||
239 | 15 | >>> verifyObject( | ||
240 | 16 | ... IBranchFileSystemApplication, | ||
241 | 17 | ... private_root.branchfilesystem) | ||
242 | 18 | True | ||
243 | 19 | |||
244 | 20 | The end point is implemented by the BranchFileSystem, which implements | ||
245 | 21 | the IBranchFileSystem class. | ||
246 | 22 | |||
247 | 23 | >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest | ||
248 | 24 | >>> from lp.code.interfaces.codehosting import IBranchFileSystem | ||
249 | 25 | >>> from lp.code.xmlrpc.codehosting import ( | ||
250 | 26 | ... BranchFileSystem) | ||
251 | 27 | |||
252 | 28 | >>> branchfs_api = BranchFileSystem( | ||
253 | 29 | ... private_root.branchfilesystem, LaunchpadTestRequest()) | ||
254 | 30 | >>> verifyObject(IBranchFileSystem, branchfs_api) | ||
255 | 31 | True | ||
256 | 32 | 0 | ||
257 | === removed file 'lib/lp/code/doc/xmlrpc-branch-puller.txt' | |||
258 | --- lib/lp/code/doc/xmlrpc-branch-puller.txt 2010-02-24 01:57:35 +0000 | |||
259 | +++ lib/lp/code/doc/xmlrpc-branch-puller.txt 1970-01-01 00:00:00 +0000 | |||
260 | @@ -1,31 +0,0 @@ | |||
261 | 1 | = The BranchPuller application = | ||
262 | 2 | |||
263 | 3 | The branch puller application is an XMLRPC service that allows the puller | ||
264 | 4 | to find and update the status of branches. It is available as the | ||
265 | 5 | branch_puller attribute of our private XMLRPC instance. | ||
266 | 6 | |||
267 | 7 | >>> from canonical.launchpad.interfaces import ( | ||
268 | 8 | ... IPrivateApplication) | ||
269 | 9 | >>> from lp.code.interfaces.codehosting import ( | ||
270 | 10 | ... IBranchPullerApplication) | ||
271 | 11 | >>> from canonical.launchpad.webapp.testing import verifyObject | ||
272 | 12 | |||
273 | 13 | >>> private_root = getUtility(IPrivateApplication) | ||
274 | 14 | >>> verifyObject( | ||
275 | 15 | ... IBranchPullerApplication, | ||
276 | 16 | ... private_root.branch_puller) | ||
277 | 17 | True | ||
278 | 18 | |||
279 | 19 | The BranchPuller view provides the IBranchPuller XML-RPC API: | ||
280 | 20 | |||
281 | 21 | >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest | ||
282 | 22 | >>> from lp.code.interfaces.codehosting import IBranchPuller | ||
283 | 23 | >>> from lp.code.xmlrpc.codehosting import BranchPuller | ||
284 | 24 | |||
285 | 25 | >>> branch_puller = BranchPuller( | ||
286 | 26 | ... private_root.branch_puller, LaunchpadTestRequest()) | ||
287 | 27 | >>> verifyObject(IBranchPuller, branch_puller) | ||
288 | 28 | True | ||
289 | 29 | |||
290 | 30 | The IBranchPuller interface defines some methods, for which see the unit | ||
291 | 31 | tests. | ||
292 | 32 | 0 | ||
293 | === added file 'lib/lp/code/doc/xmlrpc-codehosting.txt' | |||
294 | --- lib/lp/code/doc/xmlrpc-codehosting.txt 1970-01-01 00:00:00 +0000 | |||
295 | +++ lib/lp/code/doc/xmlrpc-codehosting.txt 2010-04-27 02:11:35 +0000 | |||
296 | @@ -0,0 +1,32 @@ | |||
297 | 1 | = The BranchPuller application = | ||
298 | 2 | |||
299 | 3 | The codehosting application is an XMLRPC service that allows the | ||
300 | 4 | codehosting service and puller to find and update the status of | ||
301 | 5 | branches. It is available as the codehosting attribute of our private | ||
302 | 6 | XMLRPC instance. | ||
303 | 7 | |||
304 | 8 | >>> from canonical.launchpad.interfaces import ( | ||
305 | 9 | ... IPrivateApplication) | ||
306 | 10 | >>> from lp.code.interfaces.codehosting import ( | ||
307 | 11 | ... ICodehostingApplication) | ||
308 | 12 | >>> from canonical.launchpad.webapp.testing import verifyObject | ||
309 | 13 | |||
310 | 14 | >>> private_root = getUtility(IPrivateApplication) | ||
311 | 15 | >>> verifyObject( | ||
312 | 16 | ... ICodehostingApplication, | ||
313 | 17 | ... private_root.codehosting) | ||
314 | 18 | True | ||
315 | 19 | |||
316 | 20 | The CodeHosting view provides the ICodehostingAPI XML-RPC API: | ||
317 | 21 | |||
318 | 22 | >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest | ||
319 | 23 | >>> from lp.code.interfaces.codehosting import ICodehostingAPI | ||
320 | 24 | >>> from lp.code.xmlrpc.codehosting import CodehostingAPI | ||
321 | 25 | |||
322 | 26 | >>> codehosting_api = CodehostingAPI( | ||
323 | 27 | ... private_root.codehosting, LaunchpadTestRequest()) | ||
324 | 28 | >>> verifyObject(ICodehostingAPI, codehosting_api) | ||
325 | 29 | True | ||
326 | 30 | |||
327 | 31 | The ICodehostingAPI interface defines some methods, for which see the | ||
328 | 32 | unit tests. | ||
329 | 0 | 33 | ||
330 | === modified file 'lib/lp/code/interfaces/codehosting.py' | |||
331 | --- lib/lp/code/interfaces/codehosting.py 2010-04-27 02:11:16 +0000 | |||
332 | +++ lib/lp/code/interfaces/codehosting.py 2010-04-27 02:11:35 +0000 | |||
333 | @@ -9,10 +9,8 @@ | |||
334 | 9 | __all__ = [ | 9 | __all__ = [ |
335 | 10 | 'BRANCH_TRANSPORT', | 10 | 'BRANCH_TRANSPORT', |
336 | 11 | 'CONTROL_TRANSPORT', | 11 | 'CONTROL_TRANSPORT', |
341 | 12 | 'IBranchPuller', | 12 | 'ICodehostingAPI', |
342 | 13 | 'IBranchPullerApplication', | 13 | 'ICodehostingApplication', |
339 | 14 | 'IBranchFileSystem', | ||
340 | 15 | 'IBranchFileSystemApplication', | ||
343 | 16 | 'LAUNCHPAD_ANONYMOUS', | 14 | 'LAUNCHPAD_ANONYMOUS', |
344 | 17 | 'LAUNCHPAD_SERVICES', | 15 | 'LAUNCHPAD_SERVICES', |
345 | 18 | 'READ_ONLY', | 16 | 'READ_ONLY', |
346 | @@ -48,14 +46,17 @@ | |||
347 | 48 | CONTROL_TRANSPORT = 'CONTROL_TRANSPORT' | 46 | CONTROL_TRANSPORT = 'CONTROL_TRANSPORT' |
348 | 49 | 47 | ||
349 | 50 | 48 | ||
351 | 51 | class IBranchPullerApplication(ILaunchpadApplication): | 49 | class ICodehostingApplication(ILaunchpadApplication): |
352 | 52 | """Branch Puller application root.""" | 50 | """Branch Puller application root.""" |
353 | 53 | 51 | ||
354 | 54 | 52 | ||
359 | 55 | class IBranchPuller(Interface): | 53 | class ICodehostingAPI(Interface): |
360 | 56 | """The puller's interface to the rest of Launchpad. | 54 | """The codehosting XML-RPC interface to Launchpad. |
361 | 57 | 55 | ||
362 | 58 | Published at 'branch_puller' on the private XML-RPC server. | 56 | Published at 'codehosting' on the private XML-RPC server. |
363 | 57 | |||
364 | 58 | The code hosting service and puller use this to register branches, to | ||
365 | 59 | retrieve information about a user's branches, and to update their status. | ||
366 | 59 | """ | 60 | """ |
367 | 60 | 61 | ||
368 | 61 | def acquireBranchToPull(branch_type_names): | 62 | def acquireBranchToPull(branch_type_names): |
369 | @@ -144,20 +145,6 @@ | |||
370 | 144 | 'stacked_on_location'. | 145 | 'stacked_on_location'. |
371 | 145 | """ | 146 | """ |
372 | 146 | 147 | ||
373 | 147 | |||
374 | 148 | class IBranchFileSystemApplication(ILaunchpadApplication): | ||
375 | 149 | """Branch File System end point root.""" | ||
376 | 150 | |||
377 | 151 | |||
378 | 152 | class IBranchFileSystem(Interface): | ||
379 | 153 | """An interface for dealing with hosted branches in Launchpad. | ||
380 | 154 | |||
381 | 155 | Published at `branchfilesystem`. | ||
382 | 156 | |||
383 | 157 | The code hosting service uses this to register branches, to retrieve | ||
384 | 158 | information about a user's branches, and to update their status. | ||
385 | 159 | """ | ||
386 | 160 | |||
387 | 161 | def createBranch(login_id, branch_path): | 148 | def createBranch(login_id, branch_path): |
388 | 162 | """Register a new hosted branch in Launchpad. | 149 | """Register a new hosted branch in Launchpad. |
389 | 163 | 150 | ||
390 | 164 | 151 | ||
391 | === modified file 'lib/lp/code/xmlrpc/codehosting.py' | |||
392 | --- lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:11:16 +0000 | |||
393 | +++ lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:11:35 +0000 | |||
394 | @@ -5,8 +5,7 @@ | |||
395 | 5 | 5 | ||
396 | 6 | __metaclass__ = type | 6 | __metaclass__ = type |
397 | 7 | __all__ = [ | 7 | __all__ = [ |
400 | 8 | 'BranchFileSystem', | 8 | 'CodehostingAPI', |
399 | 9 | 'BranchPuller', | ||
401 | 10 | 'datetime_from_tuple', | 9 | 'datetime_from_tuple', |
402 | 11 | ] | 10 | ] |
403 | 12 | 11 | ||
404 | @@ -43,8 +42,8 @@ | |||
405 | 43 | InvalidNamespace, lookup_branch_namespace, split_unique_name) | 42 | InvalidNamespace, lookup_branch_namespace, split_unique_name) |
406 | 44 | from lp.code.interfaces import branchpuller | 43 | from lp.code.interfaces import branchpuller |
407 | 45 | from lp.code.interfaces.codehosting import ( | 44 | from lp.code.interfaces.codehosting import ( |
410 | 46 | BRANCH_TRANSPORT, CONTROL_TRANSPORT, IBranchFileSystem, IBranchPuller, | 45 | BRANCH_TRANSPORT, CONTROL_TRANSPORT, ICodehostingAPI, LAUNCHPAD_ANONYMOUS, |
411 | 47 | LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES) | 46 | LAUNCHPAD_SERVICES) |
412 | 48 | from lp.registry.interfaces.person import IPersonSet, NoSuchPerson | 47 | from lp.registry.interfaces.person import IPersonSet, NoSuchPerson |
413 | 49 | from lp.registry.interfaces.product import NoSuchProduct | 48 | from lp.registry.interfaces.product import NoSuchProduct |
414 | 50 | from lp.services.scripts.interfaces.scriptactivity import IScriptActivitySet | 49 | from lp.services.scripts.interfaces.scriptactivity import IScriptActivitySet |
415 | @@ -54,13 +53,54 @@ | |||
416 | 54 | UTC = pytz.timezone('UTC') | 53 | UTC = pytz.timezone('UTC') |
417 | 55 | 54 | ||
418 | 56 | 55 | ||
423 | 57 | class BranchPuller(LaunchpadXMLRPCView): | 56 | def datetime_from_tuple(time_tuple): |
424 | 58 | """See `IBranchPuller`.""" | 57 | """Create a datetime from a sequence that quacks like time.struct_time. |
425 | 59 | 58 | ||
426 | 60 | implements(IBranchPuller) | 59 | The tm_isdst is (index 8) is ignored. The created datetime uses |
427 | 60 | tzinfo=UTC. | ||
428 | 61 | """ | ||
429 | 62 | [year, month, day, hour, minute, second, unused, unused, unused] = ( | ||
430 | 63 | time_tuple) | ||
431 | 64 | return datetime.datetime( | ||
432 | 65 | year, month, day, hour, minute, second, tzinfo=UTC) | ||
433 | 66 | |||
434 | 67 | |||
435 | 68 | def run_with_login(login_id, function, *args, **kwargs): | ||
436 | 69 | """Run 'function' logged in with 'login_id'. | ||
437 | 70 | |||
438 | 71 | The first argument passed to 'function' will be the Launchpad | ||
439 | 72 | `Person` object corresponding to 'login_id'. | ||
440 | 73 | |||
441 | 74 | The exception is when the requesting login ID is `LAUNCHPAD_SERVICES`. In | ||
442 | 75 | that case, we'll pass through the `LAUNCHPAD_SERVICES` variable and the | ||
443 | 76 | method will do whatever security proxy hackery is required to provide read | ||
444 | 77 | privileges to the Launchpad services. | ||
445 | 78 | """ | ||
446 | 79 | if login_id == LAUNCHPAD_SERVICES or login_id == LAUNCHPAD_ANONYMOUS: | ||
447 | 80 | # Don't pass in an actual user. Instead pass in LAUNCHPAD_SERVICES | ||
448 | 81 | # and expect `function` to use `removeSecurityProxy` or similar. | ||
449 | 82 | return function(login_id, *args, **kwargs) | ||
450 | 83 | if isinstance(login_id, basestring): | ||
451 | 84 | requester = getUtility(IPersonSet).getByName(login_id) | ||
452 | 85 | else: | ||
453 | 86 | requester = getUtility(IPersonSet).get(login_id) | ||
454 | 87 | if requester is None: | ||
455 | 88 | raise NotFoundError("No person with id %s." % login_id) | ||
456 | 89 | setupInteractionForPerson(requester) | ||
457 | 90 | try: | ||
458 | 91 | return function(requester, *args, **kwargs) | ||
459 | 92 | finally: | ||
460 | 93 | endInteraction() | ||
461 | 94 | |||
462 | 95 | |||
463 | 96 | |||
464 | 97 | class CodehostingAPI(LaunchpadXMLRPCView): | ||
465 | 98 | """See `ICodehostingAPI`.""" | ||
466 | 99 | |||
467 | 100 | implements(ICodehostingAPI) | ||
468 | 61 | 101 | ||
469 | 62 | def acquireBranchToPull(self, branch_type_names): | 102 | def acquireBranchToPull(self, branch_type_names): |
471 | 63 | """See `IBranchPuller`.""" | 103 | """See `ICodehostingAPI`.""" |
472 | 64 | branch_types = [] | 104 | branch_types = [] |
473 | 65 | for branch_type_name in branch_type_names: | 105 | for branch_type_name in branch_type_names: |
474 | 66 | try: | 106 | try: |
475 | @@ -86,7 +126,7 @@ | |||
476 | 86 | return () | 126 | return () |
477 | 87 | 127 | ||
478 | 88 | def mirrorComplete(self, branch_id, last_revision_id): | 128 | def mirrorComplete(self, branch_id, last_revision_id): |
480 | 89 | """See `IBranchPuller`.""" | 129 | """See `ICodehostingAPI`.""" |
481 | 90 | branch = getUtility(IBranchLookup).get(branch_id) | 130 | branch = getUtility(IBranchLookup).get(branch_id) |
482 | 91 | if branch is None: | 131 | if branch is None: |
483 | 92 | return faults.NoBranchWithID(branch_id) | 132 | return faults.NoBranchWithID(branch_id) |
484 | @@ -96,7 +136,7 @@ | |||
485 | 96 | return True | 136 | return True |
486 | 97 | 137 | ||
487 | 98 | def mirrorFailed(self, branch_id, reason): | 138 | def mirrorFailed(self, branch_id, reason): |
489 | 99 | """See `IBranchPuller`.""" | 139 | """See `ICodehostingAPI`.""" |
490 | 100 | branch = getUtility(IBranchLookup).get(branch_id) | 140 | branch = getUtility(IBranchLookup).get(branch_id) |
491 | 101 | if branch is None: | 141 | if branch is None: |
492 | 102 | return faults.NoBranchWithID(branch_id) | 142 | return faults.NoBranchWithID(branch_id) |
493 | @@ -105,7 +145,7 @@ | |||
494 | 105 | return True | 145 | return True |
495 | 106 | 146 | ||
496 | 107 | def recordSuccess(self, name, hostname, started_tuple, completed_tuple): | 147 | def recordSuccess(self, name, hostname, started_tuple, completed_tuple): |
498 | 108 | """See `IBranchPuller`.""" | 148 | """See `ICodehostingAPI`.""" |
499 | 109 | date_started = datetime_from_tuple(started_tuple) | 149 | date_started = datetime_from_tuple(started_tuple) |
500 | 110 | date_completed = datetime_from_tuple(completed_tuple) | 150 | date_completed = datetime_from_tuple(completed_tuple) |
501 | 111 | getUtility(IScriptActivitySet).recordSuccess( | 151 | getUtility(IScriptActivitySet).recordSuccess( |
502 | @@ -114,7 +154,7 @@ | |||
503 | 114 | return True | 154 | return True |
504 | 115 | 155 | ||
505 | 116 | def startMirroring(self, branch_id): | 156 | def startMirroring(self, branch_id): |
507 | 117 | """See `IBranchPuller`.""" | 157 | """See `ICodehostingAPI`.""" |
508 | 118 | branch = getUtility(IBranchLookup).get(branch_id) | 158 | branch = getUtility(IBranchLookup).get(branch_id) |
509 | 119 | if branch is None: | 159 | if branch is None: |
510 | 120 | return faults.NoBranchWithID(branch_id) | 160 | return faults.NoBranchWithID(branch_id) |
511 | @@ -124,7 +164,7 @@ | |||
512 | 124 | return True | 164 | return True |
513 | 125 | 165 | ||
514 | 126 | def setStackedOn(self, branch_id, stacked_on_location): | 166 | def setStackedOn(self, branch_id, stacked_on_location): |
516 | 127 | """See `IBranchPuller`.""" | 167 | """See `ICodehostingAPI`.""" |
517 | 128 | # We don't want the security proxy on the branch set because this | 168 | # We don't want the security proxy on the branch set because this |
518 | 129 | # method should be able to see all branches and set stacking | 169 | # method should be able to see all branches and set stacking |
519 | 130 | # information on any of them. | 170 | # information on any of them. |
520 | @@ -146,54 +186,8 @@ | |||
521 | 146 | stacked_branch.stacked_on = stacked_on_branch | 186 | stacked_branch.stacked_on = stacked_on_branch |
522 | 147 | return True | 187 | return True |
523 | 148 | 188 | ||
524 | 149 | |||
525 | 150 | def datetime_from_tuple(time_tuple): | ||
526 | 151 | """Create a datetime from a sequence that quacks like time.struct_time. | ||
527 | 152 | |||
528 | 153 | The tm_isdst is (index 8) is ignored. The created datetime uses | ||
529 | 154 | tzinfo=UTC. | ||
530 | 155 | """ | ||
531 | 156 | [year, month, day, hour, minute, second, unused, unused, unused] = ( | ||
532 | 157 | time_tuple) | ||
533 | 158 | return datetime.datetime( | ||
534 | 159 | year, month, day, hour, minute, second, tzinfo=UTC) | ||
535 | 160 | |||
536 | 161 | |||
537 | 162 | def run_with_login(login_id, function, *args, **kwargs): | ||
538 | 163 | """Run 'function' logged in with 'login_id'. | ||
539 | 164 | |||
540 | 165 | The first argument passed to 'function' will be the Launchpad | ||
541 | 166 | `Person` object corresponding to 'login_id'. | ||
542 | 167 | |||
543 | 168 | The exception is when the requesting login ID is `LAUNCHPAD_SERVICES`. In | ||
544 | 169 | that case, we'll pass through the `LAUNCHPAD_SERVICES` variable and the | ||
545 | 170 | method will do whatever security proxy hackery is required to provide read | ||
546 | 171 | privileges to the Launchpad services. | ||
547 | 172 | """ | ||
548 | 173 | if login_id == LAUNCHPAD_SERVICES or login_id == LAUNCHPAD_ANONYMOUS: | ||
549 | 174 | # Don't pass in an actual user. Instead pass in LAUNCHPAD_SERVICES | ||
550 | 175 | # and expect `function` to use `removeSecurityProxy` or similar. | ||
551 | 176 | return function(login_id, *args, **kwargs) | ||
552 | 177 | if isinstance(login_id, basestring): | ||
553 | 178 | requester = getUtility(IPersonSet).getByName(login_id) | ||
554 | 179 | else: | ||
555 | 180 | requester = getUtility(IPersonSet).get(login_id) | ||
556 | 181 | if requester is None: | ||
557 | 182 | raise NotFoundError("No person with id %s." % login_id) | ||
558 | 183 | setupInteractionForPerson(requester) | ||
559 | 184 | try: | ||
560 | 185 | return function(requester, *args, **kwargs) | ||
561 | 186 | finally: | ||
562 | 187 | endInteraction() | ||
563 | 188 | |||
564 | 189 | |||
565 | 190 | class BranchFileSystem(LaunchpadXMLRPCView): | ||
566 | 191 | """See `IBranchFileSystem`.""" | ||
567 | 192 | |||
568 | 193 | implements(IBranchFileSystem) | ||
569 | 194 | |||
570 | 195 | def createBranch(self, login_id, branch_path): | 189 | def createBranch(self, login_id, branch_path): |
572 | 196 | """See `IBranchFileSystem`.""" | 190 | """See `ICodehostingAPI`.""" |
573 | 197 | def create_branch(requester): | 191 | def create_branch(requester): |
574 | 198 | if not branch_path.startswith('/'): | 192 | if not branch_path.startswith('/'): |
575 | 199 | return faults.InvalidPath(branch_path) | 193 | return faults.InvalidPath(branch_path) |
576 | @@ -238,7 +232,7 @@ | |||
577 | 238 | and check_permission('launchpad.Edit', branch)) | 232 | and check_permission('launchpad.Edit', branch)) |
578 | 239 | 233 | ||
579 | 240 | def requestMirror(self, login_id, branchID): | 234 | def requestMirror(self, login_id, branchID): |
581 | 241 | """See `IBranchFileSystem`.""" | 235 | """See `ICodehostingAPI`.""" |
582 | 242 | def request_mirror(requester): | 236 | def request_mirror(requester): |
583 | 243 | branch = getUtility(IBranchLookup).get(branchID) | 237 | branch = getUtility(IBranchLookup).get(branchID) |
584 | 244 | # We don't really care who requests a mirror of a branch. | 238 | # We don't really care who requests a mirror of a branch. |
585 | @@ -248,7 +242,7 @@ | |||
586 | 248 | 242 | ||
587 | 249 | def branchChanged(self, branch_id, stacked_on_location, last_revision_id, | 243 | def branchChanged(self, branch_id, stacked_on_location, last_revision_id, |
588 | 250 | control_string, branch_string, repository_string): | 244 | control_string, branch_string, repository_string): |
590 | 251 | """See `IBranchFileSystem`.""" | 245 | """See `ICodehostingAPI`.""" |
591 | 252 | branch_set = removeSecurityProxy(getUtility(IBranchLookup)) | 246 | branch_set = removeSecurityProxy(getUtility(IBranchLookup)) |
592 | 253 | branch = branch_set.get(branch_id) | 247 | branch = branch_set.get(branch_id) |
593 | 254 | if branch is None: | 248 | if branch is None: |
594 | @@ -322,7 +316,7 @@ | |||
595 | 322 | trailing_path) | 316 | trailing_path) |
596 | 323 | 317 | ||
597 | 324 | def translatePath(self, requester_id, path): | 318 | def translatePath(self, requester_id, path): |
599 | 325 | """See `IBranchFileSystem`.""" | 319 | """See `ICodehostingAPI`.""" |
600 | 326 | @return_fault | 320 | @return_fault |
601 | 327 | def translate_path(requester): | 321 | def translate_path(requester): |
602 | 328 | if not path.startswith('/'): | 322 | if not path.startswith('/'): |
603 | 329 | 323 | ||
604 | === modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py' | |||
605 | --- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:11:16 +0000 | |||
606 | +++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:11:35 +0000 | |||
607 | @@ -20,8 +20,7 @@ | |||
608 | 20 | from canonical.launchpad.ftests import ANONYMOUS, login, logout | 20 | from canonical.launchpad.ftests import ANONYMOUS, login, logout |
609 | 21 | from lp.services.scripts.interfaces.scriptactivity import ( | 21 | from lp.services.scripts.interfaces.scriptactivity import ( |
610 | 22 | IScriptActivitySet) | 22 | IScriptActivitySet) |
613 | 23 | from lp.code.interfaces.codehosting import ( | 23 | from lp.code.interfaces.codehosting import BRANCH_TRANSPORT, CONTROL_TRANSPORT |
612 | 24 | BRANCH_TRANSPORT, CONTROL_TRANSPORT) | ||
614 | 25 | from canonical.launchpad.interfaces.launchpad import ILaunchBag | 24 | from canonical.launchpad.interfaces.launchpad import ILaunchBag |
615 | 26 | from lp.testing import TestCaseWithFactory | 25 | from lp.testing import TestCaseWithFactory |
616 | 27 | from lp.testing.factory import LaunchpadObjectFactory | 26 | from lp.testing.factory import LaunchpadObjectFactory |
617 | @@ -38,8 +37,7 @@ | |||
618 | 38 | from lp.code.interfaces.branchtarget import IBranchTarget | 37 | from lp.code.interfaces.branchtarget import IBranchTarget |
619 | 39 | from lp.code.model.tests.test_branchpuller import AcquireBranchToPullTests | 38 | from lp.code.model.tests.test_branchpuller import AcquireBranchToPullTests |
620 | 40 | from lp.code.xmlrpc.codehosting import ( | 39 | from lp.code.xmlrpc.codehosting import ( |
623 | 41 | BranchFileSystem, BranchPuller, LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES, | 40 | CodehostingAPI, LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES, run_with_login) |
622 | 42 | run_with_login) | ||
624 | 43 | 41 | ||
625 | 44 | from lp.codehosting.inmemory import InMemoryFrontend | 42 | from lp.codehosting.inmemory import InMemoryFrontend |
626 | 45 | 43 | ||
627 | @@ -126,17 +124,17 @@ | |||
628 | 126 | self.assertEqual(None, login_id) | 124 | self.assertEqual(None, login_id) |
629 | 127 | 125 | ||
630 | 128 | 126 | ||
633 | 129 | class BranchPullerTest(TestCaseWithFactory): | 127 | class CodehostingTest(TestCaseWithFactory): |
634 | 130 | """Tests for the implementation of `IBranchPuller`. | 128 | """Tests for the implementation of `ICodehostingAPI`. |
635 | 131 | 129 | ||
636 | 132 | :ivar frontend: A nullary callable that returns an object that implements | 130 | :ivar frontend: A nullary callable that returns an object that implements |
638 | 133 | getPullerEndpoint, getLaunchpadObjectFactory and getBranchLookup. | 131 | getCodehostingEndpoint, getLaunchpadObjectFactory and getBranchLookup. |
639 | 134 | """ | 132 | """ |
640 | 135 | 133 | ||
641 | 136 | def setUp(self): | 134 | def setUp(self): |
642 | 137 | TestCaseWithFactory.setUp(self) | 135 | TestCaseWithFactory.setUp(self) |
643 | 138 | frontend = self.frontend() | 136 | frontend = self.frontend() |
645 | 139 | self.storage = frontend.getPullerEndpoint() | 137 | self.codehosting_api = frontend.getCodehostingEndpoint() |
646 | 140 | self.factory = frontend.getLaunchpadObjectFactory() | 138 | self.factory = frontend.getLaunchpadObjectFactory() |
647 | 141 | self.branch_lookup = frontend.getBranchLookup() | 139 | self.branch_lookup = frontend.getBranchLookup() |
648 | 142 | self.getLastActivity = frontend.getLastActivity | 140 | self.getLastActivity = frontend.getLastActivity |
649 | @@ -189,7 +187,7 @@ | |||
650 | 189 | branch = self.factory.makeAnyBranch() | 187 | branch = self.factory.makeAnyBranch() |
651 | 190 | self.assertUnmirrored(branch) | 188 | self.assertUnmirrored(branch) |
652 | 191 | 189 | ||
654 | 192 | success = self.storage.startMirroring(branch.id) | 190 | success = self.codehosting_api.startMirroring(branch.id) |
655 | 193 | self.assertEqual(success, True) | 191 | self.assertEqual(success, True) |
656 | 194 | 192 | ||
657 | 195 | self.assertSqlAttributeEqualsDate( | 193 | self.assertSqlAttributeEqualsDate( |
658 | @@ -200,23 +198,23 @@ | |||
659 | 200 | # startMirroring returns False when given a branch id which does not | 198 | # startMirroring returns False when given a branch id which does not |
660 | 201 | # exist. | 199 | # exist. |
661 | 202 | invalid_id = self.getUnusedBranchID() | 200 | invalid_id = self.getUnusedBranchID() |
663 | 203 | fault = self.storage.startMirroring(invalid_id) | 201 | fault = self.codehosting_api.startMirroring(invalid_id) |
664 | 204 | self.assertEqual(faults.NoBranchWithID(invalid_id), fault) | 202 | self.assertEqual(faults.NoBranchWithID(invalid_id), fault) |
665 | 205 | 203 | ||
666 | 206 | def test_mirrorFailed(self): | 204 | def test_mirrorFailed(self): |
667 | 207 | branch = self.factory.makeAnyBranch() | 205 | branch = self.factory.makeAnyBranch() |
668 | 208 | self.assertUnmirrored(branch) | 206 | self.assertUnmirrored(branch) |
669 | 209 | 207 | ||
671 | 210 | self.storage.startMirroring(branch.id) | 208 | self.codehosting_api.startMirroring(branch.id) |
672 | 211 | failure_message = self.factory.getUniqueString() | 209 | failure_message = self.factory.getUniqueString() |
674 | 212 | success = self.storage.mirrorFailed(branch.id, failure_message) | 210 | success = self.codehosting_api.mirrorFailed(branch.id, failure_message) |
675 | 213 | self.assertEqual(True, success) | 211 | self.assertEqual(True, success) |
676 | 214 | self.assertMirrorFailed(branch, failure_message) | 212 | self.assertMirrorFailed(branch, failure_message) |
677 | 215 | 213 | ||
678 | 216 | def test_mirrorFailedWithNotBranchID(self): | 214 | def test_mirrorFailedWithNotBranchID(self): |
679 | 217 | branch_id = self.getUnusedBranchID() | 215 | branch_id = self.getUnusedBranchID() |
680 | 218 | failure_message = self.factory.getUniqueString() | 216 | failure_message = self.factory.getUniqueString() |
682 | 219 | fault = self.storage.mirrorFailed(branch_id, failure_message) | 217 | fault = self.codehosting_api.mirrorFailed(branch_id, failure_message) |
683 | 220 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) | 218 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) |
684 | 221 | 219 | ||
685 | 222 | def test_mirrorComplete(self): | 220 | def test_mirrorComplete(self): |
686 | @@ -225,9 +223,9 @@ | |||
687 | 225 | branch = self.factory.makeAnyBranch() | 223 | branch = self.factory.makeAnyBranch() |
688 | 226 | self.assertUnmirrored(branch) | 224 | self.assertUnmirrored(branch) |
689 | 227 | 225 | ||
691 | 228 | self.storage.startMirroring(branch.id) | 226 | self.codehosting_api.startMirroring(branch.id) |
692 | 229 | revision_id = self.factory.getUniqueString() | 227 | revision_id = self.factory.getUniqueString() |
694 | 230 | success = self.storage.mirrorComplete(branch.id, revision_id) | 228 | success = self.codehosting_api.mirrorComplete(branch.id, revision_id) |
695 | 231 | self.assertEqual(True, success) | 229 | self.assertEqual(True, success) |
696 | 232 | self.assertMirrorSucceeded(branch, revision_id) | 230 | self.assertMirrorSucceeded(branch, revision_id) |
697 | 233 | 231 | ||
698 | @@ -235,7 +233,7 @@ | |||
699 | 235 | # mirrorComplete returns a Fault if there's no branch with the given | 233 | # mirrorComplete returns a Fault if there's no branch with the given |
700 | 236 | # ID. | 234 | # ID. |
701 | 237 | branch_id = self.getUnusedBranchID() | 235 | branch_id = self.getUnusedBranchID() |
703 | 238 | fault = self.storage.mirrorComplete( | 236 | fault = self.codehosting_api.mirrorComplete( |
704 | 239 | branch_id, self.factory.getUniqueString()) | 237 | branch_id, self.factory.getUniqueString()) |
705 | 240 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) | 238 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) |
706 | 241 | 239 | ||
707 | @@ -245,15 +243,15 @@ | |||
708 | 245 | 243 | ||
709 | 246 | # First, mark the branch as failed. | 244 | # First, mark the branch as failed. |
710 | 247 | branch = self.factory.makeAnyBranch() | 245 | branch = self.factory.makeAnyBranch() |
712 | 248 | self.storage.startMirroring(branch.id) | 246 | self.codehosting_api.startMirroring(branch.id) |
713 | 249 | failure_message = self.factory.getUniqueString() | 247 | failure_message = self.factory.getUniqueString() |
715 | 250 | self.storage.mirrorFailed(branch.id, failure_message) | 248 | self.codehosting_api.mirrorFailed(branch.id, failure_message) |
716 | 251 | self.assertMirrorFailed(branch, failure_message) | 249 | self.assertMirrorFailed(branch, failure_message) |
717 | 252 | 250 | ||
718 | 253 | # Start and successfully finish a mirror. | 251 | # Start and successfully finish a mirror. |
720 | 254 | self.storage.startMirroring(branch.id) | 252 | self.codehosting_api.startMirroring(branch.id) |
721 | 255 | revision_id = self.factory.getUniqueString() | 253 | revision_id = self.factory.getUniqueString() |
723 | 256 | self.storage.mirrorComplete(branch.id, revision_id) | 254 | self.codehosting_api.mirrorComplete(branch.id, revision_id) |
724 | 257 | 255 | ||
725 | 258 | # Confirm that it succeeded. | 256 | # Confirm that it succeeded. |
726 | 259 | self.assertMirrorSucceeded(branch, revision_id) | 257 | self.assertMirrorSucceeded(branch, revision_id) |
727 | @@ -267,8 +265,9 @@ | |||
728 | 267 | branch.requestMirror() | 265 | branch.requestMirror() |
729 | 268 | 266 | ||
730 | 269 | # Simulate successfully mirroring the branch. | 267 | # Simulate successfully mirroring the branch. |
733 | 270 | self.storage.startMirroring(branch.id) | 268 | self.codehosting_api.startMirroring(branch.id) |
734 | 271 | self.storage.mirrorComplete(branch.id, self.factory.getUniqueString()) | 269 | self.codehosting_api.mirrorComplete( |
735 | 270 | branch.id, self.factory.getUniqueString()) | ||
736 | 272 | 271 | ||
737 | 273 | self.assertIs(None, branch.next_mirror_time) | 272 | self.assertIs(None, branch.next_mirror_time) |
738 | 274 | 273 | ||
739 | @@ -278,7 +277,7 @@ | |||
740 | 278 | completed = datetime.datetime(2007, 07, 05, 19, 34, 24, tzinfo=UTC) | 277 | completed = datetime.datetime(2007, 07, 05, 19, 34, 24, tzinfo=UTC) |
741 | 279 | started_tuple = tuple(started.utctimetuple()) | 278 | started_tuple = tuple(started.utctimetuple()) |
742 | 280 | completed_tuple = tuple(completed.utctimetuple()) | 279 | completed_tuple = tuple(completed.utctimetuple()) |
744 | 281 | success = self.storage.recordSuccess( | 280 | success = self.codehosting_api.recordSuccess( |
745 | 282 | 'test-recordsuccess', 'vostok', started_tuple, completed_tuple) | 281 | 'test-recordsuccess', 'vostok', started_tuple, completed_tuple) |
746 | 283 | self.assertEqual(True, success) | 282 | self.assertEqual(True, success) |
747 | 284 | 283 | ||
748 | @@ -293,7 +292,7 @@ | |||
749 | 293 | # generated as part of Launchpad's default stacking. | 292 | # generated as part of Launchpad's default stacking. |
750 | 294 | stacked_branch = self.factory.makeAnyBranch() | 293 | stacked_branch = self.factory.makeAnyBranch() |
751 | 295 | stacked_on_branch = self.factory.makeAnyBranch() | 294 | stacked_on_branch = self.factory.makeAnyBranch() |
753 | 296 | self.storage.setStackedOn( | 295 | self.codehosting_api.setStackedOn( |
754 | 297 | stacked_branch.id, '/%s' % stacked_on_branch.unique_name) | 296 | stacked_branch.id, '/%s' % stacked_on_branch.unique_name) |
755 | 298 | self.assertEqual(stacked_branch.stacked_on, stacked_on_branch) | 297 | self.assertEqual(stacked_branch.stacked_on, stacked_on_branch) |
756 | 299 | 298 | ||
757 | @@ -304,7 +303,8 @@ | |||
758 | 304 | stacked_branch = self.factory.makeAnyBranch() | 303 | stacked_branch = self.factory.makeAnyBranch() |
759 | 305 | stacked_on_branch = self.factory.makeAnyBranch( | 304 | stacked_on_branch = self.factory.makeAnyBranch( |
760 | 306 | branch_type=BranchType.MIRRORED) | 305 | branch_type=BranchType.MIRRORED) |
762 | 307 | self.storage.setStackedOn(stacked_branch.id, stacked_on_branch.url) | 306 | self.codehosting_api.setStackedOn( |
763 | 307 | stacked_branch.id, stacked_on_branch.url) | ||
764 | 308 | self.assertEqual(stacked_branch.stacked_on, stacked_on_branch) | 308 | self.assertEqual(stacked_branch.stacked_on, stacked_on_branch) |
765 | 309 | 309 | ||
766 | 310 | def test_setStackedOnExternalURLWithTrailingSlash(self): | 310 | def test_setStackedOnExternalURLWithTrailingSlash(self): |
767 | @@ -315,7 +315,7 @@ | |||
768 | 315 | stacked_on_branch = self.factory.makeAnyBranch( | 315 | stacked_on_branch = self.factory.makeAnyBranch( |
769 | 316 | branch_type=BranchType.MIRRORED) | 316 | branch_type=BranchType.MIRRORED) |
770 | 317 | url = stacked_on_branch.url + '/' | 317 | url = stacked_on_branch.url + '/' |
772 | 318 | self.storage.setStackedOn(stacked_branch.id, url) | 318 | self.codehosting_api.setStackedOn(stacked_branch.id, url) |
773 | 319 | self.assertEqual(stacked_branch.stacked_on, stacked_on_branch) | 319 | self.assertEqual(stacked_branch.stacked_on, stacked_on_branch) |
774 | 320 | 320 | ||
775 | 321 | def test_setStackedOnNothing(self): | 321 | def test_setStackedOnNothing(self): |
776 | @@ -324,7 +324,7 @@ | |||
777 | 324 | stacked_on_branch = self.factory.makeAnyBranch() | 324 | stacked_on_branch = self.factory.makeAnyBranch() |
778 | 325 | stacked_branch = self.factory.makeAnyBranch( | 325 | stacked_branch = self.factory.makeAnyBranch( |
779 | 326 | stacked_on=stacked_on_branch) | 326 | stacked_on=stacked_on_branch) |
781 | 327 | self.storage.setStackedOn(stacked_branch.id, '') | 327 | self.codehosting_api.setStackedOn(stacked_branch.id, '') |
782 | 328 | self.assertIs(stacked_branch.stacked_on, None) | 328 | self.assertIs(stacked_branch.stacked_on, None) |
783 | 329 | 329 | ||
784 | 330 | def test_setStackedOnBranchNotFound(self): | 330 | def test_setStackedOnBranchNotFound(self): |
785 | @@ -332,7 +332,7 @@ | |||
786 | 332 | # return a Fault. | 332 | # return a Fault. |
787 | 333 | stacked_branch = self.factory.makeAnyBranch() | 333 | stacked_branch = self.factory.makeAnyBranch() |
788 | 334 | url = self.factory.getUniqueURL() | 334 | url = self.factory.getUniqueURL() |
790 | 335 | fault = self.storage.setStackedOn(stacked_branch.id, url) | 335 | fault = self.codehosting_api.setStackedOn(stacked_branch.id, url) |
791 | 336 | self.assertEqual(faults.NoSuchBranch(url), fault) | 336 | self.assertEqual(faults.NoSuchBranch(url), fault) |
792 | 337 | 337 | ||
793 | 338 | def test_setStackedOnNoBranchWithID(self): | 338 | def test_setStackedOnNoBranchWithID(self): |
794 | @@ -341,110 +341,17 @@ | |||
795 | 341 | stacked_on_branch = self.factory.makeAnyBranch( | 341 | stacked_on_branch = self.factory.makeAnyBranch( |
796 | 342 | branch_type=BranchType.MIRRORED) | 342 | branch_type=BranchType.MIRRORED) |
797 | 343 | branch_id = self.getUnusedBranchID() | 343 | branch_id = self.getUnusedBranchID() |
799 | 344 | fault = self.storage.setStackedOn(branch_id, stacked_on_branch.url) | 344 | fault = self.codehosting_api.setStackedOn( |
800 | 345 | branch_id, stacked_on_branch.url) | ||
801 | 345 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) | 346 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) |
802 | 346 | 347 | ||
803 | 347 | |||
804 | 348 | class AcquireBranchToPullTestsViaEndpoint(TestCaseWithFactory, | ||
805 | 349 | AcquireBranchToPullTests): | ||
806 | 350 | """Tests for `acquireBranchToPull` method of `IBranchPuller`.""" | ||
807 | 351 | |||
808 | 352 | def setUp(self): | ||
809 | 353 | super(AcquireBranchToPullTestsViaEndpoint, self).setUp() | ||
810 | 354 | frontend = self.frontend() | ||
811 | 355 | self.storage = frontend.getPullerEndpoint() | ||
812 | 356 | self.factory = frontend.getLaunchpadObjectFactory() | ||
813 | 357 | |||
814 | 358 | def assertNoBranchIsAquired(self, *branch_types): | ||
815 | 359 | """See `AcquireBranchToPullTests`.""" | ||
816 | 360 | branch_types = tuple(branch_type.name for branch_type in branch_types) | ||
817 | 361 | pull_info = self.storage.acquireBranchToPull(branch_types) | ||
818 | 362 | self.assertEqual((), pull_info) | ||
819 | 363 | |||
820 | 364 | def assertBranchIsAquired(self, branch, *branch_types): | ||
821 | 365 | """See `AcquireBranchToPullTests`.""" | ||
822 | 366 | branch = removeSecurityProxy(branch) | ||
823 | 367 | branch_types = tuple(branch_type.name for branch_type in branch_types) | ||
824 | 368 | pull_info = self.storage.acquireBranchToPull(branch_types) | ||
825 | 369 | default_branch = branch.target.default_stacked_on_branch | ||
826 | 370 | if default_branch: | ||
827 | 371 | default_branch_name = default_branch | ||
828 | 372 | else: | ||
829 | 373 | default_branch_name = '' | ||
830 | 374 | self.assertEqual( | ||
831 | 375 | pull_info, | ||
832 | 376 | (branch.id, branch.getPullURL(), branch.unique_name, | ||
833 | 377 | default_branch_name, branch.branch_type.name)) | ||
834 | 378 | self.assertIsNot(None, branch.last_mirror_attempt) | ||
835 | 379 | self.assertIs(None, branch.next_mirror_time) | ||
836 | 380 | |||
837 | 381 | def startMirroring(self, branch): | ||
838 | 382 | """See `AcquireBranchToPullTests`.""" | ||
839 | 383 | self.storage.startMirroring(branch.id) | ||
840 | 384 | |||
841 | 385 | def test_branch_type_returned_mirrored(self): | ||
842 | 386 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) | ||
843 | 387 | branch.requestMirror() | ||
844 | 388 | pull_info = self.storage.acquireBranchToPull(()) | ||
845 | 389 | _, _, _, _, branch_type = pull_info | ||
846 | 390 | self.assertEqual('MIRRORED', branch_type) | ||
847 | 391 | |||
848 | 392 | def test_branch_type_returned_import(self): | ||
849 | 393 | branch = self.factory.makeAnyBranch(branch_type=BranchType.IMPORTED) | ||
850 | 394 | branch.requestMirror() | ||
851 | 395 | pull_info = self.storage.acquireBranchToPull(()) | ||
852 | 396 | _, _, _, _, branch_type = pull_info | ||
853 | 397 | self.assertEqual('IMPORTED', branch_type) | ||
854 | 398 | |||
855 | 399 | def test_default_stacked_on_branch_returned(self): | ||
856 | 400 | branch = self.factory.makeProductBranch( | ||
857 | 401 | branch_type=BranchType.MIRRORED) | ||
858 | 402 | self.factory.enableDefaultStackingForProduct(branch.product) | ||
859 | 403 | branch.requestMirror() | ||
860 | 404 | pull_info = self.storage.acquireBranchToPull(()) | ||
861 | 405 | _, _, _, default_stacked_on_branch, _ = pull_info | ||
862 | 406 | self.assertEqual( | ||
863 | 407 | default_stacked_on_branch, | ||
864 | 408 | '/' + branch.target.default_stacked_on_branch.unique_name) | ||
865 | 409 | |||
866 | 410 | def test_private_default_stacked_not_returned_for_mirrored_branch(self): | ||
867 | 411 | # We don't stack mirrored branches on a private default stacked on | ||
868 | 412 | # branch. | ||
869 | 413 | product = self.factory.makeProduct() | ||
870 | 414 | default_branch = self.factory.makeProductBranch( | ||
871 | 415 | product=product, private=True) | ||
872 | 416 | self.factory.enableDefaultStackingForProduct(product, default_branch) | ||
873 | 417 | mirrored_branch = self.factory.makeProductBranch( | ||
874 | 418 | branch_type=BranchType.MIRRORED, product=product) | ||
875 | 419 | mirrored_branch.requestMirror() | ||
876 | 420 | pull_info = self.storage.acquireBranchToPull(()) | ||
877 | 421 | _, _, _, default_stacked_on_branch, _ = pull_info | ||
878 | 422 | self.assertEqual( | ||
879 | 423 | '', default_stacked_on_branch) | ||
880 | 424 | |||
881 | 425 | def test_unknown_branch_type_name_raises(self): | ||
882 | 426 | self.assertRaises( | ||
883 | 427 | UnknownBranchTypeError, self.storage.acquireBranchToPull, | ||
884 | 428 | ('NO_SUCH_TYPE',)) | ||
885 | 429 | |||
886 | 430 | |||
887 | 431 | class BranchFileSystemTest(TestCaseWithFactory): | ||
888 | 432 | """Tests for the implementation of `IBranchFileSystem`.""" | ||
889 | 433 | |||
890 | 434 | def setUp(self): | ||
891 | 435 | super(BranchFileSystemTest, self).setUp() | ||
892 | 436 | frontend = self.frontend() | ||
893 | 437 | self.branchfs = frontend.getFilesystemEndpoint() | ||
894 | 438 | self.factory = frontend.getLaunchpadObjectFactory() | ||
895 | 439 | self.branch_lookup = frontend.getBranchLookup() | ||
896 | 440 | |||
897 | 441 | def test_createBranch(self): | 348 | def test_createBranch(self): |
898 | 442 | # createBranch creates a branch with the supplied details and the | 349 | # createBranch creates a branch with the supplied details and the |
899 | 443 | # caller as registrant. | 350 | # caller as registrant. |
900 | 444 | owner = self.factory.makePerson() | 351 | owner = self.factory.makePerson() |
901 | 445 | product = self.factory.makeProduct() | 352 | product = self.factory.makeProduct() |
902 | 446 | name = self.factory.getUniqueString() | 353 | name = self.factory.getUniqueString() |
904 | 447 | branch_id = self.branchfs.createBranch( | 354 | branch_id = self.codehosting_api.createBranch( |
905 | 448 | owner.id, escape('/~%s/%s/%s' % (owner.name, product.name, name))) | 355 | owner.id, escape('/~%s/%s/%s' % (owner.name, product.name, name))) |
906 | 449 | login(ANONYMOUS) | 356 | login(ANONYMOUS) |
907 | 450 | branch = self.branch_lookup.get(branch_id) | 357 | branch = self.branch_lookup.get(branch_id) |
908 | @@ -457,7 +364,7 @@ | |||
909 | 457 | def test_createBranch_no_preceding_slash(self): | 364 | def test_createBranch_no_preceding_slash(self): |
910 | 458 | requester = self.factory.makePerson() | 365 | requester = self.factory.makePerson() |
911 | 459 | path = escape(u'invalid') | 366 | path = escape(u'invalid') |
913 | 460 | fault = self.branchfs.createBranch(requester.id, path) | 367 | fault = self.codehosting_api.createBranch(requester.id, path) |
914 | 461 | login(ANONYMOUS) | 368 | login(ANONYMOUS) |
915 | 462 | self.assertEqual(faults.InvalidPath(path), fault) | 369 | self.assertEqual(faults.InvalidPath(path), fault) |
916 | 463 | 370 | ||
917 | @@ -465,7 +372,7 @@ | |||
918 | 465 | # createBranch can create +junk branches. | 372 | # createBranch can create +junk branches. |
919 | 466 | owner = self.factory.makePerson() | 373 | owner = self.factory.makePerson() |
920 | 467 | name = self.factory.getUniqueString() | 374 | name = self.factory.getUniqueString() |
922 | 468 | branch_id = self.branchfs.createBranch( | 375 | branch_id = self.codehosting_api.createBranch( |
923 | 469 | owner.id, escape('/~%s/%s/%s' % (owner.name, '+junk', name))) | 376 | owner.id, escape('/~%s/%s/%s' % (owner.name, '+junk', name))) |
924 | 470 | login(ANONYMOUS) | 377 | login(ANONYMOUS) |
925 | 471 | branch = self.branch_lookup.get(branch_id) | 378 | branch = self.branch_lookup.get(branch_id) |
926 | @@ -480,7 +387,7 @@ | |||
927 | 480 | registrant = self.factory.makePerson() | 387 | registrant = self.factory.makePerson() |
928 | 481 | team = self.factory.makeTeam(registrant) | 388 | team = self.factory.makeTeam(registrant) |
929 | 482 | name = self.factory.getUniqueString() | 389 | name = self.factory.getUniqueString() |
931 | 483 | branch_id = self.branchfs.createBranch( | 390 | branch_id = self.codehosting_api.createBranch( |
932 | 484 | registrant.id, escape('/~%s/+junk/%s' % (team.name, name))) | 391 | registrant.id, escape('/~%s/+junk/%s' % (team.name, name))) |
933 | 485 | login(ANONYMOUS) | 392 | login(ANONYMOUS) |
934 | 486 | branch = self.branch_lookup.get(branch_id) | 393 | branch = self.branch_lookup.get(branch_id) |
935 | @@ -495,7 +402,7 @@ | |||
936 | 495 | owner = self.factory.makePerson() | 402 | owner = self.factory.makePerson() |
937 | 496 | name = self.factory.getUniqueString() | 403 | name = self.factory.getUniqueString() |
938 | 497 | message = "Project 'no-such-product' does not exist." | 404 | message = "Project 'no-such-product' does not exist." |
940 | 498 | fault = self.branchfs.createBranch( | 405 | fault = self.codehosting_api.createBranch( |
941 | 499 | owner.id, escape('/~%s/no-such-product/%s' % (owner.name, name))) | 406 | owner.id, escape('/~%s/no-such-product/%s' % (owner.name, name))) |
942 | 500 | self.assertEqual(faults.NotFound(message), fault) | 407 | self.assertEqual(faults.NotFound(message), fault) |
943 | 501 | 408 | ||
944 | @@ -507,7 +414,7 @@ | |||
945 | 507 | name = self.factory.getUniqueString() | 414 | name = self.factory.getUniqueString() |
946 | 508 | message = ("%s cannot create branches owned by %s" | 415 | message = ("%s cannot create branches owned by %s" |
947 | 509 | % (creator.displayname, other_person.displayname)) | 416 | % (creator.displayname, other_person.displayname)) |
949 | 510 | fault = self.branchfs.createBranch( | 417 | fault = self.codehosting_api.createBranch( |
950 | 511 | creator.id, | 418 | creator.id, |
951 | 512 | escape('/~%s/%s/%s' % (other_person.name, product.name, name))) | 419 | escape('/~%s/%s/%s' % (other_person.name, product.name, name))) |
952 | 513 | self.assertEqual(faults.PermissionDenied(message), fault) | 420 | self.assertEqual(faults.PermissionDenied(message), fault) |
953 | @@ -519,7 +426,7 @@ | |||
954 | 519 | invalid_name = 'invalid name!' | 426 | invalid_name = 'invalid name!' |
955 | 520 | message = ("Invalid branch name '%s'. %s" | 427 | message = ("Invalid branch name '%s'. %s" |
956 | 521 | % (invalid_name, BRANCH_NAME_VALIDATION_ERROR_MESSAGE)) | 428 | % (invalid_name, BRANCH_NAME_VALIDATION_ERROR_MESSAGE)) |
958 | 522 | fault = self.branchfs.createBranch( | 429 | fault = self.codehosting_api.createBranch( |
959 | 523 | owner.id, escape( | 430 | owner.id, escape( |
960 | 524 | '/~%s/%s/%s' % (owner.name, product.name, invalid_name))) | 431 | '/~%s/%s/%s' % (owner.name, product.name, invalid_name))) |
961 | 525 | self.assertEqual(faults.PermissionDenied(message), fault) | 432 | self.assertEqual(faults.PermissionDenied(message), fault) |
962 | @@ -532,7 +439,7 @@ | |||
963 | 532 | message = ("Invalid branch name '%s'. %s" | 439 | message = ("Invalid branch name '%s'. %s" |
964 | 533 | % (invalid_name.encode('utf-8'), | 440 | % (invalid_name.encode('utf-8'), |
965 | 534 | str(BRANCH_NAME_VALIDATION_ERROR_MESSAGE))) | 441 | str(BRANCH_NAME_VALIDATION_ERROR_MESSAGE))) |
967 | 535 | fault = self.branchfs.createBranch( | 442 | fault = self.codehosting_api.createBranch( |
968 | 536 | owner.id, escape( | 443 | owner.id, escape( |
969 | 537 | '/~%s/%s/%s' % (owner.name, product.name, invalid_name))) | 444 | '/~%s/%s/%s' % (owner.name, product.name, invalid_name))) |
970 | 538 | self.assertEqual( | 445 | self.assertEqual( |
971 | @@ -544,7 +451,7 @@ | |||
972 | 544 | product = self.factory.makeProduct() | 451 | product = self.factory.makeProduct() |
973 | 545 | name = self.factory.getUniqueString() | 452 | name = self.factory.getUniqueString() |
974 | 546 | message = "User/team 'no-one' does not exist." | 453 | message = "User/team 'no-one' does not exist." |
976 | 547 | fault = self.branchfs.createBranch( | 454 | fault = self.codehosting_api.createBranch( |
977 | 548 | owner.id, escape('/~no-one/%s/%s' % (product.name, name))) | 455 | owner.id, escape('/~no-one/%s/%s' % (product.name, name))) |
978 | 549 | self.assertEqual(faults.NotFound(message), fault) | 456 | self.assertEqual(faults.NotFound(message), fault) |
979 | 550 | 457 | ||
980 | @@ -555,7 +462,7 @@ | |||
981 | 555 | owner = self.factory.makePerson() | 462 | owner = self.factory.makePerson() |
982 | 556 | name = self.factory.getUniqueString() | 463 | name = self.factory.getUniqueString() |
983 | 557 | message = "User/team 'no-one' does not exist." | 464 | message = "User/team 'no-one' does not exist." |
985 | 558 | fault = self.branchfs.createBranch( | 465 | fault = self.codehosting_api.createBranch( |
986 | 559 | owner.id, escape('/~no-one/no-product/%s' % (name,))) | 466 | owner.id, escape('/~no-one/no-product/%s' % (name,))) |
987 | 560 | self.assertEqual(faults.NotFound(message), fault) | 467 | self.assertEqual(faults.NotFound(message), fault) |
988 | 561 | 468 | ||
989 | @@ -564,7 +471,7 @@ | |||
990 | 564 | # raises a PermissionDenied fault. | 471 | # raises a PermissionDenied fault. |
991 | 565 | owner = self.factory.makePerson() | 472 | owner = self.factory.makePerson() |
992 | 566 | path = escape('/~%s' % owner.name) | 473 | path = escape('/~%s' % owner.name) |
994 | 567 | fault = self.branchfs.createBranch(owner.id, path) | 474 | fault = self.codehosting_api.createBranch(owner.id, path) |
995 | 568 | message = "Cannot create branch at '%s'" % path | 475 | message = "Cannot create branch at '%s'" % path |
996 | 569 | self.assertEqual(faults.PermissionDenied(message), fault) | 476 | self.assertEqual(faults.PermissionDenied(message), fault) |
997 | 570 | 477 | ||
998 | @@ -580,7 +487,8 @@ | |||
999 | 580 | sourcepackage.distroseries.name, | 487 | sourcepackage.distroseries.name, |
1000 | 581 | sourcepackage.sourcepackagename.name, | 488 | sourcepackage.sourcepackagename.name, |
1001 | 582 | branch_name) | 489 | branch_name) |
1003 | 583 | branch_id = self.branchfs.createBranch(owner.id, escape(unique_name)) | 490 | branch_id = self.codehosting_api.createBranch( |
1004 | 491 | owner.id, escape(unique_name)) | ||
1005 | 584 | login(ANONYMOUS) | 492 | login(ANONYMOUS) |
1006 | 585 | branch = self.branch_lookup.get(branch_id) | 493 | branch = self.branch_lookup.get(branch_id) |
1007 | 586 | self.assertEqual(owner, branch.owner) | 494 | self.assertEqual(owner, branch.owner) |
1008 | @@ -601,7 +509,7 @@ | |||
1009 | 601 | unique_name = '/~%s/ningnangnong/%s/%s/%s' % ( | 509 | unique_name = '/~%s/ningnangnong/%s/%s/%s' % ( |
1010 | 602 | owner.name, distroseries.name, sourcepackagename.name, | 510 | owner.name, distroseries.name, sourcepackagename.name, |
1011 | 603 | branch_name) | 511 | branch_name) |
1013 | 604 | fault = self.branchfs.createBranch(owner.id, escape(unique_name)) | 512 | fault = self.codehosting_api.createBranch(owner.id, escape(unique_name)) |
1014 | 605 | message = "No such distribution: 'ningnangnong'." | 513 | message = "No such distribution: 'ningnangnong'." |
1015 | 606 | self.assertEqual(faults.NotFound(message), fault) | 514 | self.assertEqual(faults.NotFound(message), fault) |
1016 | 607 | 515 | ||
1017 | @@ -615,7 +523,8 @@ | |||
1018 | 615 | unique_name = '/~%s/%s/ningnangnong/%s/%s' % ( | 523 | unique_name = '/~%s/%s/ningnangnong/%s/%s' % ( |
1019 | 616 | owner.name, distribution.name, sourcepackagename.name, | 524 | owner.name, distribution.name, sourcepackagename.name, |
1020 | 617 | branch_name) | 525 | branch_name) |
1022 | 618 | fault = self.branchfs.createBranch(owner.id, escape(unique_name)) | 526 | fault = self.codehosting_api.createBranch( |
1023 | 527 | owner.id, escape(unique_name)) | ||
1024 | 619 | message = "No such distribution series: 'ningnangnong'." | 528 | message = "No such distribution series: 'ningnangnong'." |
1025 | 620 | self.assertEqual(faults.NotFound(message), fault) | 529 | self.assertEqual(faults.NotFound(message), fault) |
1026 | 621 | 530 | ||
1027 | @@ -628,7 +537,7 @@ | |||
1028 | 628 | unique_name = '/~%s/%s/%s/ningnangnong/%s' % ( | 537 | unique_name = '/~%s/%s/%s/ningnangnong/%s' % ( |
1029 | 629 | owner.name, distroseries.distribution.name, distroseries.name, | 538 | owner.name, distroseries.distribution.name, distroseries.name, |
1030 | 630 | branch_name) | 539 | branch_name) |
1032 | 631 | fault = self.branchfs.createBranch(owner.id, escape(unique_name)) | 540 | fault = self.codehosting_api.createBranch(owner.id, escape(unique_name)) |
1033 | 632 | message = "No such source package: 'ningnangnong'." | 541 | message = "No such source package: 'ningnangnong'." |
1034 | 633 | self.assertEqual(faults.NotFound(message), fault) | 542 | self.assertEqual(faults.NotFound(message), fault) |
1035 | 634 | 543 | ||
1036 | @@ -643,7 +552,7 @@ | |||
1037 | 643 | # current time. | 552 | # current time. |
1038 | 644 | requester = self.factory.makePerson() | 553 | requester = self.factory.makePerson() |
1039 | 645 | branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED) | 554 | branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED) |
1041 | 646 | self.branchfs.requestMirror(requester.id, branch.id) | 555 | self.codehosting_api.requestMirror(requester.id, branch.id) |
1042 | 647 | self.assertSqlAttributeEqualsDate( | 556 | self.assertSqlAttributeEqualsDate( |
1043 | 648 | branch, 'next_mirror_time', UTC_NOW) | 557 | branch, 'next_mirror_time', UTC_NOW) |
1044 | 649 | 558 | ||
1045 | @@ -652,7 +561,7 @@ | |||
1046 | 652 | requester = self.factory.makePerson() | 561 | requester = self.factory.makePerson() |
1047 | 653 | branch = self.factory.makeAnyBranch(owner=requester, private=True) | 562 | branch = self.factory.makeAnyBranch(owner=requester, private=True) |
1048 | 654 | branch = removeSecurityProxy(branch) | 563 | branch = removeSecurityProxy(branch) |
1050 | 655 | self.branchfs.requestMirror(requester.id, branch.id) | 564 | self.codehosting_api.requestMirror(requester.id, branch.id) |
1051 | 656 | self.assertSqlAttributeEqualsDate( | 565 | self.assertSqlAttributeEqualsDate( |
1052 | 657 | branch, 'next_mirror_time', UTC_NOW) | 566 | branch, 'next_mirror_time', UTC_NOW) |
1053 | 658 | 567 | ||
1054 | @@ -672,7 +581,7 @@ | |||
1055 | 672 | # branchChanged sets the last_mirrored_id attribute on the branch. | 581 | # branchChanged sets the last_mirrored_id attribute on the branch. |
1056 | 673 | revid = self.factory.getUniqueString() | 582 | revid = self.factory.getUniqueString() |
1057 | 674 | branch = self.factory.makeAnyBranch() | 583 | branch = self.factory.makeAnyBranch() |
1059 | 675 | self.branchfs.branchChanged( | 584 | self.codehosting_api.branchChanged( |
1060 | 676 | branch.id, '', revid, *self.arbitrary_format_strings) | 585 | branch.id, '', revid, *self.arbitrary_format_strings) |
1061 | 677 | self.assertEqual(revid, branch.last_mirrored_id) | 586 | self.assertEqual(revid, branch.last_mirrored_id) |
1062 | 678 | 587 | ||
1063 | @@ -681,7 +590,7 @@ | |||
1064 | 681 | # passed in. | 590 | # passed in. |
1065 | 682 | branch = self.factory.makeAnyBranch() | 591 | branch = self.factory.makeAnyBranch() |
1066 | 683 | stacked_on = self.factory.makeAnyBranch() | 592 | stacked_on = self.factory.makeAnyBranch() |
1068 | 684 | self.branchfs.branchChanged( | 593 | self.codehosting_api.branchChanged( |
1069 | 685 | branch.id, stacked_on.unique_name, '', | 594 | branch.id, stacked_on.unique_name, '', |
1070 | 686 | *self.arbitrary_format_strings) | 595 | *self.arbitrary_format_strings) |
1071 | 687 | self.assertEqual(stacked_on, branch.stacked_on) | 596 | self.assertEqual(stacked_on, branch.stacked_on) |
1072 | @@ -691,7 +600,7 @@ | |||
1073 | 691 | # passed in as the stacked_on location. | 600 | # passed in as the stacked_on location. |
1074 | 692 | branch = self.factory.makeAnyBranch() | 601 | branch = self.factory.makeAnyBranch() |
1075 | 693 | removeSecurityProxy(branch).stacked_on = self.factory.makeAnyBranch() | 602 | removeSecurityProxy(branch).stacked_on = self.factory.makeAnyBranch() |
1077 | 694 | self.branchfs.branchChanged( | 603 | self.codehosting_api.branchChanged( |
1078 | 695 | branch.id, '', '', *self.arbitrary_format_strings) | 604 | branch.id, '', '', *self.arbitrary_format_strings) |
1079 | 696 | self.assertIs(None, branch.stacked_on) | 605 | self.assertIs(None, branch.stacked_on) |
1080 | 697 | 606 | ||
1081 | @@ -699,7 +608,7 @@ | |||
1082 | 699 | # branchChanged sets the last_mirrored attribute on the branch to the | 608 | # branchChanged sets the last_mirrored attribute on the branch to the |
1083 | 700 | # current time. | 609 | # current time. |
1084 | 701 | branch = self.factory.makeAnyBranch() | 610 | branch = self.factory.makeAnyBranch() |
1086 | 702 | self.branchfs.branchChanged( | 611 | self.codehosting_api.branchChanged( |
1087 | 703 | branch.id, '', '', *self.arbitrary_format_strings) | 612 | branch.id, '', '', *self.arbitrary_format_strings) |
1088 | 704 | if self.frontend == LaunchpadDatabaseFrontend: | 613 | if self.frontend == LaunchpadDatabaseFrontend: |
1089 | 705 | self.assertSqlAttributeEqualsDate( | 614 | self.assertSqlAttributeEqualsDate( |
1090 | @@ -712,7 +621,7 @@ | |||
1091 | 712 | # mirror_status_message is set to indicate the problem and stacked_on | 621 | # mirror_status_message is set to indicate the problem and stacked_on |
1092 | 713 | # set to None. | 622 | # set to None. |
1093 | 714 | branch = self.factory.makeAnyBranch() | 623 | branch = self.factory.makeAnyBranch() |
1095 | 715 | self.branchfs.branchChanged( | 624 | self.codehosting_api.branchChanged( |
1096 | 716 | branch.id, '~does/not/exist', '', *self.arbitrary_format_strings) | 625 | branch.id, '~does/not/exist', '', *self.arbitrary_format_strings) |
1097 | 717 | self.assertIs(None, branch.stacked_on) | 626 | self.assertIs(None, branch.stacked_on) |
1098 | 718 | self.assertTrue('~does/not/exist' in branch.mirror_status_message) | 627 | self.assertTrue('~does/not/exist' in branch.mirror_status_message) |
1099 | @@ -722,7 +631,7 @@ | |||
1100 | 722 | # mirror_status_message. | 631 | # mirror_status_message. |
1101 | 723 | branch = self.factory.makeAnyBranch() | 632 | branch = self.factory.makeAnyBranch() |
1102 | 724 | removeSecurityProxy(branch).mirror_status_message = 'foo' | 633 | removeSecurityProxy(branch).mirror_status_message = 'foo' |
1104 | 725 | self.branchfs.branchChanged( | 634 | self.codehosting_api.branchChanged( |
1105 | 726 | branch.id, '', '', *self.arbitrary_format_strings) | 635 | branch.id, '', '', *self.arbitrary_format_strings) |
1106 | 727 | self.assertIs(None, branch.mirror_status_message) | 636 | self.assertIs(None, branch.mirror_status_message) |
1107 | 728 | 637 | ||
1108 | @@ -731,7 +640,7 @@ | |||
1109 | 731 | # "NoBranchWithID" is returned. | 640 | # "NoBranchWithID" is returned. |
1110 | 732 | unused_id = -1 | 641 | unused_id = -1 |
1111 | 733 | expected_fault = faults.NoBranchWithID(unused_id) | 642 | expected_fault = faults.NoBranchWithID(unused_id) |
1113 | 734 | received_fault = self.branchfs.branchChanged( | 643 | received_fault = self.codehosting_api.branchChanged( |
1114 | 735 | unused_id, '', '', *self.arbitrary_format_strings) | 644 | unused_id, '', '', *self.arbitrary_format_strings) |
1115 | 736 | self.assertEqual( | 645 | self.assertEqual( |
1116 | 737 | (expected_fault.faultCode, expected_fault.faultString), | 646 | (expected_fault.faultCode, expected_fault.faultString), |
1117 | @@ -744,7 +653,7 @@ | |||
1118 | 744 | branch = self.factory.makeAnyBranch() | 653 | branch = self.factory.makeAnyBranch() |
1119 | 745 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) | 654 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) |
1120 | 746 | self.assertEqual(0, len(jobs)) | 655 | self.assertEqual(0, len(jobs)) |
1122 | 747 | self.branchfs.branchChanged( | 656 | self.codehosting_api.branchChanged( |
1123 | 748 | branch.id, '', 'rev1', *self.arbitrary_format_strings) | 657 | branch.id, '', 'rev1', *self.arbitrary_format_strings) |
1124 | 749 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) | 658 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) |
1125 | 750 | self.assertEqual(1, len(jobs)) | 659 | self.assertEqual(1, len(jobs)) |
1126 | @@ -756,14 +665,14 @@ | |||
1127 | 756 | removeSecurityProxy(branch).last_mirrored_id = 'rev1' | 665 | removeSecurityProxy(branch).last_mirrored_id = 'rev1' |
1128 | 757 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) | 666 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) |
1129 | 758 | self.assertEqual(0, len(jobs)) | 667 | self.assertEqual(0, len(jobs)) |
1131 | 759 | self.branchfs.branchChanged( | 668 | self.codehosting_api.branchChanged( |
1132 | 760 | branch.id, '', 'rev1', *self.arbitrary_format_strings) | 669 | branch.id, '', 'rev1', *self.arbitrary_format_strings) |
1133 | 761 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) | 670 | jobs = list(getUtility(IBranchScanJobSource).iterReady()) |
1134 | 762 | self.assertEqual(0, len(jobs)) | 671 | self.assertEqual(0, len(jobs)) |
1135 | 763 | 672 | ||
1136 | 764 | def test_branchChanged_2a_format(self): | 673 | def test_branchChanged_2a_format(self): |
1137 | 765 | branch = self.factory.makeAnyBranch() | 674 | branch = self.factory.makeAnyBranch() |
1139 | 766 | self.branchfs.branchChanged( | 675 | self.codehosting_api.branchChanged( |
1140 | 767 | branch.id, '', 'rev1', *self.getFormatStringsForFormatName('2a')) | 676 | branch.id, '', 'rev1', *self.getFormatStringsForFormatName('2a')) |
1141 | 768 | self.assertEqual( | 677 | self.assertEqual( |
1142 | 769 | (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_7, | 678 | (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_7, |
1143 | @@ -773,7 +682,7 @@ | |||
1144 | 773 | 682 | ||
1145 | 774 | def test_branchChanged_packs_format(self): | 683 | def test_branchChanged_packs_format(self): |
1146 | 775 | branch = self.factory.makeAnyBranch() | 684 | branch = self.factory.makeAnyBranch() |
1148 | 776 | self.branchfs.branchChanged( | 685 | self.codehosting_api.branchChanged( |
1149 | 777 | branch.id, '', 'rev1', | 686 | branch.id, '', 'rev1', |
1150 | 778 | *self.getFormatStringsForFormatName('pack-0.92')) | 687 | *self.getFormatStringsForFormatName('pack-0.92')) |
1151 | 779 | self.assertEqual( | 688 | self.assertEqual( |
1152 | @@ -784,7 +693,7 @@ | |||
1153 | 784 | 693 | ||
1154 | 785 | def test_branchChanged_knits_format(self): | 694 | def test_branchChanged_knits_format(self): |
1155 | 786 | branch = self.factory.makeAnyBranch() | 695 | branch = self.factory.makeAnyBranch() |
1157 | 787 | self.branchfs.branchChanged( | 696 | self.codehosting_api.branchChanged( |
1158 | 788 | branch.id, '', 'rev1', | 697 | branch.id, '', 'rev1', |
1159 | 789 | *self.getFormatStringsForFormatName('knit')) | 698 | *self.getFormatStringsForFormatName('knit')) |
1160 | 790 | self.assertEqual( | 699 | self.assertEqual( |
1161 | @@ -795,21 +704,21 @@ | |||
1162 | 795 | 704 | ||
1163 | 796 | def assertCannotTranslate(self, requester, path): | 705 | def assertCannotTranslate(self, requester, path): |
1164 | 797 | """Assert that we cannot translate 'path'.""" | 706 | """Assert that we cannot translate 'path'.""" |
1166 | 798 | fault = self.branchfs.translatePath(requester.id, path) | 707 | fault = self.codehosting_api.translatePath(requester.id, path) |
1167 | 799 | self.assertEqual(faults.PathTranslationError(path), fault) | 708 | self.assertEqual(faults.PathTranslationError(path), fault) |
1168 | 800 | 709 | ||
1169 | 801 | def assertNotFound(self, requester, path): | 710 | def assertNotFound(self, requester, path): |
1170 | 802 | """Assert that the given path cannot be found.""" | 711 | """Assert that the given path cannot be found.""" |
1171 | 803 | if requester not in [LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES]: | 712 | if requester not in [LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES]: |
1172 | 804 | requester = requester.id | 713 | requester = requester.id |
1174 | 805 | fault = self.branchfs.translatePath(requester, path) | 714 | fault = self.codehosting_api.translatePath(requester, path) |
1175 | 806 | self.assertEqual(faults.PathTranslationError(path), fault) | 715 | self.assertEqual(faults.PathTranslationError(path), fault) |
1176 | 807 | 716 | ||
1177 | 808 | def assertPermissionDenied(self, requester, path): | 717 | def assertPermissionDenied(self, requester, path): |
1178 | 809 | """Assert that looking at the given path gives permission denied.""" | 718 | """Assert that looking at the given path gives permission denied.""" |
1179 | 810 | if requester not in [LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES]: | 719 | if requester not in [LAUNCHPAD_ANONYMOUS, LAUNCHPAD_SERVICES]: |
1180 | 811 | requester = requester.id | 720 | requester = requester.id |
1182 | 812 | fault = self.branchfs.translatePath(requester, path) | 721 | fault = self.codehosting_api.translatePath(requester, path) |
1183 | 813 | self.assertEqual(faults.PermissionDenied(), fault) | 722 | self.assertEqual(faults.PermissionDenied(), fault) |
1184 | 814 | 723 | ||
1185 | 815 | def _makeProductWithDevFocus(self, private=False): | 724 | def _makeProductWithDevFocus(self, private=False): |
1186 | @@ -837,14 +746,14 @@ | |||
1187 | 837 | def test_translatePath_no_preceding_slash(self): | 746 | def test_translatePath_no_preceding_slash(self): |
1188 | 838 | requester = self.factory.makePerson() | 747 | requester = self.factory.makePerson() |
1189 | 839 | path = escape(u'invalid') | 748 | path = escape(u'invalid') |
1191 | 840 | fault = self.branchfs.translatePath(requester.id, path) | 749 | fault = self.codehosting_api.translatePath(requester.id, path) |
1192 | 841 | self.assertEqual(faults.InvalidPath(path), fault) | 750 | self.assertEqual(faults.InvalidPath(path), fault) |
1193 | 842 | 751 | ||
1194 | 843 | def test_translatePath_branch(self): | 752 | def test_translatePath_branch(self): |
1195 | 844 | requester = self.factory.makePerson() | 753 | requester = self.factory.makePerson() |
1196 | 845 | branch = self.factory.makeAnyBranch() | 754 | branch = self.factory.makeAnyBranch() |
1197 | 846 | path = escape(u'/%s' % branch.unique_name) | 755 | path = escape(u'/%s' % branch.unique_name) |
1199 | 847 | translation = self.branchfs.translatePath(requester.id, path) | 756 | translation = self.codehosting_api.translatePath(requester.id, path) |
1200 | 848 | login(ANONYMOUS) | 757 | login(ANONYMOUS) |
1201 | 849 | self.assertEqual( | 758 | self.assertEqual( |
1202 | 850 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 759 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1203 | @@ -854,7 +763,7 @@ | |||
1204 | 854 | requester = self.factory.makePerson() | 763 | requester = self.factory.makePerson() |
1205 | 855 | branch = self.factory.makeAnyBranch() | 764 | branch = self.factory.makeAnyBranch() |
1206 | 856 | path = escape(u'/%s/' % branch.unique_name) | 765 | path = escape(u'/%s/' % branch.unique_name) |
1208 | 857 | translation = self.branchfs.translatePath(requester.id, path) | 766 | translation = self.codehosting_api.translatePath(requester.id, path) |
1209 | 858 | login(ANONYMOUS) | 767 | login(ANONYMOUS) |
1210 | 859 | self.assertEqual( | 768 | self.assertEqual( |
1211 | 860 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 769 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1212 | @@ -864,7 +773,7 @@ | |||
1213 | 864 | requester = self.factory.makePerson() | 773 | requester = self.factory.makePerson() |
1214 | 865 | branch = self.factory.makeAnyBranch() | 774 | branch = self.factory.makeAnyBranch() |
1215 | 866 | path = escape(u'/%s/child' % branch.unique_name) | 775 | path = escape(u'/%s/child' % branch.unique_name) |
1217 | 867 | translation = self.branchfs.translatePath(requester.id, path) | 776 | translation = self.codehosting_api.translatePath(requester.id, path) |
1218 | 868 | login(ANONYMOUS) | 777 | login(ANONYMOUS) |
1219 | 869 | self.assertEqual( | 778 | self.assertEqual( |
1220 | 870 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, 'child'), | 779 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, 'child'), |
1221 | @@ -874,7 +783,7 @@ | |||
1222 | 874 | requester = self.factory.makePerson() | 783 | requester = self.factory.makePerson() |
1223 | 875 | branch = self.factory.makeAnyBranch() | 784 | branch = self.factory.makeAnyBranch() |
1224 | 876 | path = escape(u'/%s/a/b' % branch.unique_name) | 785 | path = escape(u'/%s/a/b' % branch.unique_name) |
1226 | 877 | translation = self.branchfs.translatePath(requester.id, path) | 786 | translation = self.codehosting_api.translatePath(requester.id, path) |
1227 | 878 | login(ANONYMOUS) | 787 | login(ANONYMOUS) |
1228 | 879 | self.assertEqual( | 788 | self.assertEqual( |
1229 | 880 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, 'a/b'), | 789 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, 'a/b'), |
1230 | @@ -888,7 +797,7 @@ | |||
1231 | 888 | # escaped. | 797 | # escaped. |
1232 | 889 | self.assertNotEqual(escape(child_path), child_path.encode('utf-8')) | 798 | self.assertNotEqual(escape(child_path), child_path.encode('utf-8')) |
1233 | 890 | path = escape(u'/%s/%s' % (branch.unique_name, child_path)) | 799 | path = escape(u'/%s/%s' % (branch.unique_name, child_path)) |
1235 | 891 | translation = self.branchfs.translatePath(requester.id, path) | 800 | translation = self.codehosting_api.translatePath(requester.id, path) |
1236 | 892 | login(ANONYMOUS) | 801 | login(ANONYMOUS) |
1237 | 893 | self.assertEqual( | 802 | self.assertEqual( |
1238 | 894 | (BRANCH_TRANSPORT, | 803 | (BRANCH_TRANSPORT, |
1239 | @@ -925,7 +834,7 @@ | |||
1240 | 925 | self.factory.makeAnyBranch( | 834 | self.factory.makeAnyBranch( |
1241 | 926 | branch_type=BranchType.HOSTED, private=True, owner=requester)) | 835 | branch_type=BranchType.HOSTED, private=True, owner=requester)) |
1242 | 927 | path = escape(u'/%s' % branch.unique_name) | 836 | path = escape(u'/%s' % branch.unique_name) |
1244 | 928 | translation = self.branchfs.translatePath(requester.id, path) | 837 | translation = self.codehosting_api.translatePath(requester.id, path) |
1245 | 929 | login(ANONYMOUS) | 838 | login(ANONYMOUS) |
1246 | 930 | self.assertEqual( | 839 | self.assertEqual( |
1247 | 931 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': True}, ''), | 840 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': True}, ''), |
1248 | @@ -946,7 +855,8 @@ | |||
1249 | 946 | def test_translatePath_launchpad_services_private(self): | 855 | def test_translatePath_launchpad_services_private(self): |
1250 | 947 | branch = removeSecurityProxy(self.factory.makeAnyBranch(private=True)) | 856 | branch = removeSecurityProxy(self.factory.makeAnyBranch(private=True)) |
1251 | 948 | path = escape(u'/%s' % branch.unique_name) | 857 | path = escape(u'/%s' % branch.unique_name) |
1253 | 949 | translation = self.branchfs.translatePath(LAUNCHPAD_SERVICES, path) | 858 | translation = self.codehosting_api.translatePath( |
1254 | 859 | LAUNCHPAD_SERVICES, path) | ||
1255 | 950 | login(ANONYMOUS) | 860 | login(ANONYMOUS) |
1256 | 951 | self.assertEqual( | 861 | self.assertEqual( |
1257 | 952 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 862 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1258 | @@ -960,7 +870,8 @@ | |||
1259 | 960 | def test_translatePath_anonymous_public_branch(self): | 870 | def test_translatePath_anonymous_public_branch(self): |
1260 | 961 | branch = self.factory.makeAnyBranch() | 871 | branch = self.factory.makeAnyBranch() |
1261 | 962 | path = escape(u'/%s' % branch.unique_name) | 872 | path = escape(u'/%s' % branch.unique_name) |
1263 | 963 | translation = self.branchfs.translatePath(LAUNCHPAD_ANONYMOUS, path) | 873 | translation = self.codehosting_api.translatePath( |
1264 | 874 | LAUNCHPAD_ANONYMOUS, path) | ||
1265 | 964 | self.assertEqual( | 875 | self.assertEqual( |
1266 | 965 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 876 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1267 | 966 | translation) | 877 | translation) |
1268 | @@ -970,7 +881,7 @@ | |||
1269 | 970 | branch = self.factory.makeAnyBranch( | 881 | branch = self.factory.makeAnyBranch( |
1270 | 971 | branch_type=BranchType.HOSTED, owner=requester) | 882 | branch_type=BranchType.HOSTED, owner=requester) |
1271 | 972 | path = escape(u'/%s' % branch.unique_name) | 883 | path = escape(u'/%s' % branch.unique_name) |
1273 | 973 | translation = self.branchfs.translatePath(requester.id, path) | 884 | translation = self.codehosting_api.translatePath(requester.id, path) |
1274 | 974 | login(ANONYMOUS) | 885 | login(ANONYMOUS) |
1275 | 975 | self.assertEqual( | 886 | self.assertEqual( |
1276 | 976 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': True}, ''), | 887 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': True}, ''), |
1277 | @@ -982,7 +893,7 @@ | |||
1278 | 982 | branch = self.factory.makeAnyBranch( | 893 | branch = self.factory.makeAnyBranch( |
1279 | 983 | branch_type=BranchType.HOSTED, owner=team) | 894 | branch_type=BranchType.HOSTED, owner=team) |
1280 | 984 | path = escape(u'/%s' % branch.unique_name) | 895 | path = escape(u'/%s' % branch.unique_name) |
1282 | 985 | translation = self.branchfs.translatePath(requester.id, path) | 896 | translation = self.codehosting_api.translatePath(requester.id, path) |
1283 | 986 | login(ANONYMOUS) | 897 | login(ANONYMOUS) |
1284 | 987 | self.assertEqual( | 898 | self.assertEqual( |
1285 | 988 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': True}, ''), | 899 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': True}, ''), |
1286 | @@ -994,7 +905,7 @@ | |||
1287 | 994 | branch = self.factory.makeAnyBranch( | 905 | branch = self.factory.makeAnyBranch( |
1288 | 995 | branch_type=BranchType.HOSTED, owner=team) | 906 | branch_type=BranchType.HOSTED, owner=team) |
1289 | 996 | path = escape(u'/%s' % branch.unique_name) | 907 | path = escape(u'/%s' % branch.unique_name) |
1291 | 997 | translation = self.branchfs.translatePath(requester.id, path) | 908 | translation = self.codehosting_api.translatePath(requester.id, path) |
1292 | 998 | login(ANONYMOUS) | 909 | login(ANONYMOUS) |
1293 | 999 | self.assertEqual( | 910 | self.assertEqual( |
1294 | 1000 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 911 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1295 | @@ -1005,7 +916,7 @@ | |||
1296 | 1005 | branch = self.factory.makeAnyBranch( | 916 | branch = self.factory.makeAnyBranch( |
1297 | 1006 | branch_type=BranchType.MIRRORED, owner=requester) | 917 | branch_type=BranchType.MIRRORED, owner=requester) |
1298 | 1007 | path = escape(u'/%s' % branch.unique_name) | 918 | path = escape(u'/%s' % branch.unique_name) |
1300 | 1008 | translation = self.branchfs.translatePath(requester.id, path) | 919 | translation = self.codehosting_api.translatePath(requester.id, path) |
1301 | 1009 | login(ANONYMOUS) | 920 | login(ANONYMOUS) |
1302 | 1010 | self.assertEqual( | 921 | self.assertEqual( |
1303 | 1011 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 922 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1304 | @@ -1016,7 +927,7 @@ | |||
1305 | 1016 | branch = self.factory.makeAnyBranch( | 927 | branch = self.factory.makeAnyBranch( |
1306 | 1017 | branch_type=BranchType.IMPORTED, owner=requester) | 928 | branch_type=BranchType.IMPORTED, owner=requester) |
1307 | 1018 | path = escape(u'/%s' % branch.unique_name) | 929 | path = escape(u'/%s' % branch.unique_name) |
1309 | 1019 | translation = self.branchfs.translatePath(requester.id, path) | 930 | translation = self.codehosting_api.translatePath(requester.id, path) |
1310 | 1020 | login(ANONYMOUS) | 931 | login(ANONYMOUS) |
1311 | 1021 | self.assertEqual( | 932 | self.assertEqual( |
1312 | 1022 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), | 933 | (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''), |
1313 | @@ -1036,7 +947,7 @@ | |||
1314 | 1036 | requester = self.factory.makePerson() | 947 | requester = self.factory.makePerson() |
1315 | 1037 | product, branch = self._makeProductWithDevFocus() | 948 | product, branch = self._makeProductWithDevFocus() |
1316 | 1038 | path = escape(u'/~%s/%s/.bzr' % (requester.name, product.name)) | 949 | path = escape(u'/~%s/%s/.bzr' % (requester.name, product.name)) |
1318 | 1039 | translation = self.branchfs.translatePath(requester.id, path) | 950 | translation = self.codehosting_api.translatePath(requester.id, path) |
1319 | 1040 | login(ANONYMOUS) | 951 | login(ANONYMOUS) |
1320 | 1041 | self.assertTranslationIsControlDirectory( | 952 | self.assertTranslationIsControlDirectory( |
1321 | 1042 | translation, | 953 | translation, |
1322 | @@ -1062,7 +973,7 @@ | |||
1323 | 1062 | branch = removeSecurityProxy(branch) | 973 | branch = removeSecurityProxy(branch) |
1324 | 1063 | requester = branch.owner | 974 | requester = branch.owner |
1325 | 1064 | path = escape(u'/~%s/%s/.bzr/' % (requester.name, product.name)) | 975 | path = escape(u'/~%s/%s/.bzr/' % (requester.name, product.name)) |
1327 | 1065 | translation = self.branchfs.translatePath(requester.id, path) | 976 | translation = self.codehosting_api.translatePath(requester.id, path) |
1328 | 1066 | login(ANONYMOUS) | 977 | login(ANONYMOUS) |
1329 | 1067 | self.assertTranslationIsControlDirectory( | 978 | self.assertTranslationIsControlDirectory( |
1330 | 1068 | translation, | 979 | translation, |
1331 | @@ -1074,7 +985,7 @@ | |||
1332 | 1074 | product, branch = self._makeProductWithDevFocus() | 985 | product, branch = self._makeProductWithDevFocus() |
1333 | 1075 | owner = self.factory.makePerson() | 986 | owner = self.factory.makePerson() |
1334 | 1076 | path = escape(u'/~%s/%s/.bzr' % (owner.name, product.name)) | 987 | path = escape(u'/~%s/%s/.bzr' % (owner.name, product.name)) |
1336 | 1077 | translation = self.branchfs.translatePath(requester.id, path) | 988 | translation = self.codehosting_api.translatePath(requester.id, path) |
1337 | 1078 | login(ANONYMOUS) | 989 | login(ANONYMOUS) |
1338 | 1079 | self.assertTranslationIsControlDirectory( | 990 | self.assertTranslationIsControlDirectory( |
1339 | 1080 | translation, | 991 | translation, |
1340 | @@ -1100,7 +1011,7 @@ | |||
1341 | 1100 | self.assertIsNot( | 1011 | self.assertIsNot( |
1342 | 1101 | None, IBranchTarget(package).default_stacked_on_branch) | 1012 | None, IBranchTarget(package).default_stacked_on_branch) |
1343 | 1102 | path = '/~%s/%s/.bzr/' % (requester.name, package.path) | 1013 | path = '/~%s/%s/.bzr/' % (requester.name, package.path) |
1345 | 1103 | translation = self.branchfs.translatePath(requester.id, path) | 1014 | translation = self.codehosting_api.translatePath(requester.id, path) |
1346 | 1104 | login(ANONYMOUS) | 1015 | login(ANONYMOUS) |
1347 | 1105 | self.assertTranslationIsControlDirectory( | 1016 | self.assertTranslationIsControlDirectory( |
1348 | 1106 | translation, | 1017 | translation, |
1349 | @@ -1108,6 +1019,89 @@ | |||
1350 | 1108 | trailing_path='.bzr') | 1019 | trailing_path='.bzr') |
1351 | 1109 | 1020 | ||
1352 | 1110 | 1021 | ||
1353 | 1022 | class AcquireBranchToPullTestsViaEndpoint(TestCaseWithFactory, | ||
1354 | 1023 | AcquireBranchToPullTests): | ||
1355 | 1024 | """Tests for `acquireBranchToPull` method of `ICodehostingAPI`.""" | ||
1356 | 1025 | |||
1357 | 1026 | def setUp(self): | ||
1358 | 1027 | super(AcquireBranchToPullTestsViaEndpoint, self).setUp() | ||
1359 | 1028 | frontend = self.frontend() | ||
1360 | 1029 | self.codehosting_api = frontend.getCodehostingEndpoint() | ||
1361 | 1030 | self.factory = frontend.getLaunchpadObjectFactory() | ||
1362 | 1031 | |||
1363 | 1032 | def assertNoBranchIsAquired(self, *branch_types): | ||
1364 | 1033 | """See `AcquireBranchToPullTests`.""" | ||
1365 | 1034 | branch_types = tuple(branch_type.name for branch_type in branch_types) | ||
1366 | 1035 | pull_info = self.codehosting_api.acquireBranchToPull(branch_types) | ||
1367 | 1036 | self.assertEqual((), pull_info) | ||
1368 | 1037 | |||
1369 | 1038 | def assertBranchIsAquired(self, branch, *branch_types): | ||
1370 | 1039 | """See `AcquireBranchToPullTests`.""" | ||
1371 | 1040 | branch = removeSecurityProxy(branch) | ||
1372 | 1041 | branch_types = tuple(branch_type.name for branch_type in branch_types) | ||
1373 | 1042 | pull_info = self.codehosting_api.acquireBranchToPull(branch_types) | ||
1374 | 1043 | default_branch = branch.target.default_stacked_on_branch | ||
1375 | 1044 | if default_branch: | ||
1376 | 1045 | default_branch_name = default_branch | ||
1377 | 1046 | else: | ||
1378 | 1047 | default_branch_name = '' | ||
1379 | 1048 | self.assertEqual( | ||
1380 | 1049 | pull_info, | ||
1381 | 1050 | (branch.id, branch.getPullURL(), branch.unique_name, | ||
1382 | 1051 | default_branch_name, branch.branch_type.name)) | ||
1383 | 1052 | self.assertIsNot(None, branch.last_mirror_attempt) | ||
1384 | 1053 | self.assertIs(None, branch.next_mirror_time) | ||
1385 | 1054 | |||
1386 | 1055 | def startMirroring(self, branch): | ||
1387 | 1056 | """See `AcquireBranchToPullTests`.""" | ||
1388 | 1057 | self.codehosting_api.startMirroring(branch.id) | ||
1389 | 1058 | |||
1390 | 1059 | def test_branch_type_returned_mirrored(self): | ||
1391 | 1060 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) | ||
1392 | 1061 | branch.requestMirror() | ||
1393 | 1062 | pull_info = self.codehosting_api.acquireBranchToPull(()) | ||
1394 | 1063 | _, _, _, _, branch_type = pull_info | ||
1395 | 1064 | self.assertEqual('MIRRORED', branch_type) | ||
1396 | 1065 | |||
1397 | 1066 | def test_branch_type_returned_import(self): | ||
1398 | 1067 | branch = self.factory.makeAnyBranch(branch_type=BranchType.IMPORTED) | ||
1399 | 1068 | branch.requestMirror() | ||
1400 | 1069 | pull_info = self.codehosting_api.acquireBranchToPull(()) | ||
1401 | 1070 | _, _, _, _, branch_type = pull_info | ||
1402 | 1071 | self.assertEqual('IMPORTED', branch_type) | ||
1403 | 1072 | |||
1404 | 1073 | def test_default_stacked_on_branch_returned(self): | ||
1405 | 1074 | branch = self.factory.makeProductBranch( | ||
1406 | 1075 | branch_type=BranchType.MIRRORED) | ||
1407 | 1076 | self.factory.enableDefaultStackingForProduct(branch.product) | ||
1408 | 1077 | branch.requestMirror() | ||
1409 | 1078 | pull_info = self.codehosting_api.acquireBranchToPull(()) | ||
1410 | 1079 | _, _, _, default_stacked_on_branch, _ = pull_info | ||
1411 | 1080 | self.assertEqual( | ||
1412 | 1081 | default_stacked_on_branch, | ||
1413 | 1082 | '/' + branch.target.default_stacked_on_branch.unique_name) | ||
1414 | 1083 | |||
1415 | 1084 | def test_private_default_stacked_not_returned_for_mirrored_branch(self): | ||
1416 | 1085 | # We don't stack mirrored branches on a private default stacked on | ||
1417 | 1086 | # branch. | ||
1418 | 1087 | product = self.factory.makeProduct() | ||
1419 | 1088 | default_branch = self.factory.makeProductBranch( | ||
1420 | 1089 | product=product, private=True) | ||
1421 | 1090 | self.factory.enableDefaultStackingForProduct(product, default_branch) | ||
1422 | 1091 | mirrored_branch = self.factory.makeProductBranch( | ||
1423 | 1092 | branch_type=BranchType.MIRRORED, product=product) | ||
1424 | 1093 | mirrored_branch.requestMirror() | ||
1425 | 1094 | pull_info = self.codehosting_api.acquireBranchToPull(()) | ||
1426 | 1095 | _, _, _, default_stacked_on_branch, _ = pull_info | ||
1427 | 1096 | self.assertEqual( | ||
1428 | 1097 | '', default_stacked_on_branch) | ||
1429 | 1098 | |||
1430 | 1099 | def test_unknown_branch_type_name_raises(self): | ||
1431 | 1100 | self.assertRaises( | ||
1432 | 1101 | UnknownBranchTypeError, self.codehosting_api.acquireBranchToPull, | ||
1433 | 1102 | ('NO_SUCH_TYPE',)) | ||
1434 | 1103 | |||
1435 | 1104 | |||
1436 | 1111 | class LaunchpadDatabaseFrontend: | 1105 | class LaunchpadDatabaseFrontend: |
1437 | 1112 | """A 'frontend' to Launchpad's branch services. | 1106 | """A 'frontend' to Launchpad's branch services. |
1438 | 1113 | 1107 | ||
1439 | @@ -1119,13 +1113,9 @@ | |||
1440 | 1119 | alternative implementations can be provided, see `InMemoryFrontend`. | 1113 | alternative implementations can be provided, see `InMemoryFrontend`. |
1441 | 1120 | """ | 1114 | """ |
1442 | 1121 | 1115 | ||
1444 | 1122 | def getFilesystemEndpoint(self): | 1116 | def getCodehostingEndpoint(self): |
1445 | 1123 | """Return the branch filesystem endpoint for testing.""" | 1117 | """Return the branch filesystem endpoint for testing.""" |
1451 | 1124 | return BranchFileSystem(None, None) | 1118 | return CodehostingAPI(None, None) |
1447 | 1125 | |||
1448 | 1126 | def getPullerEndpoint(self): | ||
1449 | 1127 | """Return the branch puller endpoint for testing.""" | ||
1450 | 1128 | return BranchPuller(None, None) | ||
1452 | 1129 | 1119 | ||
1453 | 1130 | def getLaunchpadObjectFactory(self): | 1120 | def getLaunchpadObjectFactory(self): |
1454 | 1131 | """Return the Launchpad object factory for testing. | 1121 | """Return the Launchpad object factory for testing. |
1455 | @@ -1148,13 +1138,13 @@ | |||
1456 | 1148 | return getUtility(IScriptActivitySet).getLastActivity(activity_name) | 1138 | return getUtility(IScriptActivitySet).getLastActivity(activity_name) |
1457 | 1149 | 1139 | ||
1458 | 1150 | 1140 | ||
1459 | 1141 | |||
1460 | 1151 | def test_suite(): | 1142 | def test_suite(): |
1461 | 1152 | loader = unittest.TestLoader() | 1143 | loader = unittest.TestLoader() |
1462 | 1153 | suite = unittest.TestSuite() | 1144 | suite = unittest.TestSuite() |
1467 | 1154 | puller_tests = unittest.TestSuite( | 1145 | endpoint_tests = unittest.TestSuite( |
1468 | 1155 | [loader.loadTestsFromTestCase(BranchPullerTest), | 1146 | [loader.loadTestsFromTestCase(AcquireBranchToPullTestsViaEndpoint), |
1469 | 1156 | loader.loadTestsFromTestCase(AcquireBranchToPullTestsViaEndpoint), | 1147 | loader.loadTestsFromTestCase(CodehostingTest), |
1466 | 1157 | loader.loadTestsFromTestCase(BranchFileSystemTest), | ||
1470 | 1158 | ]) | 1148 | ]) |
1471 | 1159 | scenarios = [ | 1149 | scenarios = [ |
1472 | 1160 | ('db', {'frontend': LaunchpadDatabaseFrontend, | 1150 | ('db', {'frontend': LaunchpadDatabaseFrontend, |
1473 | @@ -1162,6 +1152,6 @@ | |||
1474 | 1162 | ('inmemory', {'frontend': InMemoryFrontend, | 1152 | ('inmemory', {'frontend': InMemoryFrontend, |
1475 | 1163 | 'layer': FunctionalLayer}), | 1153 | 'layer': FunctionalLayer}), |
1476 | 1164 | ] | 1154 | ] |
1478 | 1165 | multiply_tests(puller_tests, scenarios, suite) | 1155 | multiply_tests(endpoint_tests, scenarios, suite) |
1479 | 1166 | suite.addTests(loader.loadTestsFromTestCase(TestRunWithLogin)) | 1156 | suite.addTests(loader.loadTestsFromTestCase(TestRunWithLogin)) |
1480 | 1167 | return suite | 1157 | return suite |
1481 | 1168 | 1158 | ||
1482 | === modified file 'lib/lp/codehosting/inmemory.py' | |||
1483 | --- lib/lp/codehosting/inmemory.py 2010-04-27 02:11:16 +0000 | |||
1484 | +++ lib/lp/codehosting/inmemory.py 2010-04-27 02:11:35 +0000 | |||
1485 | @@ -449,10 +449,18 @@ | |||
1486 | 449 | return branch | 449 | return branch |
1487 | 450 | 450 | ||
1488 | 451 | 451 | ||
1490 | 452 | class FakeBranchPuller: | 452 | class FakeCodehosting: |
1491 | 453 | 453 | ||
1493 | 454 | def __init__(self, branch_set, script_activity_set): | 454 | def __init__(self, branch_set, person_set, product_set, distribution_set, |
1494 | 455 | distroseries_set, sourcepackagename_set, factory, | ||
1495 | 456 | script_activity_set): | ||
1496 | 455 | self._branch_set = branch_set | 457 | self._branch_set = branch_set |
1497 | 458 | self._person_set = person_set | ||
1498 | 459 | self._product_set = product_set | ||
1499 | 460 | self._distribution_set = distribution_set | ||
1500 | 461 | self._distroseries_set = distroseries_set | ||
1501 | 462 | self._sourcepackagename_set = sourcepackagename_set | ||
1502 | 463 | self._factory = factory | ||
1503 | 456 | self._script_activity_set = script_activity_set | 464 | self._script_activity_set = script_activity_set |
1504 | 457 | 465 | ||
1505 | 458 | def acquireBranchToPull(self, branch_type_names): | 466 | def acquireBranchToPull(self, branch_type_names): |
1506 | @@ -538,19 +546,6 @@ | |||
1507 | 538 | return faults.NoSuchBranch(stacked_on_location) | 546 | return faults.NoSuchBranch(stacked_on_location) |
1508 | 539 | return True | 547 | return True |
1509 | 540 | 548 | ||
1510 | 541 | |||
1511 | 542 | class FakeBranchFilesystem: | ||
1512 | 543 | |||
1513 | 544 | def __init__(self, branch_set, person_set, product_set, distribution_set, | ||
1514 | 545 | distroseries_set, sourcepackagename_set, factory): | ||
1515 | 546 | self._branch_set = branch_set | ||
1516 | 547 | self._person_set = person_set | ||
1517 | 548 | self._product_set = product_set | ||
1518 | 549 | self._distribution_set = distribution_set | ||
1519 | 550 | self._distroseries_set = distroseries_set | ||
1520 | 551 | self._sourcepackagename_set = sourcepackagename_set | ||
1521 | 552 | self._factory = factory | ||
1522 | 553 | |||
1523 | 554 | def createBranch(self, requester_id, branch_path): | 549 | def createBranch(self, requester_id, branch_path): |
1524 | 555 | if not branch_path.startswith('/'): | 550 | if not branch_path.startswith('/'): |
1525 | 556 | return faults.InvalidPath(branch_path) | 551 | return faults.InvalidPath(branch_path) |
1526 | @@ -780,31 +775,22 @@ | |||
1527 | 780 | self._branch_set, self._person_set, self._product_set, | 775 | self._branch_set, self._person_set, self._product_set, |
1528 | 781 | self._distribution_set, self._distroseries_set, | 776 | self._distribution_set, self._distroseries_set, |
1529 | 782 | self._sourcepackagename_set) | 777 | self._sourcepackagename_set) |
1533 | 783 | self._puller = FakeBranchPuller( | 778 | self._codehosting = FakeCodehosting( |
1531 | 784 | self._branch_set, self._script_activity_set) | ||
1532 | 785 | self._branchfs = FakeBranchFilesystem( | ||
1534 | 786 | self._branch_set, self._person_set, self._product_set, | 779 | self._branch_set, self._person_set, self._product_set, |
1535 | 787 | self._distribution_set, self._distroseries_set, | 780 | self._distribution_set, self._distroseries_set, |
1537 | 788 | self._sourcepackagename_set, self._factory) | 781 | self._sourcepackagename_set, self._factory, |
1538 | 782 | self._script_activity_set) | ||
1539 | 789 | sm = getSiteManager() | 783 | sm = getSiteManager() |
1540 | 790 | sm.registerAdapter(fake_product_to_branch_target) | 784 | sm.registerAdapter(fake_product_to_branch_target) |
1541 | 791 | sm.registerAdapter(fake_source_package_to_branch_target) | 785 | sm.registerAdapter(fake_source_package_to_branch_target) |
1542 | 792 | 786 | ||
1544 | 793 | def getFilesystemEndpoint(self): | 787 | def getCodehostingEndpoint(self): |
1545 | 794 | """See `LaunchpadDatabaseFrontend`. | 788 | """See `LaunchpadDatabaseFrontend`. |
1546 | 795 | 789 | ||
1547 | 796 | Return an in-memory implementation of IBranchFileSystem that passes | 790 | Return an in-memory implementation of IBranchFileSystem that passes |
1548 | 797 | the tests in `test_codehosting`. | 791 | the tests in `test_codehosting`. |
1549 | 798 | """ | 792 | """ |
1559 | 799 | return self._branchfs | 793 | return self._codehosting |
1551 | 800 | |||
1552 | 801 | def getPullerEndpoint(self): | ||
1553 | 802 | """See `LaunchpadDatabaseFrontend`. | ||
1554 | 803 | |||
1555 | 804 | Return an in-memory implementation of IBranchPuller that passes the | ||
1556 | 805 | tests in `test_codehosting`. | ||
1557 | 806 | """ | ||
1558 | 807 | return self._puller | ||
1560 | 808 | 794 | ||
1561 | 809 | def getLaunchpadObjectFactory(self): | 795 | def getLaunchpadObjectFactory(self): |
1562 | 810 | """See `LaunchpadDatabaseFrontend`. | 796 | """See `LaunchpadDatabaseFrontend`. |
1563 | 811 | 797 | ||
1564 | === modified file 'lib/lp/codehosting/puller/scheduler.py' | |||
1565 | --- lib/lp/codehosting/puller/scheduler.py 2010-04-27 02:11:16 +0000 | |||
1566 | +++ lib/lp/codehosting/puller/scheduler.py 2010-04-27 02:11:35 +0000 | |||
1567 | @@ -296,7 +296,7 @@ | |||
1568 | 296 | self.branch_type_name = branch_type_name | 296 | self.branch_type_name = branch_type_name |
1569 | 297 | self.default_stacked_on_url = default_stacked_on_url | 297 | self.default_stacked_on_url = default_stacked_on_url |
1570 | 298 | self.logger = logger | 298 | self.logger = logger |
1572 | 299 | self.branch_puller_endpoint = client | 299 | self.codehosting_endpoint = client |
1573 | 300 | self._available_oops_prefixes = available_oops_prefixes | 300 | self._available_oops_prefixes = available_oops_prefixes |
1574 | 301 | 301 | ||
1575 | 302 | @cachedproperty | 302 | @cachedproperty |
1576 | @@ -348,7 +348,7 @@ | |||
1577 | 348 | return deferred | 348 | return deferred |
1578 | 349 | 349 | ||
1579 | 350 | def setStackedOn(self, stacked_on_location): | 350 | def setStackedOn(self, stacked_on_location): |
1581 | 351 | deferred = self.branch_puller_endpoint.callRemote( | 351 | deferred = self.codehosting_endpoint.callRemote( |
1582 | 352 | 'setStackedOn', self.branch_id, stacked_on_location) | 352 | 'setStackedOn', self.branch_id, stacked_on_location) |
1583 | 353 | def no_such_branch(failure): | 353 | def no_such_branch(failure): |
1584 | 354 | # If there's no branch for stacked_on_location, then we just | 354 | # If there's no branch for stacked_on_location, then we just |
1585 | @@ -365,7 +365,7 @@ | |||
1586 | 365 | def mirrorFailed(self, reason, oops): | 365 | def mirrorFailed(self, reason, oops): |
1587 | 366 | self.logger.info('Recorded %s', oops) | 366 | self.logger.info('Recorded %s', oops) |
1588 | 367 | self.logger.info('Recorded failure: %s', str(reason)) | 367 | self.logger.info('Recorded failure: %s', str(reason)) |
1590 | 368 | return self.branch_puller_endpoint.callRemote( | 368 | return self.codehosting_endpoint.callRemote( |
1591 | 369 | 'mirrorFailed', self.branch_id, reason) | 369 | 'mirrorFailed', self.branch_id, reason) |
1592 | 370 | 370 | ||
1593 | 371 | def mirrorSucceeded(self, revid_before, revid_after): | 371 | def mirrorSucceeded(self, revid_before, revid_after): |
1594 | @@ -377,7 +377,7 @@ | |||
1595 | 377 | 'Successfully mirrored %s branch %d %s to %s to from rev %s to %s' | 377 | 'Successfully mirrored %s branch %d %s to %s to from rev %s to %s' |
1596 | 378 | ' (%s)', self.branch_type_name, self.branch_id, self.source_url, | 378 | ' (%s)', self.branch_type_name, self.branch_id, self.source_url, |
1597 | 379 | self.destination_url, revid_before, revid_after, was_noop) | 379 | self.destination_url, revid_before, revid_after, was_noop) |
1599 | 380 | return self.branch_puller_endpoint.callRemote( | 380 | return self.codehosting_endpoint.callRemote( |
1600 | 381 | 'mirrorComplete', self.branch_id, revid_after) | 381 | 'mirrorComplete', self.branch_id, revid_after) |
1601 | 382 | 382 | ||
1602 | 383 | def log(self, message): | 383 | def log(self, message): |
1603 | @@ -411,8 +411,8 @@ | |||
1604 | 411 | branches. | 411 | branches. |
1605 | 412 | """ | 412 | """ |
1606 | 413 | 413 | ||
1609 | 414 | def __init__(self, branch_puller_endpoint, logger, branch_type_names): | 414 | def __init__(self, codehosting_endpoint, logger, branch_type_names): |
1610 | 415 | self.branch_puller_endpoint = branch_puller_endpoint | 415 | self.codehosting_endpoint = codehosting_endpoint |
1611 | 416 | self.logger = logger | 416 | self.logger = logger |
1612 | 417 | self.branch_type_names = branch_type_names | 417 | self.branch_type_names = branch_type_names |
1613 | 418 | self.actualLock = None | 418 | self.actualLock = None |
1614 | @@ -445,11 +445,11 @@ | |||
1615 | 445 | master = PullerMaster( | 445 | master = PullerMaster( |
1616 | 446 | branch_id, pull_url, unique_name, branch_type_name, | 446 | branch_id, pull_url, unique_name, branch_type_name, |
1617 | 447 | default_stacked_on_url, self.logger, | 447 | default_stacked_on_url, self.logger, |
1619 | 448 | self.branch_puller_endpoint, self.available_oops_prefixes) | 448 | self.codehosting_endpoint, self.available_oops_prefixes) |
1620 | 449 | return master.run | 449 | return master.run |
1621 | 450 | 450 | ||
1622 | 451 | def _poll(self): | 451 | def _poll(self): |
1624 | 452 | deferred = self.branch_puller_endpoint.callRemote( | 452 | deferred = self.codehosting_endpoint.callRemote( |
1625 | 453 | 'acquireBranchToPull', self.branch_type_names) | 453 | 'acquireBranchToPull', self.branch_type_names) |
1626 | 454 | deferred.addCallback(self._turnJobTupleIntoTask) | 454 | deferred.addCallback(self._turnJobTupleIntoTask) |
1627 | 455 | return deferred | 455 | return deferred |
1628 | @@ -483,7 +483,7 @@ | |||
1629 | 483 | """Record successful completion of the script.""" | 483 | """Record successful completion of the script.""" |
1630 | 484 | started_tuple = tuple(date_started.utctimetuple()) | 484 | started_tuple = tuple(date_started.utctimetuple()) |
1631 | 485 | completed_tuple = tuple(date_completed.utctimetuple()) | 485 | completed_tuple = tuple(date_completed.utctimetuple()) |
1633 | 486 | return self.branch_puller_endpoint.callRemote( | 486 | return self.codehosting_endpoint.callRemote( |
1634 | 487 | 'recordSuccess', self.name, socket.gethostname(), started_tuple, | 487 | 'recordSuccess', self.name, socket.gethostname(), started_tuple, |
1635 | 488 | completed_tuple) | 488 | completed_tuple) |
1636 | 489 | 489 | ||
1637 | 490 | 490 | ||
1638 | === modified file 'lib/lp/codehosting/puller/tests/test_scheduler.py' | |||
1639 | --- lib/lp/codehosting/puller/tests/test_scheduler.py 2010-04-27 02:11:16 +0000 | |||
1640 | +++ lib/lp/codehosting/puller/tests/test_scheduler.py 2010-04-27 02:11:35 +0000 | |||
1641 | @@ -40,7 +40,7 @@ | |||
1642 | 40 | from lp.testing.factory import ObjectFactory | 40 | from lp.testing.factory import ObjectFactory |
1643 | 41 | 41 | ||
1644 | 42 | 42 | ||
1646 | 43 | class FakePullerEndpointProxy: | 43 | class FakeCodehostingEndpointProxy: |
1647 | 44 | 44 | ||
1648 | 45 | def __init__(self): | 45 | def __init__(self): |
1649 | 46 | self.calls = [] | 46 | self.calls = [] |
1650 | @@ -81,7 +81,8 @@ | |||
1651 | 81 | 81 | ||
1652 | 82 | def makeJobScheduler(self, branch_type_names=()): | 82 | def makeJobScheduler(self, branch_type_names=()): |
1653 | 83 | return scheduler.JobScheduler( | 83 | return scheduler.JobScheduler( |
1655 | 84 | FakePullerEndpointProxy(), logging.getLogger(), branch_type_names) | 84 | FakeCodehostingEndpointProxy(), logging.getLogger(), |
1656 | 85 | branch_type_names) | ||
1657 | 85 | 86 | ||
1658 | 86 | def testManagerCreatesLocks(self): | 87 | def testManagerCreatesLocks(self): |
1659 | 87 | manager = self.makeJobScheduler() | 88 | manager = self.makeJobScheduler() |
1660 | @@ -105,7 +106,7 @@ | |||
1661 | 105 | manager.run() | 106 | manager.run() |
1662 | 106 | self.assertEqual( | 107 | self.assertEqual( |
1663 | 107 | [('acquireBranchToPull', ('MIRRORED',))], | 108 | [('acquireBranchToPull', ('MIRRORED',))], |
1665 | 108 | manager.branch_puller_endpoint.calls) | 109 | manager.codehosting_endpoint.calls) |
1666 | 109 | 110 | ||
1667 | 110 | 111 | ||
1668 | 111 | class TestPullerWireProtocol(TrialTestCase): | 112 | class TestPullerWireProtocol(TrialTestCase): |
1669 | @@ -421,7 +422,7 @@ | |||
1670 | 421 | layer = TwistedLayer | 422 | layer = TwistedLayer |
1671 | 422 | 423 | ||
1672 | 423 | def setUp(self): | 424 | def setUp(self): |
1674 | 424 | self.status_client = FakePullerEndpointProxy() | 425 | self.status_client = FakeCodehostingEndpointProxy() |
1675 | 425 | self.arbitrary_branch_id = 1 | 426 | self.arbitrary_branch_id = 1 |
1676 | 426 | self.eventHandler = scheduler.PullerMaster( | 427 | self.eventHandler = scheduler.PullerMaster( |
1677 | 427 | self.arbitrary_branch_id, 'arbitrary-source', 'arbitrary-dest', | 428 | self.arbitrary_branch_id, 'arbitrary-source', 'arbitrary-dest', |
1678 | @@ -528,7 +529,7 @@ | |||
1679 | 528 | branch_type_name=branch_type_name, | 529 | branch_type_name=branch_type_name, |
1680 | 529 | default_stacked_on_url=default_stacked_on_url, | 530 | default_stacked_on_url=default_stacked_on_url, |
1681 | 530 | logger=logging.getLogger(), | 531 | logger=logging.getLogger(), |
1683 | 531 | client=FakePullerEndpointProxy(), | 532 | client=FakeCodehostingEndpointProxy(), |
1684 | 532 | available_oops_prefixes=oops_prefixes) | 533 | available_oops_prefixes=oops_prefixes) |
1685 | 533 | 534 | ||
1686 | 534 | @property | 535 | @property |
1687 | @@ -642,7 +643,7 @@ | |||
1688 | 642 | branch_type=BranchType.MIRRORED, url=url).id | 643 | branch_type=BranchType.MIRRORED, url=url).id |
1689 | 643 | self.layer.txn.commit() | 644 | self.layer.txn.commit() |
1690 | 644 | self.db_branch = getUtility(IBranchLookup).get(branch_id) | 645 | self.db_branch = getUtility(IBranchLookup).get(branch_id) |
1692 | 645 | self.client = FakePullerEndpointProxy() | 646 | self.client = FakeCodehostingEndpointProxy() |
1693 | 646 | 647 | ||
1694 | 647 | def run(self, result): | 648 | def run(self, result): |
1695 | 648 | # We want to use Trial's run() method so we can return Deferreds. | 649 | # We want to use Trial's run() method so we can return Deferreds. |
1696 | 649 | 650 | ||
1697 | === modified file 'lib/lp/codehosting/sftp.py' | |||
1698 | --- lib/lp/codehosting/sftp.py 2010-04-27 02:11:16 +0000 | |||
1699 | +++ lib/lp/codehosting/sftp.py 2010-04-27 02:11:35 +0000 | |||
1700 | @@ -244,7 +244,8 @@ | |||
1701 | 244 | user_id = avatar.user_id | 244 | user_id = avatar.user_id |
1702 | 245 | branch_transport = _get_transport_for_dir( | 245 | branch_transport = _get_transport_for_dir( |
1703 | 246 | config.codehosting.mirrored_branches_root) | 246 | config.codehosting.mirrored_branches_root) |
1705 | 247 | server = LaunchpadServer(avatar.branchfs_proxy, user_id, branch_transport) | 247 | server = LaunchpadServer( |
1706 | 248 | avatar.codehosting_proxy, user_id, branch_transport) | ||
1707 | 248 | server.start_server() | 249 | server.start_server() |
1708 | 249 | transport = AsyncLaunchpadTransport(server, server.get_url()) | 250 | transport = AsyncLaunchpadTransport(server, server.get_url()) |
1709 | 250 | return TransportSFTPServer(transport) | 251 | return TransportSFTPServer(transport) |
1710 | 251 | 252 | ||
1711 | === modified file 'lib/lp/codehosting/sshserver/daemon.py' | |||
1712 | --- lib/lp/codehosting/sshserver/daemon.py 2010-04-15 15:27:30 +0000 | |||
1713 | +++ lib/lp/codehosting/sshserver/daemon.py 2010-04-27 02:11:35 +0000 | |||
1714 | @@ -45,13 +45,13 @@ | |||
1715 | 45 | class CodehostingAvatar(LaunchpadAvatar): | 45 | class CodehostingAvatar(LaunchpadAvatar): |
1716 | 46 | """An SSH avatar specific to codehosting. | 46 | """An SSH avatar specific to codehosting. |
1717 | 47 | 47 | ||
1720 | 48 | :ivar branchfs_proxy: A Twisted XML-RPC client for the authserver. The | 48 | :ivar codehosting_proxy: A Twisted XML-RPC client for the private XML-RPC |
1721 | 49 | server must implement `IBranchFileSystem`. | 49 | server. The server must implement `ICodehostingAPI`. |
1722 | 50 | """ | 50 | """ |
1723 | 51 | 51 | ||
1725 | 52 | def __init__(self, user_dict, branchfs_proxy): | 52 | def __init__(self, user_dict, codehosting_proxy): |
1726 | 53 | LaunchpadAvatar.__init__(self, user_dict) | 53 | LaunchpadAvatar.__init__(self, user_dict) |
1728 | 54 | self.branchfs_proxy = branchfs_proxy | 54 | self.codehosting_proxy = codehosting_proxy |
1729 | 55 | 55 | ||
1730 | 56 | 56 | ||
1731 | 57 | components.registerAdapter(launch_smart_server, CodehostingAvatar, ISession) | 57 | components.registerAdapter(launch_smart_server, CodehostingAvatar, ISession) |
1732 | @@ -63,9 +63,9 @@ | |||
1733 | 63 | class Realm: | 63 | class Realm: |
1734 | 64 | implements(IRealm) | 64 | implements(IRealm) |
1735 | 65 | 65 | ||
1737 | 66 | def __init__(self, authentication_proxy, branchfs_proxy): | 66 | def __init__(self, authentication_proxy, codehosting_proxy): |
1738 | 67 | self.authentication_proxy = authentication_proxy | 67 | self.authentication_proxy = authentication_proxy |
1740 | 68 | self.branchfs_proxy = branchfs_proxy | 68 | self.codehosting_proxy = codehosting_proxy |
1741 | 69 | 69 | ||
1742 | 70 | def requestAvatar(self, avatar_id, mind, *interfaces): | 70 | def requestAvatar(self, avatar_id, mind, *interfaces): |
1743 | 71 | # Fetch the user's details from the authserver | 71 | # Fetch the user's details from the authserver |
1744 | @@ -74,15 +74,15 @@ | |||
1745 | 74 | 74 | ||
1746 | 75 | # Once all those details are retrieved, we can construct the avatar. | 75 | # Once all those details are retrieved, we can construct the avatar. |
1747 | 76 | def got_user_dict(user_dict): | 76 | def got_user_dict(user_dict): |
1749 | 77 | avatar = CodehostingAvatar(user_dict, self.branchfs_proxy) | 77 | avatar = CodehostingAvatar(user_dict, self.codehosting_proxy) |
1750 | 78 | return interfaces[0], avatar, avatar.logout | 78 | return interfaces[0], avatar, avatar.logout |
1751 | 79 | 79 | ||
1752 | 80 | return deferred.addCallback(got_user_dict) | 80 | return deferred.addCallback(got_user_dict) |
1753 | 81 | 81 | ||
1754 | 82 | 82 | ||
1756 | 83 | def get_portal(authentication_proxy, branchfs_proxy): | 83 | def get_portal(authentication_proxy, codehosting_proxy): |
1757 | 84 | """Get a portal for connecting to Launchpad codehosting.""" | 84 | """Get a portal for connecting to Launchpad codehosting.""" |
1759 | 85 | portal = Portal(Realm(authentication_proxy, branchfs_proxy)) | 85 | portal = Portal(Realm(authentication_proxy, codehosting_proxy)) |
1760 | 86 | portal.registerChecker( | 86 | portal.registerChecker( |
1761 | 87 | PublicKeyFromLaunchpadChecker(authentication_proxy)) | 87 | PublicKeyFromLaunchpadChecker(authentication_proxy)) |
1762 | 88 | return portal | 88 | return portal |
1763 | @@ -101,5 +101,5 @@ | |||
1764 | 101 | """ | 101 | """ |
1765 | 102 | authentication_proxy = Proxy( | 102 | authentication_proxy = Proxy( |
1766 | 103 | config.codehosting.authentication_endpoint) | 103 | config.codehosting.authentication_endpoint) |
1769 | 104 | branchfs_proxy = Proxy(config.codehosting.branchfs_endpoint) | 104 | codehosting_proxy = Proxy(config.codehosting.codehosting_endpoint) |
1770 | 105 | return get_portal(authentication_proxy, branchfs_proxy) | 105 | return get_portal(authentication_proxy, codehosting_proxy) |
1771 | 106 | 106 | ||
1772 | === modified file 'lib/lp/codehosting/tests/test_acceptance.py' | |||
1773 | --- lib/lp/codehosting/tests/test_acceptance.py 2010-04-27 02:11:16 +0000 | |||
1774 | +++ lib/lp/codehosting/tests/test_acceptance.py 2010-04-27 02:11:35 +0000 | |||
1775 | @@ -230,14 +230,15 @@ | |||
1776 | 230 | """ | 230 | """ |
1777 | 231 | authserver = xmlrpclib.ServerProxy( | 231 | authserver = xmlrpclib.ServerProxy( |
1778 | 232 | config.codehosting.authentication_endpoint) | 232 | config.codehosting.authentication_endpoint) |
1780 | 233 | branchfs = xmlrpclib.ServerProxy(config.codehosting.branchfs_endpoint) | 233 | codehosting_api = xmlrpclib.ServerProxy( |
1781 | 234 | config.codehosting.codehosting_endpoint) | ||
1782 | 234 | if creator is None: | 235 | if creator is None: |
1783 | 235 | creator_id = authserver.getUserAndSSHKeys(user)['id'] | 236 | creator_id = authserver.getUserAndSSHKeys(user)['id'] |
1784 | 236 | else: | 237 | else: |
1785 | 237 | creator_id = authserver.getUserAndSSHKeys(creator)['id'] | 238 | creator_id = authserver.getUserAndSSHKeys(creator)['id'] |
1786 | 238 | if branch_root is None: | 239 | if branch_root is None: |
1787 | 239 | branch_root = self.server._mirror_root | 240 | branch_root = self.server._mirror_root |
1789 | 240 | branch_id = branchfs.createBranch( | 241 | branch_id = codehosting_api.createBranch( |
1790 | 241 | creator_id, '/~%s/%s/%s' % (user, product, branch)) | 242 | creator_id, '/~%s/%s/%s' % (user, product, branch)) |
1791 | 242 | branch_url = 'file://' + os.path.abspath( | 243 | branch_url = 'file://' + os.path.abspath( |
1792 | 243 | os.path.join(branch_root, branch_id_to_path(branch_id))) | 244 | os.path.join(branch_root, branch_id_to_path(branch_id))) |
1793 | 244 | 245 | ||
1794 | === modified file 'lib/lp/codehosting/tests/test_sftp.py' | |||
1795 | --- lib/lp/codehosting/tests/test_sftp.py 2010-04-15 14:29:42 +0000 | |||
1796 | +++ lib/lp/codehosting/tests/test_sftp.py 2010-04-27 02:11:35 +0000 | |||
1797 | @@ -107,13 +107,13 @@ | |||
1798 | 107 | TrialTestCase.setUp(self) | 107 | TrialTestCase.setUp(self) |
1799 | 108 | frontend = InMemoryFrontend() | 108 | frontend = InMemoryFrontend() |
1800 | 109 | self.factory = frontend.getLaunchpadObjectFactory() | 109 | self.factory = frontend.getLaunchpadObjectFactory() |
1803 | 110 | self.branchfs_endpoint = XMLRPCWrapper( | 110 | self.codehosting_endpoint = XMLRPCWrapper( |
1804 | 111 | frontend.getFilesystemEndpoint()) | 111 | frontend.getCodehostingEndpoint()) |
1805 | 112 | 112 | ||
1806 | 113 | def makeCodehostingAvatar(self): | 113 | def makeCodehostingAvatar(self): |
1807 | 114 | user = self.factory.makePerson() | 114 | user = self.factory.makePerson() |
1808 | 115 | user_dict = dict(id=user.id, name=user.name) | 115 | user_dict = dict(id=user.id, name=user.name) |
1810 | 116 | return CodehostingAvatar(user_dict, self.branchfs_endpoint) | 116 | return CodehostingAvatar(user_dict, self.codehosting_endpoint) |
1811 | 117 | 117 | ||
1812 | 118 | def test_canAdaptToSFTPServer(self): | 118 | def test_canAdaptToSFTPServer(self): |
1813 | 119 | avatar = self.makeCodehostingAvatar() | 119 | avatar = self.makeCodehostingAvatar() |
1814 | 120 | 120 | ||
1815 | === modified file 'lib/lp/codehosting/vfs/branchfs.py' | |||
1816 | --- lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:11:16 +0000 | |||
1817 | +++ lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:11:35 +0000 | |||
1818 | @@ -68,8 +68,8 @@ | |||
1819 | 68 | from bzrlib.bzrdir import BzrDir, BzrDirFormat | 68 | from bzrlib.bzrdir import BzrDir, BzrDirFormat |
1820 | 69 | from bzrlib.config import TransportConfig | 69 | from bzrlib.config import TransportConfig |
1821 | 70 | from bzrlib.errors import ( | 70 | from bzrlib.errors import ( |
1824 | 71 | NoSuchFile, NotBranchError, NotStacked, PermissionDenied, | 71 | NoSuchFile, NotStacked, PermissionDenied, TransportNotPossible, |
1825 | 72 | TransportNotPossible, UnstackableBranchFormat) | 72 | UnstackableBranchFormat) |
1826 | 73 | from bzrlib.plugins.loom.branch import LoomSupport | 73 | from bzrlib.plugins.loom.branch import LoomSupport |
1827 | 74 | from bzrlib.smart.request import jail_info | 74 | from bzrlib.smart.request import jail_info |
1828 | 75 | from bzrlib.transport import get_transport | 75 | from bzrlib.transport import get_transport |
1829 | @@ -169,12 +169,12 @@ | |||
1830 | 169 | 169 | ||
1831 | 170 | def get_scanner_server(): | 170 | def get_scanner_server(): |
1832 | 171 | """Get a Launchpad internal server for scanning branches.""" | 171 | """Get a Launchpad internal server for scanning branches.""" |
1835 | 172 | proxy = xmlrpclib.ServerProxy(config.codehosting.branchfs_endpoint) | 172 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) |
1836 | 173 | branchfs_endpoint = BlockingProxy(proxy) | 173 | codehosting_endpoint = BlockingProxy(proxy) |
1837 | 174 | branch_transport = get_readonly_transport( | 174 | branch_transport = get_readonly_transport( |
1838 | 175 | get_transport(config.codehosting.internal_branch_by_id_root)) | 175 | get_transport(config.codehosting.internal_branch_by_id_root)) |
1839 | 176 | return LaunchpadInternalServer( | 176 | return LaunchpadInternalServer( |
1841 | 177 | 'lp-mirrored:///', branchfs_endpoint, branch_transport) | 177 | 'lp-mirrored:///', codehosting_endpoint, branch_transport) |
1842 | 178 | 178 | ||
1843 | 179 | 179 | ||
1844 | 180 | def get_rw_server(): | 180 | def get_rw_server(): |
1845 | @@ -185,10 +185,10 @@ | |||
1846 | 185 | """ | 185 | """ |
1847 | 186 | hosted_transport = get_chrooted_transport( | 186 | hosted_transport = get_chrooted_transport( |
1848 | 187 | config.codehosting.mirrored_branches_root, mkdir=True) | 187 | config.codehosting.mirrored_branches_root, mkdir=True) |
1851 | 188 | proxy = xmlrpclib.ServerProxy(config.codehosting.branchfs_endpoint) | 188 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) |
1852 | 189 | branchfs_endpoint = BlockingProxy(proxy) | 189 | codehosting_endpoint = BlockingProxy(proxy) |
1853 | 190 | return LaunchpadInternalServer( | 190 | return LaunchpadInternalServer( |
1855 | 191 | 'lp-internal:///', branchfs_endpoint, hosted_transport) | 191 | 'lp-internal:///', codehosting_endpoint, hosted_transport) |
1856 | 192 | 192 | ||
1857 | 193 | 193 | ||
1858 | 194 | def get_multi_server(write_hosted=False, write_mirrored=False, | 194 | def get_multi_server(write_hosted=False, write_mirrored=False, |
1859 | @@ -223,11 +223,11 @@ | |||
1860 | 223 | if direct_database: | 223 | if direct_database: |
1861 | 224 | make_server = DirectDatabaseLaunchpadServer | 224 | make_server = DirectDatabaseLaunchpadServer |
1862 | 225 | else: | 225 | else: |
1865 | 226 | proxy = xmlrpclib.ServerProxy(config.codehosting.branchfs_endpoint) | 226 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) |
1866 | 227 | branchfs_endpoint = BlockingProxy(proxy) | 227 | codehosting_endpoint = BlockingProxy(proxy) |
1867 | 228 | def make_server(scheme, transport): | 228 | def make_server(scheme, transport): |
1868 | 229 | return LaunchpadInternalServer( | 229 | return LaunchpadInternalServer( |
1870 | 230 | scheme, branchfs_endpoint, transport) | 230 | scheme, codehosting_endpoint, transport) |
1871 | 231 | hosted_server = make_server('lp-hosted:///', hosted_transport) | 231 | hosted_server = make_server('lp-hosted:///', hosted_transport) |
1872 | 232 | mirrored_server = make_server('lp-mirrored:///', mirrored_transport) | 232 | mirrored_server = make_server('lp-mirrored:///', mirrored_transport) |
1873 | 233 | return _MultiServer(hosted_server, mirrored_server) | 233 | return _MultiServer(hosted_server, mirrored_server) |
1874 | @@ -367,39 +367,41 @@ | |||
1875 | 367 | 367 | ||
1876 | 368 | For more information, see the module docstring. | 368 | For more information, see the module docstring. |
1877 | 369 | 369 | ||
1879 | 370 | :ivar _authserver: An object that has a method 'translatePath' that | 370 | :ivar _branchfs_client: An object that has a method 'translatePath' that |
1880 | 371 | returns a Deferred that fires information about how a path can be | 371 | returns a Deferred that fires information about how a path can be |
1881 | 372 | translated into a transport. See `IBranchFilesystem['translatePath']`. | 372 | translated into a transport. See `IBranchFilesystem['translatePath']`. |
1882 | 373 | 373 | ||
1883 | 374 | :ivar _transport_dispatch: An `ITransportDispatch` provider used to | 374 | :ivar _transport_dispatch: An `ITransportDispatch` provider used to |
1885 | 375 | convert the data from the authserver into an actual transport and | 375 | convert the data from the branchfs client into an actual transport and |
1886 | 376 | path on that transport. | 376 | path on that transport. |
1887 | 377 | """ | 377 | """ |
1888 | 378 | 378 | ||
1890 | 379 | def __init__(self, scheme, authserver, user_id, | 379 | def __init__(self, scheme, codehosting_api, user_id, |
1891 | 380 | seen_new_branch_hook=None): | 380 | seen_new_branch_hook=None): |
1892 | 381 | """Construct a LaunchpadServer. | 381 | """Construct a LaunchpadServer. |
1893 | 382 | 382 | ||
1894 | 383 | :param scheme: The URL scheme to use. | 383 | :param scheme: The URL scheme to use. |
1896 | 384 | :param authserver: An XML-RPC client that implements callRemote. | 384 | :param codehosting_api: An XML-RPC client that implements callRemote. |
1897 | 385 | :param user_id: The database ID for the user who is accessing | 385 | :param user_id: The database ID for the user who is accessing |
1898 | 386 | branches. | 386 | branches. |
1899 | 387 | :param seen_new_branch_hook: A callable that will be called once for | 387 | :param seen_new_branch_hook: A callable that will be called once for |
1900 | 388 | each branch accessed via this server. | 388 | each branch accessed via this server. |
1901 | 389 | """ | 389 | """ |
1902 | 390 | AsyncVirtualServer.__init__(self, scheme) | 390 | AsyncVirtualServer.__init__(self, scheme) |
1905 | 391 | self._authserver = BranchFileSystemClient( | 391 | self._branchfs_client = BranchFileSystemClient( |
1906 | 392 | authserver, user_id, seen_new_branch_hook=seen_new_branch_hook) | 392 | codehosting_api, user_id, |
1907 | 393 | seen_new_branch_hook=seen_new_branch_hook) | ||
1908 | 393 | self._is_start_server = False | 394 | self._is_start_server = False |
1909 | 394 | 395 | ||
1910 | 395 | def translateVirtualPath(self, virtual_url_fragment): | 396 | def translateVirtualPath(self, virtual_url_fragment): |
1911 | 396 | """See `AsyncVirtualServer.translateVirtualPath`. | 397 | """See `AsyncVirtualServer.translateVirtualPath`. |
1912 | 397 | 398 | ||
1916 | 398 | Call 'translatePath' on the authserver with the fragment and then use | 399 | Call 'translatePath' on the branchfs client with the fragment and then |
1917 | 399 | 'makeTransport' on the _transport_dispatch to translate that result | 400 | use 'makeTransport' on the _transport_dispatch to translate that |
1918 | 400 | into a transport and trailing path. | 401 | result into a transport and trailing path. |
1919 | 401 | """ | 402 | """ |
1921 | 402 | deferred = self._authserver.translatePath('/' + virtual_url_fragment) | 403 | deferred = self._branchfs_client.translatePath( |
1922 | 404 | '/' + virtual_url_fragment) | ||
1923 | 403 | 405 | ||
1924 | 404 | def path_not_translated(failure): | 406 | def path_not_translated(failure): |
1925 | 405 | trap_fault( | 407 | trap_fault( |
1926 | @@ -426,19 +428,20 @@ | |||
1927 | 426 | Intended for use with the branch puller and scanner. | 428 | Intended for use with the branch puller and scanner. |
1928 | 427 | """ | 429 | """ |
1929 | 428 | 430 | ||
1931 | 429 | def __init__(self, scheme, authserver, branch_transport): | 431 | def __init__(self, scheme, codehosting_api, branch_transport): |
1932 | 430 | """Construct a `LaunchpadInternalServer`. | 432 | """Construct a `LaunchpadInternalServer`. |
1933 | 431 | 433 | ||
1934 | 432 | :param scheme: The URL scheme to use. | 434 | :param scheme: The URL scheme to use. |
1935 | 433 | 435 | ||
1937 | 434 | :param authserver: An object that provides a 'translatePath' method. | 436 | :param codehosting_api: An object that provides a 'translatePath' |
1938 | 437 | method. | ||
1939 | 435 | 438 | ||
1940 | 436 | :param branch_transport: A Bazaar `Transport` that refers to an | 439 | :param branch_transport: A Bazaar `Transport` that refers to an |
1941 | 437 | area where Launchpad branches are stored, generally either the | 440 | area where Launchpad branches are stored, generally either the |
1942 | 438 | hosted or mirrored areas. | 441 | hosted or mirrored areas. |
1943 | 439 | """ | 442 | """ |
1944 | 440 | super(LaunchpadInternalServer, self).__init__( | 443 | super(LaunchpadInternalServer, self).__init__( |
1946 | 441 | scheme, authserver, LAUNCHPAD_SERVICES) | 444 | scheme, codehosting_api, LAUNCHPAD_SERVICES) |
1947 | 442 | self._transport_dispatch = BranchTransportDispatch(branch_transport) | 445 | self._transport_dispatch = BranchTransportDispatch(branch_transport) |
1948 | 443 | 446 | ||
1949 | 444 | def start_server(self): | 447 | def start_server(self): |
1950 | @@ -564,13 +567,13 @@ | |||
1951 | 564 | 567 | ||
1952 | 565 | asyncTransportFactory = AsyncLaunchpadTransport | 568 | asyncTransportFactory = AsyncLaunchpadTransport |
1953 | 566 | 569 | ||
1955 | 567 | def __init__(self, authserver, user_id, branch_transport, | 570 | def __init__(self, codehosting_api, user_id, branch_transport, |
1956 | 568 | seen_new_branch_hook=None): | 571 | seen_new_branch_hook=None): |
1957 | 569 | """Construct a `LaunchpadServer`. | 572 | """Construct a `LaunchpadServer`. |
1958 | 570 | 573 | ||
1959 | 571 | See `_BaseLaunchpadServer` for more information. | 574 | See `_BaseLaunchpadServer` for more information. |
1960 | 572 | 575 | ||
1962 | 573 | :param authserver: An object that has 'createBranch' and | 576 | :param codehosting_api: An object that has 'createBranch' and |
1963 | 574 | 'branchChanged' methods in addition to a 'translatePath' method. | 577 | 'branchChanged' methods in addition to a 'translatePath' method. |
1964 | 575 | These methods should return Deferreds. | 578 | These methods should return Deferreds. |
1965 | 576 | XXX: JonathanLange 2008-11-19: Specify this interface better. | 579 | XXX: JonathanLange 2008-11-19: Specify this interface better. |
1966 | @@ -583,7 +586,7 @@ | |||
1967 | 583 | """ | 586 | """ |
1968 | 584 | scheme = 'lp-%d:///' % id(self) | 587 | scheme = 'lp-%d:///' % id(self) |
1969 | 585 | super(LaunchpadServer, self).__init__( | 588 | super(LaunchpadServer, self).__init__( |
1971 | 586 | scheme, authserver, user_id, seen_new_branch_hook) | 589 | scheme, codehosting_api, user_id, seen_new_branch_hook) |
1972 | 587 | self._transport_dispatch = TransportDispatch(branch_transport) | 590 | self._transport_dispatch = TransportDispatch(branch_transport) |
1973 | 588 | 591 | ||
1974 | 589 | def createBranch(self, virtual_url_fragment): | 592 | def createBranch(self, virtual_url_fragment): |
1975 | @@ -604,7 +607,7 @@ | |||
1976 | 604 | that its creation is forbidden by a policy. | 607 | that its creation is forbidden by a policy. |
1977 | 605 | :raise Fault: If the XML-RPC server raises errors. | 608 | :raise Fault: If the XML-RPC server raises errors. |
1978 | 606 | """ | 609 | """ |
1980 | 607 | deferred = self._authserver.createBranch(virtual_url_fragment) | 610 | deferred = self._branchfs_client.createBranch(virtual_url_fragment) |
1981 | 608 | 611 | ||
1982 | 609 | def translate_fault(failure): | 612 | def translate_fault(failure): |
1983 | 610 | # We turn faults.NotFound into a PermissionDenied, even | 613 | # We turn faults.NotFound into a PermissionDenied, even |
1984 | @@ -667,7 +670,8 @@ | |||
1985 | 667 | :param virtual_url_fragment: A url fragment that points to a path | 670 | :param virtual_url_fragment: A url fragment that points to a path |
1986 | 668 | owned by a branch. | 671 | owned by a branch. |
1987 | 669 | """ | 672 | """ |
1989 | 670 | deferred = self._authserver.translatePath('/' + virtual_url_fragment) | 673 | deferred = self._branchfs_client.translatePath( |
1990 | 674 | '/' + virtual_url_fragment) | ||
1991 | 671 | 675 | ||
1992 | 672 | def got_path_info((transport_type, data, trailing_path)): | 676 | def got_path_info((transport_type, data, trailing_path)): |
1993 | 673 | if transport_type != BRANCH_TRANSPORT: | 677 | if transport_type != BRANCH_TRANSPORT: |
1994 | @@ -693,7 +697,7 @@ | |||
1995 | 693 | jail_info.transports.remove(transport) | 697 | jail_info.transports.remove(transport) |
1996 | 694 | if stacked_on_url is None: | 698 | if stacked_on_url is None: |
1997 | 695 | stacked_on_url = '' | 699 | stacked_on_url = '' |
1999 | 696 | return self._authserver.branchChanged( | 700 | return self._branchfs_client.branchChanged( |
2000 | 697 | data['id'], stacked_on_url, last_revision, | 701 | data['id'], stacked_on_url, last_revision, |
2001 | 698 | control_string, branch_string, repository_string) | 702 | control_string, branch_string, repository_string) |
2002 | 699 | 703 | ||
2003 | @@ -703,29 +707,29 @@ | |||
2004 | 703 | return deferred.addCallback(got_path_info).addErrback(log.err) | 707 | return deferred.addCallback(got_path_info).addErrback(log.err) |
2005 | 704 | 708 | ||
2006 | 705 | 709 | ||
2008 | 706 | def get_lp_server(user_id, branchfs_endpoint_url=None, branch_directory=None, | 710 | def get_lp_server(user_id, codehosting_endpoint_url=None, branch_directory=None, |
2009 | 707 | seen_new_branch_hook=None): | 711 | seen_new_branch_hook=None): |
2010 | 708 | """Create a Launchpad server. | 712 | """Create a Launchpad server. |
2011 | 709 | 713 | ||
2012 | 710 | :param user_id: A unique database ID of the user whose branches are | 714 | :param user_id: A unique database ID of the user whose branches are |
2013 | 711 | being served. | 715 | being served. |
2015 | 712 | :param branchfs_endpoint_url: URL for the branch file system end-point. | 716 | :param codehosting_endpoint_url: URL for the branch file system end-point. |
2016 | 713 | :param hosted_directory: Where the branches are uploaded to. | 717 | :param hosted_directory: Where the branches are uploaded to. |
2017 | 714 | :param mirror_directory: Where all Launchpad branches are mirrored. | 718 | :param mirror_directory: Where all Launchpad branches are mirrored. |
2018 | 715 | :param seen_new_branch_hook: | 719 | :param seen_new_branch_hook: |
2019 | 716 | :return: A `LaunchpadServer`. | 720 | :return: A `LaunchpadServer`. |
2020 | 717 | """ | 721 | """ |
2021 | 718 | # Get the defaults from the config. | 722 | # Get the defaults from the config. |
2024 | 719 | if branchfs_endpoint_url is None: | 723 | if codehosting_endpoint_url is None: |
2025 | 720 | branchfs_endpoint_url = config.codehosting.branchfs_endpoint | 724 | codehosting_endpoint_url = config.codehosting.codehosting_endpoint |
2026 | 721 | if branch_directory is None: | 725 | if branch_directory is None: |
2027 | 722 | branch_directory = config.codehosting.mirrored_branches_root | 726 | branch_directory = config.codehosting.mirrored_branches_root |
2028 | 723 | 727 | ||
2029 | 724 | branch_url = urlutils.local_path_to_url(branch_directory) | 728 | branch_url = urlutils.local_path_to_url(branch_directory) |
2031 | 725 | branchfs_client = xmlrpclib.ServerProxy(branchfs_endpoint_url) | 729 | codehosting_client = xmlrpclib.ServerProxy(codehosting_endpoint_url) |
2032 | 726 | branch_transport = get_chrooted_transport(branch_url) | 730 | branch_transport = get_chrooted_transport(branch_url) |
2033 | 727 | lp_server = LaunchpadServer( | 731 | lp_server = LaunchpadServer( |
2035 | 728 | BlockingProxy(branchfs_client), user_id, branch_transport, | 732 | BlockingProxy(codehosting_client), user_id, branch_transport, |
2036 | 729 | seen_new_branch_hook) | 733 | seen_new_branch_hook) |
2037 | 730 | return lp_server | 734 | return lp_server |
2038 | 731 | 735 | ||
2039 | 732 | 736 | ||
2040 | === modified file 'lib/lp/codehosting/vfs/branchfsclient.py' | |||
2041 | --- lib/lp/codehosting/vfs/branchfsclient.py 2010-04-27 02:11:16 +0000 | |||
2042 | +++ lib/lp/codehosting/vfs/branchfsclient.py 2010-04-27 02:11:35 +0000 | |||
2043 | @@ -34,20 +34,23 @@ | |||
2044 | 34 | 34 | ||
2045 | 35 | 35 | ||
2046 | 36 | class BranchFileSystemClient: | 36 | class BranchFileSystemClient: |
2050 | 37 | """Wrapper for the branch filesystem endpoint for a particular user. | 37 | """Wrapper for some methods of the codehosting endpoint. |
2051 | 38 | 38 | ||
2052 | 39 | This wrapper caches the results of calls to translatePath in order to | 39 | Instances of this class wrap the methods of the codehosting endpoint |
2053 | 40 | required by the VFS code, specialized for a particular user. | ||
2054 | 41 | |||
2055 | 42 | The wrapper also caches the results of calls to translatePath in order to | ||
2056 | 40 | avoid a large number of roundtrips. In the normal course of operation, our | 43 | avoid a large number of roundtrips. In the normal course of operation, our |
2057 | 41 | Bazaar transport translates virtual paths to real paths on disk using this | 44 | Bazaar transport translates virtual paths to real paths on disk using this |
2058 | 42 | client. It does this many, many times for a single Bazaar operation, so we | 45 | client. It does this many, many times for a single Bazaar operation, so we |
2059 | 43 | cache the results here. | 46 | cache the results here. |
2060 | 44 | """ | 47 | """ |
2061 | 45 | 48 | ||
2063 | 46 | def __init__(self, branchfs_endpoint, user_id, expiry_time=None, | 49 | def __init__(self, codehosting_endpoint, user_id, expiry_time=None, |
2064 | 47 | seen_new_branch_hook=None, _now=time.time): | 50 | seen_new_branch_hook=None, _now=time.time): |
2066 | 48 | """Construct a caching branchfs_endpoint. | 51 | """Construct a caching codehosting_endpoint. |
2067 | 49 | 52 | ||
2069 | 50 | :param branchfs_endpoint: An XML-RPC proxy that implements callRemote. | 53 | :param codehosting_endpoint: An XML-RPC proxy that implements callRemote. |
2070 | 51 | :param user_id: The database ID of the user who will be making these | 54 | :param user_id: The database ID of the user who will be making these |
2071 | 52 | requests. An integer. | 55 | requests. An integer. |
2072 | 53 | :param expiry_time: If supplied, only cache the results of | 56 | :param expiry_time: If supplied, only cache the results of |
2073 | @@ -56,7 +59,7 @@ | |||
2074 | 56 | :param seen_new_branch_hook: A callable that will be called with the | 59 | :param seen_new_branch_hook: A callable that will be called with the |
2075 | 57 | unique_name of each new branch that is accessed. | 60 | unique_name of each new branch that is accessed. |
2076 | 58 | """ | 61 | """ |
2078 | 59 | self._branchfs_endpoint = branchfs_endpoint | 62 | self._codehosting_endpoint = codehosting_endpoint |
2079 | 60 | self._cache = {} | 63 | self._cache = {} |
2080 | 61 | self._user_id = user_id | 64 | self._user_id = user_id |
2081 | 62 | self.expiry_time = expiry_time | 65 | self.expiry_time = expiry_time |
2082 | @@ -104,16 +107,16 @@ | |||
2083 | 104 | def createBranch(self, branch_path): | 107 | def createBranch(self, branch_path): |
2084 | 105 | """Create a Launchpad `IBranch` in the database. | 108 | """Create a Launchpad `IBranch` in the database. |
2085 | 106 | 109 | ||
2089 | 107 | This raises any Faults that might be raised by the branchfs_endpoint's | 110 | This raises any Faults that might be raised by the |
2090 | 108 | `createBranch` method, so for more information see | 111 | codehosting_endpoint's `createBranch` method, so for more information |
2091 | 109 | `IBranchFileSystem.createBranch`. | 112 | see `IBranchFileSystem.createBranch`. |
2092 | 110 | 113 | ||
2093 | 111 | :param branch_path: The path to the branch to create. | 114 | :param branch_path: The path to the branch to create. |
2094 | 112 | :return: A `Deferred` that fires the ID of the created branch. | 115 | :return: A `Deferred` that fires the ID of the created branch. |
2095 | 113 | """ | 116 | """ |
2096 | 114 | return defer.maybeDeferred( | 117 | return defer.maybeDeferred( |
2099 | 115 | self._branchfs_endpoint.callRemote, 'createBranch', self._user_id, | 118 | self._codehosting_endpoint.callRemote, 'createBranch', |
2100 | 116 | branch_path) | 119 | self._user_id, branch_path) |
2101 | 117 | 120 | ||
2102 | 118 | def branchChanged(self, branch_id, stacked_on_url, last_revision_id, | 121 | def branchChanged(self, branch_id, stacked_on_url, last_revision_id, |
2103 | 119 | control_string, branch_string, repository_string): | 122 | control_string, branch_string, repository_string): |
2104 | @@ -122,7 +125,7 @@ | |||
2105 | 122 | :param branch_id: The database ID of the branch. | 125 | :param branch_id: The database ID of the branch. |
2106 | 123 | """ | 126 | """ |
2107 | 124 | return defer.maybeDeferred( | 127 | return defer.maybeDeferred( |
2109 | 125 | self._branchfs_endpoint.callRemote, | 128 | self._codehosting_endpoint.callRemote, |
2110 | 126 | 'branchChanged', branch_id, stacked_on_url, last_revision_id, | 129 | 'branchChanged', branch_id, stacked_on_url, last_revision_id, |
2111 | 127 | control_string, branch_string, repository_string) | 130 | control_string, branch_string, repository_string) |
2112 | 128 | 131 | ||
2113 | @@ -132,7 +135,7 @@ | |||
2114 | 132 | return defer.succeed(self._getFromCache(path)) | 135 | return defer.succeed(self._getFromCache(path)) |
2115 | 133 | except NotInCache: | 136 | except NotInCache: |
2116 | 134 | deferred = defer.maybeDeferred( | 137 | deferred = defer.maybeDeferred( |
2118 | 135 | self._branchfs_endpoint.callRemote, | 138 | self._codehosting_endpoint.callRemote, |
2119 | 136 | 'translatePath', self._user_id, path) | 139 | 'translatePath', self._user_id, path) |
2120 | 137 | deferred.addCallback(self._addToCache, path) | 140 | deferred.addCallback(self._addToCache, path) |
2121 | 138 | return deferred | 141 | return deferred |
2122 | 139 | 142 | ||
2123 | === modified file 'lib/lp/codehosting/vfs/tests/test_branchfs.py' | |||
2124 | --- lib/lp/codehosting/vfs/tests/test_branchfs.py 2010-04-27 02:11:16 +0000 | |||
2125 | +++ lib/lp/codehosting/vfs/tests/test_branchfs.py 2010-04-27 02:11:35 +0000 | |||
2126 | @@ -176,13 +176,13 @@ | |||
2127 | 176 | 176 | ||
2128 | 177 | def setUp(self): | 177 | def setUp(self): |
2129 | 178 | frontend = InMemoryFrontend() | 178 | frontend = InMemoryFrontend() |
2131 | 179 | self.authserver = frontend.getFilesystemEndpoint() | 179 | self.codehosting_api = frontend.getCodehostingEndpoint() |
2132 | 180 | self.factory = frontend.getLaunchpadObjectFactory() | 180 | self.factory = frontend.getLaunchpadObjectFactory() |
2133 | 181 | self.requester = self.factory.makePerson() | 181 | self.requester = self.factory.makePerson() |
2134 | 182 | self.server = self.getLaunchpadServer( | 182 | self.server = self.getLaunchpadServer( |
2136 | 183 | self.authserver, self.requester.id) | 183 | self.codehosting_api, self.requester.id) |
2137 | 184 | 184 | ||
2139 | 185 | def getLaunchpadServer(self, authserver, user_id): | 185 | def getLaunchpadServer(self, codehosting_api, user_id): |
2140 | 186 | raise NotImplementedError( | 186 | raise NotImplementedError( |
2141 | 187 | "Override this with a Launchpad server factory.") | 187 | "Override this with a Launchpad server factory.") |
2142 | 188 | 188 | ||
2143 | @@ -213,9 +213,9 @@ | |||
2144 | 213 | BzrTestCase.setUp(self) | 213 | BzrTestCase.setUp(self) |
2145 | 214 | MixinBaseLaunchpadServerTests.setUp(self) | 214 | MixinBaseLaunchpadServerTests.setUp(self) |
2146 | 215 | 215 | ||
2148 | 216 | def getLaunchpadServer(self, authserver, user_id): | 216 | def getLaunchpadServer(self, codehosting_api, user_id): |
2149 | 217 | return LaunchpadServer( | 217 | return LaunchpadServer( |
2151 | 218 | XMLRPCWrapper(authserver), user_id, MemoryTransport()) | 218 | XMLRPCWrapper(codehosting_api), user_id, MemoryTransport()) |
2152 | 219 | 219 | ||
2153 | 220 | def test_translateControlPath(self): | 220 | def test_translateControlPath(self): |
2154 | 221 | branch = self.factory.makeProductBranch(owner=self.requester) | 221 | branch = self.factory.makeProductBranch(owner=self.requester) |
2155 | @@ -342,9 +342,9 @@ | |||
2156 | 342 | self.disable_directory_isolation() | 342 | self.disable_directory_isolation() |
2157 | 343 | MixinBaseLaunchpadServerTests.setUp(self) | 343 | MixinBaseLaunchpadServerTests.setUp(self) |
2158 | 344 | 344 | ||
2160 | 345 | def getLaunchpadServer(self, authserver, user_id): | 345 | def getLaunchpadServer(self, codehosting_api, user_id): |
2161 | 346 | return LaunchpadInternalServer( | 346 | return LaunchpadInternalServer( |
2163 | 347 | 'lp-test:///', XMLRPCWrapper(authserver), MemoryTransport()) | 347 | 'lp-test:///', XMLRPCWrapper(codehosting_api), MemoryTransport()) |
2164 | 348 | 348 | ||
2165 | 349 | 349 | ||
2166 | 350 | class TestDirectDatabaseLaunchpadServer(TestCaseWithFactory, TrialTestCase, | 350 | class TestDirectDatabaseLaunchpadServer(TestCaseWithFactory, TrialTestCase, |
2167 | @@ -472,11 +472,11 @@ | |||
2168 | 472 | def setUp(self): | 472 | def setUp(self): |
2169 | 473 | frontend = InMemoryFrontend() | 473 | frontend = InMemoryFrontend() |
2170 | 474 | self.factory = frontend.getLaunchpadObjectFactory() | 474 | self.factory = frontend.getLaunchpadObjectFactory() |
2172 | 475 | authserver = frontend.getFilesystemEndpoint() | 475 | codehosting_api = frontend.getCodehostingEndpoint() |
2173 | 476 | self.requester = self.factory.makePerson() | 476 | self.requester = self.factory.makePerson() |
2174 | 477 | self.backing_transport = MemoryTransport() | 477 | self.backing_transport = MemoryTransport() |
2175 | 478 | self.server = self.getServer( | 478 | self.server = self.getServer( |
2177 | 479 | authserver, self.requester.id, self.backing_transport) | 479 | codehosting_api, self.requester.id, self.backing_transport) |
2178 | 480 | self.server.start_server() | 480 | self.server.start_server() |
2179 | 481 | self.addCleanup(self.server.stop_server) | 481 | self.addCleanup(self.server.stop_server) |
2180 | 482 | 482 | ||
2181 | @@ -507,9 +507,9 @@ | |||
2182 | 507 | """Call `function` and return an appropriate Deferred.""" | 507 | """Call `function` and return an appropriate Deferred.""" |
2183 | 508 | raise NotImplementedError | 508 | raise NotImplementedError |
2184 | 509 | 509 | ||
2186 | 510 | def getServer(self, authserver, user_id, backing_transport): | 510 | def getServer(self, codehosting_api, user_id, backing_transport): |
2187 | 511 | return LaunchpadServer( | 511 | return LaunchpadServer( |
2189 | 512 | XMLRPCWrapper(authserver), user_id, backing_transport) | 512 | XMLRPCWrapper(codehosting_api), user_id, backing_transport) |
2190 | 513 | 513 | ||
2191 | 514 | def getTransport(self): | 514 | def getTransport(self): |
2192 | 515 | """Return the transport to be tested.""" | 515 | """Return the transport to be tested.""" |
2193 | @@ -820,8 +820,8 @@ | |||
2194 | 820 | self._branch_changed_log = [] | 820 | self._branch_changed_log = [] |
2195 | 821 | frontend = InMemoryFrontend() | 821 | frontend = InMemoryFrontend() |
2196 | 822 | self.factory = frontend.getLaunchpadObjectFactory() | 822 | self.factory = frontend.getLaunchpadObjectFactory() |
2199 | 823 | self.authserver = frontend.getFilesystemEndpoint() | 823 | self.codehosting_api = frontend.getCodehostingEndpoint() |
2200 | 824 | self.authserver.branchChanged = self._replacement_branchChanged | 824 | self.codehosting_api.branchChanged = self._replacement_branchChanged |
2201 | 825 | self.requester = self.factory.makePerson() | 825 | self.requester = self.factory.makePerson() |
2202 | 826 | self.backing_transport = MemoryTransport() | 826 | self.backing_transport = MemoryTransport() |
2203 | 827 | self.disable_directory_isolation() | 827 | self.disable_directory_isolation() |
2204 | @@ -835,7 +835,7 @@ | |||
2205 | 835 | def get_server(self): | 835 | def get_server(self): |
2206 | 836 | if self._server is None: | 836 | if self._server is None: |
2207 | 837 | self._server = LaunchpadServer( | 837 | self._server = LaunchpadServer( |
2209 | 838 | XMLRPCWrapper(self.authserver), self.requester.id, | 838 | XMLRPCWrapper(self.codehosting_api), self.requester.id, |
2210 | 839 | self.backing_transport) | 839 | self.backing_transport) |
2211 | 840 | self._server.start_server() | 840 | self._server.start_server() |
2212 | 841 | self.addCleanup(self._server.stop_server) | 841 | self.addCleanup(self._server.stop_server) |
2213 | @@ -987,7 +987,7 @@ | |||
2214 | 987 | self._frontend = InMemoryFrontend() | 987 | self._frontend = InMemoryFrontend() |
2215 | 988 | self.factory = self._frontend.getLaunchpadObjectFactory() | 988 | self.factory = self._frontend.getLaunchpadObjectFactory() |
2216 | 989 | 989 | ||
2218 | 990 | authserver = self._frontend.getFilesystemEndpoint() | 990 | codehosting_api = self._frontend.getCodehostingEndpoint() |
2219 | 991 | self.requester = self.factory.makePerson() | 991 | self.requester = self.factory.makePerson() |
2220 | 992 | 992 | ||
2221 | 993 | self.writable_branch = self.factory.makeAnyBranch( | 993 | self.writable_branch = self.factory.makeAnyBranch( |
2222 | @@ -997,7 +997,7 @@ | |||
2223 | 997 | branch_type=BranchType.HOSTED).unique_name | 997 | branch_type=BranchType.HOSTED).unique_name |
2224 | 998 | 998 | ||
2225 | 999 | self.lp_server = self._setUpLaunchpadServer( | 999 | self.lp_server = self._setUpLaunchpadServer( |
2227 | 1000 | self.requester.id, authserver, backing_transport) | 1000 | self.requester.id, codehosting_api, backing_transport) |
2228 | 1001 | self.lp_transport = get_transport(self.lp_server.get_url()) | 1001 | self.lp_transport = get_transport(self.lp_server.get_url()) |
2229 | 1002 | self.lp_transport.mkdir(os.path.dirname(self.writable_file)) | 1002 | self.lp_transport.mkdir(os.path.dirname(self.writable_file)) |
2230 | 1003 | self.lp_transport.put_bytes(self.writable_file, 'Hello World!') | 1003 | self.lp_transport.put_bytes(self.writable_file, 'Hello World!') |
2231 | @@ -1008,9 +1008,9 @@ | |||
2232 | 1008 | self.addCleanup(memory_server.stop_server) | 1008 | self.addCleanup(memory_server.stop_server) |
2233 | 1009 | return memory_server | 1009 | return memory_server |
2234 | 1010 | 1010 | ||
2236 | 1011 | def _setUpLaunchpadServer(self, user_id, authserver, backing_transport): | 1011 | def _setUpLaunchpadServer(self, user_id, codehosting_api, backing_transport): |
2237 | 1012 | server = LaunchpadServer( | 1012 | server = LaunchpadServer( |
2239 | 1013 | XMLRPCWrapper(authserver), user_id, backing_transport) | 1013 | XMLRPCWrapper(codehosting_api), user_id, backing_transport) |
2240 | 1014 | server.start_server() | 1014 | server.start_server() |
2241 | 1015 | self.addCleanup(server.stop_server) | 1015 | self.addCleanup(server.stop_server) |
2242 | 1016 | return server | 1016 | return server |
2243 | 1017 | 1017 | ||
2244 | === modified file 'lib/lp/codehosting/vfs/tests/test_branchfsclient.py' | |||
2245 | --- lib/lp/codehosting/vfs/tests/test_branchfsclient.py 2010-04-09 12:39:23 +0000 | |||
2246 | +++ lib/lp/codehosting/vfs/tests/test_branchfsclient.py 2010-04-27 02:11:35 +0000 | |||
2247 | @@ -25,7 +25,7 @@ | |||
2248 | 25 | frontend = InMemoryFrontend() | 25 | frontend = InMemoryFrontend() |
2249 | 26 | self.factory = frontend.getLaunchpadObjectFactory() | 26 | self.factory = frontend.getLaunchpadObjectFactory() |
2250 | 27 | self.user = self.factory.makePerson() | 27 | self.user = self.factory.makePerson() |
2252 | 28 | self._xmlrpc_client = XMLRPCWrapper(frontend.getFilesystemEndpoint()) | 28 | self._xmlrpc_client = XMLRPCWrapper(frontend.getCodehostingEndpoint()) |
2253 | 29 | self.fake_time = FakeTime(12345) | 29 | self.fake_time = FakeTime(12345) |
2254 | 30 | 30 | ||
2255 | 31 | def advanceTime(self, amount): | 31 | def advanceTime(self, amount): |
2256 | 32 | 32 | ||
2257 | === modified file 'lib/lp/codehosting/vfs/tests/test_filesystem.py' | |||
2258 | --- lib/lp/codehosting/vfs/tests/test_filesystem.py 2010-04-27 02:11:16 +0000 | |||
2259 | +++ lib/lp/codehosting/vfs/tests/test_filesystem.py 2010-04-27 02:11:35 +0000 | |||
2260 | @@ -30,7 +30,7 @@ | |||
2261 | 30 | self.disable_directory_isolation() | 30 | self.disable_directory_isolation() |
2262 | 31 | frontend = InMemoryFrontend() | 31 | frontend = InMemoryFrontend() |
2263 | 32 | self.factory = frontend.getLaunchpadObjectFactory() | 32 | self.factory = frontend.getLaunchpadObjectFactory() |
2265 | 33 | endpoint = XMLRPCWrapper(frontend.getFilesystemEndpoint()) | 33 | endpoint = XMLRPCWrapper(frontend.getCodehostingEndpoint()) |
2266 | 34 | self.requester = self.factory.makePerson() | 34 | self.requester = self.factory.makePerson() |
2267 | 35 | self._server = LaunchpadServer( | 35 | self._server = LaunchpadServer( |
2268 | 36 | endpoint, self.requester.id, MemoryTransport()) | 36 | endpoint, self.requester.id, MemoryTransport()) |
2269 | 37 | 37 | ||
2270 | === modified file 'lib/lp/codehosting/vfs/tests/test_transport.py' | |||
2271 | --- lib/lp/codehosting/vfs/tests/test_transport.py 2010-01-20 02:00:32 +0000 | |||
2272 | +++ lib/lp/codehosting/vfs/tests/test_transport.py 2010-04-27 02:11:35 +0000 | |||
2273 | @@ -32,7 +32,7 @@ | |||
2274 | 32 | an in-memory XML-RPC client and backed onto a LocalTransport. | 32 | an in-memory XML-RPC client and backed onto a LocalTransport. |
2275 | 33 | """ | 33 | """ |
2276 | 34 | frontend = InMemoryFrontend() | 34 | frontend = InMemoryFrontend() |
2278 | 35 | branchfs = frontend.getFilesystemEndpoint() | 35 | branchfs = frontend.getCodehostingEndpoint() |
2279 | 36 | branch = frontend.getLaunchpadObjectFactory().makeAnyBranch() | 36 | branch = frontend.getLaunchpadObjectFactory().makeAnyBranch() |
2280 | 37 | self._branch_path = branch.unique_name | 37 | self._branch_path = branch.unique_name |
2281 | 38 | # XXX: JonathanLange bug=276972 2008-10-07: This should back on to a | 38 | # XXX: JonathanLange bug=276972 2008-10-07: This should back on to a |
2282 | 39 | 39 | ||
2283 | === modified file 'scripts/update-stacked-on.py' | |||
2284 | --- scripts/update-stacked-on.py 2010-02-16 15:25:52 +0000 | |||
2285 | +++ scripts/update-stacked-on.py 2010-04-27 02:11:35 +0000 | |||
2286 | @@ -39,7 +39,7 @@ | |||
2287 | 39 | 39 | ||
2288 | 40 | def get_server(read_only): | 40 | def get_server(read_only): |
2289 | 41 | """Get a server that can write to both hosted and mirrored areas.""" | 41 | """Get a server that can write to both hosted and mirrored areas.""" |
2291 | 42 | proxy = xmlrpclib.ServerProxy(config.codehosting.branchfs_endpoint) | 42 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) |
2292 | 43 | authserver = BlockingProxy(proxy) | 43 | authserver = BlockingProxy(proxy) |
2293 | 44 | hosted_transport = get_chrooted_transport( | 44 | hosted_transport = get_chrooted_transport( |
2294 | 45 | config.codehosting.hosted_branches_root) | 45 | config.codehosting.hosted_branches_root) |
The xmlrpc- codehosting. txt file has the heading "The BranchPuller application".
Perhaps we could rename the 'self.storage' to 'self.codehosting' in the ng_api' to be even move verbose.
CodehostingTest, or 'self.codehosti
M-% FTW
lib/lp/ codehosting/ sshserver/ daemon. py
- still mentions the authserver :-)
Apart from that, your were right, it is a boring branch, but good to go some renames.