Merge lp:~mwhudson/launchpad/no-hosted-area-remove-mirrorComplete 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-remove-mirrorComplete
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area-make-puller-call-branchChanged
Diff against target: 510 lines (+51/-209)
13 files modified
lib/lp/code/configure.zcml (+0/-1)
lib/lp/code/interfaces/branch.py (+0/-7)
lib/lp/code/interfaces/codehosting.py (+0/-24)
lib/lp/code/mail/tests/test_codehandler.py (+4/-2)
lib/lp/code/model/branch.py (+2/-19)
lib/lp/code/model/tests/test_branch.py (+6/-15)
lib/lp/code/model/tests/test_branchpuller.py (+4/-2)
lib/lp/code/model/tests/test_branchtarget.py (+10/-5)
lib/lp/code/stories/branches/xx-branch-mirror-failures.txt (+1/-1)
lib/lp/code/xmlrpc/codehosting.py (+2/-21)
lib/lp/code/xmlrpc/tests/test_codehosting.py (+11/-79)
lib/lp/codehosting/inmemory.py (+3/-21)
lib/lp/testing/factory.py (+8/-12)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-remove-mirrorComplete
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23892@code.launchpad.net

Description of the change

Hi Tim yet again!

This branch removes the now obsolete mirrorComplete branch method and also removes the long-obsolete 'startMirroring' method from the XML-RPC endpoint (it's still a branch method: acquireBranchToPull calls it).

Cheers,
mwh

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

We must be getting close now...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/configure.zcml'
--- lib/lp/code/configure.zcml 2010-04-27 02:05:59 +0000
+++ lib/lp/code/configure.zcml 2010-04-27 02:06:23 +0000
@@ -521,7 +521,6 @@
521 getPullURL521 getPullURL
522 requestMirror522 requestMirror
523 startMirroring523 startMirroring
524 mirrorComplete
525 mirrorFailed524 mirrorFailed
526 branch_format525 branch_format
527 repository_format526 repository_format
528527
=== modified file 'lib/lp/code/interfaces/branch.py'
--- lib/lp/code/interfaces/branch.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/interfaces/branch.py 2010-04-27 02:06:23 +0000
@@ -1105,13 +1105,6 @@
1105 branch.1105 branch.
1106 """1106 """
11071107
1108 def mirrorComplete(last_revision_id):
1109 """Signal that a mirror attempt has completed successfully.
1110
1111 :param last_revision_id: The revision ID of the tip of the mirrored
1112 branch.
1113 """
1114
1115 def mirrorFailed(reason):1108 def mirrorFailed(reason):
1116 """Signal that a mirror attempt failed.1109 """Signal that a mirror attempt failed.
11171110
11181111
=== modified file 'lib/lp/code/interfaces/codehosting.py'
--- lib/lp/code/interfaces/codehosting.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/interfaces/codehosting.py 2010-04-27 02:06:23 +0000
@@ -82,30 +82,6 @@
82 or (), the empty tuple, if there is no branch to pull.82 or (), the empty tuple, if there is no branch to pull.
83 """83 """
8484
85 def startMirroring(branchID):
86 """Notify Launchpad that the given branch has started mirroring.
87
88 The last_mirror_attempt field of the given branch record will be
89 updated appropriately.
90
91 :param branchID: The database ID of the given branch.
92 :returns: True if the branch status was successfully updated.
93 `NoBranchWithID` fault if there's no branch with the given id.
94 """
95
96 def mirrorComplete(branchID, lastRevisionID):
97 """Notify Launchpad that the branch has been successfully mirrored.
98
99 In the Launchpad database, the last_mirrored field will be updated to
100 match the last_mirror_attempt value, the mirror_failures counter will
101 be reset to zero and the next_mirror_time will be set to NULL.
102
103 :param branchID: The database ID of the given branch.
104 :param lastRevisionID: The last revision ID mirrored.
105 :returns: True if the branch status was successfully updated.
106 `NoBranchWithID` fault if there's no branch with the given id.
107 """
108
109 def mirrorFailed(branchID, reason):85 def mirrorFailed(branchID, reason):
110 """Notify Launchpad that the branch could not be mirrored.86 """Notify Launchpad that the branch could not be mirrored.
11187
11288
=== modified file 'lib/lp/code/mail/tests/test_codehandler.py'
--- lib/lp/code/mail/tests/test_codehandler.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/mail/tests/test_codehandler.py 2010-04-27 02:06:23 +0000
@@ -872,7 +872,8 @@
872 target_tree.commit('rev1')872 target_tree.commit('rev1')
873 # Make sure that the created branch has been mirrored.873 # Make sure that the created branch has been mirrored.
874 db_target_branch.startMirroring()874 db_target_branch.startMirroring()
875 db_target_branch.mirrorComplete('rev1')875 removeSecurityProxy(db_target_branch).branchChanged(
876 '', 'rev1', None, None, None)
876 source_tree = target_tree.bzrdir.sprout('source').open_workingtree()877 source_tree = target_tree.bzrdir.sprout('source').open_workingtree()
877 source_tree.commit('rev2')878 source_tree.commit('rev2')
878 message = self.factory.makeBundleMergeDirectiveEmail(879 message = self.factory.makeBundleMergeDirectiveEmail(
@@ -1000,7 +1001,8 @@
1000 target_tree.commit('rev1')1001 target_tree.commit('rev1')
1001 # Make sure that the created branch has been mirrored.1002 # Make sure that the created branch has been mirrored.
1002 db_target_branch.startMirroring()1003 db_target_branch.startMirroring()
1003 db_target_branch.mirrorComplete('rev1')1004 removeSecurityProxy(db_target_branch).branchChanged(
1005 '', 'rev1', None, None, None)
10041006
1005 db_source_branch, source_tree = self.create_branch_and_tree(1007 db_source_branch, source_tree = self.create_branch_and_tree(
1006 'lpsource', db_target_branch.product, hosted=True,1008 'lpsource', db_target_branch.product, hosted=True,
10071009
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/model/branch.py 2010-04-27 02:06:23 +0000
@@ -832,6 +832,8 @@
832 new_data_pushed = (832 new_data_pushed = (
833 self.branch_type in (BranchType.HOSTED, BranchType.IMPORTED)833 self.branch_type in (BranchType.HOSTED, BranchType.IMPORTED)
834 and self.next_mirror_time is not None)834 and self.next_mirror_time is not None)
835 # XXX 2010-04-22, MichaelHudson: This should really look for a branch
836 # scan job.
835 pulled_but_not_scanned = self.last_mirrored_id != self.last_scanned_id837 pulled_but_not_scanned = self.last_mirrored_id != self.last_scanned_id
836 pull_in_progress = (838 pull_in_progress = (
837 self.last_mirror_attempt is not None839 self.last_mirror_attempt is not None
@@ -931,25 +933,6 @@
931 self.branch_format = branch_format933 self.branch_format = branch_format
932 self.repository_format = repository_format934 self.repository_format = repository_format
933935
934 def mirrorComplete(self, last_revision_id):
935 """See `IBranch`."""
936 if self.branch_type == BranchType.REMOTE:
937 raise BranchTypeError(self.unique_name)
938 assert self.last_mirror_attempt != None, (
939 "startMirroring must be called before mirrorComplete.")
940 self.last_mirrored = self.last_mirror_attempt
941 self.mirror_failures = 0
942 self.mirror_status_message = None
943 if (self.next_mirror_time is None
944 and self.branch_type == BranchType.MIRRORED):
945 # No mirror was requested since we started mirroring.
946 increment = getUtility(IBranchPuller).MIRROR_TIME_INCREMENT
947 self.next_mirror_time = (
948 datetime.now(pytz.timezone('UTC')) + increment)
949 self.last_mirrored_id = last_revision_id
950 from lp.code.model.branchjob import BranchScanJob
951 BranchScanJob.create(self)
952
953 def mirrorFailed(self, reason):936 def mirrorFailed(self, reason):
954 """See `IBranch`."""937 """See `IBranch`."""
955 if self.branch_type == BranchType.REMOTE:938 if self.branch_type == BranchType.REMOTE:
956939
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/model/tests/test_branch.py 2010-04-27 02:06:23 +0000
@@ -1794,28 +1794,18 @@
1794 branch = self.factory.makeAnyBranch()1794 branch = self.factory.makeAnyBranch()
1795 branch.startMirroring()1795 branch.startMirroring()
1796 rev_id = self.factory.getUniqueString('rev-id')1796 rev_id = self.factory.getUniqueString('rev-id')
1797 branch.mirrorComplete(rev_id)1797 removeSecurityProxy(branch).branchChanged(
1798 '', rev_id, None, None, None)
1798 self.assertEqual(True, branch.pending_writes)1799 self.assertEqual(True, branch.pending_writes)
17991800
1800 def test_mirrorComplete_creates_scan_job(self):
1801 # After a branch has been pulled, it should have created a
1802 # BranchScanJob to complete the process.
1803 branch = self.factory.makeAnyBranch()
1804 branch.startMirroring()
1805 rev_id = self.factory.getUniqueString('rev-id')
1806 branch.mirrorComplete(rev_id)
1807
1808 store = Store.of(branch)
1809 scan_jobs = store.find(BranchJob, job_type=BranchJobType.SCAN_BRANCH)
1810 self.assertEqual(scan_jobs.count(), 1)
1811
1812 def test_pulled_and_scanned(self):1801 def test_pulled_and_scanned(self):
1813 # If a branch has been pulled and scanned, then there are no pending1802 # If a branch has been pulled and scanned, then there are no pending
1814 # writes.1803 # writes.
1815 branch = self.factory.makeAnyBranch()1804 branch = self.factory.makeAnyBranch()
1816 branch.startMirroring()1805 branch.startMirroring()
1817 rev_id = self.factory.getUniqueString('rev-id')1806 rev_id = self.factory.getUniqueString('rev-id')
1818 branch.mirrorComplete(rev_id)1807 removeSecurityProxy(branch).branchChanged(
1808 '', rev_id, None, None, None)
1819 # Cheat! The actual API for marking a branch as scanned is1809 # Cheat! The actual API for marking a branch as scanned is
1820 # updateScannedDetails. That requires a revision in the database1810 # updateScannedDetails. That requires a revision in the database
1821 # though.1811 # though.
@@ -1835,7 +1825,8 @@
1835 branch = self.factory.makeAnyBranch()1825 branch = self.factory.makeAnyBranch()
1836 branch.startMirroring()1826 branch.startMirroring()
1837 rev_id = self.factory.getUniqueString('rev-id')1827 rev_id = self.factory.getUniqueString('rev-id')
1838 branch.mirrorComplete(rev_id)1828 removeSecurityProxy(branch).branchChanged(
1829 '', rev_id, None, None, None)
1839 # Cheat! The actual API for marking a branch as scanned is1830 # Cheat! The actual API for marking a branch as scanned is
1840 # updateScannedDetails. That requires a revision in the database1831 # updateScannedDetails. That requires a revision in the database
1841 # though.1832 # though.
18421833
=== modified file 'lib/lp/code/model/tests/test_branchpuller.py'
--- lib/lp/code/model/tests/test_branchpuller.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/model/tests/test_branchpuller.py 2010-04-27 02:06:23 +0000
@@ -84,7 +84,8 @@
84 branch.requestMirror()84 branch.requestMirror()
85 transaction.commit()85 transaction.commit()
86 branch.startMirroring()86 branch.startMirroring()
87 branch.mirrorComplete('rev1')87 removeSecurityProxy(branch).branchChanged(
88 '', 'rev1', None, None, None)
88 self.assertEqual(None, branch.next_mirror_time)89 self.assertEqual(None, branch.next_mirror_time)
8990
90 def test_mirrorFailureResetsMirrorRequest(self):91 def test_mirrorFailureResetsMirrorRequest(self):
@@ -152,7 +153,8 @@
152 branch.requestMirror()153 branch.requestMirror()
153 transaction.commit()154 transaction.commit()
154 branch.startMirroring()155 branch.startMirroring()
155 branch.mirrorComplete('rev1')156 removeSecurityProxy(branch).branchChanged(
157 '', 'rev1', None, None, None)
156 self.assertInFuture(branch.next_mirror_time, self.increment)158 self.assertInFuture(branch.next_mirror_time, self.increment)
157 self.assertEqual(0, branch.mirror_failures)159 self.assertEqual(0, branch.mirror_failures)
158160
159161
=== modified file 'lib/lp/code/model/tests/test_branchtarget.py'
--- lib/lp/code/model/tests/test_branchtarget.py 2010-04-13 15:08:13 +0000
+++ lib/lp/code/model/tests/test_branchtarget.py 2010-04-27 02:06:23 +0000
@@ -108,7 +108,8 @@
108 default_branch = self.factory.makePackageBranch(108 default_branch = self.factory.makePackageBranch(
109 sourcepackage=development_package)109 sourcepackage=development_package)
110 default_branch.startMirroring()110 default_branch.startMirroring()
111 default_branch.mirrorComplete(self.factory.getUniqueString())111 removeSecurityProxy(default_branch).branchChanged(
112 '', self.factory.getUniqueString(), None, None, None)
112 ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches113 ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches
113 run_with_login(114 run_with_login(
114 ubuntu_branches.teamowner,115 ubuntu_branches.teamowner,
@@ -347,7 +348,8 @@
347 branch = self.factory.makeProductBranch(product=self.original)348 branch = self.factory.makeProductBranch(product=self.original)
348 self._setDevelopmentFocus(self.original, branch)349 self._setDevelopmentFocus(self.original, branch)
349 branch.startMirroring()350 branch.startMirroring()
350 branch.mirrorComplete('rev1')351 removeSecurityProxy(branch).branchChanged(
352 '', 'rev1', None, None, None)
351 target = IBranchTarget(self.original)353 target = IBranchTarget(self.original)
352 self.assertEqual(branch, target.default_stacked_on_branch)354 self.assertEqual(branch, target.default_stacked_on_branch)
353355
@@ -450,7 +452,8 @@
450 # life.452 # life.
451 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)453 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
452 branch.startMirroring()454 branch.startMirroring()
453 branch.mirrorComplete(self.factory.getUniqueString())455 removeSecurityProxy(branch).branchChanged(
456 '', self.factory.getUniqueString(), None, None, None)
454 removeSecurityProxy(branch).branch_type = BranchType.REMOTE457 removeSecurityProxy(branch).branch_type = BranchType.REMOTE
455 self.assertIs(None, check_default_stacked_on(branch))458 self.assertIs(None, check_default_stacked_on(branch))
456459
@@ -466,7 +469,8 @@
466 branch = self.factory.makeAnyBranch(private=True)469 branch = self.factory.makeAnyBranch(private=True)
467 naked_branch = removeSecurityProxy(branch)470 naked_branch = removeSecurityProxy(branch)
468 naked_branch.startMirroring()471 naked_branch.startMirroring()
469 naked_branch.mirrorComplete(self.factory.getUniqueString())472 naked_branch.branchChanged(
473 '', self.factory.getUniqueString(), None, None, None)
470 self.assertIs(None, check_default_stacked_on(branch))474 self.assertIs(None, check_default_stacked_on(branch))
471475
472 def test_been_mirrored(self):476 def test_been_mirrored(self):
@@ -475,7 +479,8 @@
475 # futile.479 # futile.
476 branch = self.factory.makeAnyBranch()480 branch = self.factory.makeAnyBranch()
477 branch.startMirroring()481 branch.startMirroring()
478 branch.mirrorComplete('rev1')482 removeSecurityProxy(branch).branchChanged(
483 '', self.factory.getUniqueString(), None, None, None)
479 self.assertEqual(branch, check_default_stacked_on(branch))484 self.assertEqual(branch, check_default_stacked_on(branch))
480485
481486
482487
=== modified file 'lib/lp/code/stories/branches/xx-branch-mirror-failures.txt'
--- lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2009-06-12 16:36:02 +0000
+++ lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2010-04-27 02:06:23 +0000
@@ -163,7 +163,7 @@
163 >>> login(ANONYMOUS)163 >>> login(ANONYMOUS)
164 >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name)164 >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name)
165 >>> mirror_branch.startMirroring()165 >>> mirror_branch.startMirroring()
166 >>> mirror_branch.mirrorComplete('some-revision-id')166 >>> mirror_branch.branchChanged('', 'some-revision-id', None, None, None)
167 >>> logout()167 >>> logout()
168168
169 >>> browser.open(branch_location)169 >>> browser.open(branch_location)
170170
=== modified file 'lib/lp/code/xmlrpc/codehosting.py'
--- lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:06:23 +0000
@@ -123,22 +123,13 @@
123 else:123 else:
124 return ()124 return ()
125125
126 def mirrorComplete(self, branch_id, last_revision_id):
127 """See `ICodehostingAPI`."""
128 branch = getUtility(IBranchLookup).get(branch_id)
129 if branch is None:
130 return faults.NoBranchWithID(branch_id)
131 # See comment in startMirroring.
132 branch = removeSecurityProxy(branch)
133 branch.mirrorComplete(last_revision_id)
134 return True
135
136 def mirrorFailed(self, branch_id, reason):126 def mirrorFailed(self, branch_id, reason):
137 """See `ICodehostingAPI`."""127 """See `ICodehostingAPI`."""
138 branch = getUtility(IBranchLookup).get(branch_id)128 branch = getUtility(IBranchLookup).get(branch_id)
139 if branch is None:129 if branch is None:
140 return faults.NoBranchWithID(branch_id)130 return faults.NoBranchWithID(branch_id)
141 # See comment in startMirroring.131 # The puller runs as no user and may pull private branches. We need to
132 # bypass Zope's security proxy to set the mirroring information.
142 removeSecurityProxy(branch).mirrorFailed(reason)133 removeSecurityProxy(branch).mirrorFailed(reason)
143 return True134 return True
144135
@@ -151,16 +142,6 @@
151 date_completed=date_completed, hostname=hostname)142 date_completed=date_completed, hostname=hostname)
152 return True143 return True
153144
154 def startMirroring(self, branch_id):
155 """See `ICodehostingAPI`."""
156 branch = getUtility(IBranchLookup).get(branch_id)
157 if branch is None:
158 return faults.NoBranchWithID(branch_id)
159 # The puller runs as no user and may pull private branches. We need to
160 # bypass Zope's security proxy to set the mirroring information.
161 removeSecurityProxy(branch).startMirroring()
162 return True
163
164 def createBranch(self, login_id, branch_path):145 def createBranch(self, login_id, branch_path):
165 """See `ICodehostingAPI`."""146 """See `ICodehostingAPI`."""
166 def create_branch(requester):147 def create_branch(requester):
167148
=== modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py'
--- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:05:59 +0000
+++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:06:23 +0000
@@ -179,34 +179,17 @@
179 self.assertIs(self.branch_lookup.get(branch_id), None)179 self.assertIs(self.branch_lookup.get(branch_id), None)
180 return branch_id180 return branch_id
181181
182 def test_startMirroring(self):
183 # startMirroring updates last_mirror_attempt to 'now', leaves
184 # last_mirrored alone and returns True when passed the id of an
185 # existing branch.
186 branch = self.factory.makeAnyBranch()
187 self.assertUnmirrored(branch)
188
189 success = self.codehosting_api.startMirroring(branch.id)
190 self.assertEqual(success, True)
191
192 self.assertSqlAttributeEqualsDate(
193 branch, 'last_mirror_attempt', UTC_NOW)
194 self.assertIs(None, branch.last_mirrored)
195
196 def test_startMirroringInvalidBranch(self):
197 # startMirroring returns False when given a branch id which does not
198 # exist.
199 invalid_id = self.getUnusedBranchID()
200 fault = self.codehosting_api.startMirroring(invalid_id)
201 self.assertEqual(faults.NoBranchWithID(invalid_id), fault)
202
203 def test_mirrorFailed(self):182 def test_mirrorFailed(self):
204 branch = self.factory.makeAnyBranch()183 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
205 self.assertUnmirrored(branch)184 self.assertUnmirrored(branch)
206185
207 self.codehosting_api.startMirroring(branch.id)186 branch.requestMirror()
187 self.assertEquals(
188 branch.id, self.codehosting_api.acquireBranchToPull([])[0])
189
208 failure_message = self.factory.getUniqueString()190 failure_message = self.factory.getUniqueString()
209 success = self.codehosting_api.mirrorFailed(branch.id, failure_message)191 success = self.codehosting_api.mirrorFailed(
192 branch.id, failure_message)
210 self.assertEqual(True, success)193 self.assertEqual(True, success)
211 self.assertMirrorFailed(branch, failure_message)194 self.assertMirrorFailed(branch, failure_message)
212195
@@ -216,60 +199,6 @@
216 fault = self.codehosting_api.mirrorFailed(branch_id, failure_message)199 fault = self.codehosting_api.mirrorFailed(branch_id, failure_message)
217 self.assertEqual(faults.NoBranchWithID(branch_id), fault)200 self.assertEqual(faults.NoBranchWithID(branch_id), fault)
218201
219 def test_mirrorComplete(self):
220 # mirrorComplete marks the branch as having been successfully
221 # mirrored, with no failures and no status message.
222 branch = self.factory.makeAnyBranch()
223 self.assertUnmirrored(branch)
224
225 self.codehosting_api.startMirroring(branch.id)
226 revision_id = self.factory.getUniqueString()
227 success = self.codehosting_api.mirrorComplete(branch.id, revision_id)
228 self.assertEqual(True, success)
229 self.assertMirrorSucceeded(branch, revision_id)
230
231 def test_mirrorCompleteWithNoBranchID(self):
232 # mirrorComplete returns a Fault if there's no branch with the given
233 # ID.
234 branch_id = self.getUnusedBranchID()
235 fault = self.codehosting_api.mirrorComplete(
236 branch_id, self.factory.getUniqueString())
237 self.assertEqual(faults.NoBranchWithID(branch_id), fault)
238
239 def test_mirrorComplete_resets_failure_count(self):
240 # mirrorComplete marks the branch as successfully mirrored and removes
241 # all memory of failure.
242
243 # First, mark the branch as failed.
244 branch = self.factory.makeAnyBranch()
245 self.codehosting_api.startMirroring(branch.id)
246 failure_message = self.factory.getUniqueString()
247 self.codehosting_api.mirrorFailed(branch.id, failure_message)
248 self.assertMirrorFailed(branch, failure_message)
249
250 # Start and successfully finish a mirror.
251 self.codehosting_api.startMirroring(branch.id)
252 revision_id = self.factory.getUniqueString()
253 self.codehosting_api.mirrorComplete(branch.id, revision_id)
254
255 # Confirm that it succeeded.
256 self.assertMirrorSucceeded(branch, revision_id)
257
258 def test_mirrorComplete_resets_mirror_request(self):
259 # After successfully mirroring a hosted branch, next_mirror_time
260 # should be set to NULL.
261 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
262
263 # Request that branch be mirrored. This sets next_mirror_time.
264 branch.requestMirror()
265
266 # Simulate successfully mirroring the branch.
267 self.codehosting_api.startMirroring(branch.id)
268 self.codehosting_api.mirrorComplete(
269 branch.id, self.factory.getUniqueString())
270
271 self.assertIs(None, branch.next_mirror_time)
272
273 def test_recordSuccess(self):202 def test_recordSuccess(self):
274 # recordSuccess must insert the given data into ScriptActivity.203 # recordSuccess must insert the given data into ScriptActivity.
275 started = datetime.datetime(2007, 07, 05, 19, 32, 1, tzinfo=UTC)204 started = datetime.datetime(2007, 07, 05, 19, 32, 1, tzinfo=UTC)
@@ -939,7 +868,10 @@
939868
940 def startMirroring(self, branch):869 def startMirroring(self, branch):
941 """See `AcquireBranchToPullTests`."""870 """See `AcquireBranchToPullTests`."""
942 self.codehosting_api.startMirroring(branch.id)871 # This is a bit random, but it works. acquireBranchToPull marks the
872 # branch it returns as started mirroring, but we should check that the
873 # one we want is returned...
874 self.assertBranchIsAquired(branch, branch.branch_type)
943875
944 def test_branch_type_returned_mirrored(self):876 def test_branch_type_returned_mirrored(self):
945 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)877 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
946878
=== modified file 'lib/lp/codehosting/inmemory.py'
--- lib/lp/codehosting/inmemory.py 2010-04-27 02:05:59 +0000
+++ lib/lp/codehosting/inmemory.py 2010-04-27 02:06:23 +0000
@@ -480,7 +480,9 @@
480 key=operator.attrgetter('next_mirror_time'))480 key=operator.attrgetter('next_mirror_time'))
481 if branches:481 if branches:
482 branch = branches[-1]482 branch = branches[-1]
483 self.startMirroring(branch.id)483 # Mark it as started mirroring.
484 branch.last_mirror_attempt = UTC_NOW
485 branch.next_mirror_time = None
484 default_branch = branch.target.default_stacked_on_branch486 default_branch = branch.target.default_stacked_on_branch
485 if default_branch is None:487 if default_branch is None:
486 default_branch_name = ''488 default_branch_name = ''
@@ -494,26 +496,6 @@
494 else:496 else:
495 return ()497 return ()
496498
497 def startMirroring(self, branch_id):
498 branch = self._branch_set.get(branch_id)
499 if branch is None:
500 return faults.NoBranchWithID(branch_id)
501 branch.last_mirror_attempt = UTC_NOW
502 branch.next_mirror_time = None
503 return True
504
505 def mirrorComplete(self, branch_id, last_revision_id):
506 branch = self._branch_set.get(branch_id)
507 if branch is None:
508 return faults.NoBranchWithID(branch_id)
509 branch.last_mirrored_id = last_revision_id
510 branch.last_mirrored = UTC_NOW
511 branch.mirror_failures = 0
512 for stacked_branch in self._branch_set:
513 if stacked_branch.stacked_on is branch:
514 stacked_branch.requestMirror()
515 return True
516
517 def mirrorFailed(self, branch_id, reason):499 def mirrorFailed(self, branch_id, reason):
518 branch = self._branch_set.get(branch_id)500 branch = self._branch_set.get(branch_id)
519 if branch is None:501 if branch is None:
520502
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-04-27 02:05:59 +0000
+++ lib/lp/testing/factory.py 2010-04-27 02:06:23 +0000
@@ -863,13 +863,10 @@
863 """863 """
864 if branch is None:864 if branch is None:
865 branch = self.makeBranch(product=product)865 branch = self.makeBranch(product=product)
866 # 'branch' might be private, so we remove the security proxy to get at866 # We just remove the security proxies to be able to change the objects
867 # the methods.867 # here.
868 naked_branch = removeSecurityProxy(branch)868 removeSecurityProxy(branch).branchChanged(
869 naked_branch.startMirroring()869 '', 'rev1', None, None, None)
870 naked_branch.mirrorComplete('rev1')
871 # Likewise, we might not have permission to set the branch of the
872 # development focus series.
873 naked_series = removeSecurityProxy(product.development_focus)870 naked_series = removeSecurityProxy(product.development_focus)
874 naked_series.branch = branch871 naked_series.branch = branch
875 return branch872 return branch
@@ -881,11 +878,10 @@
881 :param branch: The branch that should be the default stacked-on878 :param branch: The branch that should be the default stacked-on
882 branch.879 branch.
883 """880 """
884 # 'branch' might be private, so we remove the security proxy to get at881 # We just remove the security proxies to be able to change the branch
885 # the methods.882 # here.
886 naked_branch = removeSecurityProxy(branch)883 removeSecurityProxy(branch).branchChanged(
887 naked_branch.startMirroring()884 '', 'rev1', None, None, None)
888 naked_branch.mirrorComplete('rev1')
889 ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches885 ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches
890 run_with_login(886 run_with_login(
891 ubuntu_branches.teamowner,887 ubuntu_branches.teamowner,