Merge lp:~wallyworld/launchpad/package-defaults-192076 into lp:launchpad

Proposed by Ian Booth on 2012-10-26
Status: Merged
Approved by: Ian Booth on 2012-11-01
Approved revision: no longer in the source branch.
Merged at revision: 16220
Proposed branch: lp:~wallyworld/launchpad/package-defaults-192076
Merge into: lp:launchpad
Diff against target: 195 lines (+90/-18)
3 files modified
lib/lp/archiveuploader/nascentupload.py (+20/-4)
lib/lp/archiveuploader/nascentuploadfile.py (+23/-12)
lib/lp/archiveuploader/tests/test_uploadprocessor.py (+47/-2)
To merge this branch: bzr merge lp:~wallyworld/launchpad/package-defaults-192076
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code 2012-10-26 Approve on 2012-11-01
Review via email: mp+131509@code.launchpad.net

Commit Message

Correctly set the overridden component for binary publications.

Description of the Change

== Implementation ==

I added a small extra block of code to the NascentUpload find_and_apply_overrides() method - if there is no ancestory for binary uploads, see if there is a current corresponding source publication and use the component from that if available.

== Tests ==

I added some new tests to test_uploadprocessor, since this test module seemed to be the main place where the end-end operation of the nascent upload and processing functionality was tested.

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/archiveuploader/nascentupload.py
  lib/lp/archiveuploader/nascentuploadfile.py
  lib/lp/archiveuploader/tests/test_uploadprocessor.py

To post a comment you must log in.
Steve Kowalik (stevenk) wrote :

I think I'd rather see this an Override Policy, like SetToExistingOverridePolicy or so. Instantiate it with the uploaded_file, and allow the policy to work everything out.

review: Needs Fixing (code)
Ian Booth (wallyworld) wrote :

I'd like not to have to do that here - the idea was simply to tweak the
existing implementation. There's already been a previous attempt to
re-implement the override stuff as an adaptor but that stuff is not
used everywhere yet. That level of refactoring is best done in a
separate branch. I just wanted to fix the critical here. The
refactoring is not really critical. I think William agrees with the
approach.

On Wed 31 Oct 2012 16:22:20 EST, Steve Kowalik wrote:
> Review: Needs Fixing code
>
> I think I'd rather see this an Override Policy, like SetToExistingOverridePolicy or so. Instantiate it with the uploaded_file, and allow the policy to work everything out.

Steve Kowalik (stevenk) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/nascentupload.py'
2--- lib/lp/archiveuploader/nascentupload.py 2012-10-24 09:43:58 +0000
3+++ lib/lp/archiveuploader/nascentupload.py 2012-10-31 23:46:22 +0000
4@@ -723,10 +723,11 @@
5 # That's why we need this conversion here.
6 uploaded_file.priority_name = override.priority.name.lower()
7
8- def processUnknownFile(self, uploaded_file):
9+ def processUnknownFile(self, uploaded_file, override=None):
10 """Apply a set of actions for newly-uploaded (unknown) files.
11
12- Here we use the override policy defined in UnknownOverridePolicy.
13+ Here we use the override, if specified, or simply default to the policy
14+ defined in UnknownOverridePolicy.
15
16 In the case of a PPA, files are not touched. They are always
17 overridden to 'main' at publishing time, though.
18@@ -749,7 +750,10 @@
19 # Don't override partner uploads.
20 return
21
22- # Apply the component override and default to universe.
23+ # Use the specified override, or delegate to UnknownOverridePolicy.
24+ if override:
25+ uploaded_file.component_name = override.component.name
26+ return
27 component_name_override = UnknownOverridePolicy.getComponentOverride(
28 uploaded_file.component_name)
29 uploaded_file.component_name = component_name_override
30@@ -759,6 +763,9 @@
31
32 Anything not yet in the DB gets tagged as 'new' and won't count
33 towards the permission check.
34+
35+ XXX: wallyworld 2012-11-01 bug=1073755: This work should be done using
36+ override polices defined in lp.soyuz.adapters.overrides.py
37 """
38 self.logger.debug("Finding and applying overrides.")
39
40@@ -819,7 +826,16 @@
41 else:
42 self.logger.debug(
43 "%s: (binary) NEW" % (uploaded_file.package))
44- self.processUnknownFile(uploaded_file)
45+ # Check the current source publication's component.
46+ # If there is a corresponding source publication, we will
47+ # use the component from that, otherwise default mappings
48+ # are used.
49+ spph = None
50+ try:
51+ spph = uploaded_file.findCurrentSourcePublication()
52+ except UploadError:
53+ pass
54+ self.processUnknownFile(uploaded_file, spph)
55
56 #
57 # Actually processing accepted or rejected uploads -- and mailing people
58
59=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
60--- lib/lp/archiveuploader/nascentuploadfile.py 2012-09-24 01:05:18 +0000
61+++ lib/lp/archiveuploader/nascentuploadfile.py 2012-10-31 23:46:22 +0000
62@@ -794,16 +794,13 @@
63 #
64 # Database relationship methods
65 #
66- def findSourcePackageRelease(self):
67- """Return the respective ISourcePackageRelease for this binary upload.
68-
69- It inspect publication in the targeted DistroSeries.
70-
71- It raises UploadError if the source was not found.
72-
73- Verifications on the designed source are delayed because for
74- mixed_uploads (source + binary) we do not have the source stored
75- in DB yet (see verifySourcepackagerelease).
76+ def findCurrentSourcePublication(self):
77+ """Return the respective ISourcePackagePublishingHistory for this
78+ binary upload.
79+
80+ It inspects publication in the targeted DistroSeries.
81+
82+ It raises UploadError if the spph was not found.
83 """
84 assert self.source_name is not None
85 assert self.source_version is not None
86@@ -814,12 +811,26 @@
87 # Workaround storm bug in EmptyResultSet.
88 spphs = list(spphs[:1])
89 try:
90- return spphs[0].sourcepackagerelease
91+ return spphs[0]
92 except IndexError:
93 raise UploadError(
94- "Unable to find source package %s/%s in %s" % (
95+ "Unable to find source publication %s/%s in %s" % (
96 self.source_name, self.source_version, distroseries.name))
97
98+ def findSourcePackageRelease(self):
99+ """Return the respective ISourcePackageRelease for this binary upload.
100+
101+ It inspect publication in the targeted DistroSeries.
102+
103+ It raises UploadError if the source was not found.
104+
105+ Verifications on the designed source are delayed because for
106+ mixed_uploads (source + binary) we do not have the source stored
107+ in DB yet (see verifySourcepackagerelease).
108+ """
109+ spph = self.findCurrentSourcePublication()
110+ return spph.sourcepackagerelease
111+
112 def verifySourcePackageRelease(self, sourcepackagerelease):
113 """Check if the given ISourcePackageRelease matches the context."""
114 assert 'source' in self.changes.architectures, (
115
116=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
117--- lib/lp/archiveuploader/tests/test_uploadprocessor.py 2012-10-24 11:03:29 +0000
118+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py 2012-10-31 23:46:22 +0000
119@@ -198,7 +198,8 @@
120 self.switchToUploader()
121 return upload_processor
122
123- def publishPackage(self, packagename, version, source=True, archive=None):
124+ def publishPackage(self, packagename, version, source=True, archive=None,
125+ component_override=None):
126 """Publish a single package that is currently NEW in the queue."""
127 self.switchToAdmin()
128
129@@ -215,6 +216,8 @@
130 pubrec = queue_item.sources[0].publish(self.log)
131 else:
132 pubrec = queue_item.builds[0].publish(self.log)
133+ if component_override:
134+ pubrec.component = component_override
135 self.switchToUploader()
136 return pubrec
137
138@@ -1325,7 +1328,7 @@
139 # The following three tests check this.
140 def checkComponentOverride(self, upload_dir_name,
141 expected_component_name):
142- """Helper function to check overridden component names.
143+ """Helper function to check overridden source component names.
144
145 Upload a 'bar' package from upload_dir_name, then
146 inspect the package 'bar' in the NEW queue and ensure its
147@@ -1370,6 +1373,48 @@
148 """
149 self.checkComponentOverride("bar_1.0-1", "universe")
150
151+ def checkBinaryComponentOverride(self, component_override=None,
152+ expected_component_name='universe'):
153+ """Helper function to check overridden binary component names.
154+
155+ Upload a 'bar' package from upload_dir_name, publish it, and then
156+ override the publication's component. When the binary release is
157+ published, it's component correspond to the source publication's
158+ component.
159+
160+ The original component comes from the source package contained
161+ in upload_dir_name.
162+ """
163+ uploadprocessor = self.setupBreezyAndGetUploadProcessor()
164+ # Upload 'bar-1.0-1' source and binary to ubuntu/breezy.
165+ upload_dir = self.queueUpload("bar_1.0-1")
166+ self.processUpload(uploadprocessor, upload_dir)
167+ bar_source_pub = self.publishPackage(
168+ 'bar', '1.0-1', component_override=component_override)
169+ [bar_original_build] = bar_source_pub.createMissingBuilds()
170+
171+ self.options.context = 'buildd'
172+ upload_dir = self.queueUpload("bar_1.0-1_binary")
173+ build_uploadprocessor = self.getUploadProcessor(
174+ self.layer.txn, builds=True)
175+ self.processUpload(
176+ build_uploadprocessor, upload_dir, build=bar_original_build)
177+ [bar_binary_pub] = self.publishPackage("bar", "1.0-1", source=False)
178+ self.assertEqual(
179+ bar_binary_pub.component.name, expected_component_name)
180+ self.assertEqual(
181+ bar_binary_pub.binarypackagerelease.component.name,
182+ expected_component_name)
183+
184+ def testBinaryPackageDefaultComponent(self):
185+ """The default component is universe."""
186+ self.checkBinaryComponentOverride(None, "universe")
187+
188+ def testBinaryPackageSourcePublicationOverride(self):
189+ """The source publication's component is used."""
190+ restricted = getUtility(IComponentSet)["restricted"]
191+ self.checkBinaryComponentOverride(restricted, "restricted")
192+
193 def testOopsCreation(self):
194 """Test that an unhandled exception generates an OOPS."""
195 self.options.builds = False