Merge lp:~stevenk/launchpad/lucille-archivepermission into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 11461
Proposed branch: lp:~stevenk/launchpad/lucille-archivepermission
Merge into: lp:launchpad
Diff against target: 297 lines (+8/-263)
3 files modified
database/schema/security.cfg (+1/-0)
lib/lp/archiveuploader/tests/test_securityuploads.py.THIS (+0/-263)
lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py (+7/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/lucille-archivepermission
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+33873@code.launchpad.net

Commit message

Allow lucille to SELECT and INSERT on public.archivepermission, fixing initialise-from-parent. Also remove a stray .THIS file.

Description of the change

This branch adds a test for, and corrects an issue I tripped over and cowboyed on mawson while I was QA'ing my change for initialise-from-parent.py

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2010-08-23 22:05:26 +0000
+++ database/schema/security.cfg 2010-08-27 08:16:01 +0000
@@ -770,6 +770,7 @@
770public.archive = SELECT, UPDATE770public.archive = SELECT, UPDATE
771public.archivearch = SELECT771public.archivearch = SELECT
772public.archiveauthtoken = SELECT, UPDATE772public.archiveauthtoken = SELECT, UPDATE
773public.archivepermission = SELECT, INSERT
773public.archivesubscriber = SELECT, UPDATE774public.archivesubscriber = SELECT, UPDATE
774public.binarypackagepublishinghistory = SELECT775public.binarypackagepublishinghistory = SELECT
775public.gpgkey = SELECT, INSERT, UPDATE776public.gpgkey = SELECT, INSERT, UPDATE
776777
=== removed file 'lib/lp/archiveuploader/tests/test_securityuploads.py.THIS'
--- lib/lp/archiveuploader/tests/test_securityuploads.py.THIS 2010-08-26 15:28:34 +0000
+++ lib/lp/archiveuploader/tests/test_securityuploads.py.THIS 1970-01-01 00:00:00 +0000
@@ -1,263 +0,0 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Test security uploads use-cases."""
5
6__metaclass__ = type
7
8import os
9
10from zope.component import getUtility
11
12from canonical.launchpad.interfaces import (
13 IDistributionSet,
14 )
15from lp.archiveuploader.tests.test_uploadprocessor import (
16 TestUploadProcessorBase,
17 )
18from lp.registry.interfaces.pocket import PackagePublishingPocket
19from lp.soyuz.enums import PackageUploadStatus
20from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
21from lp.soyuz.model.processor import ProcessorFamily
22
23
24class TestStagedBinaryUploadBase(TestUploadProcessorBase):
25 name = 'baz'
26 version = '1.0-1'
27 distribution_name = None
28 distroseries_name = None
29 pocket = None
30 policy = 'buildd'
31 no_mails = True
32
33 @property
34 def distribution(self):
35 return getUtility(IDistributionSet)[self.distribution_name]
36
37 @property
38 def distroseries(self):
39 return self.distribution[self.distroseries_name]
40
41 @property
42 def package_name(self):
43 return "%s_%s" % (self.name, self.version)
44
45 @property
46 def source_dir(self):
47 return self.package_name
48
49 @property
50 def source_changesfile(self):
51 return "%s_source.changes" % self.package_name
52
53 @property
54 def binary_dir(self):
55 return "%s_binary" % self.package_name
56
57 def getBinaryChangesfileFor(self, archtag):
58 return "%s_%s.changes" % (self.package_name, archtag)
59
60 def setUp(self):
61 """Setup environment for staged binaries upload via security policy.
62
63 1. Setup queue directory and other basic attributes
64 2. Override policy options to get security policy and not send emails
65 3. Setup a common UploadProcessor with the overridden options
66 4. Store number of build present before issuing any upload
67 5. Upload the source package via security policy
68 6. Clean log messages.
69 7. Commit transaction, so the upload source can be seen.
70 """
71 super(TestStagedBinaryUploadBase, self).setUp()
72 self.options.context = self.policy
73 self.options.nomails = self.no_mails
74 # Set up the uploadprocessor with appropriate options and logger
75 self.uploadprocessor = self.getUploadProcessor(self.layer.txn)
76 self.builds_before_upload = BinaryPackageBuild.select().count()
77 self.source_queue = None
78 self._uploadSource()
79 self.log.lines = []
80 self.layer.txn.commit()
81
82 def assertBuildsCreated(self, amount):
83 """Assert that a given 'amount' of build records was created."""
84 builds_count = BinaryPackageBuild.select().count()
85 self.assertEqual(
86 self.builds_before_upload + amount, builds_count)
87
88 def _prepareUpload(self, upload_dir):
89 """Place a copy of the upload directory into incoming queue."""
90 os.system("cp -a %s %s" %
91 (os.path.join(self.test_files_dir, upload_dir),
92 os.path.join(self.queue_folder, "incoming")))
93
94 def _uploadSource(self):
95 """Upload and Accept (if necessary) the base source."""
96 self._prepareUpload(self.source_dir)
97 self.uploadprocessor.processChangesFile(
98 os.path.join(self.queue_folder, "incoming", self.source_dir),
99 self.source_changesfile)
100 queue_item = self.uploadprocessor.last_processed_upload.queue_root
101 self.assertTrue(
102 queue_item is not None,
103 "Source Upload Failed\nGot: %s" % "\n".join(self.log.lines))
104 acceptable_statuses = [
105 PackageUploadStatus.NEW,
106 PackageUploadStatus.UNAPPROVED,
107 ]
108 if queue_item.status in acceptable_statuses:
109 queue_item.setAccepted()
110 # Store source queue item for future use.
111 self.source_queue = queue_item
112
113 def _uploadBinary(self, archtag):
114 """Upload the base binary.
115
116 Ensure it got processed and has a respective queue record.
117 Return the IBuild attached to upload.
118 """
119 self._prepareUpload(self.binary_dir)
120 self.uploadprocessor.processChangesFile(
121 os.path.join(self.queue_folder, "incoming", self.binary_dir),
122 self.getBinaryChangesfileFor(archtag))
123 queue_item = self.uploadprocessor.last_processed_upload.queue_root
124 self.assertTrue(
125 queue_item is not None,
126 "Binary Upload Failed\nGot: %s" % "\n".join(self.log.lines))
127 self.assertEqual(queue_item.builds.count(), 1)
128 return queue_item.builds[0].build
129
130 def _createBuild(self, archtag):
131 """Create a build record attached to the base source."""
132 spr = self.source_queue.sources[0].sourcepackagerelease
133 build = spr.createBuild(
134 distro_arch_series=self.distroseries[archtag],
135 pocket=self.pocket, archive=self.distroseries.main_archive)
136 self.layer.txn.commit()
137 return build
138
139
140class TestStagedSecurityUploads(TestStagedBinaryUploadBase):
141 """Test how security uploads behave inside Soyuz.
142
143 Security uploads still coming from dak system, we have special upload
144 policy which allows source and binary uploads.
145
146 An upload of a source and its binaries does not necessary need
147 to happen in the same batch, and Soyuz is prepared to cope with it.
148
149 The only mandatory condition is to process the sources first.
150
151 This class will start to tests all known/possible cases using a test
152 (empty) upload and its binary.
153
154 * 'lib/lp/archivepublisher/tests/data/suite/baz_1.0-1/'
155 * 'lib/lp/archivepublisher/tests/data/suite/baz_1.0-1_binary/'
156 """
157 name = 'baz'
158 version = '1.0-1'
159 distribution_name = 'ubuntu'
160 distroseries_name = 'warty'
161 pocket = PackagePublishingPocket.SECURITY
162 policy = 'security'
163 no_mails = True
164
165 def setUp(self):
166 """Setup base class and create the required new distroarchseries."""
167 super(TestStagedSecurityUploads, self).setUp()
168 distribution = getUtility(IDistributionSet).getByName(
169 self.distribution_name)
170 distroseries = distribution[self.distroseries.name]
171 proc_family = ProcessorFamily.selectOneBy(name='amd64')
172 distroseries.newArch(
173 'amd64', proc_family, True, distribution.owner)
174
175 def testBuildCreation(self):
176 """Check if the builds get created for a binary security uploads.
177
178 That is the usual case, security binary uploads come after the
179 not published (accepted) source but in the same batch.
180
181 NascentUpload should create appropriate builds attached to the
182 correct source for the incoming binaries.
183 """
184 build_used = self._uploadBinary('i386')
185
186 self.assertBuildsCreated(1)
187 self.assertEqual(
188 u'i386 build of baz 1.0-1 in ubuntu warty SECURITY',
189 build_used.title)
190 self.assertEqual('FULLYBUILT', build_used.status.name)
191
192 build_used = self._uploadBinary('amd64')
193
194 self.assertBuildsCreated(2)
195 self.assertEqual(
196 u'amd64 build of baz 1.0-1 in ubuntu warty SECURITY',
197 build_used.title)
198
199 self.assertEqual('FULLYBUILT', build_used.status.name)
200
201 def testBuildLookup(self):
202 """Check if an available build gets used when it is appropriate.
203
204 It happens when the security source upload got already published
205 when the binary uploads arrive.
206 The queue-build has already created build records for it and
207 NascentUpload should identify this condition and used them instead
208 of creating new ones.
209 Also verify that builds for another architecture does not got
210 erroneously attached.
211 """
212 build_right_candidate = self._createBuild('i386')
213 build_wrong_candidate = self._createBuild('hppa')
214 build_used = self._uploadBinary('i386')
215
216 self.assertEqual(build_right_candidate.id, build_used.id)
217 self.assertNotEqual(build_wrong_candidate.id, build_used.id)
218 self.assertBuildsCreated(2)
219 self.assertEqual(
220 u'i386 build of baz 1.0-1 in ubuntu warty SECURITY',
221 build_used.title)
222 self.assertEqual('FULLYBUILT', build_used.status.name)
223
224 def testCorrectBuildPassedViaCommandLine(self):
225 """Check if command-line build argument gets attached correctly.
226
227 It's also possible to pass an specific buildid via the command-line
228 to be attached to the current upload.
229
230 This is only used in 'buildd' policy and does not produce very useful
231 results in 'security', however we want to check if it, at least,
232 does not 'break the system' entirely.
233 """
234 build_candidate = self._createBuild('i386')
235 self.options.buildid = str(build_candidate.id)
236 self.uploadprocessor = self.getUploadProcessor(self.layer.txn)
237
238 build_used = self._uploadBinary('i386')
239
240 self.assertEqual(build_candidate.id, build_used.id)
241 self.assertBuildsCreated(1)
242 self.assertEqual(
243 u'i386 build of baz 1.0-1 in ubuntu warty SECURITY',
244 build_used.title)
245
246 self.assertEqual('FULLYBUILT', build_used.status.name)
247
248 def testWrongBuildPassedViaCommandLine(self):
249 """Check if a misapplied passed buildid is correctly identified.
250
251 When we identify misapplied build, either by getting it from command
252 line or by a failure in lookup methods the upload is rejected before
253 anything wrong gets into the DB.
254 """
255 build_candidate = self._createBuild('hppa')
256 self.options.buildid = str(build_candidate.id)
257 self.uploadprocessor = self.getUploadProcessor(self.layer.txn)
258
259 self.assertRaises(AssertionError, self._uploadBinary, 'i386')
260
261 self.assertLogContains(
262 "UploadError: Attempt to upload binaries specifying build %d, "
263 "where they don't fit.\n" % (build_candidate.id, ))
2640
=== modified file 'lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py'
--- lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 2010-08-26 08:02:08 +0000
+++ lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 2010-08-27 08:16:01 +0000
@@ -244,6 +244,13 @@
244244
245 def test_script(self):245 def test_script(self):
246 # Do an end-to-end test using the command-line tool246 # Do an end-to-end test using the command-line tool
247 uploader = self.factory.makePerson()
248 test1 = getUtility(IPackagesetSet).new(
249 u'test1', u'test 1 packageset', self.hoary.owner,
250 distroseries=self.hoary)
251 test1.addSources('pmount')
252 getUtility(IArchivePermissionSet).newPackagesetUploader(
253 self.hoary.main_archive, uploader, test1)
247 foobuntu = self._create_distroseries(self.hoary)254 foobuntu = self._create_distroseries(self.hoary)
248 self._set_pending_to_failed(self.hoary)255 self._set_pending_to_failed(self.hoary)
249 transaction.commit()256 transaction.commit()