Merge lp:~cjwatson/launchpad/improve-livefs-scoring into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18438
Proposed branch: lp:~cjwatson/launchpad/improve-livefs-scoring
Merge into: lp:launchpad
Diff against target: 235 lines (+57/-12)
7 files modified
lib/lp/security.py (+5/-0)
lib/lp/soyuz/browser/livefs.py (+7/-3)
lib/lp/soyuz/configure.zcml (+5/-1)
lib/lp/soyuz/interfaces/livefs.py (+16/-2)
lib/lp/soyuz/model/livefs.py (+4/-1)
lib/lp/soyuz/model/livefsbuild.py (+4/-2)
lib/lp/soyuz/tests/test_livefs.py (+16/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad/improve-livefs-scoring
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+327639@code.launchpad.net

Commit message

Allow setting a relative build score on live filesystems.

To post a comment you must log in.
Revision history for this message
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/security.py'
2--- lib/lp/security.py 2017-06-16 10:02:47 +0000
3+++ lib/lp/security.py 2017-07-18 16:38:02 +0000
4@@ -3095,6 +3095,11 @@
5 user.in_commercial_admin or user.in_admin)
6
7
8+class ModerateLiveFS(ModerateArchive):
9+ """Restrict changing the build score on live filesystems."""
10+ usedfor = ILiveFS
11+
12+
13 class AdminLiveFS(AuthorizationBase):
14 """Restrict changing build settings on live filesystems.
15
16
17=== modified file 'lib/lp/soyuz/browser/livefs.py'
18--- lib/lp/soyuz/browser/livefs.py 2015-05-07 10:52:10 +0000
19+++ lib/lp/soyuz/browser/livefs.py 2017-07-18 16:38:02 +0000
20@@ -1,4 +1,4 @@
21-# Copyright 2014-2015 Canonical Ltd. This software is licensed under the
22+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
23 # GNU Affero General Public License version 3 (see the file LICENSE).
24
25 """LiveFS views."""
26@@ -181,6 +181,7 @@
27 'owner',
28 'name',
29 'require_virtualized',
30+ 'relative_build_score',
31 ])
32 distro_series = Choice(
33 vocabulary='BuildableDistroSeries', title=u'Distribution series')
34@@ -282,11 +283,14 @@
35
36 label = title
37
38- field_names = ['require_virtualized']
39+ field_names = ['require_virtualized', 'relative_build_score']
40
41 @property
42 def initial_values(self):
43- return {'require_virtualized': self.context.require_virtualized}
44+ return {
45+ 'require_virtualized': self.context.require_virtualized,
46+ 'relative_build_score': self.context.relative_build_score,
47+ }
48
49
50 class LiveFSEditView(LiveFSMetadataValidatorMixin, BaseLiveFSEditView):
51
52=== modified file 'lib/lp/soyuz/configure.zcml'
53--- lib/lp/soyuz/configure.zcml 2016-11-12 22:25:52 +0000
54+++ lib/lp/soyuz/configure.zcml 2017-07-18 16:38:02 +0000
55@@ -1,4 +1,4 @@
56-<!-- Copyright 2009-2016 Canonical Ltd. This software is licensed under the
57+<!-- Copyright 2009-2017 Canonical Ltd. This software is licensed under the
58 GNU Affero General Public License version 3 (see the file LICENSE).
59 -->
60
61@@ -951,12 +951,16 @@
62 permission="launchpad.View"
63 interface=".interfaces.livefs.ILiveFSView
64 .interfaces.livefs.ILiveFSEditableAttributes
65+ .interfaces.livefs.ILiveFSModerateAttributes
66 .interfaces.livefs.ILiveFSAdminAttributes"/>
67 <require
68 permission="launchpad.Edit"
69 interface=".interfaces.livefs.ILiveFSEdit"
70 set_schema=".interfaces.livefs.ILiveFSEditableAttributes"/>
71 <require
72+ permission="launchpad.Moderate"
73+ set_schema=".interfaces.livefs.ILiveFSModerateAttributes"/>
74+ <require
75 permission="launchpad.Admin"
76 set_schema=".interfaces.livefs.ILiveFSAdminAttributes"/>
77 </class>
78
79=== modified file 'lib/lp/soyuz/interfaces/livefs.py'
80--- lib/lp/soyuz/interfaces/livefs.py 2015-09-15 20:16:47 +0000
81+++ lib/lp/soyuz/interfaces/livefs.py 2017-07-18 16:38:02 +0000
82@@ -1,4 +1,4 @@
83-# Copyright 2014-2015 Canonical Ltd. This software is licensed under the
84+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
85 # GNU Affero General Public License version 3 (see the file LICENSE).
86
87 """Live filesystem interfaces."""
88@@ -10,6 +10,7 @@
89 'DuplicateLiveFSName',
90 'ILiveFS',
91 'ILiveFSEditableAttributes',
92+ 'ILiveFSEditableAttributes',
93 'ILiveFSSet',
94 'ILiveFSView',
95 'LIVEFS_FEATURE_FLAG',
96@@ -249,6 +250,19 @@
97 key_type=TextLine(), required=True, readonly=False))
98
99
100+class ILiveFSModerateAttributes(Interface):
101+ """Restricted `ILiveFS` attributes.
102+
103+ These attributes need launchpad.View to see, and launchpad.Moderate to
104+ change.
105+ """
106+ relative_build_score = exported(Int(
107+ title=_("Relative build score"), required=True, readonly=False,
108+ description=_(
109+ "A delta to apply to all build scores for the live filesystem. "
110+ "Builds with a higher score will build sooner.")))
111+
112+
113 class ILiveFSAdminAttributes(Interface):
114 """`ILiveFS` attributes that can be edited by admins.
115
116@@ -262,7 +276,7 @@
117
118 class ILiveFS(
119 ILiveFSView, ILiveFSEdit, ILiveFSEditableAttributes,
120- ILiveFSAdminAttributes):
121+ ILiveFSModerateAttributes, ILiveFSAdminAttributes):
122 """A buildable live filesystem image."""
123
124 # XXX cjwatson 2014-05-06 bug=760849: "beta" is a lie to get WADL
125
126=== modified file 'lib/lp/soyuz/model/livefs.py'
127--- lib/lp/soyuz/model/livefs.py 2015-11-26 15:46:38 +0000
128+++ lib/lp/soyuz/model/livefs.py 2017-07-18 16:38:02 +0000
129@@ -1,4 +1,4 @@
130-# Copyright 2014-2015 Canonical Ltd. This software is licensed under the
131+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
132 # GNU Affero General Public License version 3 (see the file LICENSE).
133
134 __metaclass__ = type
135@@ -111,6 +111,8 @@
136
137 require_virtualized = Bool(name='require_virtualized')
138
139+ relative_build_score = Int(name='relative_build_score', allow_none=False)
140+
141 def __init__(self, registrant, owner, distro_series, name,
142 metadata, require_virtualized, date_created):
143 """Construct a `LiveFS`."""
144@@ -123,6 +125,7 @@
145 self.name = name
146 self.metadata = metadata
147 self.require_virtualized = require_virtualized
148+ self.relative_build_score = 0
149 self.date_created = date_created
150 self.date_last_modified = date_created
151
152
153=== modified file 'lib/lp/soyuz/model/livefsbuild.py'
154--- lib/lp/soyuz/model/livefsbuild.py 2016-08-12 12:56:41 +0000
155+++ lib/lp/soyuz/model/livefsbuild.py 2017-07-18 16:38:02 +0000
156@@ -1,4 +1,4 @@
157-# Copyright 2014-2015 Canonical Ltd. This software is licensed under the
158+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
159 # GNU Affero General Public License version 3 (see the file LICENSE).
160
161 __metaclass__ = type
162@@ -250,7 +250,9 @@
163 self.buildqueue_record.cancel()
164
165 def calculateScore(self):
166- return 2510 + self.archive.relative_build_score
167+ return (
168+ 2510 + self.archive.relative_build_score +
169+ self.livefs.relative_build_score)
170
171 def getMedianBuildDuration(self):
172 """Return the median duration of our successful builds."""
173
174=== modified file 'lib/lp/soyuz/tests/test_livefs.py'
175--- lib/lp/soyuz/tests/test_livefs.py 2016-08-12 12:56:41 +0000
176+++ lib/lp/soyuz/tests/test_livefs.py 2017-07-18 16:38:02 +0000
177@@ -1,4 +1,4 @@
178-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
179+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
180 # GNU Affero General Public License version 3 (see the file LICENSE).
181
182 """Test live filesystems."""
183@@ -17,6 +17,7 @@
184 import transaction
185 from zope.component import getUtility
186 from zope.event import notify
187+from zope.security.interfaces import Unauthorized
188 from zope.security.proxy import removeSecurityProxy
189
190 from lp.buildmaster.enums import (
191@@ -44,6 +45,7 @@
192 from lp.testing import (
193 ANONYMOUS,
194 api_url,
195+ celebrity_logged_in,
196 login,
197 logout,
198 person_logged_in,
199@@ -109,6 +111,16 @@
200 self.assertSqlAttributeEqualsDate(
201 livefs, "date_last_modified", UTC_NOW)
202
203+ def test_relative_build_score(self):
204+ # Buildd admins can change the relative build score of a LiveFS, but
205+ # ordinary users cannot.
206+ livefs = self.factory.makeLiveFS()
207+ with person_logged_in(livefs.owner):
208+ self.assertRaises(
209+ Unauthorized, setattr, livefs, "relative_build_score", 100)
210+ with celebrity_logged_in("buildd_admin"):
211+ livefs.relative_build_score = 100
212+
213 def test_requestBuild(self):
214 # requestBuild creates a new LiveFSBuild.
215 livefs = self.factory.makeLiveFS()
216@@ -150,8 +162,9 @@
217 self.assertEqual(2510, queue_record.lastscore)
218
219 def test_requestBuild_relative_build_score(self):
220- # Offsets for archives are respected.
221+ # Offsets for archives and livefses are respected.
222 livefs = self.factory.makeLiveFS()
223+ removeSecurityProxy(livefs).relative_build_score = 50
224 archive = self.factory.makeArchive(owner=livefs.owner)
225 removeSecurityProxy(archive).relative_build_score = 100
226 distroarchseries = self.factory.makeDistroArchSeries(
227@@ -161,7 +174,7 @@
228 PackagePublishingPocket.RELEASE)
229 queue_record = build.buildqueue_record
230 queue_record.score()
231- self.assertEqual(2610, queue_record.lastscore)
232+ self.assertEqual(2660, queue_record.lastscore)
233
234 def test_requestBuild_rejects_repeats(self):
235 # requestBuild refuses if there is already a pending build.