Merge lp:~mwhudson/launchpad/no-hosted-area-fix-branch-distro into lp:launchpad

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 10828
Proposed branch: lp:~mwhudson/launchpad/no-hosted-area-fix-branch-distro
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area-remove-mirrorComplete
Diff against target: 611 lines (+116/-250)
7 files modified
lib/lp/code/model/branch.py (+0/-4)
lib/lp/code/model/tests/test_branch.py (+0/-6)
lib/lp/codehosting/branchdistro.py (+64/-78)
lib/lp/codehosting/tests/test_branchdistro.py (+33/-143)
lib/lp/codehosting/vfs/branchfs.py (+13/-6)
lib/lp/testing/__init__.py (+4/-10)
scripts/branch-distro.py (+2/-3)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-fix-branch-distro
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23896@code.launchpad.net

Description of the change

Hi Tim,

This branch fixes the branch-distro.py script to work without the hosted/mirror split. It's quite a bit simpler -- a shame that we're not quite going to get this landed in time to use it for opening maverick! Oh well.

Cheers,
mwh

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2010-04-27 02:13:58 +0000
+++ lib/lp/code/model/branch.py 2010-04-27 02:14:19 +0000
@@ -873,10 +873,6 @@
873 # another RCS system such as CVS.873 # another RCS system such as CVS.
874 prefix = config.launchpad.bzr_imports_root_url874 prefix = config.launchpad.bzr_imports_root_url
875 return urlappend(prefix, '%08x' % self.id)875 return urlappend(prefix, '%08x' % self.id)
876 elif self.branch_type == BranchType.HOSTED:
877 # This is a push branch, hosted on Launchpad (pushed there by
878 # users via sftp or bzr+ssh).
879 return 'lp-hosted:///%s' % (self.unique_name,)
880 else:876 else:
881 raise AssertionError("No pull URL for %r" % (self,))877 raise AssertionError("No pull URL for %r" % (self,))
882878
883879
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2010-04-27 02:13:58 +0000
+++ lib/lp/code/model/tests/test_branch.py 2010-04-27 02:14:19 +0000
@@ -260,12 +260,6 @@
260260
261 layer = DatabaseFunctionalLayer261 layer = DatabaseFunctionalLayer
262262
263 def test_pullURLHosted(self):
264 # Hosted branches are pulled from internal Launchpad URLs.
265 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
266 self.assertEqual(
267 'lp-hosted:///%s' % branch.unique_name, branch.getPullURL())
268
269 def test_pullURLMirrored(self):263 def test_pullURLMirrored(self):
270 # Mirrored branches are pulled from their actual URLs -- that's the264 # Mirrored branches are pulled from their actual URLs -- that's the
271 # point.265 # point.
272266
=== modified file 'lib/lp/codehosting/branchdistro.py'
--- lib/lp/codehosting/branchdistro.py 2009-10-26 22:37:15 +0000
+++ lib/lp/codehosting/branchdistro.py 2010-04-27 02:14:19 +0000
@@ -21,8 +21,6 @@
21from bzrlib.bzrdir import BzrDir21from bzrlib.bzrdir import BzrDir
22from bzrlib.errors import NotBranchError, NotStacked22from bzrlib.errors import NotBranchError, NotStacked
2323
24from lazr.uri import URI
25
26import transaction24import transaction
2725
28from zope.component import getUtility26from zope.component import getUtility
@@ -79,12 +77,9 @@
79 # location so that it works to set the stacked on url to '/' + a77 # location so that it works to set the stacked on url to '/' + a
80 # unique_name.78 # unique_name.
81 new_location_bzrdir = BzrDir.open(79 new_location_bzrdir = BzrDir.open(
82 str(URI(80 scheme + ':///' + new_db_branch.unique_name)
83 scheme=scheme, host='', path='/' + new_db_branch.unique_name)))
84 old_location_bzrdir = new_location_bzrdir.clone(81 old_location_bzrdir = new_location_bzrdir.clone(
85 str(URI(82 scheme + ':///' + old_db_branch.unique_name, revision_id='null:')
86 scheme=scheme, host='', path='/' + old_db_branch.unique_name)),
87 revision_id='null:')
8883
89 # Set the stacked on url for old location.84 # Set the stacked on url for old location.
90 old_location_branch = old_location_bzrdir.open_branch()85 old_location_branch = old_location_bzrdir.open_branch()
@@ -207,8 +202,7 @@
207202
208 This function checks that every official package branch in the old203 This function checks that every official package branch in the old
209 distroseries has a matching branch in the new distroseries and that204 distroseries has a matching branch in the new distroseries and that
210 stacking is set up as we expect in both the hosted and mirrored areas205 stacking is set up as we expect on disk.
211 on disk.
212206
213 Every branch will be checked, even if some fail.207 Every branch will be checked, even if some fail.
214208
@@ -234,8 +228,7 @@
234 """Check a branch in the old distroseries has been copied to the new.228 """Check a branch in the old distroseries has been copied to the new.
235229
236 This function checks that `old_db_branch` has a matching branch in the230 This function checks that `old_db_branch` has a matching branch in the
237 new distroseries and that stacking is set up as we expect in both the231 new distroseries and that stacking is set up as we expect on disk.
238 hosted and mirrored areas on disk.
239232
240 This function simply returns True or False -- any problems will be233 This function simply returns True or False -- any problems will be
241 logged to ``self.logger``.234 logged to ``self.logger``.
@@ -258,71 +251,67 @@
258 ok = self.checkConsistentOfficialPackageBranch(new_db_branch)251 ok = self.checkConsistentOfficialPackageBranch(new_db_branch)
259 if not ok:252 if not ok:
260 return ok253 return ok
261 # for both mirrored and hosted areas:254 # the branch in the new distroseries is unstacked
262 for scheme in 'lp-mirrored', 'lp-hosted':255 new_location = 'lp-internal:///' + new_db_branch.unique_name
263 # the branch in the new distroseries is unstacked256 try:
264 new_location = str(URI(257 new_bzr_branch = Branch.open(new_location)
265 scheme=scheme, host='', path='/' + new_db_branch.unique_name))258 except NotBranchError:
266 try:259 self.logger.warning(
267 new_bzr_branch = Branch.open(new_location)260 "No bzr branch at new location %s", new_location)
268 except NotBranchError:261 ok = False
269 self.logger.warning(262 else:
270 "No bzr branch at new location %s", new_location)263 try:
271 ok = False264 new_stacked_on_url = new_bzr_branch.get_stacked_on_url()
272 else:265 ok = False
273 try:266 self.logger.warning(
274 new_stacked_on_url = new_bzr_branch.get_stacked_on_url()267 "New branch at %s is stacked on %s, should be "
275 ok = False268 "unstacked.", new_location, new_stacked_on_url)
276 self.logger.warning(269 except NotStacked:
277 "New branch at %s is stacked on %s, should be "270 pass
278 "unstacked.", new_location, new_stacked_on_url)271 # The branch in the old distroseries is stacked on that in the
279 except NotStacked:272 # new.
280 pass273 old_location = 'lp-internal:///' + old_db_branch.unique_name
281 # The branch in the old distroseries is stacked on that in the274 try:
282 # new.275 old_bzr_branch = Branch.open(old_location)
283 old_location = str(URI(276 except NotBranchError:
284 scheme=scheme, host='', path='/' + old_db_branch.unique_name))277 self.logger.warning(
285 try:278 "No bzr branch at old location %s", old_location)
286 old_bzr_branch = Branch.open(old_location)279 ok = False
287 except NotBranchError:280 else:
288 self.logger.warning(281 try:
289 "No bzr branch at old location %s", old_location)282 old_stacked_on_url = old_bzr_branch.get_stacked_on_url()
290 ok = False283 if old_stacked_on_url != '/' + new_db_branch.unique_name:
291 else:284 self.logger.warning(
292 try:285 "Old branch at %s is stacked on %s, should be "
293 old_stacked_on_url = old_bzr_branch.get_stacked_on_url()286 "stacked on %s", old_location, old_stacked_on_url,
294 if old_stacked_on_url != '/' + new_db_branch.unique_name:
295 self.logger.warning(
296 "Old branch at %s is stacked on %s, should be "
297 "stacked on %s", old_location, old_stacked_on_url,
298 '/' + new_db_branch.unique_name)
299 ok = False
300 except NotStacked:
301 self.logger.warning(
302 "Old branch at %s is not stacked, should be stacked "
303 "on %s", old_location,
304 '/' + new_db_branch.unique_name)287 '/' + new_db_branch.unique_name)
305 ok = False288 ok = False
306 # The branch in the old distroseries has no revisions in its289 except NotStacked:
307 # repository. We open the repository independently of the290 self.logger.warning(
308 # branch because the branch's repository has had its fallback291 "Old branch at %s is not stacked, should be stacked "
309 # location activated. Note that this check might fail if new292 "on %s", old_location,
310 # revisions get pushed to the branch in the old distroseries,293 '/' + new_db_branch.unique_name)
311 # which shouldn't happen but isn't totally impossible.294 ok = False
312 old_repo = BzrDir.open(old_location).open_repository()295 # The branch in the old distroseries has no revisions in its
313 if len(old_repo.all_revision_ids()) > 0:296 # repository. We open the repository independently of the
314 self.logger.warning(297 # branch because the branch's repository has had its fallback
315 "Repository at %s has %s revisions.",298 # location activated. Note that this check might fail if new
316 old_location, len(old_repo.all_revision_ids()))299 # revisions get pushed to the branch in the old distroseries,
317 ok = False300 # which shouldn't happen but isn't totally impossible.
318 # The branch in the old distroseries has at least some301 old_repo = BzrDir.open(old_location).open_repository()
319 # history. (We can't check that the tips are the same because302 if len(old_repo.all_revision_ids()) > 0:
320 # the branch in the new distroseries might have new revisons).303 self.logger.warning(
321 if old_bzr_branch.last_revision() == 'null:':304 "Repository at %s has %s revisions.",
322 self.logger.warning(305 old_location, len(old_repo.all_revision_ids()))
323 "Old branch at %s has null tip revision.",306 ok = False
324 old_location)307 # The branch in the old distroseries has at least some
325 ok = False308 # history. (We can't check that the tips are the same because
309 # the branch in the new distroseries might have new revisons).
310 if old_bzr_branch.last_revision() == 'null:':
311 self.logger.warning(
312 "Old branch at %s has null tip revision.",
313 old_location)
314 ok = False
326 return ok315 return ok
327316
328 def makeOneNewBranch(self, old_db_branch):317 def makeOneNewBranch(self, old_db_branch):
@@ -357,9 +346,6 @@
357 # again. So commit before doing that.346 # again. So commit before doing that.
358 transaction.commit()347 transaction.commit()
359 switch_branches(348 switch_branches(
360 config.codehosting.hosted_branches_root,
361 'lp-hosted', old_db_branch, new_db_branch)
362 switch_branches(
363 config.codehosting.mirrored_branches_root,349 config.codehosting.mirrored_branches_root,
364 'lp-mirrored', old_db_branch, new_db_branch)350 'lp-internal', old_db_branch, new_db_branch)
365 return new_db_branch351 return new_db_branch
366352
=== modified file 'lib/lp/codehosting/tests/test_branchdistro.py'
--- lib/lp/codehosting/tests/test_branchdistro.py 2010-01-20 23:10:44 +0000
+++ lib/lp/codehosting/tests/test_branchdistro.py 2010-04-27 02:14:19 +0000
@@ -118,12 +118,8 @@
118 transaction.commit()118 transaction.commit()
119119
120 _, tree = self.create_branch_and_tree(120 _, tree = self.create_branch_and_tree(
121 tree_location=self.factory.getUniqueString(), db_branch=db_branch,121 tree_location=self.factory.getUniqueString(), db_branch=db_branch)
122 hosted=True)
123 tree.commit('')122 tree.commit('')
124 mirrored_branch = BzrDir.create_branch_convenience(
125 db_branch.warehouse_url)
126 mirrored_branch.pull(tree.branch)
127123
128 return db_branch124 return db_branch
129125
@@ -396,229 +392,123 @@
396 ['^WARNING .*/.*/.* is the official branch for .*/.*/.* but not '392 ['^WARNING .*/.*/.* is the official branch for .*/.*/.* but not '
397 'its sourcepackage$'])393 'its sourcepackage$'])
398394
399 def checkOneBranch_new_branch_missing(self, branch_type):395 def test_checkOneBranch_new_branch_missing(self):
400 # checkOneBranch returns False when there is no bzr branch for the396 # checkOneBranch returns False when there is no bzr branch for the
401 # database branch in the new distroseries.397 # database branch in the new distroseries.
402 assert branch_type in ('hosted', 'mirrored')
403 db_branch = self.makeOfficialPackageBranch()398 db_branch = self.makeOfficialPackageBranch()
404 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)399 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
405 new_db_branch = brancher.makeOneNewBranch(db_branch)400 new_db_branch = brancher.makeOneNewBranch(db_branch)
406 if branch_type == 'hosted':401 url = 'lp-internal:///' + new_db_branch.unique_name
407 url = new_db_branch.getPullURL()
408 else:
409 url = new_db_branch.warehouse_url
410 get_transport(url).delete_tree('.bzr')402 get_transport(url).delete_tree('.bzr')
411 ok = brancher.checkOneBranch(db_branch)403 ok = brancher.checkOneBranch(db_branch)
412 self.assertFalse(ok)404 self.assertFalse(ok)
413 # Deleting the new branch will break the old branch, as that's stacked405 # Deleting the new branch will break the old branch, as that's stacked
414 # on the new one.406 # on the new one.
415 self.assertLogMessages([407 self.assertLogMessages([
416 '^WARNING No bzr branch at new location lp-%s:///.*/.*/.*/.*$'408 '^WARNING No bzr branch at new location '
417 % branch_type,409 'lp-internal:///.*/.*/.*/.*$',
418 '^WARNING No bzr branch at old location lp-%s:///.*/.*/.*/.*$'410 '^WARNING No bzr branch at old location '
419 % branch_type,411 'lp-internal:///.*/.*/.*/.*$',
420 ])412 ])
421413
422 def test_checkOneBranch_new_hosted_branch_missing(self):414 def test_checkOneBranch_old_branch_missing(self):
423 # checkOneBranch returns False when there is no bzr branch in the
424 # hosted area for the database branch in the new distroseries.
425 self.checkOneBranch_new_branch_missing('hosted')
426
427 def test_checkOneBranch_new_mirrored_branch_missing(self):
428 # checkOneBranch returns False when there is no bzr branch in the
429 # mirrored area for the database branch in the new distroseries.
430 self.checkOneBranch_new_branch_missing('mirrored')
431
432 def checkOneBranch_old_branch_missing(self, branch_type):
433 # checkOneBranch returns False when there is no bzr branchfor the415 # checkOneBranch returns False when there is no bzr branchfor the
434 # database branch in old distroseries.416 # database branch in old distroseries.
435 assert branch_type in ('hosted', 'mirrored')
436 db_branch = self.makeOfficialPackageBranch()417 db_branch = self.makeOfficialPackageBranch()
437 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)418 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
438 brancher.makeOneNewBranch(db_branch)419 brancher.makeOneNewBranch(db_branch)
439 if branch_type == 'hosted':420 url = 'lp-internal:///' + db_branch.unique_name
440 url = db_branch.getPullURL()
441 else:
442 url = db_branch.warehouse_url
443 get_transport(url).delete_tree('.bzr')421 get_transport(url).delete_tree('.bzr')
444 ok = brancher.checkOneBranch(db_branch)422 ok = brancher.checkOneBranch(db_branch)
445 self.assertFalse(ok)423 self.assertFalse(ok)
446 self.assertLogMessages([424 self.assertLogMessages([
447 '^WARNING No bzr branch at old location lp-%s:///.*/.*/.*/.*$'425 '^WARNING No bzr branch at old location '
448 % branch_type,426 'lp-internal:///.*/.*/.*/.*$'
449 ])427 ])
450428
451 def test_checkOneBranch_old_hosted_branch_missing(self):429 def test_checkOneBranch_new_stacked(self):
452 # checkOneBranch returns False when there is no bzr branch in the
453 # hosted area for the database branch in old distroseries.
454 self.checkOneBranch_old_branch_missing('hosted')
455
456 def test_checkOneBranch_old_mirrored_branch_missing(self):
457 # checkOneBranch returns False when there is no bzr branch in the
458 # mirrored area for the database branch in old distroseries.
459 self.checkOneBranch_old_branch_missing('mirrored')
460
461 def checkOneBranch_new_stacked(self, branch_type):
462 # checkOneBranch returns False when the bzr branch for the database430 # checkOneBranch returns False when the bzr branch for the database
463 # branch in new distroseries is stacked.431 # branch in new distroseries is stacked.
464 assert branch_type in ('hosted', 'mirrored')
465 db_branch = self.makeOfficialPackageBranch()432 db_branch = self.makeOfficialPackageBranch()
466 b, _ = self.create_branch_and_tree(433 b, _ = self.create_branch_and_tree(self.factory.getUniqueString())
467 self.factory.getUniqueString(), hosted=(branch_type == 'hosted'))
468 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)434 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
469 new_db_branch = brancher.makeOneNewBranch(db_branch)435 new_db_branch = brancher.makeOneNewBranch(db_branch)
470 if branch_type == 'hosted':436 url = 'lp-internal:///' + new_db_branch.unique_name
471 url = new_db_branch.getPullURL()
472 else:
473 url = new_db_branch.warehouse_url
474 Branch.open(url).set_stacked_on_url('/' + b.unique_name)437 Branch.open(url).set_stacked_on_url('/' + b.unique_name)
475 ok = brancher.checkOneBranch(db_branch)438 ok = brancher.checkOneBranch(db_branch)
476 self.assertFalse(ok)439 self.assertFalse(ok)
477 self.assertLogMessages([440 self.assertLogMessages([
478 '^WARNING New branch at lp-%s:///.*/.*/.*/.* is stacked on '441 '^WARNING New branch at lp-internal:///.*/.*/.*/.* is stacked on '
479 '/.*/.*/.*, should be unstacked.$' % branch_type,442 '/.*/.*/.*, should be unstacked.$',
480 ])443 ])
481444
482 def test_checkOneBranch_new_hosted_stacked(self):445 def test_checkOneBranch_old_unstacked(self):
483 # checkOneBranch returns False when the bzr branch in the hosted area
484 # for the database branch in new distroseries is stacked.
485 self.checkOneBranch_new_stacked('hosted')
486
487 def test_checkOneBranch_new_mirrored_stacked(self):
488 # checkOneBranch returns False when the bzr branch in the mirrored
489 # area for the database branch in new distroseries is stacked.
490 self.checkOneBranch_new_stacked('mirrored')
491
492 def checkOneBranch_old_unstacked(self, branch_type):
493 # checkOneBranch returns False when the bzr branch for the database446 # checkOneBranch returns False when the bzr branch for the database
494 # branch in old distroseries is not stacked.447 # branch in old distroseries is not stacked.
495 assert branch_type in ('hosted', 'mirrored')
496 db_branch = self.makeOfficialPackageBranch()448 db_branch = self.makeOfficialPackageBranch()
497 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)449 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
498 brancher.makeOneNewBranch(db_branch)450 brancher.makeOneNewBranch(db_branch)
499 if branch_type == 'hosted':451 url = 'lp-internal:///' + db_branch.unique_name
500 url = db_branch.getPullURL()
501 else:
502 url = db_branch.warehouse_url
503 old_bzr_branch = Branch.open(url)452 old_bzr_branch = Branch.open(url)
504 old_bzr_branch.set_stacked_on_url(None)453 old_bzr_branch.set_stacked_on_url(None)
505 ok = brancher.checkOneBranch(db_branch)454 ok = brancher.checkOneBranch(db_branch)
506 self.assertLogMessages([455 self.assertLogMessages([
507 '^WARNING Old branch at lp-%s:///.*/.*/.*/.* is not stacked, '456 '^WARNING Old branch at lp-internal:///.*/.*/.*/.* is not '
508 'should be stacked on /.*/.*/.*.$' % branch_type,457 'stacked, should be stacked on /.*/.*/.*.$',
509 '^.*has .* revisions.*$',458 '^.*has .* revisions.*$',
510 ])459 ])
511 self.assertFalse(ok)460 self.assertFalse(ok)
512461
513 def test_checkOneBranch_old_hosted_unstacked(self):462 def test_checkOneBranch_old_misstacked(self):
514 # checkOneBranch returns False when the bzr branch in the hosted area
515 # for the database branch in old distroseries is not stacked.
516 self.checkOneBranch_old_unstacked('hosted')
517
518 def test_checkOneBranch_old_mirrored_unstacked(self):
519 # checkOneBranch returns False when the bzr branch in the mirrored
520 # area for the database branch in old distroseries is not stacked.
521 self.checkOneBranch_old_unstacked('mirrored')
522
523 def checkOneBranch_old_misstacked(self, branch_type):
524 # checkOneBranch returns False when the bzr branch for the database463 # checkOneBranch returns False when the bzr branch for the database
525 # branch in old distroseries stacked on some other branch than the464 # branch in old distroseries stacked on some other branch than the
526 # branch in the new distroseries.465 # branch in the new distroseries.
527 assert branch_type in ('hosted', 'mirrored')
528 db_branch = self.makeOfficialPackageBranch()466 db_branch = self.makeOfficialPackageBranch()
529 b, _ = self.create_branch_and_tree(467 b, _ = self.create_branch_and_tree(self.factory.getUniqueString())
530 self.factory.getUniqueString(), hosted=(branch_type == 'hosted'))
531 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)468 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
532 brancher.makeOneNewBranch(db_branch)469 brancher.makeOneNewBranch(db_branch)
533 if branch_type == 'hosted':470 url = 'lp-internal:///' + db_branch.unique_name
534 url = db_branch.getPullURL()
535 else:
536 url = db_branch.warehouse_url
537 Branch.open(url).set_stacked_on_url('/' + b.unique_name)471 Branch.open(url).set_stacked_on_url('/' + b.unique_name)
538 ok = brancher.checkOneBranch(db_branch)472 ok = brancher.checkOneBranch(db_branch)
539 self.assertLogMessages([473 self.assertLogMessages([
540 '^WARNING Old branch at lp-%s:///.*/.*/.*/.* is stacked on '474 '^WARNING Old branch at lp-internal:///.*/.*/.*/.* is stacked on '
541 '/.*/.*/.*, should be stacked on /.*/.*/.*.$' % branch_type,475 '/.*/.*/.*, should be stacked on /.*/.*/.*.$',
542 ])476 ])
543 self.assertFalse(ok)477 self.assertFalse(ok)
544478
545 def test_checkOneBranch_old_hosted_misstacked(self):479 def test_checkOneBranch_old_has_revisions(self):
546 # checkOneBranch returns False when the bzr branch in the hosted area
547 # for the database branch in old distroseries stacked on some other
548 # branch than the branch in the new distroseries.
549 self.checkOneBranch_old_misstacked('hosted')
550
551 def test_checkOneBranch_old_mirrored_misstacked(self):
552 # checkOneBranch returns False when the bzr branch in the mirrored
553 # area for the database branch in old distroseries stacked on some
554 # other branch than the branch in the new distroseries.
555 self.checkOneBranch_old_misstacked('mirrored')
556
557 def checkOneBranch_old_has_revisions(self, branch_type):
558 # checkOneBranch returns False when the bzr branch for the database480 # checkOneBranch returns False when the bzr branch for the database
559 # branch in old distroseries has a repository that contains revisions.481 # branch in old distroseries has a repository that contains revisions.
560 assert branch_type in ('hosted', 'mirrored')
561 db_branch = self.makeOfficialPackageBranch()482 db_branch = self.makeOfficialPackageBranch()
562 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)483 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
563 brancher.makeOneNewBranch(db_branch)484 brancher.makeOneNewBranch(db_branch)
564 if branch_type == 'hosted':485 url = 'lp-internal:///' + db_branch.unique_name
565 url = db_branch.getPullURL()
566 else:
567 url = db_branch.warehouse_url
568 old_bzr_branch = Branch.open(url)486 old_bzr_branch = Branch.open(url)
569 old_bzr_branch.create_checkout(487 old_bzr_branch.create_checkout(
570 self.factory.getUniqueString()).commit('')488 self.factory.getUniqueString()).commit('')
571 ok = brancher.checkOneBranch(db_branch)489 ok = brancher.checkOneBranch(db_branch)
572 self.assertLogMessages([490 self.assertLogMessages([
573 '^WARNING Repository at lp-%s:///.*/.*/.*/.* has 1 revisions.'491 '^WARNING Repository at lp-internal:///.*/.*/.*/.* has 1 '
574 % branch_type492 'revisions.'
575 ])493 ])
576 self.assertFalse(ok)494 self.assertFalse(ok)
577495
578 def test_checkOneBranch_old_hosted_has_revisions(self):496 def test_checkOneBranch_old_has_null_tip(self):
579 # checkOneBranch returns False when the bzr branch in the hosted area
580 # for the database branch in old distroseries has a repository that
581 # contains revisions.
582 self.checkOneBranch_old_has_revisions('hosted')
583
584 def test_checkOneBranch_old_mirrored_has_revisions(self):
585 # checkOneBranch returns False when the bzr branch in the mirrored
586 # area for the database branch in old distroseries has a repository
587 # that contains revisions.
588 self.checkOneBranch_old_has_revisions('mirrored')
589
590 def checkOneBranch_old_has_null_tip(self, branch_type):
591 # checkOneBranch returns False when the bzr branch for the database497 # checkOneBranch returns False when the bzr branch for the database
592 # branch in old distroseries has tip revision of 'null:'.498 # branch in old distroseries has tip revision of 'null:'.
593 assert branch_type in ('hosted', 'mirrored')
594 db_branch = self.makeOfficialPackageBranch()499 db_branch = self.makeOfficialPackageBranch()
595 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)500 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
596 brancher.makeOneNewBranch(db_branch)501 brancher.makeOneNewBranch(db_branch)
597 if branch_type == 'hosted':502 url = 'lp-internal:///' + db_branch.unique_name
598 url = db_branch.getPullURL()
599 else:
600 url = db_branch.warehouse_url
601 old_bzr_branch = Branch.open(url)503 old_bzr_branch = Branch.open(url)
602 old_bzr_branch.set_last_revision_info(0, 'null:')504 old_bzr_branch.set_last_revision_info(0, 'null:')
603 ok = brancher.checkOneBranch(db_branch)505 ok = brancher.checkOneBranch(db_branch)
604 self.assertLogMessages([506 self.assertLogMessages([
605 '^WARNING Old branch at lp-%s:///.*/.*/.*/.* has null tip '507 '^WARNING Old branch at lp-internal:///.*/.*/.*/.* has null tip '
606 'revision.' % branch_type508 'revision.'
607 ])509 ])
608 self.assertFalse(ok)510 self.assertFalse(ok)
609511
610 def test_checkOneBranch_old_hosted_has_null_tip(self):
611 # checkOneBranch returns False when the bzr branch in the hosted area
612 # for the database branch in old distroseries has tip revision of
613 # 'null:'.
614 self.checkOneBranch_old_has_null_tip('hosted')
615
616 def test_checkOneBranch_old_mirrored_has_null_tip(self):
617 # checkOneBranch returns False when the bzr branch in the mirrored
618 # area for the database branch in old distroseries has tip revision of
619 # 'null:'.
620 self.checkOneBranch_old_has_null_tip('mirrored')
621
622 def runBranchDistroScript(self, args):512 def runBranchDistroScript(self, args):
623 """Run the branch-distro.py script with the given arguments.513 """Run the branch-distro.py script with the given arguments.
624514
625515
=== modified file 'lib/lp/codehosting/vfs/branchfs.py'
--- lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:13:58 +0000
+++ lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:14:19 +0000
@@ -177,18 +177,25 @@
177 'lp-mirrored:///', codehosting_endpoint, branch_transport)177 'lp-mirrored:///', codehosting_endpoint, branch_transport)
178178
179179
180def get_rw_server():180def get_rw_server(direct_database=False):
181 """Get a server that can write to the Launchpad branch vfs.181 """Get a server that can write to the Launchpad branch vfs.
182182
183 You can only call this usefully on the codehost -- the transport this183 You can only call this usefully on the codehost -- the transport this
184 server provides are backed onto file:/// URLs.184 server provides are backed onto file:/// URLs.
185
186 :param direct_database: if True, use a server implementation that talks
187 directly to the database. If False, the default, use a server
188 implementation that talks to the internal XML-RPC server.
185 """189 """
186 hosted_transport = get_chrooted_transport(190 transport = get_chrooted_transport(
187 config.codehosting.mirrored_branches_root, mkdir=True)191 config.codehosting.mirrored_branches_root, mkdir=True)
188 proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint)192 if direct_database:
189 codehosting_endpoint = BlockingProxy(proxy)193 return DirectDatabaseLaunchpadServer('lp-internal:///', transport)
190 return LaunchpadInternalServer(194 else:
191 'lp-internal:///', codehosting_endpoint, hosted_transport)195 proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint)
196 codehosting_endpoint = BlockingProxy(proxy)
197 return LaunchpadInternalServer(
198 'lp-internal:///', codehosting_endpoint, transport)
192199
193200
194def get_multi_server(write_hosted=False, write_mirrored=False,201def get_multi_server(write_hosted=False, write_mirrored=False,
195202
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py 2010-04-24 02:41:03 +0000
+++ lib/lp/testing/__init__.py 2010-04-27 02:14:19 +0000
@@ -84,7 +84,7 @@
84from canonical.launchpad.webapp.interaction import ANONYMOUS84from canonical.launchpad.webapp.interaction import ANONYMOUS
85from canonical.launchpad.webapp.interfaces import ILaunchBag85from canonical.launchpad.webapp.interfaces import ILaunchBag
86from canonical.launchpad.windmill.testing import constants86from canonical.launchpad.windmill.testing import constants
87from lp.codehosting.vfs import branch_id_to_path, get_multi_server87from lp.codehosting.vfs import branch_id_to_path, get_rw_server
88from lp.registry.interfaces.packaging import IPackagingUtil88from lp.registry.interfaces.packaging import IPackagingUtil
89# Import the login and logout functions here as it is a much better89# Import the login and logout functions here as it is a much better
90# place to import them from in tests.90# place to import them from in tests.
@@ -452,14 +452,12 @@
452 branch_url, format=format)452 branch_url, format=format)
453453
454 def create_branch_and_tree(self, tree_location=None, product=None,454 def create_branch_and_tree(self, tree_location=None, product=None,
455 hosted=False, db_branch=None, format=None,455 db_branch=None, format=None,
456 **kwargs):456 **kwargs):
457 """Create a database branch, bzr branch and bzr checkout.457 """Create a database branch, bzr branch and bzr checkout.
458458
459 :param tree_location: The path on disk to create the tree at.459 :param tree_location: The path on disk to create the tree at.
460 :param product: The product to associate with the branch.460 :param product: The product to associate with the branch.
461 :param hosted: If True, create in the hosted area. Otherwise, create
462 in the mirrored area.
463 :param db_branch: If supplied, the database branch to use.461 :param db_branch: If supplied, the database branch to use.
464 :param format: Override the default bzrdir format to create.462 :param format: Override the default bzrdir format to create.
465 :return: a `Branch` and a workingtree.463 :return: a `Branch` and a workingtree.
@@ -469,10 +467,7 @@
469 db_branch = self.factory.makeAnyBranch(**kwargs)467 db_branch = self.factory.makeAnyBranch(**kwargs)
470 else:468 else:
471 db_branch = self.factory.makeProductBranch(product, **kwargs)469 db_branch = self.factory.makeProductBranch(product, **kwargs)
472 if hosted:470 branch_url = 'lp-internal:///' + db_branch.unique_name
473 branch_url = db_branch.getPullURL()
474 else:
475 branch_url = db_branch.warehouse_url
476 if self.real_bzr_server:471 if self.real_bzr_server:
477 transaction.commit()472 transaction.commit()
478 bzr_branch = self.createBranchAtURL(branch_url, format=format)473 bzr_branch = self.createBranchAtURL(branch_url, format=format)
@@ -552,8 +547,7 @@
552 self.useTempBzrHome()547 self.useTempBzrHome()
553 self.real_bzr_server = real_server548 self.real_bzr_server = real_server
554 if real_server:549 if real_server:
555 server = get_multi_server(550 server = get_rw_server(
556 write_hosted=True, write_mirrored=True,
557 direct_database=direct_database)551 direct_database=direct_database)
558 server.start_server()552 server.start_server()
559 self.addCleanup(server.destroy)553 self.addCleanup(server.destroy)
560554
=== modified file 'scripts/branch-distro.py'
--- scripts/branch-distro.py 2010-02-16 15:25:52 +0000
+++ scripts/branch-distro.py 2010-04-27 02:14:19 +0000
@@ -6,7 +6,7 @@
6import _pythonpath6import _pythonpath
77
8from lp.codehosting.branchdistro import DistroBrancher8from lp.codehosting.branchdistro import DistroBrancher
9from lp.codehosting.vfs import get_multi_server9from lp.codehosting.vfs import get_rw_server
10from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure10from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure
1111
1212
@@ -24,8 +24,7 @@
24 if len(self.args) != 3:24 if len(self.args) != 3:
25 self.parser.error("Wrong number of arguments.")25 self.parser.error("Wrong number of arguments.")
26 brancher = DistroBrancher.fromNames(self.logger, *self.args)26 brancher = DistroBrancher.fromNames(self.logger, *self.args)
27 server = get_multi_server(27 server = get_rw_server(direct_database=True)
28 write_mirrored=True, write_hosted=True, direct_database=True)
29 server.start_server()28 server.start_server()
30 try:29 try:
31 if self.options.check:30 if self.options.check: