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

Proposed by Steve Kowalik on 2012-03-14
Status: Merged
Approved by: Steve Kowalik on 2012-03-14
Approved revision: no longer in the source branch.
Merged at revision: 14944
Proposed branch: lp:~stevenk/launchpad/information_type-bugs-garbo
Merge into: lp:launchpad
Prerequisite: lp:~stevenk/launchpad/information_type-model
Diff against target: 74 lines (+35/-0)
3 files modified
lib/lp/bugs/model/tests/test_bug.py (+2/-0)
lib/lp/scripts/garbo.py (+23/-0)
lib/lp/scripts/tests/test_garbo.py (+10/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/information_type-bugs-garbo
Reviewer Review Type Date Requested Status
Ian Booth (community) 2012-03-14 Approve on 2012-03-14
Review via email: mp+97335@code.launchpad.net

Commit Message

Add a garbo job that will populate IBug.information_type.

Description of the Change

Add a garbo job that will populate IBug.information_type.

To post a comment you must log in.
Ian Booth (wallyworld) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/model/tests/test_bug.py'
2--- lib/lp/bugs/model/tests/test_bug.py 2012-03-14 03:22:20 +0000
3+++ lib/lp/bugs/model/tests/test_bug.py 2012-03-14 03:22:20 +0000
4@@ -919,6 +919,8 @@
5
6 def test_bug_information_type(self):
7 # Bugs have the correct corresponding information type.
8+ # Public security bugs are currently untested since it is impossible
9+ # to create one at the moment.
10 bug = self.factory.makeBug()
11 private_bug = self.factory.makeBug(private=True)
12 private_sec_bug = self.factory.makeBug(
13
14=== modified file 'lib/lp/scripts/garbo.py'
15--- lib/lp/scripts/garbo.py 2012-03-12 19:26:47 +0000
16+++ lib/lp/scripts/garbo.py 2012-03-14 03:22:20 +0000
17@@ -1160,6 +1160,28 @@
18 self.offset += chunk_size
19
20
21+class BugsInformationTypeMigrator(TunableLoop):
22+ """A `TunableLoop` to populate information_type for all bugs."""
23+
24+ maximum_chunk_size = 5000
25+
26+ def __init__(self, log, abort_time=None):
27+ super(BugsInformationTypeMigrator, self).__init__(log, abort_time)
28+ self.transaction = transaction
29+ self.store = IMasterStore(Bug)
30+
31+ def findBugs(self):
32+ return self.store.find(Bug, Bug.information_type == None)
33+
34+ def isDone(self):
35+ return self.findBugs().is_empty()
36+
37+ def __call__(self, chunk_size):
38+ for bug in self.findBugs()[:chunk_size]:
39+ bug._setInformationType()
40+ self.transaction.commit()
41+
42+
43 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
44 """Abstract base class to run a collection of TunableLoops."""
45 script_name = None # Script name for locking and database user. Override.
46@@ -1413,6 +1435,7 @@
47 BugHeatUpdater,
48 AccessPolicyDistributionAddition,
49 AccessPolicyProductAddition,
50+ BugsInformationTypeMigrator,
51 ]
52 experimental_tunable_loops = []
53
54
55=== modified file 'lib/lp/scripts/tests/test_garbo.py'
56--- lib/lp/scripts/tests/test_garbo.py 2012-03-12 18:54:13 +0000
57+++ lib/lp/scripts/tests/test_garbo.py 2012-03-14 03:22:20 +0000
58@@ -1126,6 +1126,16 @@
59 self.assertEqual(whiteboard, spec.whiteboard)
60 self.assertEqual(0, spec.work_items.count())
61
62+ def test_BugsInformationTypeMigrator(self):
63+ # A non-migrated bug will have information_type set correctly.
64+ switch_dbuser('testadmin')
65+ bug = self.factory.makeBug(private=True)
66+ # Since creating a bug will set information_type, unset it.
67+ removeSecurityProxy(bug).information_type = None
68+ transaction.commit()
69+ self.runHourly()
70+ self.assertEqual(InformationType.USERDATA, bug.information_type)
71+
72
73 class TestGarboTasks(TestCaseWithFactory):
74 layer = LaunchpadZopelessLayer