← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/accesspolicy-garbo into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/accesspolicy-garbo into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/accesspolicy-garbo/+merge/95834

Add two garbo jobs that add two AccessPolicyTypes for each product and distribution.
-- 
https://code.launchpad.net/~stevenk/launchpad/accesspolicy-garbo/+merge/95834
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/accesspolicy-garbo into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2012-03-02 02:51:37 +0000
+++ database/schema/security.cfg	2012-03-05 03:47:21 +0000
@@ -2132,6 +2132,7 @@
 
 [garbo]
 groups=script,read
+public.accesspolicy                     = SELECT, INSERT
 public.account                          = SELECT, DELETE
 public.answercontact                    = SELECT, DELETE
 public.branch                           = SELECT, UPDATE

=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py	2012-03-02 18:01:12 +0000
+++ lib/lp/scripts/garbo.py	2012-03-05 03:47:21 +0000
@@ -13,6 +13,7 @@
     datetime,
     timedelta,
     )
+import itertools
 import logging
 import multiprocessing
 import os
@@ -26,7 +27,16 @@
 import iso8601
 from psycopg2 import IntegrityError
 import pytz
+<<<<<<< TREE
 from storm.expr import In
+=======
+from storm.expr import (
+    Exists,
+    In,
+    Not,
+    Select,
+    )
+>>>>>>> MERGE-SOURCE
 from storm.locals import (
     Max,
     Min,
@@ -57,7 +67,12 @@
     RevisionCache,
     )
 from lp.hardwaredb.model.hwdb import HWSubmission
+from lp.registry.enums import AccessPolicyType
+from lp.registry.interfaces.accesspolicy import IAccessPolicySource
+from lp.registry.model.accesspolicy import AccessPolicy
+from lp.registry.model.distribution import Distribution
 from lp.registry.model.person import Person
+from lp.registry.model.product import Product
 from lp.services.config import config
 from lp.services.database import postgresql
 from lp.services.database.constants import UTC_NOW
@@ -990,6 +1005,7 @@
         transaction.commit()
 
 
+<<<<<<< TREE
 class SpecificationWorkitemMigrator(TunableLoop):
     """Migrate work-items from Specification.whiteboard to
     SpecificationWorkItem.
@@ -1064,6 +1080,66 @@
         self.offset += chunk_size
 
 
+=======
+class AccessPolicyDistributionAddition(TunableLoop):
+    """A `TunableLoop` to add AccessPolicy for all distributions."""
+
+    maximum_chunk_size = 5000
+
+    def __init__(self, log, abort_time=None):
+        super(AccessPolicyDistributionAddition, self).__init__(
+            log, abort_time)
+        self.transaction = transaction
+        self.store = IMasterStore(Distribution)
+
+    def findDistributions(self):
+        return self.store.find(
+            Distribution,
+            Not(Exists(
+                Select(AccessPolicy.id,
+                tables=[AccessPolicy], where=[
+                    AccessPolicy.distribution_id == Distribution.id]))))
+
+    def isDone(self):
+        return self.findDistributions().is_empty()
+
+    def __call__(self, chunk_size):
+        policies = itertools.product(
+            self.findDistributions()[:chunk_size],
+            (AccessPolicyType.USERDATA, AccessPolicyType.PROPRIETARY))
+        getUtility(IAccessPolicySource).create(policies)
+        self.transaction.commit()
+
+
+class AccessPolicyProductAddition(TunableLoop):
+    """A `TunableLoop` to add AccessPolicy for all products."""
+
+    maximum_chunk_size = 5000
+
+    def __init__(self, log, abort_time=None):
+        super(AccessPolicyProductAddition, self).__init__(log, abort_time)
+        self.transaction = transaction
+        self.store = IMasterStore(Product)
+
+    def findProducts(self):
+        return self.store.find(
+            Product,
+            Not(Exists(
+                Select(AccessPolicy.id, tables=[AccessPolicy], where=[
+                    AccessPolicy.product_id == Product.id]))))
+
+    def isDone(self):
+        return self.findProducts().is_empty()
+
+    def __call__(self, chunk_size):
+        policies = itertools.product(
+            self.findProducts()[:chunk_size],
+            (AccessPolicyType.USERDATA, AccessPolicyType.PROPRIETARY))
+        getUtility(IAccessPolicySource).create(policies)
+        self.transaction.commit()
+
+
+>>>>>>> MERGE-SOURCE
 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
     """Abstract base class to run a collection of TunableLoops."""
     script_name = None  # Script name for locking and database user. Override.
@@ -1315,6 +1391,8 @@
         UnusedSessionPruner,
         DuplicateSessionPruner,
         BugHeatUpdater,
+        AccessPolicyDistributionAddition,
+        AccessPolicyProductAddition,
         ]
     experimental_tunable_loops = []
 

=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py	2012-03-02 18:01:12 +0000
+++ lib/lp/scripts/tests/test_garbo.py	2012-03-05 03:47:21 +0000
@@ -54,6 +54,7 @@
     )
 from lp.code.model.codeimportevent import CodeImportEvent
 from lp.code.model.codeimportresult import CodeImportResult
+from lp.registry.interfaces.accesspolicy import IAccessPolicySource
 from lp.registry.interfaces.person import IPersonSet
 from lp.scripts.garbo import (
     AntiqueSessionPruner,
@@ -136,6 +137,7 @@
             "cronscripts/garbo-hourly.py", ["-q"], expect_returncode=0)
         self.failIf(out.strip(), "Output to stdout: %s" % out)
         self.failIf(err.strip(), "Output to stderr: %s" % err)
+        DatabaseLayer.force_dirty_database()
 
 
 class BulkFoo(Storm):
@@ -1018,6 +1020,7 @@
         self.runHourly()
         self.assertNotEqual(old_update, bug.heat_last_updated)
 
+<<<<<<< TREE
     def test_SpecificationWorkitemMigrator_not_enabled_by_default(self):
         self.assertFalse(getFeatureFlag('garbo.workitem_migrator.enabled'))
         switch_dbuser('testadmin')
@@ -1085,6 +1088,24 @@
         self.assertEqual(0, spec.work_items.count())
 
 
+=======
+    def test_AccessPolicyDistributionAddition(self):
+        switch_dbuser('testadmin')
+        distribution = self.factory.makeDistribution()
+        transaction.commit()
+        self.runHourly()
+        ap = getUtility(IAccessPolicySource).findByPillar((distribution,))
+        self.assertEqual(2, ap.count())
+
+    def test_AccessPolicyProductAddition(self):
+        switch_dbuser('testadmin')
+        product = self.factory.makeProduct()
+        transaction.commit()
+        self.runHourly()
+        ap = getUtility(IAccessPolicySource).findByPillar((product,))
+        self.assertEqual(2, ap.count())
+
+>>>>>>> MERGE-SOURCE
 
 class TestGarboTasks(TestCaseWithFactory):
     layer = LaunchpadZopelessLayer