Merge lp:~stevenk/launchpad/destroy-populate-project-sharing-policies into lp:launchpad

Proposed by Steve Kowalik on 2012-09-03
Status: Merged
Approved by: William Grant on 2012-09-03
Approved revision: no longer in the source branch.
Merged at revision: 15899
Proposed branch: lp:~stevenk/launchpad/destroy-populate-project-sharing-policies
Merge into: lp:launchpad
Diff against target: 214 lines (+3/-132)
2 files modified
lib/lp/scripts/garbo.py (+1/-65)
lib/lp/scripts/tests/test_garbo.py (+2/-67)
To merge this branch: bzr merge lp:~stevenk/launchpad/destroy-populate-project-sharing-policies
Reviewer Review Type Date Requested Status
William Grant code 2012-09-03 Approve on 2012-09-03
Review via email: mp+122442@code.launchpad.net

Commit Message

PopulateProjectSharingPolicies is done. To thank it for its work, kick it and its tests out of the codebase.

Description of the Change

PopulateProjectSharingPolicies is done. To thank it for its work, kick it and its tests out of the codebase.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/scripts/garbo.py'
2--- lib/lp/scripts/garbo.py 2012-08-31 01:27:57 +0000
3+++ lib/lp/scripts/garbo.py 2012-09-03 05:40:39 +0000
4@@ -27,14 +27,7 @@
5 import iso8601
6 from psycopg2 import IntegrityError
7 import pytz
8-from storm.expr import (
9- And,
10- Exists,
11- In,
12- Not,
13- Select,
14- Update,
15- Or)
16+from storm.expr import In
17 from storm.locals import (
18 Max,
19 Min,
20@@ -56,10 +49,8 @@
21 BugWatchScheduler,
22 MAX_SAMPLE_SIZE,
23 )
24-from lp.code.enums import BranchVisibilityRule
25 from lp.code.interfaces.revision import IRevisionSet
26 from lp.code.model.branchnamespace import BRANCH_POLICY_ALLOWED_TYPES
27-from lp.code.model.branchvisibilitypolicy import BranchVisibilityTeamPolicy
28 from lp.code.model.codeimportevent import CodeImportEvent
29 from lp.code.model.codeimportresult import CodeImportResult
30 from lp.code.model.revision import (
31@@ -73,7 +64,6 @@
32 IAccessPolicyGrantSource,
33 IAccessPolicySource,
34 )
35-from lp.registry.model.commercialsubscription import CommercialSubscription
36 from lp.registry.model.person import Person
37 from lp.registry.model.product import Product
38 from lp.services.config import config
39@@ -1010,59 +1000,6 @@
40 transaction.commit()
41
42
43-class PopulateProjectSharingPolicies(TunableLoop):
44- """Sets bug and branch sharing policies for non commercial projects."""
45-
46- maximum_chunk_size = 5000
47-
48- def __init__(self, log, abort_time=None):
49- super(PopulateProjectSharingPolicies, self).__init__(log, abort_time)
50- self.store = IMasterStore(Product)
51-
52- def getProducts(self):
53- """ Load the products to process.
54-
55- We only want products which:
56- - are non-commercial products which have neither bug nor
57- branch sharing policy set
58- - have private_bugs = false
59- - have no branch visibility policies other than public
60- """
61- return self.store.find(
62- Product.id,
63- Not(
64- Or(
65- Exists(Select(1, tables=[CommercialSubscription],
66- where=And(
67- CommercialSubscription.product == Product.id,
68- CommercialSubscription.date_expires > datetime.now(
69- pytz.UTC)))),
70- Product.private_bugs == True,
71- Exists(Select(1, tables=[BranchVisibilityTeamPolicy],
72- where=And(
73- BranchVisibilityTeamPolicy.product == Product.id,
74- BranchVisibilityTeamPolicy.rule !=
75- BranchVisibilityRule.PUBLIC))),
76- )),
77- And(Product.bug_sharing_policy == None,
78- Product.branch_sharing_policy == None)).order_by(Product.id)
79-
80- def isDone(self):
81- return self.getProducts().is_empty()
82-
83- def __call__(self, chunk_size):
84- products_to_process = self.getProducts()[:chunk_size]
85- changes = {
86- Product.bug_sharing_policy: 1,
87- Product.branch_sharing_policy: 1
88- }
89- expr = Update(
90- changes,
91- where=Product.id.is_in(products_to_process))
92- self.store.execute(expr, noresult=True)
93- transaction.commit()
94-
95-
96 class UnusedAccessPolicyPruner(TunableLoop):
97 """Deletes unused AccessPolicy and AccessPolicyGrants for products."""
98
99@@ -1360,7 +1297,6 @@
100 UnusedSessionPruner,
101 DuplicateSessionPruner,
102 BugHeatUpdater,
103- PopulateProjectSharingPolicies,
104 ]
105 experimental_tunable_loops = []
106
107
108=== modified file 'lib/lp/scripts/tests/test_garbo.py'
109--- lib/lp/scripts/tests/test_garbo.py 2012-08-29 21:45:07 +0000
110+++ lib/lp/scripts/tests/test_garbo.py 2012-09-03 05:40:39 +0000
111@@ -19,7 +19,6 @@
112 In,
113 Min,
114 Not,
115- Or,
116 SQL,
117 )
118 from storm.locals import (
119@@ -44,10 +43,7 @@
120 BranchFormat,
121 RepositoryFormat,
122 )
123-from lp.code.enums import (
124- BranchVisibilityRule,
125- CodeImportResultStatus,
126- )
127+from lp.code.enums import CodeImportResultStatus
128 from lp.code.interfaces.codeimportevent import ICodeImportEventSet
129 from lp.code.model.branchjob import (
130 BranchJob,
131@@ -62,8 +58,6 @@
132 )
133 from lp.registry.interfaces.accesspolicy import IAccessPolicySource
134 from lp.registry.interfaces.person import IPersonSet
135-from lp.registry.interfaces.product import IProductSet
136-from lp.registry.model.product import Product
137 from lp.scripts.garbo import (
138 AntiqueSessionPruner,
139 BulkPruner,
140@@ -114,10 +108,7 @@
141 TestCase,
142 TestCaseWithFactory,
143 )
144-from lp.testing.dbuser import (
145- dbuser,
146- switch_dbuser,
147- )
148+from lp.testing.dbuser import switch_dbuser
149 from lp.testing.layers import (
150 DatabaseLayer,
151 LaunchpadScriptLayer,
152@@ -1031,62 +1022,6 @@
153 self.runHourly()
154 self.assertNotEqual(old_update, naked_bug.heat_last_updated)
155
156- def test_PopulateProjectSharingPolicies(self):
157- # Non commercial projects have their bug and branch sharing policies
158- # set.
159- with dbuser('testadmin'):
160- non_commercial_products = [
161- self.factory.makeLegacyProduct()
162- for i in range(10)]
163- commercial_project = self.factory.makeLegacyProduct()
164- self.factory.makeCommercialSubscription(commercial_project)
165- configured_project = self.factory.makeProduct(
166- bug_sharing_policy=BugSharingPolicy.PROPRIETARY)
167- removeSecurityProxy(
168- configured_project).branch_sharing_policy = None
169- private_project = self.factory.makeLegacyProduct(private_bugs=True)
170- project_with_bvp = self.factory.makeLegacyProduct()
171- project_with_bvp.setBranchVisibilityTeamPolicy(
172- None, BranchVisibilityRule.FORBIDDEN)
173-
174-
175- def get_non_migrated_products():
176- return IMasterStore(Product).find(
177- Product,
178- Or(
179- Product.bug_sharing_policy == None,
180- Product.branch_sharing_policy == None))
181-
182- self.runHourly()
183-
184- # Check only the expected projects have been migrated.
185- # landscape and launchpad are projects in the test database which have
186- # non public branch visibility policies so are also not migrated.
187- product_set = getUtility(IProductSet)
188- landscape = product_set.getByName('landscape')
189- launchpad = product_set.getByName('launchpad')
190- self.assertContentEqual(
191- [commercial_project, configured_project, private_project,
192- project_with_bvp, landscape, launchpad],
193- get_non_migrated_products())
194- # The non migrated projects still have their original policies.
195- self.assertIsNone(commercial_project.bug_sharing_policy)
196- self.assertIsNone(commercial_project.branch_sharing_policy)
197- self.assertIsNone(private_project.bug_sharing_policy)
198- self.assertIsNone(private_project.branch_sharing_policy)
199- self.assertIsNone(project_with_bvp.bug_sharing_policy)
200- self.assertIsNone(project_with_bvp.branch_sharing_policy)
201- self.assertIsNone(configured_project.branch_sharing_policy)
202- self.assertEquals(
203- BugSharingPolicy.PROPRIETARY,
204- configured_project.bug_sharing_policy)
205- # The migrated projects have the expected policies.
206- for product in non_commercial_products:
207- self.assertEqual(
208- BranchSharingPolicy.PUBLIC, product.branch_sharing_policy)
209- self.assertEqual(
210- BugSharingPolicy.PUBLIC, product.bug_sharing_policy)
211-
212 def getAccessPolicyTypes(self, pillar):
213 return [
214 ap.type