Merge lp:~mwhudson/launchpad/no-hosted-area-remove-mirrorComplete into lp:launchpad
- no-hosted-area-remove-mirrorComplete
- Merge into devel
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Review via email:
|
Commit message
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.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/lp/code/configure.zcml' | |||
2 | --- lib/lp/code/configure.zcml 2010-04-27 02:05:59 +0000 | |||
3 | +++ lib/lp/code/configure.zcml 2010-04-27 02:06:23 +0000 | |||
4 | @@ -521,7 +521,6 @@ | |||
5 | 521 | getPullURL | 521 | getPullURL |
6 | 522 | requestMirror | 522 | requestMirror |
7 | 523 | startMirroring | 523 | startMirroring |
8 | 524 | mirrorComplete | ||
9 | 525 | mirrorFailed | 524 | mirrorFailed |
10 | 526 | branch_format | 525 | branch_format |
11 | 527 | repository_format | 526 | repository_format |
12 | 528 | 527 | ||
13 | === modified file 'lib/lp/code/interfaces/branch.py' | |||
14 | --- lib/lp/code/interfaces/branch.py 2010-04-27 02:05:59 +0000 | |||
15 | +++ lib/lp/code/interfaces/branch.py 2010-04-27 02:06:23 +0000 | |||
16 | @@ -1105,13 +1105,6 @@ | |||
17 | 1105 | branch. | 1105 | branch. |
18 | 1106 | """ | 1106 | """ |
19 | 1107 | 1107 | ||
20 | 1108 | def mirrorComplete(last_revision_id): | ||
21 | 1109 | """Signal that a mirror attempt has completed successfully. | ||
22 | 1110 | |||
23 | 1111 | :param last_revision_id: The revision ID of the tip of the mirrored | ||
24 | 1112 | branch. | ||
25 | 1113 | """ | ||
26 | 1114 | |||
27 | 1115 | def mirrorFailed(reason): | 1108 | def mirrorFailed(reason): |
28 | 1116 | """Signal that a mirror attempt failed. | 1109 | """Signal that a mirror attempt failed. |
29 | 1117 | 1110 | ||
30 | 1118 | 1111 | ||
31 | === modified file 'lib/lp/code/interfaces/codehosting.py' | |||
32 | --- lib/lp/code/interfaces/codehosting.py 2010-04-27 02:05:59 +0000 | |||
33 | +++ lib/lp/code/interfaces/codehosting.py 2010-04-27 02:06:23 +0000 | |||
34 | @@ -82,30 +82,6 @@ | |||
35 | 82 | or (), the empty tuple, if there is no branch to pull. | 82 | or (), the empty tuple, if there is no branch to pull. |
36 | 83 | """ | 83 | """ |
37 | 84 | 84 | ||
38 | 85 | def startMirroring(branchID): | ||
39 | 86 | """Notify Launchpad that the given branch has started mirroring. | ||
40 | 87 | |||
41 | 88 | The last_mirror_attempt field of the given branch record will be | ||
42 | 89 | updated appropriately. | ||
43 | 90 | |||
44 | 91 | :param branchID: The database ID of the given branch. | ||
45 | 92 | :returns: True if the branch status was successfully updated. | ||
46 | 93 | `NoBranchWithID` fault if there's no branch with the given id. | ||
47 | 94 | """ | ||
48 | 95 | |||
49 | 96 | def mirrorComplete(branchID, lastRevisionID): | ||
50 | 97 | """Notify Launchpad that the branch has been successfully mirrored. | ||
51 | 98 | |||
52 | 99 | In the Launchpad database, the last_mirrored field will be updated to | ||
53 | 100 | match the last_mirror_attempt value, the mirror_failures counter will | ||
54 | 101 | be reset to zero and the next_mirror_time will be set to NULL. | ||
55 | 102 | |||
56 | 103 | :param branchID: The database ID of the given branch. | ||
57 | 104 | :param lastRevisionID: The last revision ID mirrored. | ||
58 | 105 | :returns: True if the branch status was successfully updated. | ||
59 | 106 | `NoBranchWithID` fault if there's no branch with the given id. | ||
60 | 107 | """ | ||
61 | 108 | |||
62 | 109 | def mirrorFailed(branchID, reason): | 85 | def mirrorFailed(branchID, reason): |
63 | 110 | """Notify Launchpad that the branch could not be mirrored. | 86 | """Notify Launchpad that the branch could not be mirrored. |
64 | 111 | 87 | ||
65 | 112 | 88 | ||
66 | === modified file 'lib/lp/code/mail/tests/test_codehandler.py' | |||
67 | --- lib/lp/code/mail/tests/test_codehandler.py 2010-04-27 02:05:59 +0000 | |||
68 | +++ lib/lp/code/mail/tests/test_codehandler.py 2010-04-27 02:06:23 +0000 | |||
69 | @@ -872,7 +872,8 @@ | |||
70 | 872 | target_tree.commit('rev1') | 872 | target_tree.commit('rev1') |
71 | 873 | # Make sure that the created branch has been mirrored. | 873 | # Make sure that the created branch has been mirrored. |
72 | 874 | db_target_branch.startMirroring() | 874 | db_target_branch.startMirroring() |
74 | 875 | db_target_branch.mirrorComplete('rev1') | 875 | removeSecurityProxy(db_target_branch).branchChanged( |
75 | 876 | '', 'rev1', None, None, None) | ||
76 | 876 | source_tree = target_tree.bzrdir.sprout('source').open_workingtree() | 877 | source_tree = target_tree.bzrdir.sprout('source').open_workingtree() |
77 | 877 | source_tree.commit('rev2') | 878 | source_tree.commit('rev2') |
78 | 878 | message = self.factory.makeBundleMergeDirectiveEmail( | 879 | message = self.factory.makeBundleMergeDirectiveEmail( |
79 | @@ -1000,7 +1001,8 @@ | |||
80 | 1000 | target_tree.commit('rev1') | 1001 | target_tree.commit('rev1') |
81 | 1001 | # Make sure that the created branch has been mirrored. | 1002 | # Make sure that the created branch has been mirrored. |
82 | 1002 | db_target_branch.startMirroring() | 1003 | db_target_branch.startMirroring() |
84 | 1003 | db_target_branch.mirrorComplete('rev1') | 1004 | removeSecurityProxy(db_target_branch).branchChanged( |
85 | 1005 | '', 'rev1', None, None, None) | ||
86 | 1004 | 1006 | ||
87 | 1005 | db_source_branch, source_tree = self.create_branch_and_tree( | 1007 | db_source_branch, source_tree = self.create_branch_and_tree( |
88 | 1006 | 'lpsource', db_target_branch.product, hosted=True, | 1008 | 'lpsource', db_target_branch.product, hosted=True, |
89 | 1007 | 1009 | ||
90 | === modified file 'lib/lp/code/model/branch.py' | |||
91 | --- lib/lp/code/model/branch.py 2010-04-27 02:05:59 +0000 | |||
92 | +++ lib/lp/code/model/branch.py 2010-04-27 02:06:23 +0000 | |||
93 | @@ -832,6 +832,8 @@ | |||
94 | 832 | new_data_pushed = ( | 832 | new_data_pushed = ( |
95 | 833 | self.branch_type in (BranchType.HOSTED, BranchType.IMPORTED) | 833 | self.branch_type in (BranchType.HOSTED, BranchType.IMPORTED) |
96 | 834 | and self.next_mirror_time is not None) | 834 | and self.next_mirror_time is not None) |
97 | 835 | # XXX 2010-04-22, MichaelHudson: This should really look for a branch | ||
98 | 836 | # scan job. | ||
99 | 835 | pulled_but_not_scanned = self.last_mirrored_id != self.last_scanned_id | 837 | pulled_but_not_scanned = self.last_mirrored_id != self.last_scanned_id |
100 | 836 | pull_in_progress = ( | 838 | pull_in_progress = ( |
101 | 837 | self.last_mirror_attempt is not None | 839 | self.last_mirror_attempt is not None |
102 | @@ -931,25 +933,6 @@ | |||
103 | 931 | self.branch_format = branch_format | 933 | self.branch_format = branch_format |
104 | 932 | self.repository_format = repository_format | 934 | self.repository_format = repository_format |
105 | 933 | 935 | ||
106 | 934 | def mirrorComplete(self, last_revision_id): | ||
107 | 935 | """See `IBranch`.""" | ||
108 | 936 | if self.branch_type == BranchType.REMOTE: | ||
109 | 937 | raise BranchTypeError(self.unique_name) | ||
110 | 938 | assert self.last_mirror_attempt != None, ( | ||
111 | 939 | "startMirroring must be called before mirrorComplete.") | ||
112 | 940 | self.last_mirrored = self.last_mirror_attempt | ||
113 | 941 | self.mirror_failures = 0 | ||
114 | 942 | self.mirror_status_message = None | ||
115 | 943 | if (self.next_mirror_time is None | ||
116 | 944 | and self.branch_type == BranchType.MIRRORED): | ||
117 | 945 | # No mirror was requested since we started mirroring. | ||
118 | 946 | increment = getUtility(IBranchPuller).MIRROR_TIME_INCREMENT | ||
119 | 947 | self.next_mirror_time = ( | ||
120 | 948 | datetime.now(pytz.timezone('UTC')) + increment) | ||
121 | 949 | self.last_mirrored_id = last_revision_id | ||
122 | 950 | from lp.code.model.branchjob import BranchScanJob | ||
123 | 951 | BranchScanJob.create(self) | ||
124 | 952 | |||
125 | 953 | def mirrorFailed(self, reason): | 936 | def mirrorFailed(self, reason): |
126 | 954 | """See `IBranch`.""" | 937 | """See `IBranch`.""" |
127 | 955 | if self.branch_type == BranchType.REMOTE: | 938 | if self.branch_type == BranchType.REMOTE: |
128 | 956 | 939 | ||
129 | === modified file 'lib/lp/code/model/tests/test_branch.py' | |||
130 | --- lib/lp/code/model/tests/test_branch.py 2010-04-27 02:05:59 +0000 | |||
131 | +++ lib/lp/code/model/tests/test_branch.py 2010-04-27 02:06:23 +0000 | |||
132 | @@ -1794,28 +1794,18 @@ | |||
133 | 1794 | branch = self.factory.makeAnyBranch() | 1794 | branch = self.factory.makeAnyBranch() |
134 | 1795 | branch.startMirroring() | 1795 | branch.startMirroring() |
135 | 1796 | rev_id = self.factory.getUniqueString('rev-id') | 1796 | rev_id = self.factory.getUniqueString('rev-id') |
137 | 1797 | branch.mirrorComplete(rev_id) | 1797 | removeSecurityProxy(branch).branchChanged( |
138 | 1798 | '', rev_id, None, None, None) | ||
139 | 1798 | self.assertEqual(True, branch.pending_writes) | 1799 | self.assertEqual(True, branch.pending_writes) |
140 | 1799 | 1800 | ||
141 | 1800 | def test_mirrorComplete_creates_scan_job(self): | ||
142 | 1801 | # After a branch has been pulled, it should have created a | ||
143 | 1802 | # BranchScanJob to complete the process. | ||
144 | 1803 | branch = self.factory.makeAnyBranch() | ||
145 | 1804 | branch.startMirroring() | ||
146 | 1805 | rev_id = self.factory.getUniqueString('rev-id') | ||
147 | 1806 | branch.mirrorComplete(rev_id) | ||
148 | 1807 | |||
149 | 1808 | store = Store.of(branch) | ||
150 | 1809 | scan_jobs = store.find(BranchJob, job_type=BranchJobType.SCAN_BRANCH) | ||
151 | 1810 | self.assertEqual(scan_jobs.count(), 1) | ||
152 | 1811 | |||
153 | 1812 | def test_pulled_and_scanned(self): | 1801 | def test_pulled_and_scanned(self): |
154 | 1813 | # If a branch has been pulled and scanned, then there are no pending | 1802 | # If a branch has been pulled and scanned, then there are no pending |
155 | 1814 | # writes. | 1803 | # writes. |
156 | 1815 | branch = self.factory.makeAnyBranch() | 1804 | branch = self.factory.makeAnyBranch() |
157 | 1816 | branch.startMirroring() | 1805 | branch.startMirroring() |
158 | 1817 | rev_id = self.factory.getUniqueString('rev-id') | 1806 | rev_id = self.factory.getUniqueString('rev-id') |
160 | 1818 | branch.mirrorComplete(rev_id) | 1807 | removeSecurityProxy(branch).branchChanged( |
161 | 1808 | '', rev_id, None, None, None) | ||
162 | 1819 | # Cheat! The actual API for marking a branch as scanned is | 1809 | # Cheat! The actual API for marking a branch as scanned is |
163 | 1820 | # updateScannedDetails. That requires a revision in the database | 1810 | # updateScannedDetails. That requires a revision in the database |
164 | 1821 | # though. | 1811 | # though. |
165 | @@ -1835,7 +1825,8 @@ | |||
166 | 1835 | branch = self.factory.makeAnyBranch() | 1825 | branch = self.factory.makeAnyBranch() |
167 | 1836 | branch.startMirroring() | 1826 | branch.startMirroring() |
168 | 1837 | rev_id = self.factory.getUniqueString('rev-id') | 1827 | rev_id = self.factory.getUniqueString('rev-id') |
170 | 1838 | branch.mirrorComplete(rev_id) | 1828 | removeSecurityProxy(branch).branchChanged( |
171 | 1829 | '', rev_id, None, None, None) | ||
172 | 1839 | # Cheat! The actual API for marking a branch as scanned is | 1830 | # Cheat! The actual API for marking a branch as scanned is |
173 | 1840 | # updateScannedDetails. That requires a revision in the database | 1831 | # updateScannedDetails. That requires a revision in the database |
174 | 1841 | # though. | 1832 | # though. |
175 | 1842 | 1833 | ||
176 | === modified file 'lib/lp/code/model/tests/test_branchpuller.py' | |||
177 | --- lib/lp/code/model/tests/test_branchpuller.py 2010-04-27 02:05:59 +0000 | |||
178 | +++ lib/lp/code/model/tests/test_branchpuller.py 2010-04-27 02:06:23 +0000 | |||
179 | @@ -84,7 +84,8 @@ | |||
180 | 84 | branch.requestMirror() | 84 | branch.requestMirror() |
181 | 85 | transaction.commit() | 85 | transaction.commit() |
182 | 86 | branch.startMirroring() | 86 | branch.startMirroring() |
184 | 87 | branch.mirrorComplete('rev1') | 87 | removeSecurityProxy(branch).branchChanged( |
185 | 88 | '', 'rev1', None, None, None) | ||
186 | 88 | self.assertEqual(None, branch.next_mirror_time) | 89 | self.assertEqual(None, branch.next_mirror_time) |
187 | 89 | 90 | ||
188 | 90 | def test_mirrorFailureResetsMirrorRequest(self): | 91 | def test_mirrorFailureResetsMirrorRequest(self): |
189 | @@ -152,7 +153,8 @@ | |||
190 | 152 | branch.requestMirror() | 153 | branch.requestMirror() |
191 | 153 | transaction.commit() | 154 | transaction.commit() |
192 | 154 | branch.startMirroring() | 155 | branch.startMirroring() |
194 | 155 | branch.mirrorComplete('rev1') | 156 | removeSecurityProxy(branch).branchChanged( |
195 | 157 | '', 'rev1', None, None, None) | ||
196 | 156 | self.assertInFuture(branch.next_mirror_time, self.increment) | 158 | self.assertInFuture(branch.next_mirror_time, self.increment) |
197 | 157 | self.assertEqual(0, branch.mirror_failures) | 159 | self.assertEqual(0, branch.mirror_failures) |
198 | 158 | 160 | ||
199 | 159 | 161 | ||
200 | === modified file 'lib/lp/code/model/tests/test_branchtarget.py' | |||
201 | --- lib/lp/code/model/tests/test_branchtarget.py 2010-04-13 15:08:13 +0000 | |||
202 | +++ lib/lp/code/model/tests/test_branchtarget.py 2010-04-27 02:06:23 +0000 | |||
203 | @@ -108,7 +108,8 @@ | |||
204 | 108 | default_branch = self.factory.makePackageBranch( | 108 | default_branch = self.factory.makePackageBranch( |
205 | 109 | sourcepackage=development_package) | 109 | sourcepackage=development_package) |
206 | 110 | default_branch.startMirroring() | 110 | default_branch.startMirroring() |
208 | 111 | default_branch.mirrorComplete(self.factory.getUniqueString()) | 111 | removeSecurityProxy(default_branch).branchChanged( |
209 | 112 | '', self.factory.getUniqueString(), None, None, None) | ||
210 | 112 | ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches | 113 | ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches |
211 | 113 | run_with_login( | 114 | run_with_login( |
212 | 114 | ubuntu_branches.teamowner, | 115 | ubuntu_branches.teamowner, |
213 | @@ -347,7 +348,8 @@ | |||
214 | 347 | branch = self.factory.makeProductBranch(product=self.original) | 348 | branch = self.factory.makeProductBranch(product=self.original) |
215 | 348 | self._setDevelopmentFocus(self.original, branch) | 349 | self._setDevelopmentFocus(self.original, branch) |
216 | 349 | branch.startMirroring() | 350 | branch.startMirroring() |
218 | 350 | branch.mirrorComplete('rev1') | 351 | removeSecurityProxy(branch).branchChanged( |
219 | 352 | '', 'rev1', None, None, None) | ||
220 | 351 | target = IBranchTarget(self.original) | 353 | target = IBranchTarget(self.original) |
221 | 352 | self.assertEqual(branch, target.default_stacked_on_branch) | 354 | self.assertEqual(branch, target.default_stacked_on_branch) |
222 | 353 | 355 | ||
223 | @@ -450,7 +452,8 @@ | |||
224 | 450 | # life. | 452 | # life. |
225 | 451 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) | 453 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) |
226 | 452 | branch.startMirroring() | 454 | branch.startMirroring() |
228 | 453 | branch.mirrorComplete(self.factory.getUniqueString()) | 455 | removeSecurityProxy(branch).branchChanged( |
229 | 456 | '', self.factory.getUniqueString(), None, None, None) | ||
230 | 454 | removeSecurityProxy(branch).branch_type = BranchType.REMOTE | 457 | removeSecurityProxy(branch).branch_type = BranchType.REMOTE |
231 | 455 | self.assertIs(None, check_default_stacked_on(branch)) | 458 | self.assertIs(None, check_default_stacked_on(branch)) |
232 | 456 | 459 | ||
233 | @@ -466,7 +469,8 @@ | |||
234 | 466 | branch = self.factory.makeAnyBranch(private=True) | 469 | branch = self.factory.makeAnyBranch(private=True) |
235 | 467 | naked_branch = removeSecurityProxy(branch) | 470 | naked_branch = removeSecurityProxy(branch) |
236 | 468 | naked_branch.startMirroring() | 471 | naked_branch.startMirroring() |
238 | 469 | naked_branch.mirrorComplete(self.factory.getUniqueString()) | 472 | naked_branch.branchChanged( |
239 | 473 | '', self.factory.getUniqueString(), None, None, None) | ||
240 | 470 | self.assertIs(None, check_default_stacked_on(branch)) | 474 | self.assertIs(None, check_default_stacked_on(branch)) |
241 | 471 | 475 | ||
242 | 472 | def test_been_mirrored(self): | 476 | def test_been_mirrored(self): |
243 | @@ -475,7 +479,8 @@ | |||
244 | 475 | # futile. | 479 | # futile. |
245 | 476 | branch = self.factory.makeAnyBranch() | 480 | branch = self.factory.makeAnyBranch() |
246 | 477 | branch.startMirroring() | 481 | branch.startMirroring() |
248 | 478 | branch.mirrorComplete('rev1') | 482 | removeSecurityProxy(branch).branchChanged( |
249 | 483 | '', self.factory.getUniqueString(), None, None, None) | ||
250 | 479 | self.assertEqual(branch, check_default_stacked_on(branch)) | 484 | self.assertEqual(branch, check_default_stacked_on(branch)) |
251 | 480 | 485 | ||
252 | 481 | 486 | ||
253 | 482 | 487 | ||
254 | === modified file 'lib/lp/code/stories/branches/xx-branch-mirror-failures.txt' | |||
255 | --- lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2009-06-12 16:36:02 +0000 | |||
256 | +++ lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2010-04-27 02:06:23 +0000 | |||
257 | @@ -163,7 +163,7 @@ | |||
258 | 163 | >>> login(ANONYMOUS) | 163 | >>> login(ANONYMOUS) |
259 | 164 | >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name) | 164 | >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name) |
260 | 165 | >>> mirror_branch.startMirroring() | 165 | >>> mirror_branch.startMirroring() |
262 | 166 | >>> mirror_branch.mirrorComplete('some-revision-id') | 166 | >>> mirror_branch.branchChanged('', 'some-revision-id', None, None, None) |
263 | 167 | >>> logout() | 167 | >>> logout() |
264 | 168 | 168 | ||
265 | 169 | >>> browser.open(branch_location) | 169 | >>> browser.open(branch_location) |
266 | 170 | 170 | ||
267 | === modified file 'lib/lp/code/xmlrpc/codehosting.py' | |||
268 | --- lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:05:59 +0000 | |||
269 | +++ lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:06:23 +0000 | |||
270 | @@ -123,22 +123,13 @@ | |||
271 | 123 | else: | 123 | else: |
272 | 124 | return () | 124 | return () |
273 | 125 | 125 | ||
274 | 126 | def mirrorComplete(self, branch_id, last_revision_id): | ||
275 | 127 | """See `ICodehostingAPI`.""" | ||
276 | 128 | branch = getUtility(IBranchLookup).get(branch_id) | ||
277 | 129 | if branch is None: | ||
278 | 130 | return faults.NoBranchWithID(branch_id) | ||
279 | 131 | # See comment in startMirroring. | ||
280 | 132 | branch = removeSecurityProxy(branch) | ||
281 | 133 | branch.mirrorComplete(last_revision_id) | ||
282 | 134 | return True | ||
283 | 135 | |||
284 | 136 | def mirrorFailed(self, branch_id, reason): | 126 | def mirrorFailed(self, branch_id, reason): |
285 | 137 | """See `ICodehostingAPI`.""" | 127 | """See `ICodehostingAPI`.""" |
286 | 138 | branch = getUtility(IBranchLookup).get(branch_id) | 128 | branch = getUtility(IBranchLookup).get(branch_id) |
287 | 139 | if branch is None: | 129 | if branch is None: |
288 | 140 | return faults.NoBranchWithID(branch_id) | 130 | return faults.NoBranchWithID(branch_id) |
290 | 141 | # See comment in startMirroring. | 131 | # The puller runs as no user and may pull private branches. We need to |
291 | 132 | # bypass Zope's security proxy to set the mirroring information. | ||
292 | 142 | removeSecurityProxy(branch).mirrorFailed(reason) | 133 | removeSecurityProxy(branch).mirrorFailed(reason) |
293 | 143 | return True | 134 | return True |
294 | 144 | 135 | ||
295 | @@ -151,16 +142,6 @@ | |||
296 | 151 | date_completed=date_completed, hostname=hostname) | 142 | date_completed=date_completed, hostname=hostname) |
297 | 152 | return True | 143 | return True |
298 | 153 | 144 | ||
299 | 154 | def startMirroring(self, branch_id): | ||
300 | 155 | """See `ICodehostingAPI`.""" | ||
301 | 156 | branch = getUtility(IBranchLookup).get(branch_id) | ||
302 | 157 | if branch is None: | ||
303 | 158 | return faults.NoBranchWithID(branch_id) | ||
304 | 159 | # The puller runs as no user and may pull private branches. We need to | ||
305 | 160 | # bypass Zope's security proxy to set the mirroring information. | ||
306 | 161 | removeSecurityProxy(branch).startMirroring() | ||
307 | 162 | return True | ||
308 | 163 | |||
309 | 164 | def createBranch(self, login_id, branch_path): | 145 | def createBranch(self, login_id, branch_path): |
310 | 165 | """See `ICodehostingAPI`.""" | 146 | """See `ICodehostingAPI`.""" |
311 | 166 | def create_branch(requester): | 147 | def create_branch(requester): |
312 | 167 | 148 | ||
313 | === modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py' | |||
314 | --- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:05:59 +0000 | |||
315 | +++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:06:23 +0000 | |||
316 | @@ -179,34 +179,17 @@ | |||
317 | 179 | self.assertIs(self.branch_lookup.get(branch_id), None) | 179 | self.assertIs(self.branch_lookup.get(branch_id), None) |
318 | 180 | return branch_id | 180 | return branch_id |
319 | 181 | 181 | ||
320 | 182 | def test_startMirroring(self): | ||
321 | 183 | # startMirroring updates last_mirror_attempt to 'now', leaves | ||
322 | 184 | # last_mirrored alone and returns True when passed the id of an | ||
323 | 185 | # existing branch. | ||
324 | 186 | branch = self.factory.makeAnyBranch() | ||
325 | 187 | self.assertUnmirrored(branch) | ||
326 | 188 | |||
327 | 189 | success = self.codehosting_api.startMirroring(branch.id) | ||
328 | 190 | self.assertEqual(success, True) | ||
329 | 191 | |||
330 | 192 | self.assertSqlAttributeEqualsDate( | ||
331 | 193 | branch, 'last_mirror_attempt', UTC_NOW) | ||
332 | 194 | self.assertIs(None, branch.last_mirrored) | ||
333 | 195 | |||
334 | 196 | def test_startMirroringInvalidBranch(self): | ||
335 | 197 | # startMirroring returns False when given a branch id which does not | ||
336 | 198 | # exist. | ||
337 | 199 | invalid_id = self.getUnusedBranchID() | ||
338 | 200 | fault = self.codehosting_api.startMirroring(invalid_id) | ||
339 | 201 | self.assertEqual(faults.NoBranchWithID(invalid_id), fault) | ||
340 | 202 | |||
341 | 203 | def test_mirrorFailed(self): | 182 | def test_mirrorFailed(self): |
343 | 204 | branch = self.factory.makeAnyBranch() | 183 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) |
344 | 205 | self.assertUnmirrored(branch) | 184 | self.assertUnmirrored(branch) |
345 | 206 | 185 | ||
347 | 207 | self.codehosting_api.startMirroring(branch.id) | 186 | branch.requestMirror() |
348 | 187 | self.assertEquals( | ||
349 | 188 | branch.id, self.codehosting_api.acquireBranchToPull([])[0]) | ||
350 | 189 | |||
351 | 208 | failure_message = self.factory.getUniqueString() | 190 | failure_message = self.factory.getUniqueString() |
353 | 209 | success = self.codehosting_api.mirrorFailed(branch.id, failure_message) | 191 | success = self.codehosting_api.mirrorFailed( |
354 | 192 | branch.id, failure_message) | ||
355 | 210 | self.assertEqual(True, success) | 193 | self.assertEqual(True, success) |
356 | 211 | self.assertMirrorFailed(branch, failure_message) | 194 | self.assertMirrorFailed(branch, failure_message) |
357 | 212 | 195 | ||
358 | @@ -216,60 +199,6 @@ | |||
359 | 216 | fault = self.codehosting_api.mirrorFailed(branch_id, failure_message) | 199 | fault = self.codehosting_api.mirrorFailed(branch_id, failure_message) |
360 | 217 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) | 200 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) |
361 | 218 | 201 | ||
362 | 219 | def test_mirrorComplete(self): | ||
363 | 220 | # mirrorComplete marks the branch as having been successfully | ||
364 | 221 | # mirrored, with no failures and no status message. | ||
365 | 222 | branch = self.factory.makeAnyBranch() | ||
366 | 223 | self.assertUnmirrored(branch) | ||
367 | 224 | |||
368 | 225 | self.codehosting_api.startMirroring(branch.id) | ||
369 | 226 | revision_id = self.factory.getUniqueString() | ||
370 | 227 | success = self.codehosting_api.mirrorComplete(branch.id, revision_id) | ||
371 | 228 | self.assertEqual(True, success) | ||
372 | 229 | self.assertMirrorSucceeded(branch, revision_id) | ||
373 | 230 | |||
374 | 231 | def test_mirrorCompleteWithNoBranchID(self): | ||
375 | 232 | # mirrorComplete returns a Fault if there's no branch with the given | ||
376 | 233 | # ID. | ||
377 | 234 | branch_id = self.getUnusedBranchID() | ||
378 | 235 | fault = self.codehosting_api.mirrorComplete( | ||
379 | 236 | branch_id, self.factory.getUniqueString()) | ||
380 | 237 | self.assertEqual(faults.NoBranchWithID(branch_id), fault) | ||
381 | 238 | |||
382 | 239 | def test_mirrorComplete_resets_failure_count(self): | ||
383 | 240 | # mirrorComplete marks the branch as successfully mirrored and removes | ||
384 | 241 | # all memory of failure. | ||
385 | 242 | |||
386 | 243 | # First, mark the branch as failed. | ||
387 | 244 | branch = self.factory.makeAnyBranch() | ||
388 | 245 | self.codehosting_api.startMirroring(branch.id) | ||
389 | 246 | failure_message = self.factory.getUniqueString() | ||
390 | 247 | self.codehosting_api.mirrorFailed(branch.id, failure_message) | ||
391 | 248 | self.assertMirrorFailed(branch, failure_message) | ||
392 | 249 | |||
393 | 250 | # Start and successfully finish a mirror. | ||
394 | 251 | self.codehosting_api.startMirroring(branch.id) | ||
395 | 252 | revision_id = self.factory.getUniqueString() | ||
396 | 253 | self.codehosting_api.mirrorComplete(branch.id, revision_id) | ||
397 | 254 | |||
398 | 255 | # Confirm that it succeeded. | ||
399 | 256 | self.assertMirrorSucceeded(branch, revision_id) | ||
400 | 257 | |||
401 | 258 | def test_mirrorComplete_resets_mirror_request(self): | ||
402 | 259 | # After successfully mirroring a hosted branch, next_mirror_time | ||
403 | 260 | # should be set to NULL. | ||
404 | 261 | branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED) | ||
405 | 262 | |||
406 | 263 | # Request that branch be mirrored. This sets next_mirror_time. | ||
407 | 264 | branch.requestMirror() | ||
408 | 265 | |||
409 | 266 | # Simulate successfully mirroring the branch. | ||
410 | 267 | self.codehosting_api.startMirroring(branch.id) | ||
411 | 268 | self.codehosting_api.mirrorComplete( | ||
412 | 269 | branch.id, self.factory.getUniqueString()) | ||
413 | 270 | |||
414 | 271 | self.assertIs(None, branch.next_mirror_time) | ||
415 | 272 | |||
416 | 273 | def test_recordSuccess(self): | 202 | def test_recordSuccess(self): |
417 | 274 | # recordSuccess must insert the given data into ScriptActivity. | 203 | # recordSuccess must insert the given data into ScriptActivity. |
418 | 275 | started = datetime.datetime(2007, 07, 05, 19, 32, 1, tzinfo=UTC) | 204 | started = datetime.datetime(2007, 07, 05, 19, 32, 1, tzinfo=UTC) |
419 | @@ -939,7 +868,10 @@ | |||
420 | 939 | 868 | ||
421 | 940 | def startMirroring(self, branch): | 869 | def startMirroring(self, branch): |
422 | 941 | """See `AcquireBranchToPullTests`.""" | 870 | """See `AcquireBranchToPullTests`.""" |
424 | 942 | self.codehosting_api.startMirroring(branch.id) | 871 | # This is a bit random, but it works. acquireBranchToPull marks the |
425 | 872 | # branch it returns as started mirroring, but we should check that the | ||
426 | 873 | # one we want is returned... | ||
427 | 874 | self.assertBranchIsAquired(branch, branch.branch_type) | ||
428 | 943 | 875 | ||
429 | 944 | def test_branch_type_returned_mirrored(self): | 876 | def test_branch_type_returned_mirrored(self): |
430 | 945 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) | 877 | branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED) |
431 | 946 | 878 | ||
432 | === modified file 'lib/lp/codehosting/inmemory.py' | |||
433 | --- lib/lp/codehosting/inmemory.py 2010-04-27 02:05:59 +0000 | |||
434 | +++ lib/lp/codehosting/inmemory.py 2010-04-27 02:06:23 +0000 | |||
435 | @@ -480,7 +480,9 @@ | |||
436 | 480 | key=operator.attrgetter('next_mirror_time')) | 480 | key=operator.attrgetter('next_mirror_time')) |
437 | 481 | if branches: | 481 | if branches: |
438 | 482 | branch = branches[-1] | 482 | branch = branches[-1] |
440 | 483 | self.startMirroring(branch.id) | 483 | # Mark it as started mirroring. |
441 | 484 | branch.last_mirror_attempt = UTC_NOW | ||
442 | 485 | branch.next_mirror_time = None | ||
443 | 484 | default_branch = branch.target.default_stacked_on_branch | 486 | default_branch = branch.target.default_stacked_on_branch |
444 | 485 | if default_branch is None: | 487 | if default_branch is None: |
445 | 486 | default_branch_name = '' | 488 | default_branch_name = '' |
446 | @@ -494,26 +496,6 @@ | |||
447 | 494 | else: | 496 | else: |
448 | 495 | return () | 497 | return () |
449 | 496 | 498 | ||
450 | 497 | def startMirroring(self, branch_id): | ||
451 | 498 | branch = self._branch_set.get(branch_id) | ||
452 | 499 | if branch is None: | ||
453 | 500 | return faults.NoBranchWithID(branch_id) | ||
454 | 501 | branch.last_mirror_attempt = UTC_NOW | ||
455 | 502 | branch.next_mirror_time = None | ||
456 | 503 | return True | ||
457 | 504 | |||
458 | 505 | def mirrorComplete(self, branch_id, last_revision_id): | ||
459 | 506 | branch = self._branch_set.get(branch_id) | ||
460 | 507 | if branch is None: | ||
461 | 508 | return faults.NoBranchWithID(branch_id) | ||
462 | 509 | branch.last_mirrored_id = last_revision_id | ||
463 | 510 | branch.last_mirrored = UTC_NOW | ||
464 | 511 | branch.mirror_failures = 0 | ||
465 | 512 | for stacked_branch in self._branch_set: | ||
466 | 513 | if stacked_branch.stacked_on is branch: | ||
467 | 514 | stacked_branch.requestMirror() | ||
468 | 515 | return True | ||
469 | 516 | |||
470 | 517 | def mirrorFailed(self, branch_id, reason): | 499 | def mirrorFailed(self, branch_id, reason): |
471 | 518 | branch = self._branch_set.get(branch_id) | 500 | branch = self._branch_set.get(branch_id) |
472 | 519 | if branch is None: | 501 | if branch is None: |
473 | 520 | 502 | ||
474 | === modified file 'lib/lp/testing/factory.py' | |||
475 | --- lib/lp/testing/factory.py 2010-04-27 02:05:59 +0000 | |||
476 | +++ lib/lp/testing/factory.py 2010-04-27 02:06:23 +0000 | |||
477 | @@ -863,13 +863,10 @@ | |||
478 | 863 | """ | 863 | """ |
479 | 864 | if branch is None: | 864 | if branch is None: |
480 | 865 | branch = self.makeBranch(product=product) | 865 | branch = self.makeBranch(product=product) |
488 | 866 | # 'branch' might be private, so we remove the security proxy to get at | 866 | # We just remove the security proxies to be able to change the objects |
489 | 867 | # the methods. | 867 | # here. |
490 | 868 | naked_branch = removeSecurityProxy(branch) | 868 | removeSecurityProxy(branch).branchChanged( |
491 | 869 | naked_branch.startMirroring() | 869 | '', 'rev1', None, None, None) |
485 | 870 | naked_branch.mirrorComplete('rev1') | ||
486 | 871 | # Likewise, we might not have permission to set the branch of the | ||
487 | 872 | # development focus series. | ||
492 | 873 | naked_series = removeSecurityProxy(product.development_focus) | 870 | naked_series = removeSecurityProxy(product.development_focus) |
493 | 874 | naked_series.branch = branch | 871 | naked_series.branch = branch |
494 | 875 | return branch | 872 | return branch |
495 | @@ -881,11 +878,10 @@ | |||
496 | 881 | :param branch: The branch that should be the default stacked-on | 878 | :param branch: The branch that should be the default stacked-on |
497 | 882 | branch. | 879 | branch. |
498 | 883 | """ | 880 | """ |
504 | 884 | # 'branch' might be private, so we remove the security proxy to get at | 881 | # We just remove the security proxies to be able to change the branch |
505 | 885 | # the methods. | 882 | # here. |
506 | 886 | naked_branch = removeSecurityProxy(branch) | 883 | removeSecurityProxy(branch).branchChanged( |
507 | 887 | naked_branch.startMirroring() | 884 | '', 'rev1', None, None, None) |
503 | 888 | naked_branch.mirrorComplete('rev1') | ||
508 | 889 | ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches | 885 | ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches |
509 | 890 | run_with_login( | 886 | run_with_login( |
510 | 891 | ubuntu_branches.teamowner, | 887 | ubuntu_branches.teamowner, |
We must be getting close now...