← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/information_type-bugs-garbo into lp:launchpad with lp:~stevenk/launchpad/information_type-model as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/information_type-bugs-garbo/+merge/97335

Add a garbo job that will populate IBug.information_type.
-- 
https://code.launchpad.net/~stevenk/launchpad/information_type-bugs-garbo/+merge/97335
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/information_type-bugs-garbo into lp:launchpad.
=== modified file 'lib/lp/bugs/model/tests/test_bug.py'
--- lib/lp/bugs/model/tests/test_bug.py	2012-03-14 03:19:21 +0000
+++ lib/lp/bugs/model/tests/test_bug.py	2012-03-14 03:19:21 +0000
@@ -919,6 +919,8 @@
 
     def test_bug_information_type(self):
         # Bugs have the correct corresponding information type.
+        # Public security bugs are currently untested since it is impossible
+        # to create one at the moment.
         bug = self.factory.makeBug()
         private_bug = self.factory.makeBug(private=True)
         private_sec_bug = self.factory.makeBug(

=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py	2012-03-12 19:26:47 +0000
+++ lib/lp/scripts/garbo.py	2012-03-14 03:19:21 +0000
@@ -1160,6 +1160,28 @@
         self.offset += chunk_size
 
 
+class BugsInformationTypeMigrator(TunableLoop):
+    """A `TunableLoop` to populate information_type for all bugs."""
+
+    maximum_chunk_size = 5000
+
+    def __init__(self, log, abort_time=None):
+        super(BugsInformationTypeMigrator, self).__init__(log, abort_time)
+        self.transaction = transaction
+        self.store = IMasterStore(Bug)
+
+    def findBugs(self):
+        return self.store.find(Bug, Bug.information_type == None)
+
+    def isDone(self):
+        return self.findBugs().is_empty()
+
+    def __call__(self, chunk_size):
+        for bug in self.findBugs()[:chunk_size]:
+            bug._setInformationType()
+        self.transaction.commit()
+
+
 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
     """Abstract base class to run a collection of TunableLoops."""
     script_name = None  # Script name for locking and database user. Override.
@@ -1413,6 +1435,7 @@
         BugHeatUpdater,
         AccessPolicyDistributionAddition,
         AccessPolicyProductAddition,
+        BugsInformationTypeMigrator,
         ]
     experimental_tunable_loops = []
 

=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py	2012-03-12 18:54:13 +0000
+++ lib/lp/scripts/tests/test_garbo.py	2012-03-14 03:19:21 +0000
@@ -1126,6 +1126,16 @@
         self.assertEqual(whiteboard, spec.whiteboard)
         self.assertEqual(0, spec.work_items.count())
 
+    def test_BugsInformationTypeMigrator(self):
+        # A non-migrated bug will have information_type set correctly.
+        switch_dbuser('testadmin')
+        bug = self.factory.makeBug(private=True)
+        # Since creating a bug will set information_type, unset it.
+        removeSecurityProxy(bug).information_type = None
+        transaction.commit()
+        self.runHourly()
+        self.assertEqual(InformationType.USERDATA, bug.information_type)
+
 
 class TestGarboTasks(TestCaseWithFactory):
     layer = LaunchpadZopelessLayer