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