← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/launchpad/bug-805502 into lp:launchpad

 

Raphaël Victor Badin has proposed merging lp:~rvb/launchpad/bug-805502 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #805502 in Launchpad itself: "The initializeddistroseries database user is missing "binarypackagefile" select permission"
  https://bugs.launchpad.net/launchpad/+bug/805502

For more details, see:
https://code.launchpad.net/~rvb/launchpad/bug-805502/+merge/67185

This branch fixes a few permissions required by the package copier which is now used to initialize a distroseries from multiple parents.

= Test =

./bin/test -vvc test_initderiveddistroseries test_multiple_parents_binary_packages

= Q/A =

Initializing a distroseries from multiple parents with binary packages in the second parent should not trigger a "permission denied" exception.
-- 
https://code.launchpad.net/~rvb/launchpad/bug-805502/+merge/67185
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/launchpad/bug-805502 into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2011-06-16 20:21:11 +0000
+++ database/schema/security.cfg	2011-07-07 13:16:11 +0000
@@ -964,6 +964,7 @@
 public.archive                                  = SELECT
 public.archivepermission                        = SELECT, INSERT
 public.binarypackagebuild                       = SELECT, INSERT
+public.binarypackagefile                        = SELECT
 public.binarypackagename                        = SELECT
 public.binarypackagepublishinghistory           = SELECT, INSERT
 public.binarypackagerelease                     = SELECT
@@ -974,6 +975,7 @@
 public.componentselection                       = SELECT, INSERT
 public.distribution                             = SELECT
 public.distributionjob                          = SELECT
+public.distributionsourcepackage                = SELECT, INSERT
 public.distroarchseries                         = SELECT, INSERT
 public.distroseries                             = SELECT, UPDATE
 public.distroseriesparent                       = SELECT, INSERT, UPDATE
@@ -989,9 +991,11 @@
 public.packagesetinclusion                      = SELECT, INSERT
 public.packagesetsources                        = SELECT, INSERT
 public.packageupload                            = SELECT
+public.packageuploadsource                      = SELECT
 public.packaging                                = SELECT, INSERT
 public.person                                   = SELECT
 public.processor                                = SELECT
+public.pocketchroot                             = SELECT
 public.processorfamily                          = SELECT
 public.section                                  = SELECT
 public.sectionselection                         = SELECT, INSERT

=== modified file 'lib/lp/registry/tests/test_initderiveddistroseries.py'
--- lib/lp/registry/tests/test_initderiveddistroseries.py	2011-06-09 10:50:25 +0000
+++ lib/lp/registry/tests/test_initderiveddistroseries.py	2011-07-07 13:16:11 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test initializing a distroseries using
@@ -6,15 +6,22 @@
 
 __metaclass__ = type
 
+import transaction
 from zope.component import getUtility
 from zope.security.interfaces import Unauthorized
 from zope.security.proxy import removeSecurityProxy
 
-from canonical.testing.layers import LaunchpadFunctionalLayer
+from canonical.testing.layers import (
+    LaunchpadFunctionalLayer,
+    LaunchpadZopelessLayer,
+    )
 from lp.registry.interfaces.distroseries import DerivationError
 from lp.soyuz.interfaces.distributionjob import (
     IInitializeDistroSeriesJobSource,
     )
+from lp.soyuz.scripts.tests.test_initialize_distroseries import (
+    InitializationTestHelper,
+    )
 from lp.testing import (
     ANONYMOUS,
     login,
@@ -58,3 +65,33 @@
         [job] = list(
             getUtility(IInitializeDistroSeriesJobSource).iterReady())
         self.assertEqual(job.distroseries, self.child)
+
+
+class TestDeriveDistroSeriesMultipleParents(InitializationTestHelper):
+
+    layer = LaunchpadZopelessLayer
+
+    def test_multiple_parents_binary_packages(self):
+        # An initialization from many parents (using the package copier)
+        # can happen using the same the db user the job will use
+        # ('initializedistroseries').
+        self.parent1, unused = self.setupParent(
+            packages={'p1': '0.1-1'})
+        self.parent2, unused = self.setupParent(
+            packages={'p2': '2.1'})
+        child = self.factory.makeDistroSeries()
+        transaction.commit()
+        self.layer.switchDbUser('initializedistroseries')
+
+        child = self._fullInitialize(
+            [self.parent1, self.parent2], child=child)
+        pub_sources = child.main_archive.getPublishedSources(
+            distroseries=child)
+        binaries = sorted(
+            [(p.getBuiltBinaries()[0].binarypackagerelease.sourcepackagename,
+              p.getBuiltBinaries()[0].binarypackagerelease.version)
+                 for p in pub_sources])
+
+        self.assertEquals(
+            [(u'p1', u'0.1-1'), (u'p2', u'2.1')],
+            binaries)

=== modified file 'lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py'
--- lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py	2011-07-06 20:06:36 +0000
+++ lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py	2011-07-07 13:16:11 +0000
@@ -42,9 +42,10 @@
 from lp.testing import TestCaseWithFactory
 
 
-class TestInitializeDistroSeries(TestCaseWithFactory):
-
-    layer = LaunchpadZopelessLayer
+class InitializationTestHelper(TestCaseWithFactory):
+    # Helper class to:
+    # - setup/populate parents with packages;
+    # - initialize a child from parents.
 
     def setupParent(self, packages=None, format_selection=None,
                     distribution=None):
@@ -94,6 +95,26 @@
                     distroarchseries=parent_das,
                     pocket=PackagePublishingPocket.RELEASE,
                     status=PackagePublishingStatus.PUBLISHED)
+                self.factory.makeBinaryPackageFile(binarypackagerelease=bpr)
+
+    def _fullInitialize(self, parents, child=None, previous_series=None,
+                        arches=(), packagesets=(), rebuild=False,
+                        distribution=None, overlays=(),
+                        overlay_pockets=(), overlay_components=()):
+        if child is None:
+            child = self.factory.makeDistroSeries(
+                distribution=distribution, previous_series=previous_series)
+        ids = InitializeDistroSeries(
+            child, [parent.id for parent in parents], arches, packagesets,
+            rebuild, overlays, overlay_pockets, overlay_components)
+        ids.check()
+        ids.initialize()
+        return child
+
+
+class TestInitializeDistroSeries(InitializationTestHelper):
+
+    layer = LaunchpadZopelessLayer
 
     def test_failure_for_already_released_distroseries(self):
         # Initializing a distro series that has already been used will
@@ -208,20 +229,6 @@
         # Other configuration bits are copied too.
         self.assertTrue(child.backports_not_automatic)
 
-    def _fullInitialize(self, parents, child=None, previous_series=None,
-                        arches=(), packagesets=(), rebuild=False,
-                        distribution=None, overlays=(),
-                        overlay_pockets=(), overlay_components=()):
-        if child is None:
-            child = self.factory.makeDistroSeries(
-                distribution=distribution, previous_series=previous_series)
-        ids = InitializeDistroSeries(
-            child, [parent.id for parent in parents], arches, packagesets,
-            rebuild, overlays, overlay_pockets, overlay_components)
-        ids.check()
-        ids.initialize()
-        return child
-
     def test_initialize(self):
         # Test a full initialize with no errors.
         self.parent, self.parent_das = self.setupParent()