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

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: no longer in the source branch.
Merged at revision: 10828
Proposed branch: lp:~mwhudson/launchpad/no-hosted-area-fix-reclaim-branch-space
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area-fix-branch-distro
Diff against target: 213 lines (+25/-100)
4 files modified
lib/lp/code/model/branchjob.py (+3/-8)
lib/lp/code/model/tests/test_branchjob.py (+12/-49)
lib/lp/codehosting/scripts/modifiedbranches.py (+5/-12)
lib/lp/codehosting/scripts/tests/test_modifiedbranches.py (+5/-31)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-fix-reclaim-branch-space
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23975@code.launchpad.net

Description of the change

Hi Tim,

This near-trivial branch fixes the reclaim branch space and modifiedbranch scripts to work without the hosted/mirror script. They're both now simpler :-)

Cheers,
mwh

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

> lib/lp/codehosting/scripts/tests/test_modifiedbranches.py
> ...
> # A hosted branch prints mirrored locations.

This doesn't really make any sense by itself any more.

Perhaps just something like:

# A branch location is the physical disk directory.

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/branchjob.py'
--- lib/lp/code/model/branchjob.py 2010-03-17 18:44:32 +0000
+++ lib/lp/code/model/branchjob.py 2010-04-27 02:22:38 +0000
@@ -944,13 +944,8 @@
944 return self.metadata['branch_id']944 return self.metadata['branch_id']
945945
946 def run(self):946 def run(self):
947 mirrored_path = os.path.join(947 branch_path = os.path.join(
948 config.codehosting.mirrored_branches_root,948 config.codehosting.mirrored_branches_root,
949 branch_id_to_path(self.branch_id))949 branch_id_to_path(self.branch_id))
950 hosted_path = os.path.join(950 if os.path.exists(branch_path):
951 config.codehosting.hosted_branches_root,951 shutil.rmtree(branch_path)
952 branch_id_to_path(self.branch_id))
953 if os.path.exists(mirrored_path):
954 shutil.rmtree(mirrored_path)
955 if os.path.exists(hosted_path):
956 shutil.rmtree(hosted_path)
957952
=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
--- lib/lp/code/model/tests/test_branchjob.py 2010-03-15 21:18:52 +0000
+++ lib/lp/code/model/tests/test_branchjob.py 2010-04-27 02:22:38 +0000
@@ -1264,13 +1264,8 @@
12641264
1265 layer = LaunchpadZopelessLayer1265 layer = LaunchpadZopelessLayer
12661266
1267 def cleanHostedAndMirroredAreas(self):1267 def cleanBranchArea(self):
1268 """Ensure that hosted and mirrored branch areas are present and empty.1268 """Ensure that the branc areas is present and empty."""
1269 """
1270 hosted = config.codehosting.hosted_branches_root
1271 shutil.rmtree(hosted, ignore_errors=True)
1272 os.makedirs(hosted)
1273 self.addCleanup(shutil.rmtree, hosted)
1274 mirrored = config.codehosting.mirrored_branches_root1269 mirrored = config.codehosting.mirrored_branches_root
1275 shutil.rmtree(mirrored, ignore_errors=True)1270 shutil.rmtree(mirrored, ignore_errors=True)
1276 os.makedirs(mirrored)1271 os.makedirs(mirrored)
@@ -1278,7 +1273,7 @@
12781273
1279 def setUp(self):1274 def setUp(self):
1280 TestCaseWithFactory.setUp(self)1275 TestCaseWithFactory.setUp(self)
1281 self.cleanHostedAndMirroredAreas()1276 self.cleanBranchArea()
12821277
1283 def test_providesInterface(self):1278 def test_providesInterface(self):
1284 # ReclaimBranchSpaceJob implements IReclaimBranchSpaceJob.1279 # ReclaimBranchSpaceJob implements IReclaimBranchSpaceJob.
@@ -1324,7 +1319,7 @@
1324 job_count += 11319 job_count += 1
1325 self.assertTrue(job_count > 0, "No jobs ran!")1320 self.assertTrue(job_count > 0, "No jobs ran!")
13261321
1327 def test_run_branch_in_neither_area(self):1322 def test_run_no_branch_on_disk(self):
1328 # Running a job to reclaim space for a branch that was never pushed to1323 # Running a job to reclaim space for a branch that was never pushed to
1329 # does nothing quietly.1324 # does nothing quietly.
1330 branch_id = self.factory.getUniqueInteger()1325 branch_id = self.factory.getUniqueInteger()
@@ -1333,51 +1328,19 @@
1333 # Just "assertNotRaises"1328 # Just "assertNotRaises"
1334 self.runReadyJobs()1329 self.runReadyJobs()
13351330
1336 def test_run_branch_in_hosted_area(self):1331 def test_run_with_branch_on_disk(self):
1337 # Running a job to reclaim space for a branch that was pushed to1332 # Running a job to reclaim space for a branch that was pushed to
1338 # but never mirrored removes the branch from the hosted area.1333 # but never mirrored removes the branch from the hosted area.
1339 branch_id = self.factory.getUniqueInteger()1334 branch_id = self.factory.getUniqueInteger()
1340 job = getUtility(IReclaimBranchSpaceJobSource).create(branch_id)1335 job = getUtility(IReclaimBranchSpaceJobSource).create(branch_id)
1341 self.makeJobReady(job)1336 self.makeJobReady(job)
1342 hosted_branch_path = os.path.join(1337 branch_path = os.path.join(
1343 config.codehosting.hosted_branches_root,1338 config.codehosting.mirrored_branches_root,
1344 branch_id_to_path(branch_id), '.bzr')1339 branch_id_to_path(branch_id), '.bzr')
1345 os.makedirs(hosted_branch_path)1340 os.makedirs(branch_path)
1346 self.runReadyJobs()1341 self.runReadyJobs()
1347 self.assertFalse(os.path.exists(hosted_branch_path))1342 self.assertFalse(os.path.exists(branch_path))
13481343
1349 def test_run_branch_in_mirrored_area(self):
1350 # Running a job to reclaim space for a branch that only exists in the
1351 # mirrored area (e.g. a MIRRORED branch) removes the branch from the
1352 # mirrored area.
1353 branch_id = self.factory.getUniqueInteger()
1354 job = getUtility(IReclaimBranchSpaceJobSource).create(branch_id)
1355 self.makeJobReady(job)
1356 mirrored_branch_path = os.path.join(
1357 config.codehosting.mirrored_branches_root,
1358 branch_id_to_path(branch_id), '.bzr')
1359 os.makedirs(mirrored_branch_path)
1360 self.runReadyJobs()
1361 self.assertFalse(os.path.exists(mirrored_branch_path))
1362
1363 def test_run_branch_in_both_areas(self):
1364 # Running a job to reclaim space for a branch is present in both the
1365 # mirrored and hosted area removes the branch from both areas.
1366 branch_id = self.factory.getUniqueInteger()
1367 job = getUtility(IReclaimBranchSpaceJobSource).create(branch_id)
1368 self.makeJobReady(job)
1369 hosted_branch_path = os.path.join(
1370 config.codehosting.hosted_branches_root,
1371 branch_id_to_path(branch_id), '.bzr')
1372 mirrored_branch_path = os.path.join(
1373 config.codehosting.mirrored_branches_root,
1374 branch_id_to_path(branch_id), '.bzr')
1375 os.makedirs(hosted_branch_path)
1376 os.makedirs(mirrored_branch_path)
1377 self.runReadyJobs()
1378 self.assertFalse(
1379 os.path.exists(hosted_branch_path)
1380 or os.path.exists(mirrored_branch_path))
13811344
13821345
1383def test_suite():1346def test_suite():
13841347
=== modified file 'lib/lp/codehosting/scripts/modifiedbranches.py'
--- lib/lp/codehosting/scripts/modifiedbranches.py 2009-08-20 00:21:24 +0000
+++ lib/lp/codehosting/scripts/modifiedbranches.py 2010-04-27 02:22:38 +0000
@@ -29,11 +29,6 @@
29 returned. It is possible that the branch will have been modified only in29 returned. It is possible that the branch will have been modified only in
30 the web UI and not actually received any more revisions, and will be a30 the web UI and not actually received any more revisions, and will be a
31 false positive.31 false positive.
32
33 If the branch is REMOTE it is ignored.
34 If the branch is HOSTED, both the hosted and mirrored area are returned.
35 If the branch is an IMPORT or MIRROR branch, only the mirrored area is
36 shown.
37 """32 """
3833
39 description = (34 description = (
@@ -89,12 +84,10 @@
89 # Make the datetime timezone aware.84 # Make the datetime timezone aware.
90 return last_modified.replace(tzinfo=pytz.UTC)85 return last_modified.replace(tzinfo=pytz.UTC)
9186
92 def branch_locations(self, branch):87 def branch_location(self, branch):
93 """Return a list of branch paths for the given branch."""88 """Return the branch path for the given branch."""
94 path = branch_id_to_path(branch.id)89 path = branch_id_to_path(branch.id)
95 yield os.path.join(config.codehosting.mirrored_branches_root, path)90 return os.path.join(config.codehosting.mirrored_branches_root, path)
96 if branch.branch_type == BranchType.HOSTED:
97 yield os.path.join(config.codehosting.hosted_branches_root, path)
9891
99 def process_location(self, location):92 def process_location(self, location):
100 """Strip the defined prefix, and append the suffix as configured."""93 """Strip the defined prefix, and append the suffix as configured."""
@@ -122,8 +115,8 @@
122 collection = collection.scannedSince(last_modified)115 collection = collection.scannedSince(last_modified)
123 for branch in collection.getBranches():116 for branch in collection.getBranches():
124 self.logger.info(branch.unique_name)117 self.logger.info(branch.unique_name)
125 for location in self.branch_locations(branch):118 location = self.branch_location(branch)
126 self.update_locations(self.process_location(location))119 self.update_locations(self.process_location(location))
127120
128 for location in sorted(self.locations):121 for location in sorted(self.locations):
129 print location122 print location
130123
=== modified file 'lib/lp/codehosting/scripts/tests/test_modifiedbranches.py'
--- lib/lp/codehosting/scripts/tests/test_modifiedbranches.py 2009-08-20 00:21:24 +0000
+++ lib/lp/codehosting/scripts/tests/test_modifiedbranches.py 2010-04-27 02:22:38 +0000
@@ -26,42 +26,16 @@
2626
27 layer = DatabaseFunctionalLayer27 layer = DatabaseFunctionalLayer
2828
29 def assertHostedLocation(self, branch, location):29 def test_branch(self):
30 """Assert that the location is the hosted location for the branch."""30 # A branch location is the physical disk directory.
31 path = branch_id_to_path(branch.id)31 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
32 self.assertEqual(32 script = ModifiedBranchesScript('modified-branches', test_args=[])
33 os.path.join(config.codehosting.hosted_branches_root, path),33 location = script.branch_location(branch)
34 location)
35
36 def assertMirroredLocation(self, branch, location):
37 """Assert that the location is the mirror location for the branch."""
38 path = branch_id_to_path(branch.id)34 path = branch_id_to_path(branch.id)
39 self.assertEqual(35 self.assertEqual(
40 os.path.join(config.codehosting.mirrored_branches_root, path),36 os.path.join(config.codehosting.mirrored_branches_root, path),
41 location)37 location)
4238
43 def test_hosted_branch(self):
44 # A hosted branch prints both the hosted and mirrored locations.
45 branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
46 script = ModifiedBranchesScript('modified-branches', test_args=[])
47 [mirrored, hosted] = script.branch_locations(branch)
48 self.assertHostedLocation(branch, hosted)
49 self.assertMirroredLocation(branch, mirrored)
50
51 def test_mirrored_branch(self):
52 # A mirrored branch prints only the mirrored location.
53 branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
54 script = ModifiedBranchesScript('modified-branches', test_args=[])
55 [mirrored] = script.branch_locations(branch)
56 self.assertMirroredLocation(branch, mirrored)
57
58 def test_imported_branch(self):
59 # A mirrored branch prints only the mirrored location.
60 branch = self.factory.makeAnyBranch(branch_type=BranchType.IMPORTED)
61 script = ModifiedBranchesScript('modified-branches', test_args=[])
62 [mirrored] = script.branch_locations(branch)
63 self.assertMirroredLocation(branch, mirrored)
64
6539
66class TestModifiedBranchesLastModifiedEpoch(TestCase):40class TestModifiedBranchesLastModifiedEpoch(TestCase):
67 """Test the calculation of the last modifed date."""41 """Test the calculation of the last modifed date."""