Merge ~cjwatson/launchpad:fix-populate-archive-component into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c17b9a4637edf2ef703f226c61f3379f1aee4f97
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-populate-archive-component
Merge into: launchpad:master
Diff against target: 235 lines (+96/-14)
2 files modified
lib/lp/soyuz/model/packagecloner.py (+8/-8)
lib/lp/soyuz/tests/test_packagecloner.py (+88/-6)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+443099@code.launchpad.net

Commit message

populate-archive: Fix --component option

Description of the change

https://git.launchpad.net/launchpad/commit?id=4c62ec226f broke the `--component` option to `populate-archive.py`, because the old-style `quote` and `sqlvalues` functions no longer work to escape instances of models that use native Storm rather than SQLObject emulation.

We should probably convert all of `PackageCloner` to use the Storm query compiler at some point; but this makes a few more targeted changes to get things working again in the meantime.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/model/packagecloner.py b/lib/lp/soyuz/model/packagecloner.py
2index 8092672..2a87c1d 100644
3--- a/lib/lp/soyuz/model/packagecloner.py
4+++ b/lib/lp/soyuz/model/packagecloner.py
5@@ -13,7 +13,7 @@ from zope.interface import implementer
6
7 from lp.services.database.constants import UTC_NOW
8 from lp.services.database.interfaces import IStore
9-from lp.services.database.sqlbase import quote, sqlvalues
10+from lp.services.database.sqlbase import sqlvalues
11 from lp.soyuz.enums import PackagePublishingStatus
12 from lp.soyuz.interfaces.packagecloner import IPackageCloner
13 from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
14@@ -299,8 +299,8 @@ class PackageCloner:
15 )
16
17 if origin.component is not None:
18- find_newer_packages += " AND secsrc.component = %s" % quote(
19- origin.component
20+ find_newer_packages += (
21+ " AND secsrc.component = %s" % origin.component.id
22 )
23 store.execute(find_newer_packages)
24
25@@ -342,8 +342,8 @@ class PackageCloner:
26 )
27
28 if origin.component is not None:
29- find_origin_only_packages += " AND secsrc.component = %s" % quote(
30- origin.component
31+ find_origin_only_packages += (
32+ " AND secsrc.component = %s" % origin.component.id
33 )
34 store.execute(find_origin_only_packages)
35
36@@ -422,8 +422,8 @@ class PackageCloner:
37 )
38
39 if destination.component is not None:
40- pop_query += " AND secsrc.component = %s" % quote(
41- destination.component
42+ pop_query += (
43+ " AND secsrc.component = %s" % destination.component.id
44 )
45 store.execute(pop_query)
46
47@@ -504,7 +504,7 @@ class PackageCloner:
48 )
49
50 if origin.component:
51- query += "and spph.component = %s" % sqlvalues(origin.component)
52+ query += "AND spph.component = %s" % origin.component.id
53
54 store.execute(query)
55
56diff --git a/lib/lp/soyuz/tests/test_packagecloner.py b/lib/lp/soyuz/tests/test_packagecloner.py
57index 5f4c6e1..12a2641 100644
58--- a/lib/lp/soyuz/tests/test_packagecloner.py
59+++ b/lib/lp/soyuz/tests/test_packagecloner.py
60@@ -125,7 +125,8 @@ class PackageClonerTests(TestCaseWithFactory):
61 def makeCopyArchive(
62 self,
63 package_infos,
64- component="main",
65+ from_component=None,
66+ to_component="main",
67 source_pocket=None,
68 target_pocket=None,
69 processors=None,
70@@ -135,11 +136,14 @@ class PackageClonerTests(TestCaseWithFactory):
71 copy_archive = self.getTargetArchive(
72 distroseries.distribution, processors=processors
73 )
74- to_component = getUtility(IComponentSet).ensure(component)
75+ if from_component is not None:
76+ from_component = getUtility(IComponentSet).ensure(from_component)
77+ to_component = getUtility(IComponentSet).ensure(to_component)
78 self.copyArchive(
79 copy_archive,
80 distroseries,
81 from_pocket=source_pocket,
82+ from_component=from_component,
83 to_pocket=target_pocket,
84 to_component=to_component,
85 processors=processors,
86@@ -174,6 +178,7 @@ class PackageClonerTests(TestCaseWithFactory):
87 from_archive=None,
88 from_distroseries=None,
89 from_pocket=None,
90+ from_component=None,
91 to_pocket=None,
92 to_component=None,
93 packagesets=None,
94@@ -195,16 +200,16 @@ class PackageClonerTests(TestCaseWithFactory):
95 from_distroseries.distribution,
96 from_distroseries,
97 from_pocket,
98+ component=from_component,
99+ packagesets=packagesets,
100 )
101 destination = PackageLocation(
102 to_archive,
103 to_distroseries.distribution,
104 to_distroseries,
105 to_pocket,
106+ component=to_component,
107 )
108- origin.packagesets = packagesets
109- if to_component is not None:
110- destination.component = to_component
111 cloner = getUtility(IPackageCloner)
112 cloner.clonePackages(
113 origin,
114@@ -277,10 +282,31 @@ class PackageClonerTests(TestCaseWithFactory):
115 ),
116 ]
117 copy_archive, distroseries = self.makeCopyArchive(
118- package_infos, component="main"
119+ package_infos, to_component="main"
120 )
121 self.checkCopiedSources(copy_archive, distroseries, package_infos)
122
123+ def testCopySingleComponent(self):
124+ """Setting the origin's component limits the sources copied."""
125+ package_infos = [
126+ PackageInfo(
127+ "bzr",
128+ "2.1",
129+ status=PackagePublishingStatus.PUBLISHED,
130+ component="universe",
131+ ),
132+ PackageInfo(
133+ "apt",
134+ "2.2",
135+ status=PackagePublishingStatus.PUBLISHED,
136+ component="main",
137+ ),
138+ ]
139+ copy_archive, distroseries = self.makeCopyArchive(
140+ package_infos, from_component="main", to_component="main"
141+ )
142+ self.checkCopiedSources(copy_archive, distroseries, [package_infos[1]])
143+
144 def testSubsetsBasedOnPackageset(self):
145 """Test that --package-set limits the sources copied."""
146 package_infos = [
147@@ -478,25 +504,37 @@ class PackageClonerTests(TestCaseWithFactory):
148 self,
149 target_archive,
150 target_distroseries,
151+ target_component=None,
152 source_archive=None,
153 source_distroseries=None,
154+ source_component=None,
155 ):
156 """Run a packageSetDiff of two archives."""
157 if source_distroseries is None:
158 source_distroseries = target_distroseries
159 if source_archive is None:
160 source_archive = source_distroseries.distribution.main_archive
161+ if source_component is not None:
162+ source_component = getUtility(IComponentSet).ensure(
163+ source_component
164+ )
165 source_location = PackageLocation(
166 source_archive,
167 source_distroseries.distribution,
168 source_distroseries,
169 PackagePublishingPocket.RELEASE,
170+ component=source_component,
171 )
172+ if target_component is not None:
173+ target_component = getUtility(IComponentSet).ensure(
174+ target_component
175+ )
176 target_location = PackageLocation(
177 target_archive,
178 target_distroseries.distribution,
179 target_distroseries,
180 PackagePublishingPocket.RELEASE,
181+ component=target_component,
182 )
183 cloner = getUtility(IPackageCloner)
184 return cloner.packageSetDiff(source_location, target_location)
185@@ -612,6 +650,50 @@ class PackageClonerTests(TestCaseWithFactory):
186 distroseries.distribution.main_archive,
187 )
188
189+ def testPackageSetDiffInComponent(self):
190+ old_package_infos = [
191+ PackageInfo(
192+ "bzr",
193+ "2.1",
194+ status=PackagePublishingStatus.PUBLISHED,
195+ component="universe",
196+ ),
197+ PackageInfo(
198+ "apt",
199+ "1.2",
200+ status=PackagePublishingStatus.PUBLISHED,
201+ component="main",
202+ ),
203+ ]
204+ copy_archive, distroseries = self.makeCopyArchive(old_package_infos)
205+ new_package_infos = [
206+ PackageInfo(
207+ "bzr",
208+ "2.2",
209+ status=PackagePublishingStatus.PUBLISHED,
210+ component="universe",
211+ ),
212+ PackageInfo(
213+ "apt",
214+ "1.3",
215+ status=PackagePublishingStatus.PENDING,
216+ component="main",
217+ ),
218+ ]
219+ self.createSourcePublications(new_package_infos, distroseries)
220+ diff = self.diffArchives(
221+ copy_archive,
222+ distroseries,
223+ target_component="main",
224+ source_component="main",
225+ )
226+ self.checkPackageDiff(
227+ [new_package_infos[1]],
228+ [],
229+ diff,
230+ distroseries.distribution.main_archive,
231+ )
232+
233 def mergeCopy(
234 self,
235 target_archive,

Subscribers

People subscribed via source and target branches

to status/vote changes: