Merge lp:~thumper/launchpad/stop-mirroring-hosted into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: no longer in the source branch.
Merged at revision: 11250
Proposed branch: lp:~thumper/launchpad/stop-mirroring-hosted
Merge into: lp:launchpad
Diff against target: 201 lines (+19/-30)
6 files modified
lib/lp/code/browser/tests/test_branch.py (+2/-2)
lib/lp/code/model/branch.py (+4/-4)
lib/lp/code/model/tests/test_branch.py (+9/-8)
lib/lp/code/model/tests/test_branchmergeproposaljobs.py (+0/-1)
lib/lp/code/model/tests/test_branchtarget.py (+1/-7)
lib/lp/code/xmlrpc/tests/test_codehosting.py (+3/-8)
To merge this branch: bzr merge lp:~thumper/launchpad/stop-mirroring-hosted
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+31116@code.launchpad.net

Commit message

Make the world explode if requestMirror, startMirror, or mirrorFailed are called on hosted branches.

Description of the change

This is the final branch in the stack that enforces not calling the branch mirror methods on hosted branches.

Exceptions are now raised if requestMirror, startMirror, or mirrorFailed are called on hosted branches.

Several tests that were doing this have been fixed.

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

This looks basically fine. I'm not sure the comment in pending_writes is ideal now -- we shouldn't really have conversations in our source code :-) If you can fix that up a bit, please merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/tests/test_branch.py'
--- lib/lp/code/browser/tests/test_branch.py 2010-07-09 10:11:47 +0000
+++ lib/lp/code/browser/tests/test_branch.py 2010-07-28 22:53:45 +0000
@@ -125,7 +125,7 @@
125125
126 def testMirrorStatusMessageIsTruncated(self):126 def testMirrorStatusMessageIsTruncated(self):
127 """mirror_status_message is truncated if the text is overly long."""127 """mirror_status_message is truncated if the text is overly long."""
128 branch = self.factory.makeBranch()128 branch = self.factory.makeBranch(branch_type=BranchType.MIRRORED)
129 branch.mirrorFailed(129 branch.mirrorFailed(
130 "on quick brown fox the dog jumps to" *130 "on quick brown fox the dog jumps to" *
131 BranchMirrorStatusView.MAXIMUM_STATUS_MESSAGE_LENGTH)131 BranchMirrorStatusView.MAXIMUM_STATUS_MESSAGE_LENGTH)
@@ -137,7 +137,7 @@
137137
138 def testMirrorStatusMessage(self):138 def testMirrorStatusMessage(self):
139 """mirror_status_message on the view is the same as on the branch."""139 """mirror_status_message on the view is the same as on the branch."""
140 branch = self.factory.makeBranch()140 branch = self.factory.makeBranch(branch_type=BranchType.MIRRORED)
141 branch.mirrorFailed("This is a short error message.")141 branch.mirrorFailed("This is a short error message.")
142 branch_view = BranchMirrorStatusView(branch, self.request)142 branch_view = BranchMirrorStatusView(branch, self.request)
143 self.assertTrue(143 self.assertTrue(
144144
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2010-07-25 12:55:56 +0000
+++ lib/lp/code/model/branch.py 2010-07-28 22:53:45 +0000
@@ -848,7 +848,7 @@
848 mirrored.848 mirrored.
849 """849 """
850 new_data_pushed = (850 new_data_pushed = (
851 self.branch_type in (BranchType.HOSTED, BranchType.IMPORTED)851 self.branch_type == BranchType.IMPORTED
852 and self.next_mirror_time is not None)852 and self.next_mirror_time is not None)
853 # XXX 2010-04-22, MichaelHudson: This should really look for a branch853 # XXX 2010-04-22, MichaelHudson: This should really look for a branch
854 # scan job.854 # scan job.
@@ -896,7 +896,7 @@
896896
897 def requestMirror(self):897 def requestMirror(self):
898 """See `IBranch`."""898 """See `IBranch`."""
899 if self.branch_type == BranchType.REMOTE:899 if self.branch_type in (BranchType.REMOTE, BranchType.HOSTED):
900 raise BranchTypeError(self.unique_name)900 raise BranchTypeError(self.unique_name)
901 branch = Store.of(self).find(901 branch = Store.of(self).find(
902 Branch,902 Branch,
@@ -909,7 +909,7 @@
909909
910 def startMirroring(self):910 def startMirroring(self):
911 """See `IBranch`."""911 """See `IBranch`."""
912 if self.branch_type == BranchType.REMOTE:912 if self.branch_type in (BranchType.REMOTE, BranchType.HOSTED):
913 raise BranchTypeError(self.unique_name)913 raise BranchTypeError(self.unique_name)
914 self.last_mirror_attempt = UTC_NOW914 self.last_mirror_attempt = UTC_NOW
915 self.next_mirror_time = None915 self.next_mirror_time = None
@@ -948,7 +948,7 @@
948948
949 def mirrorFailed(self, reason):949 def mirrorFailed(self, reason):
950 """See `IBranch`."""950 """See `IBranch`."""
951 if self.branch_type == BranchType.REMOTE:951 if self.branch_type in (BranchType.REMOTE, BranchType.HOSTED):
952 raise BranchTypeError(self.unique_name)952 raise BranchTypeError(self.unique_name)
953 self.mirror_failures += 1953 self.mirror_failures += 1
954 self.mirror_status_message = reason954 self.mirror_status_message = reason
955955
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2010-07-25 12:55:56 +0000
+++ lib/lp/code/model/tests/test_branch.py 2010-07-28 22:53:45 +0000
@@ -1954,11 +1954,12 @@
1954 branch = self.factory.makeAnyBranch()1954 branch = self.factory.makeAnyBranch()
1955 self.assertEqual(False, branch.pending_writes)1955 self.assertEqual(False, branch.pending_writes)
19561956
1957 def test_requestMirror_for_hosted(self):1957 def test_branchChanged_for_hosted(self):
1958 # If a hosted branch has a requested mirror, then someone has just1958 # If branchChanged has been called with a new tip revision id, there
1959 # pushed something up. Therefore, pending writes.1959 # are pending writes.
1960 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)1960 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
1961 branch.requestMirror()1961 with person_logged_in(branch.owner):
1962 branch.branchChanged('', 'new-tip', None, None, None)
1962 self.assertEqual(True, branch.pending_writes)1963 self.assertEqual(True, branch.pending_writes)
19631964
1964 def test_requestMirror_for_imported(self):1965 def test_requestMirror_for_imported(self):
@@ -1980,7 +1981,7 @@
1980 # If a branch has been pulled (mirrored) but not scanned, then we have1981 # If a branch has been pulled (mirrored) but not scanned, then we have
1981 # yet to load the revisions into the database. This means there are1982 # yet to load the revisions into the database. This means there are
1982 # pending writes.1983 # pending writes.
1983 branch = self.factory.makeAnyBranch()1984 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
1984 branch.startMirroring()1985 branch.startMirroring()
1985 rev_id = self.factory.getUniqueString('rev-id')1986 rev_id = self.factory.getUniqueString('rev-id')
1986 removeSecurityProxy(branch).branchChanged(1987 removeSecurityProxy(branch).branchChanged(
@@ -1990,7 +1991,7 @@
1990 def test_pulled_and_scanned(self):1991 def test_pulled_and_scanned(self):
1991 # If a branch has been pulled and scanned, then there are no pending1992 # If a branch has been pulled and scanned, then there are no pending
1992 # writes.1993 # writes.
1993 branch = self.factory.makeAnyBranch()1994 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
1994 branch.startMirroring()1995 branch.startMirroring()
1995 rev_id = self.factory.getUniqueString('rev-id')1996 rev_id = self.factory.getUniqueString('rev-id')
1996 removeSecurityProxy(branch).branchChanged(1997 removeSecurityProxy(branch).branchChanged(
@@ -2004,14 +2005,14 @@
2004 def test_first_mirror_started(self):2005 def test_first_mirror_started(self):
2005 # If we have started mirroring the branch for the first time, then2006 # If we have started mirroring the branch for the first time, then
2006 # there are probably pending writes.2007 # there are probably pending writes.
2007 branch = self.factory.makeAnyBranch()2008 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
2008 branch.startMirroring()2009 branch.startMirroring()
2009 self.assertEqual(True, branch.pending_writes)2010 self.assertEqual(True, branch.pending_writes)
20102011
2011 def test_following_mirror_started(self):2012 def test_following_mirror_started(self):
2012 # If we have started mirroring the branch, then there are probably2013 # If we have started mirroring the branch, then there are probably
2013 # pending writes.2014 # pending writes.
2014 branch = self.factory.makeAnyBranch()2015 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
2015 branch.startMirroring()2016 branch.startMirroring()
2016 rev_id = self.factory.getUniqueString('rev-id')2017 rev_id = self.factory.getUniqueString('rev-id')
2017 removeSecurityProxy(branch).branchChanged(2018 removeSecurityProxy(branch).branchChanged(
20182019
=== modified file 'lib/lp/code/model/tests/test_branchmergeproposaljobs.py'
--- lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2010-04-30 04:51:04 +0000
+++ lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2010-07-28 22:53:45 +0000
@@ -123,7 +123,6 @@
123 def test_getOopsMailController(self):123 def test_getOopsMailController(self):
124 """The registrant is notified about merge proposal creation issues."""124 """The registrant is notified about merge proposal creation issues."""
125 bmp = self.factory.makeBranchMergeProposal()125 bmp = self.factory.makeBranchMergeProposal()
126 bmp.source_branch.requestMirror()
127 job = MergeProposalCreatedJob.create(bmp)126 job = MergeProposalCreatedJob.create(bmp)
128 ctrl = job.getOopsMailController('1234')127 ctrl = job.getOopsMailController('1234')
129 self.assertEqual([bmp.registrant.preferredemail.email], ctrl.to_addrs)128 self.assertEqual([bmp.registrant.preferredemail.email], ctrl.to_addrs)
130129
=== modified file 'lib/lp/code/model/tests/test_branchtarget.py'
--- lib/lp/code/model/tests/test_branchtarget.py 2010-04-23 08:26:27 +0000
+++ lib/lp/code/model/tests/test_branchtarget.py 2010-07-28 22:53:45 +0000
@@ -107,7 +107,6 @@
107 development_package = self.original.development_version107 development_package = self.original.development_version
108 default_branch = self.factory.makePackageBranch(108 default_branch = self.factory.makePackageBranch(
109 sourcepackage=development_package)109 sourcepackage=development_package)
110 default_branch.startMirroring()
111 removeSecurityProxy(default_branch).branchChanged(110 removeSecurityProxy(default_branch).branchChanged(
112 '', self.factory.getUniqueString(), None, None, None)111 '', self.factory.getUniqueString(), None, None, None)
113 ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches112 ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches
@@ -347,7 +346,6 @@
347 # default stacked-on branch.346 # default stacked-on branch.
348 branch = self.factory.makeProductBranch(product=self.original)347 branch = self.factory.makeProductBranch(product=self.original)
349 self._setDevelopmentFocus(self.original, branch)348 self._setDevelopmentFocus(self.original, branch)
350 branch.startMirroring()
351 removeSecurityProxy(branch).branchChanged(349 removeSecurityProxy(branch).branchChanged(
352 '', 'rev1', None, None, None)350 '', 'rev1', None, None, None)
353 target = IBranchTarget(self.original)351 target = IBranchTarget(self.original)
@@ -468,17 +466,13 @@
468 # the current user, even if those branches have already been mirrored.466 # the current user, even if those branches have already been mirrored.
469 branch = self.factory.makeAnyBranch(private=True)467 branch = self.factory.makeAnyBranch(private=True)
470 naked_branch = removeSecurityProxy(branch)468 naked_branch = removeSecurityProxy(branch)
471 naked_branch.startMirroring()
472 naked_branch.branchChanged(469 naked_branch.branchChanged(
473 '', self.factory.getUniqueString(), None, None, None)470 '', self.factory.getUniqueString(), None, None, None)
474 self.assertIs(None, check_default_stacked_on(branch))471 self.assertIs(None, check_default_stacked_on(branch))
475472
476 def test_been_mirrored(self):473 def test_been_mirrored(self):
477 # `check_default_stacked_on` returns None if passed a remote branch.474 # `check_default_stacked_on` returns the branch if it has revisions.
478 # We have no Bazaar data for remote branches, so stacking on one is
479 # futile.
480 branch = self.factory.makeAnyBranch()475 branch = self.factory.makeAnyBranch()
481 branch.startMirroring()
482 removeSecurityProxy(branch).branchChanged(476 removeSecurityProxy(branch).branchChanged(
483 '', self.factory.getUniqueString(), None, None, None)477 '', self.factory.getUniqueString(), None, None, None)
484 self.assertEqual(branch, check_default_stacked_on(branch))478 self.assertEqual(branch, check_default_stacked_on(branch))
485479
=== modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py'
--- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-21 22:44:02 +0000
+++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-07-28 22:53:45 +0000
@@ -410,17 +410,11 @@
410 message = "No such source package: 'ningnangnong'."410 message = "No such source package: 'ningnangnong'."
411 self.assertEqual(faults.NotFound(message), fault)411 self.assertEqual(faults.NotFound(message), fault)
412412
413 def test_initialMirrorRequest(self):
414 # The default 'next_mirror_time' for a newly created hosted branch
415 # should be None.
416 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
417 self.assertIs(None, branch.next_mirror_time)
418
419 def test_requestMirror(self):413 def test_requestMirror(self):
420 # requestMirror should set the next_mirror_time field to be the414 # requestMirror should set the next_mirror_time field to be the
421 # current time.415 # current time.
422 requester = self.factory.makePerson()416 requester = self.factory.makePerson()
423 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)417 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
424 self.codehosting_api.requestMirror(requester.id, branch.id)418 self.codehosting_api.requestMirror(requester.id, branch.id)
425 self.assertSqlAttributeEqualsDate(419 self.assertSqlAttributeEqualsDate(
426 branch, 'next_mirror_time', UTC_NOW)420 branch, 'next_mirror_time', UTC_NOW)
@@ -428,7 +422,8 @@
428 def test_requestMirror_private(self):422 def test_requestMirror_private(self):
429 # requestMirror can be used to request the mirror of a private branch.423 # requestMirror can be used to request the mirror of a private branch.
430 requester = self.factory.makePerson()424 requester = self.factory.makePerson()
431 branch = self.factory.makeAnyBranch(owner=requester, private=True)425 branch = self.factory.makeAnyBranch(
426 owner=requester, private=True, branch_type=BranchType.MIRRORED)
432 branch = removeSecurityProxy(branch)427 branch = removeSecurityProxy(branch)
433 self.codehosting_api.requestMirror(requester.id, branch.id)428 self.codehosting_api.requestMirror(requester.id, branch.id)
434 self.assertSqlAttributeEqualsDate(429 self.assertSqlAttributeEqualsDate(