Merge lp:~thumper/launchpad/branch-distro-avoid-scan into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 11607
Proposed branch: lp:~thumper/launchpad/branch-distro-avoid-scan
Merge into: lp:launchpad
Prerequisite: lp:~thumper/launchpad/fix-branchChanged-scan-request
Diff against target: 138 lines (+65/-1)
3 files modified
database/schema/security.cfg (+2/-0)
lib/lp/codehosting/branchdistro.py (+23/-1)
lib/lp/codehosting/tests/test_branchdistro.py (+40/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/branch-distro-avoid-scan
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+36103@code.launchpad.net

Commit message

Copy the branch revision and revision details for the branch during new branch creation when running branch-distro.py.

Description of the change

When branching the distro, we don't want to tie up the scanner for three days, like we have in the past. Given that we are just copying the details of one branch to the other, we can do that as we create the branches.

tests:
  lp.codehosting.tests.test_branchdistro

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Nice! r=me.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2010-09-21 23:09:42 +0000
3+++ database/schema/security.cfg 2010-09-22 08:59:46 +0000
4@@ -629,6 +629,7 @@
5 [branch-distro]
6 type=user
7 public.branch = SELECT, INSERT, UPDATE
8+public.branchrevision = SELECT, INSERT
9 public.branchsubscription = SELECT, INSERT
10 public.distribution = SELECT
11 public.distroseries = SELECT
12@@ -636,6 +637,7 @@
13 public.karmaaction = SELECT
14 public.person = SELECT
15 public.product = SELECT
16+public.revision = SELECT
17 public.seriessourcepackagebranch = SELECT, INSERT, DELETE
18 public.sourcepackagename = SELECT
19 public.teamparticipation = SELECT
20
21=== modified file 'lib/lp/codehosting/branchdistro.py'
22--- lib/lp/codehosting/branchdistro.py 2010-09-21 03:47:19 +0000
23+++ lib/lp/codehosting/branchdistro.py 2010-09-22 08:59:46 +0000
24@@ -27,7 +27,7 @@
25 from zope.component import getUtility
26
27 from canonical.config import config
28-from canonical.launchpad.interfaces import ILaunchpadCelebrities
29+from canonical.launchpad.interfaces import ILaunchpadCelebrities, IMasterStore
30 from lp.code.enums import BranchLifecycleStatus, BranchType
31 from lp.code.errors import BranchExists
32 from lp.code.interfaces.branchcollection import IAllBranches
33@@ -35,6 +35,7 @@
34 from lp.code.interfaces.seriessourcepackagebranch import (
35 IFindOfficialBranchLinks,
36 )
37+from lp.code.model.branchrevision import BranchRevision
38 from lp.codehosting.vfs import branch_id_to_path
39 from lp.registry.interfaces.distribution import IDistributionSet
40 from lp.registry.interfaces.pocket import PackagePublishingPocket
41@@ -350,4 +351,25 @@
42 switch_branches(
43 config.codehosting.mirrored_branches_root,
44 'lp-internal', old_db_branch, new_db_branch)
45+ # Directly copy the branch revisions from the old branch to the new branch.
46+ store = IMasterStore(BranchRevision)
47+ store.execute(
48+ """
49+ INSERT INTO BranchRevision (branch, revision, sequence)
50+ SELECT %s, BranchRevision.revision, BranchRevision.sequence
51+ FROM BranchRevision
52+ WHERE branch = %s
53+ """ % (new_db_branch.id, old_db_branch.id))
54+
55+ # Update the scanned details first, that way when hooking into
56+ # branchChanged, it won't try to create a new scan job.
57+ tip_revision = old_db_branch.getTipRevision()
58+ new_db_branch.updateScannedDetails(
59+ tip_revision, old_db_branch.revision_count)
60+ new_db_branch.branchChanged(
61+ '', tip_revision.revision_id,
62+ old_db_branch.control_format,
63+ old_db_branch.branch_format,
64+ old_db_branch.repository_format)
65+ transaction.commit()
66 return new_db_branch
67
68=== modified file 'lib/lp/codehosting/tests/test_branchdistro.py'
69--- lib/lp/codehosting/tests/test_branchdistro.py 2010-09-20 04:32:49 +0000
70+++ lib/lp/codehosting/tests/test_branchdistro.py 2010-09-22 08:59:46 +0000
71@@ -27,6 +27,8 @@
72 from bzrlib.transport.chroot import ChrootServer
73 from lazr.uri import URI
74 import transaction
75+from zope.component import getUtility
76+from zope.security.proxy import removeSecurityProxy
77
78 from canonical.config import config
79 from canonical.launchpad.scripts.logger import (
80@@ -35,6 +37,7 @@
81 )
82 from canonical.testing.layers import LaunchpadZopelessLayer
83 from lp.code.enums import BranchLifecycleStatus
84+from lp.code.interfaces.branchjob import IBranchScanJobSource
85 from lp.codehosting.branchdistro import (
86 DistroBrancher,
87 switch_branches,
88@@ -127,6 +130,7 @@
89 """Make an official package branch with an underlying bzr branch."""
90 db_branch = self.factory.makePackageBranch(distroseries=distroseries)
91 db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
92+ self.factory.makeRevisionsForBranch(db_branch, count=1)
93
94 transaction.commit()
95
96@@ -241,6 +245,42 @@
97 self.assertEqual(
98 BranchLifecycleStatus.MATURE, db_branch.lifecycle_status)
99
100+ def test_makeOneNewBranch_avoids_need_for_scan(self):
101+ # makeOneNewBranch sets the appropriate properties of the new branch
102+ # so a scan is unnecessary. This can be done because we are making a
103+ # copy of the source branch.
104+ db_branch = self.makeOfficialPackageBranch()
105+ self.factory.makeRevisionsForBranch(db_branch, count=10)
106+ tip_revision_id = db_branch.last_mirrored_id
107+ self.assertIsNot(None, tip_revision_id)
108+ # The makeRevisionsForBranch will create a scan job for the db_branch.
109+ # We don't really care about that, but what we do care about is that
110+ # no new jobs are created.
111+ existing_scan_job_count = len(
112+ list(getUtility(IBranchScanJobSource).iterReady()))
113+
114+ brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
115+ brancher.makeOneNewBranch(db_branch)
116+ new_branch = brancher.new_distroseries.getSourcePackage(
117+ db_branch.sourcepackage.name).getBranch(RELEASE)
118+
119+ self.assertEqual(tip_revision_id, new_branch.last_mirrored_id)
120+ self.assertEqual(tip_revision_id, new_branch.last_scanned_id)
121+ # Make sure that the branch revisions have been copied.
122+ old_ancestry, old_history = removeSecurityProxy(
123+ db_branch).getScannerData()
124+ new_ancestry, new_history = removeSecurityProxy(
125+ new_branch).getScannerData()
126+ self.assertEqual(old_ancestry, new_ancestry)
127+ self.assertEqual(old_history, new_history)
128+ self.assertFalse(new_branch.pending_writes)
129+ # The script doesn't have permission to create branch jobs, but just
130+ # to be insanely paradoid.
131+ transaction.commit()
132+ self.layer.switchDbUser('launchpad')
133+ scan_jobs = list(getUtility(IBranchScanJobSource).iterReady())
134+ self.assertEqual(existing_scan_job_count, len(scan_jobs))
135+
136 def test_makeOneNewBranch_inconsistent_branch(self):
137 # makeOneNewBranch skips over an inconsistent official package branch
138 # (see `checkConsistentOfficialPackageBranch` for precisely what an