Merge lp:~cjwatson/launchpad/snap-request-builds-ui into lp:launchpad
- snap-request-builds-ui
- Merge into devel
Proposed by
Colin Watson
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 18780 | ||||
Proposed branch: | lp:~cjwatson/launchpad/snap-request-builds-ui | ||||
Merge into: | lp:launchpad | ||||
Prerequisite: | lp:~cjwatson/launchpad/snap-daily-builds-request-builds | ||||
Diff against target: |
1746 lines (+1034/-232) 14 files modified
lib/lp/app/browser/configure.zcml (+8/-1) lib/lp/app/browser/tales.py (+35/-1) lib/lp/snappy/browser/snap.py (+20/-17) lib/lp/snappy/browser/tests/test_snap.py (+62/-23) lib/lp/snappy/interfaces/snap.py (+36/-3) lib/lp/snappy/interfaces/snapjob.py (+21/-0) lib/lp/snappy/javascript/snap.update_build_statuses.js (+131/-38) lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.html (+20/-14) lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.js (+342/-126) lib/lp/snappy/model/snap.py (+100/-3) lib/lp/snappy/model/snapjob.py (+62/-4) lib/lp/snappy/templates/snap-index.pt (+12/-0) lib/lp/snappy/tests/test_snap.py (+172/-2) lib/lp/testing/factory.py (+13/-0) |
||||
To merge this branch: | bzr merge lp:~cjwatson/launchpad/snap-request-builds-ui | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email: mp+348299@code.launchpad.net |
Commit message
Convert the snap web UI to use Snap.requestBuilds.
Description of the change
The hard bit here was sorting out the JavaScript that auto-refreshes bits of Snap:+index. I went for converting Snap.getBuildSu
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/app/browser/configure.zcml' | |||
2 | --- lib/lp/app/browser/configure.zcml 2017-09-01 12:57:34 +0000 | |||
3 | +++ lib/lp/app/browser/configure.zcml 2018-09-13 15:15:44 +0000 | |||
4 | @@ -1,4 +1,4 @@ | |||
6 | 1 | <!-- Copyright 2009-2015 Canonical Ltd. This software is licensed under the | 1 | <!-- Copyright 2009-2018 Canonical Ltd. This software is licensed under the |
7 | 2 | GNU Affero General Public License version 3 (see the file LICENSE). | 2 | GNU Affero General Public License version 3 (see the file LICENSE). |
8 | 3 | --> | 3 | --> |
9 | 4 | 4 | ||
10 | @@ -591,6 +591,13 @@ | |||
11 | 591 | name="image" | 591 | name="image" |
12 | 592 | /> | 592 | /> |
13 | 593 | 593 | ||
14 | 594 | <adapter | ||
15 | 595 | for="lp.snappy.interfaces.snap.ISnapBuildRequest" | ||
16 | 596 | provides="zope.traversing.interfaces.IPathAdapter" | ||
17 | 597 | factory="lp.app.browser.tales.SnapBuildRequestImageDisplayAPI" | ||
18 | 598 | name="image" | ||
19 | 599 | /> | ||
20 | 600 | |||
21 | 594 | <!-- TALES badges: namespace --> | 601 | <!-- TALES badges: namespace --> |
22 | 595 | 602 | ||
23 | 596 | <adapter | 603 | <adapter |
24 | 597 | 604 | ||
25 | === modified file 'lib/lp/app/browser/tales.py' | |||
26 | --- lib/lp/app/browser/tales.py 2017-11-10 11:23:27 +0000 | |||
27 | +++ lib/lp/app/browser/tales.py 2018-09-13 15:15:44 +0000 | |||
28 | @@ -1,4 +1,4 @@ | |||
30 | 1 | # Copyright 2009-2017 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2009-2018 Canonical Ltd. This software is licensed under the |
31 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
32 | 3 | 3 | ||
33 | 4 | """Implementation of the lp: htmlform: fmt: namespaces in TALES.""" | 4 | """Implementation of the lp: htmlform: fmt: namespaces in TALES.""" |
34 | @@ -95,6 +95,7 @@ | |||
35 | 95 | ) | 95 | ) |
36 | 96 | from lp.services.webapp.session import get_cookie_domain | 96 | from lp.services.webapp.session import get_cookie_domain |
37 | 97 | from lp.services.webapp.url import urlappend | 97 | from lp.services.webapp.url import urlappend |
38 | 98 | from lp.snappy.interfaces.snap import SnapBuildRequestStatus | ||
39 | 98 | from lp.soyuz.enums import ArchivePurpose | 99 | from lp.soyuz.enums import ArchivePurpose |
40 | 99 | from lp.soyuz.interfaces.archive import ( | 100 | from lp.soyuz.interfaces.archive import ( |
41 | 100 | IArchive, | 101 | IArchive, |
42 | @@ -1164,6 +1165,39 @@ | |||
43 | 1164 | return self.icon_template % (alt, title, source) | 1165 | return self.icon_template % (alt, title, source) |
44 | 1165 | 1166 | ||
45 | 1166 | 1167 | ||
46 | 1168 | class SnapBuildRequestImageDisplayAPI(ObjectImageDisplayAPI): | ||
47 | 1169 | """Adapter for ISnapBuildRequest objects to an image. | ||
48 | 1170 | |||
49 | 1171 | Used for image:icon. | ||
50 | 1172 | """ | ||
51 | 1173 | icon_template = ( | ||
52 | 1174 | '<img width="%(width)s" height="14" alt="%(alt)s" ' | ||
53 | 1175 | 'title="%(title)s" src="%(src)s" />') | ||
54 | 1176 | |||
55 | 1177 | def icon(self): | ||
56 | 1178 | """Return the appropriate <img> tag for the build request icon.""" | ||
57 | 1179 | icon_map = { | ||
58 | 1180 | SnapBuildRequestStatus.PENDING: {'src': "/@@/processing"}, | ||
59 | 1181 | SnapBuildRequestStatus.FAILED: { | ||
60 | 1182 | 'src': "/@@/build-failed", | ||
61 | 1183 | 'width': "16", | ||
62 | 1184 | }, | ||
63 | 1185 | SnapBuildRequestStatus.COMPLETED: {'src': "/@@/build-success"}, | ||
64 | 1186 | } | ||
65 | 1187 | |||
66 | 1188 | alt = '[%s]' % self._context.status.name | ||
67 | 1189 | title = self._context.status.title | ||
68 | 1190 | source = icon_map[self._context.status].get('src') | ||
69 | 1191 | width = icon_map[self._context.status].get('width', '14') | ||
70 | 1192 | |||
71 | 1193 | return self.icon_template % { | ||
72 | 1194 | 'alt': alt, | ||
73 | 1195 | 'title': title, | ||
74 | 1196 | 'src': source, | ||
75 | 1197 | 'width': width, | ||
76 | 1198 | } | ||
77 | 1199 | |||
78 | 1200 | |||
79 | 1167 | class BadgeDisplayAPI: | 1201 | class BadgeDisplayAPI: |
80 | 1168 | """Adapter for IHasBadges to the images for the badges. | 1202 | """Adapter for IHasBadges to the images for the badges. |
81 | 1169 | 1203 | ||
82 | 1170 | 1204 | ||
83 | === modified file 'lib/lp/snappy/browser/snap.py' | |||
84 | --- lib/lp/snappy/browser/snap.py 2018-09-13 09:36:38 +0000 | |||
85 | +++ lib/lp/snappy/browser/snap.py 2018-09-13 15:15:44 +0000 | |||
86 | @@ -257,11 +257,16 @@ | |||
87 | 257 | archive = Reference(IArchive, title=u'Source archive', required=True) | 257 | archive = Reference(IArchive, title=u'Source archive', required=True) |
88 | 258 | distro_arch_series = List( | 258 | distro_arch_series = List( |
89 | 259 | Choice(vocabulary='SnapDistroArchSeries'), | 259 | Choice(vocabulary='SnapDistroArchSeries'), |
91 | 260 | title=u'Architectures', required=True) | 260 | title=u'Architectures', required=True, |
92 | 261 | description=( | ||
93 | 262 | u'If you do not explicitly select any architectures, then ' | ||
94 | 263 | u'the snap package will be built for all architectures ' | ||
95 | 264 | u'allowed by its configuration.')) | ||
96 | 261 | pocket = Choice( | 265 | pocket = Choice( |
97 | 262 | title=u'Pocket', vocabulary=PackagePublishingPocket, required=True, | 266 | title=u'Pocket', vocabulary=PackagePublishingPocket, required=True, |
100 | 263 | description=u'The package stream within the source distribution ' | 267 | description=( |
101 | 264 | 'series to use when building the snap package.') | 268 | u'The package stream within the source distribution series ' |
102 | 269 | u'to use when building the snap package.')) | ||
103 | 265 | 270 | ||
104 | 266 | custom_widget_archive = SnapArchiveWidget | 271 | custom_widget_archive = SnapArchiveWidget |
105 | 267 | custom_widget_distro_arch_series = LabeledMultiCheckBoxWidget | 272 | custom_widget_distro_arch_series = LabeledMultiCheckBoxWidget |
106 | @@ -280,18 +285,10 @@ | |||
107 | 280 | """See `LaunchpadFormView`.""" | 285 | """See `LaunchpadFormView`.""" |
108 | 281 | return { | 286 | return { |
109 | 282 | 'archive': self.context.distro_series.main_archive, | 287 | 'archive': self.context.distro_series.main_archive, |
111 | 283 | 'distro_arch_series': self.context.getAllowedArchitectures(), | 288 | 'distro_arch_series': [], |
112 | 284 | 'pocket': PackagePublishingPocket.UPDATES, | 289 | 'pocket': PackagePublishingPocket.UPDATES, |
113 | 285 | } | 290 | } |
114 | 286 | 291 | ||
115 | 287 | def validate(self, data): | ||
116 | 288 | """See `LaunchpadFormView`.""" | ||
117 | 289 | arches = data.get('distro_arch_series', []) | ||
118 | 290 | if not arches: | ||
119 | 291 | self.setFieldError( | ||
120 | 292 | 'distro_arch_series', | ||
121 | 293 | "You need to select at least one architecture.") | ||
122 | 294 | |||
123 | 295 | def requestBuild(self, data): | 292 | def requestBuild(self, data): |
124 | 296 | """User action for requesting a number of builds. | 293 | """User action for requesting a number of builds. |
125 | 297 | 294 | ||
126 | @@ -318,12 +315,18 @@ | |||
127 | 318 | 315 | ||
128 | 319 | @action('Request builds', name='request') | 316 | @action('Request builds', name='request') |
129 | 320 | def request_action(self, action, data): | 317 | def request_action(self, action, data): |
131 | 321 | builds, informational = self.requestBuild(data) | 318 | if data['distro_arch_series']: |
132 | 319 | builds, informational = self.requestBuild(data) | ||
133 | 320 | already_pending = informational.get('already_pending') | ||
134 | 321 | notification_text = new_builds_notification_text( | ||
135 | 322 | builds, already_pending) | ||
136 | 323 | self.request.response.addNotification(notification_text) | ||
137 | 324 | else: | ||
138 | 325 | self.context.requestBuilds( | ||
139 | 326 | self.user, data['archive'], data['pocket']) | ||
140 | 327 | self.request.response.addNotification( | ||
141 | 328 | _('Builds will be dispatched soon.')) | ||
142 | 322 | self.next_url = self.cancel_url | 329 | self.next_url = self.cancel_url |
143 | 323 | already_pending = informational.get('already_pending') | ||
144 | 324 | notification_text = new_builds_notification_text( | ||
145 | 325 | builds, already_pending) | ||
146 | 326 | self.request.response.addNotification(notification_text) | ||
147 | 327 | 330 | ||
148 | 328 | 331 | ||
149 | 329 | class ISnapEditSchema(Interface): | 332 | class ISnapEditSchema(Interface): |
150 | 330 | 333 | ||
151 | === modified file 'lib/lp/snappy/browser/tests/test_snap.py' | |||
152 | --- lib/lp/snappy/browser/tests/test_snap.py 2018-07-13 16:42:08 +0000 | |||
153 | +++ lib/lp/snappy/browser/tests/test_snap.py 2018-09-13 15:15:44 +0000 | |||
154 | @@ -26,6 +26,9 @@ | |||
155 | 26 | import responses | 26 | import responses |
156 | 27 | import soupmatchers | 27 | import soupmatchers |
157 | 28 | from testtools.matchers import ( | 28 | from testtools.matchers import ( |
158 | 29 | AfterPreprocessing, | ||
159 | 30 | Equals, | ||
160 | 31 | Is, | ||
161 | 29 | MatchesSetwise, | 32 | MatchesSetwise, |
162 | 30 | MatchesStructure, | 33 | MatchesStructure, |
163 | 31 | ) | 34 | ) |
164 | @@ -33,6 +36,7 @@ | |||
165 | 33 | from zope.component import getUtility | 36 | from zope.component import getUtility |
166 | 34 | from zope.publisher.interfaces import NotFound | 37 | from zope.publisher.interfaces import NotFound |
167 | 35 | from zope.security.interfaces import Unauthorized | 38 | from zope.security.interfaces import Unauthorized |
168 | 39 | from zope.security.proxy import removeSecurityProxy | ||
169 | 36 | 40 | ||
170 | 37 | from lp.app.enums import InformationType | 41 | from lp.app.enums import InformationType |
171 | 38 | from lp.app.interfaces.launchpad import ILaunchpadCelebrities | 42 | from lp.app.interfaces.launchpad import ILaunchpadCelebrities |
172 | @@ -64,6 +68,7 @@ | |||
173 | 64 | ISnapSet, | 68 | ISnapSet, |
174 | 65 | SNAP_PRIVATE_FEATURE_FLAG, | 69 | SNAP_PRIVATE_FEATURE_FLAG, |
175 | 66 | SNAP_TESTING_FLAGS, | 70 | SNAP_TESTING_FLAGS, |
176 | 71 | SnapBuildRequestStatus, | ||
177 | 67 | SnapPrivateFeatureDisabled, | 72 | SnapPrivateFeatureDisabled, |
178 | 68 | ) | 73 | ) |
179 | 69 | from lp.snappy.interfaces.snappyseries import ISnappyDistroSeriesSet | 74 | from lp.snappy.interfaces.snappyseries import ISnappyDistroSeriesSet |
180 | @@ -1443,6 +1448,9 @@ | |||
181 | 1443 | Architectures: | 1448 | Architectures: |
182 | 1444 | amd64 | 1449 | amd64 |
183 | 1445 | i386 | 1450 | i386 |
184 | 1451 | If you do not explicitly select any architectures, then the snap | ||
185 | 1452 | package will be built for all architectures allowed by its | ||
186 | 1453 | configuration. | ||
187 | 1446 | Pocket: | 1454 | Pocket: |
188 | 1447 | Release | 1455 | Release |
189 | 1448 | Security | 1456 | Security |
190 | @@ -1462,12 +1470,13 @@ | |||
191 | 1462 | self.assertRaises( | 1470 | self.assertRaises( |
192 | 1463 | Unauthorized, self.getViewBrowser, self.snap, "+request-builds") | 1471 | Unauthorized, self.getViewBrowser, self.snap, "+request-builds") |
193 | 1464 | 1472 | ||
196 | 1465 | def test_request_builds_action(self): | 1473 | def test_request_builds_with_architectures_action(self): |
197 | 1466 | # Requesting a build creates pending builds. | 1474 | # Requesting a build with architectures selected creates pending |
198 | 1475 | # builds. | ||
199 | 1467 | browser = self.getViewBrowser( | 1476 | browser = self.getViewBrowser( |
200 | 1468 | self.snap, "+request-builds", user=self.person) | 1477 | self.snap, "+request-builds", user=self.person) |
203 | 1469 | self.assertTrue(browser.getControl("amd64").selected) | 1478 | browser.getControl("amd64").selected = True |
204 | 1470 | self.assertTrue(browser.getControl("i386").selected) | 1479 | browser.getControl("i386").selected = True |
205 | 1471 | browser.getControl("Request builds").click() | 1480 | browser.getControl("Request builds").click() |
206 | 1472 | 1481 | ||
207 | 1473 | login_person(self.person) | 1482 | login_person(self.person) |
208 | @@ -1483,44 +1492,74 @@ | |||
209 | 1483 | self.assertContentEqual( | 1492 | self.assertContentEqual( |
210 | 1484 | [2510], set(build.buildqueue_record.lastscore for build in builds)) | 1493 | [2510], set(build.buildqueue_record.lastscore for build in builds)) |
211 | 1485 | 1494 | ||
214 | 1486 | def test_request_builds_ppa(self): | 1495 | def test_request_builds_with_architectures_ppa(self): |
215 | 1487 | # Selecting a different archive creates builds in that archive. | 1496 | # Selecting a different archive with architectures selected creates |
216 | 1497 | # builds in that archive. | ||
217 | 1488 | ppa = self.factory.makeArchive( | 1498 | ppa = self.factory.makeArchive( |
218 | 1489 | distribution=self.ubuntu, owner=self.person, name="snap-ppa") | 1499 | distribution=self.ubuntu, owner=self.person, name="snap-ppa") |
219 | 1490 | browser = self.getViewBrowser( | 1500 | browser = self.getViewBrowser( |
220 | 1491 | self.snap, "+request-builds", user=self.person) | 1501 | self.snap, "+request-builds", user=self.person) |
221 | 1492 | browser.getControl("PPA").click() | 1502 | browser.getControl("PPA").click() |
222 | 1493 | browser.getControl(name="field.archive.ppa").value = ppa.reference | 1503 | browser.getControl(name="field.archive.ppa").value = ppa.reference |
225 | 1494 | self.assertTrue(browser.getControl("amd64").selected) | 1504 | browser.getControl("amd64").selected = True |
226 | 1495 | browser.getControl("i386").selected = False | 1505 | self.assertFalse(browser.getControl("i386").selected) |
227 | 1496 | browser.getControl("Request builds").click() | 1506 | browser.getControl("Request builds").click() |
228 | 1497 | 1507 | ||
229 | 1498 | login_person(self.person) | 1508 | login_person(self.person) |
230 | 1499 | builds = self.snap.pending_builds | 1509 | builds = self.snap.pending_builds |
231 | 1500 | self.assertEqual([ppa], [build.archive for build in builds]) | 1510 | self.assertEqual([ppa], [build.archive for build in builds]) |
232 | 1501 | 1511 | ||
246 | 1502 | def test_request_builds_no_architectures(self): | 1512 | def test_request_builds_with_architectures_rejects_duplicate(self): |
247 | 1503 | # Selecting no architectures causes a validation failure. | 1513 | # A duplicate build request with architectures selected causes a |
248 | 1504 | browser = self.getViewBrowser( | 1514 | # notification. |
236 | 1505 | self.snap, "+request-builds", user=self.person) | ||
237 | 1506 | browser.getControl("amd64").selected = False | ||
238 | 1507 | browser.getControl("i386").selected = False | ||
239 | 1508 | browser.getControl("Request builds").click() | ||
240 | 1509 | self.assertIn( | ||
241 | 1510 | "You need to select at least one architecture.", | ||
242 | 1511 | extract_text(find_main_content(browser.contents))) | ||
243 | 1512 | |||
244 | 1513 | def test_request_builds_rejects_duplicate(self): | ||
245 | 1514 | # A duplicate build request causes a notification. | ||
249 | 1515 | self.snap.requestBuild( | 1515 | self.snap.requestBuild( |
250 | 1516 | self.person, self.ubuntu.main_archive, self.distroseries["amd64"], | 1516 | self.person, self.ubuntu.main_archive, self.distroseries["amd64"], |
251 | 1517 | PackagePublishingPocket.UPDATES) | 1517 | PackagePublishingPocket.UPDATES) |
252 | 1518 | browser = self.getViewBrowser( | 1518 | browser = self.getViewBrowser( |
253 | 1519 | self.snap, "+request-builds", user=self.person) | 1519 | self.snap, "+request-builds", user=self.person) |
256 | 1520 | self.assertTrue(browser.getControl("amd64").selected) | 1520 | browser.getControl("amd64").selected = True |
257 | 1521 | self.assertTrue(browser.getControl("i386").selected) | 1521 | browser.getControl("i386").selected = True |
258 | 1522 | browser.getControl("Request builds").click() | 1522 | browser.getControl("Request builds").click() |
259 | 1523 | main_text = extract_text(find_main_content(browser.contents)) | 1523 | main_text = extract_text(find_main_content(browser.contents)) |
260 | 1524 | self.assertIn("1 new build has been queued.", main_text) | 1524 | self.assertIn("1 new build has been queued.", main_text) |
261 | 1525 | self.assertIn( | 1525 | self.assertIn( |
262 | 1526 | "An identical build is already pending for amd64.", main_text) | 1526 | "An identical build is already pending for amd64.", main_text) |
263 | 1527 | |||
264 | 1528 | def test_request_builds_no_architectures_action(self): | ||
265 | 1529 | # Requesting a build with no architectures selected creates a | ||
266 | 1530 | # pending build request. | ||
267 | 1531 | browser = self.getViewBrowser( | ||
268 | 1532 | self.snap, "+request-builds", user=self.person) | ||
269 | 1533 | self.assertFalse(browser.getControl("amd64").selected) | ||
270 | 1534 | self.assertFalse(browser.getControl("i386").selected) | ||
271 | 1535 | browser.getControl("Request builds").click() | ||
272 | 1536 | |||
273 | 1537 | login_person(self.person) | ||
274 | 1538 | [request] = self.snap.pending_build_requests | ||
275 | 1539 | self.assertThat(removeSecurityProxy(request), MatchesStructure( | ||
276 | 1540 | snap=Equals(self.snap), | ||
277 | 1541 | status=Equals(SnapBuildRequestStatus.PENDING), | ||
278 | 1542 | error_message=Is(None), | ||
279 | 1543 | builds=AfterPreprocessing(list, Equals([])), | ||
280 | 1544 | archive=Equals(self.ubuntu.main_archive), | ||
281 | 1545 | _job=MatchesStructure( | ||
282 | 1546 | requester=Equals(self.person), | ||
283 | 1547 | pocket=Equals(PackagePublishingPocket.UPDATES), | ||
284 | 1548 | channels=Is(None)))) | ||
285 | 1549 | |||
286 | 1550 | def test_request_builds_no_architectures_ppa(self): | ||
287 | 1551 | # Selecting a different archive with no architectures selected | ||
288 | 1552 | # creates a build request targeting that archive. | ||
289 | 1553 | ppa = self.factory.makeArchive( | ||
290 | 1554 | distribution=self.ubuntu, owner=self.person, name="snap-ppa") | ||
291 | 1555 | browser = self.getViewBrowser( | ||
292 | 1556 | self.snap, "+request-builds", user=self.person) | ||
293 | 1557 | browser.getControl("PPA").click() | ||
294 | 1558 | browser.getControl(name="field.archive.ppa").value = ppa.reference | ||
295 | 1559 | self.assertFalse(browser.getControl("amd64").selected) | ||
296 | 1560 | self.assertFalse(browser.getControl("i386").selected) | ||
297 | 1561 | browser.getControl("Request builds").click() | ||
298 | 1562 | |||
299 | 1563 | login_person(self.person) | ||
300 | 1564 | [request] = self.snap.pending_build_requests | ||
301 | 1565 | self.assertEqual(ppa, request.archive) | ||
302 | 1527 | 1566 | ||
303 | === modified file 'lib/lp/snappy/interfaces/snap.py' | |||
304 | --- lib/lp/snappy/interfaces/snap.py 2018-09-10 11:18:42 +0000 | |||
305 | +++ lib/lp/snappy/interfaces/snap.py 2018-09-13 15:15:44 +0000 | |||
306 | @@ -317,6 +317,11 @@ | |||
307 | 317 | value_type=Reference(schema=Interface), | 317 | value_type=Reference(schema=Interface), |
308 | 318 | required=True, readonly=True)) | 318 | required=True, readonly=True)) |
309 | 319 | 319 | ||
310 | 320 | archive = Reference( | ||
311 | 321 | IArchive, | ||
312 | 322 | title=u"The source archive for builds produced by this request", | ||
313 | 323 | required=True, readonly=True) | ||
314 | 324 | |||
315 | 320 | 325 | ||
316 | 321 | class ISnapView(Interface): | 326 | class ISnapView(Interface): |
317 | 322 | """`ISnap` attributes that require launchpad.View permission.""" | 327 | """`ISnap` attributes that require launchpad.View permission.""" |
318 | @@ -449,21 +454,49 @@ | |||
319 | 449 | :return: `ISnapBuildRequest`. | 454 | :return: `ISnapBuildRequest`. |
320 | 450 | """ | 455 | """ |
321 | 451 | 456 | ||
322 | 457 | pending_build_requests = exported(doNotSnapshot(CollectionField( | ||
323 | 458 | title=_("Pending build requests for this snap package."), | ||
324 | 459 | value_type=Reference(ISnapBuildRequest), | ||
325 | 460 | required=True, readonly=True))) | ||
326 | 461 | |||
327 | 462 | # XXX cjwatson 2018-06-20: Deprecated as an exported method; can become | ||
328 | 463 | # an internal helper method once production JavaScript no longer uses | ||
329 | 464 | # it. | ||
330 | 452 | @operation_parameters( | 465 | @operation_parameters( |
331 | 453 | snap_build_ids=List( | 466 | snap_build_ids=List( |
334 | 454 | title=_("A list of snap build ids."), | 467 | title=_("A list of snap build IDs."), value_type=Int())) |
333 | 455 | value_type=Int())) | ||
335 | 456 | @export_read_operation() | 468 | @export_read_operation() |
336 | 457 | @operation_for_version("devel") | 469 | @operation_for_version("devel") |
337 | 458 | def getBuildSummariesForSnapBuildIds(snap_build_ids): | 470 | def getBuildSummariesForSnapBuildIds(snap_build_ids): |
338 | 459 | """Return a dictionary containing a summary of the build statuses. | 471 | """Return a dictionary containing a summary of the build statuses. |
339 | 460 | 472 | ||
341 | 461 | :param snap_build_ids: A list of snap build ids. | 473 | :param snap_build_ids: A list of snap build IDs. |
342 | 462 | :type source_ids: ``list`` | 474 | :type source_ids: ``list`` |
343 | 463 | :return: A dict consisting of the overall status summaries for the | 475 | :return: A dict consisting of the overall status summaries for the |
344 | 464 | given snap builds. | 476 | given snap builds. |
345 | 465 | """ | 477 | """ |
346 | 466 | 478 | ||
347 | 479 | @call_with(user=REQUEST_USER) | ||
348 | 480 | @operation_parameters( | ||
349 | 481 | request_ids=List( | ||
350 | 482 | title=_("A list of snap build request IDs."), value_type=Int(), | ||
351 | 483 | required=False), | ||
352 | 484 | build_ids=List( | ||
353 | 485 | title=_("A list of snap build IDs."), value_type=Int(), | ||
354 | 486 | required=False)) | ||
355 | 487 | @export_read_operation() | ||
356 | 488 | @operation_for_version("devel") | ||
357 | 489 | def getBuildSummaries(request_ids=None, build_ids=None, user=None): | ||
358 | 490 | """Return a dictionary containing a summary of build information. | ||
359 | 491 | |||
360 | 492 | :param request_ids: A list of snap build request IDs. | ||
361 | 493 | :param build_ids: A list of snap build IDs. | ||
362 | 494 | :param user: The `IPerson` requesting this information. | ||
363 | 495 | :return: A dict of {"requests", "builds"}, consisting of the overall | ||
364 | 496 | status summaries for the given snap build requests and snap | ||
365 | 497 | builds respectively. | ||
366 | 498 | """ | ||
367 | 499 | |||
368 | 467 | builds = exported(doNotSnapshot(CollectionField( | 500 | builds = exported(doNotSnapshot(CollectionField( |
369 | 468 | title=_("All builds of this snap package."), | 501 | title=_("All builds of this snap package."), |
370 | 469 | description=_( | 502 | description=_( |
371 | 470 | 503 | ||
372 | === modified file 'lib/lp/snappy/interfaces/snapjob.py' | |||
373 | --- lib/lp/snappy/interfaces/snapjob.py 2018-09-10 11:18:42 +0000 | |||
374 | +++ lib/lp/snappy/interfaces/snapjob.py 2018-09-13 15:15:44 +0000 | |||
375 | @@ -112,6 +112,16 @@ | |||
376 | 112 | for these builds. | 112 | for these builds. |
377 | 113 | """ | 113 | """ |
378 | 114 | 114 | ||
379 | 115 | def findBySnap(snap, statuses=None, job_ids=None): | ||
380 | 116 | """Find jobs for a snap. | ||
381 | 117 | |||
382 | 118 | :param snap: A snap package to search for. | ||
383 | 119 | :param statuses: An optional iterable of `JobStatus`es to search for. | ||
384 | 120 | :param job_ids: An optional iterable of job IDs to search for. | ||
385 | 121 | :return: A sequence of `SnapRequestBuildsJob`s with the specified | ||
386 | 122 | snap. | ||
387 | 123 | """ | ||
388 | 124 | |||
389 | 115 | def getBySnapAndID(snap, job_id): | 125 | def getBySnapAndID(snap, job_id): |
390 | 116 | """Get a job by snap and job ID. | 126 | """Get a job by snap and job ID. |
391 | 117 | 127 | ||
392 | @@ -119,3 +129,14 @@ | |||
393 | 119 | :raises: `NotFoundError` if there is no job with the specified snap | 129 | :raises: `NotFoundError` if there is no job with the specified snap |
394 | 120 | and ID, or its `job_type` is not `SnapJobType.REQUEST_BUILDS`. | 130 | and ID, or its `job_type` is not `SnapJobType.REQUEST_BUILDS`. |
395 | 121 | """ | 131 | """ |
396 | 132 | |||
397 | 133 | def findBuildsForJobs(jobs, user=None): | ||
398 | 134 | """Find builds resulting from an iterable of `SnapRequestBuildJob`s. | ||
399 | 135 | |||
400 | 136 | :param jobs: An iterable of `SnapRequestBuildJob`s to search for. | ||
401 | 137 | :param user: If passed, check that the builds are for archives | ||
402 | 138 | visible by this user. (No access checks are performed on the | ||
403 | 139 | snaps or on the builds.) | ||
404 | 140 | :return: A dictionary mapping `SnapRequestBuildJob` IDs to lists of | ||
405 | 141 | their resulting builds. | ||
406 | 142 | """ | ||
407 | 122 | 143 | ||
408 | === modified file 'lib/lp/snappy/javascript/snap.update_build_statuses.js' | |||
409 | --- lib/lp/snappy/javascript/snap.update_build_statuses.js 2017-08-31 13:35:55 +0000 | |||
410 | +++ lib/lp/snappy/javascript/snap.update_build_statuses.js 2018-09-13 15:15:44 +0000 | |||
411 | @@ -1,4 +1,4 @@ | |||
413 | 1 | /* Copyright 2016 Canonical Ltd. This software is licensed under the | 1 | /* Copyright 2016-2018 Canonical Ltd. This software is licensed under the |
414 | 2 | * GNU Affero General Public License version 3 (see the file LICENSE). | 2 | * GNU Affero General Public License version 3 (see the file LICENSE). |
415 | 3 | * | 3 | * |
416 | 4 | * The lp.snappy.snap.update_build_statuses module uses the | 4 | * The lp.snappy.snap.update_build_statuses module uses the |
417 | @@ -15,11 +15,108 @@ | |||
418 | 15 | module.pending_states = [ | 15 | module.pending_states = [ |
419 | 16 | "NEEDSBUILD", "BUILDING", "UPLOADING", "CANCELLING"]; | 16 | "NEEDSBUILD", "BUILDING", "UPLOADING", "CANCELLING"]; |
420 | 17 | 17 | ||
421 | 18 | module.update_date_built = function(node, build_summary) { | ||
422 | 19 | node.set("text", build_summary.when_complete); | ||
423 | 20 | if (build_summary.when_complete_estimate) { | ||
424 | 21 | node.appendChild(document.createTextNode(' (estimated)')); | ||
425 | 22 | } | ||
426 | 23 | if (build_summary.build_log_url !== null) { | ||
427 | 24 | var new_link = Y.Node.create( | ||
428 | 25 | '<a class="sprite download">buildlog</a>'); | ||
429 | 26 | new_link.setAttribute('href', build_summary.build_log_url); | ||
430 | 27 | node.appendChild(document.createTextNode(' ')); | ||
431 | 28 | node.appendChild(new_link); | ||
432 | 29 | if (build_summary.build_log_size !== null) { | ||
433 | 30 | node.appendChild(document.createTextNode(' ')); | ||
434 | 31 | node.append("(" + build_summary.build_log_size + " bytes)"); | ||
435 | 32 | } | ||
436 | 33 | } | ||
437 | 34 | }; | ||
438 | 35 | |||
439 | 18 | module.domUpdate = function(table, data_object) { | 36 | module.domUpdate = function(table, data_object) { |
441 | 19 | Y.each(data_object, function(build_summary, build_id) { | 37 | var tbody = table.one('tbody'); |
442 | 38 | if (tbody === null) { | ||
443 | 39 | return; | ||
444 | 40 | } | ||
445 | 41 | var tbody_changed = false; | ||
446 | 42 | |||
447 | 43 | Y.each(data_object['requests'], function(request_summary, request_id) { | ||
448 | 44 | var tr_elem = tbody.one('tr#request-' + request_id); | ||
449 | 45 | if (tr_elem === null) { | ||
450 | 46 | return; | ||
451 | 47 | } | ||
452 | 48 | |||
453 | 49 | if (request_summary['status'] === 'FAILED') { | ||
454 | 50 | // XXX cjwatson 2018-06-18: Maybe we should show the error | ||
455 | 51 | // message in this case, but we don't show non-pending | ||
456 | 52 | // requests in the non-JS case, so it's not clear where | ||
457 | 53 | // would be appropriate. | ||
458 | 54 | tr_elem.remove(); | ||
459 | 55 | tbody_changed = true; | ||
460 | 56 | return; | ||
461 | 57 | } else if (request_summary['status'] === 'COMPLETED') { | ||
462 | 58 | // Insert rows for the new builds. | ||
463 | 59 | Y.Array.each(request_summary['builds'], | ||
464 | 60 | function(build_summary) { | ||
465 | 61 | // Construct the new row. | ||
466 | 62 | var new_row = Y.Node.create( | ||
467 | 63 | '<tr>' + | ||
468 | 64 | '<td class="build_status"><img/><a/></td>' + | ||
469 | 65 | '<td class="datebuilt"/>' + | ||
470 | 66 | '<td><a class="sprite distribution"/></td>' + | ||
471 | 67 | '<td><span class="archive-placeholder"/></td>' + | ||
472 | 68 | '</tr>'); | ||
473 | 69 | new_row.set('id', 'build-' + build_summary.id); | ||
474 | 70 | new_row.one('td.build_status a') | ||
475 | 71 | .set('href', build_summary.self_link); | ||
476 | 72 | Y.lp.buildmaster.buildstatus.update_build_status( | ||
477 | 73 | new_row.one('td.build_status'), build_summary); | ||
478 | 74 | if (build_summary.when_complete !== null) { | ||
479 | 75 | module.update_date_built( | ||
480 | 76 | new_row.one('td.datebuilt'), build_summary); | ||
481 | 77 | } | ||
482 | 78 | new_row.one('td a.distribution') | ||
483 | 79 | .set('href', build_summary.distro_arch_series_link) | ||
484 | 80 | .set('text', build_summary.architecture_tag); | ||
485 | 81 | new_row.one('td .archive-placeholder') | ||
486 | 82 | .replace(build_summary.archive_link); | ||
487 | 83 | |||
488 | 84 | // Insert the new row, maintaining descending-ID sorted | ||
489 | 85 | // order. | ||
490 | 86 | var tr_next = null; | ||
491 | 87 | tbody.get('children').some(function(tr) { | ||
492 | 88 | var tr_id = tr.get('id'); | ||
493 | 89 | if (tr_id !== null && | ||
494 | 90 | tr_id.substr(0, 6) === 'build-') { | ||
495 | 91 | var build_id = parseInt( | ||
496 | 92 | tr_id.replace('build-', ''), 10); | ||
497 | 93 | if (!isNaN(build_id) && | ||
498 | 94 | build_id < build_summary.id) { | ||
499 | 95 | tr_next = tr; | ||
500 | 96 | return true; | ||
501 | 97 | } | ||
502 | 98 | } | ||
503 | 99 | return false; | ||
504 | 100 | }); | ||
505 | 101 | tbody.insert(new_row, tr_next); | ||
506 | 102 | }); | ||
507 | 103 | |||
508 | 104 | // Remove the completed build request row. | ||
509 | 105 | tr_elem.remove(); | ||
510 | 106 | tbody_changed = true; | ||
511 | 107 | return; | ||
512 | 108 | } | ||
513 | 109 | }); | ||
514 | 110 | |||
515 | 111 | if (tbody_changed) { | ||
516 | 112 | var anim = Y.lp.anim.green_flash({node: tbody}); | ||
517 | 113 | anim.run(); | ||
518 | 114 | } | ||
519 | 115 | |||
520 | 116 | Y.each(data_object['builds'], function(build_summary, build_id) { | ||
521 | 20 | var ui_changed = false; | 117 | var ui_changed = false; |
522 | 21 | 118 | ||
524 | 22 | var tr_elem = Y.one("tr#build-" + build_id); | 119 | var tr_elem = tbody.one("tr#build-" + build_id); |
525 | 23 | if (tr_elem === null) { | 120 | if (tr_elem === null) { |
526 | 24 | return; | 121 | return; |
527 | 25 | } | 122 | } |
528 | @@ -38,25 +135,7 @@ | |||
529 | 38 | 135 | ||
530 | 39 | if (build_summary.when_complete !== null) { | 136 | if (build_summary.when_complete !== null) { |
531 | 40 | ui_changed = true; | 137 | ui_changed = true; |
551 | 41 | td_datebuilt.set("innerHTML", build_summary.when_complete); | 138 | module.update_date_built(td_datebuilt, build_summary); |
533 | 42 | if (build_summary.when_complete_estimate) { | ||
534 | 43 | td_datebuilt.appendChild( | ||
535 | 44 | document.createTextNode(' (estimated)')); | ||
536 | 45 | } | ||
537 | 46 | if (build_summary.build_log_url !== null) { | ||
538 | 47 | var new_link = Y.Node.create( | ||
539 | 48 | '<a class="sprite download">buildlog</a>'); | ||
540 | 49 | new_link.setAttribute( | ||
541 | 50 | 'href', build_summary.build_log_url); | ||
542 | 51 | td_datebuilt.appendChild(document.createTextNode(' ')); | ||
543 | 52 | td_datebuilt.appendChild(new_link); | ||
544 | 53 | if (build_summary.build_log_size !== null) { | ||
545 | 54 | td_datebuilt.appendChild( | ||
546 | 55 | document.createTextNode(' ')); | ||
547 | 56 | td_datebuilt.append( | ||
548 | 57 | "(" + build_summary.build_log_size + " bytes)"); | ||
549 | 58 | } | ||
550 | 59 | } | ||
552 | 60 | } | 139 | } |
553 | 61 | 140 | ||
554 | 62 | if (ui_changed) { | 141 | if (ui_changed) { |
555 | @@ -67,32 +146,46 @@ | |||
556 | 67 | }; | 146 | }; |
557 | 68 | 147 | ||
558 | 69 | module.parameterEvaluator = function(table_node) { | 148 | module.parameterEvaluator = function(table_node) { |
562 | 70 | var td_list = table_node.all('td.build_status'); | 149 | var td_request_list = table_node.all('td.request_status'); |
563 | 71 | var pending = td_list.filter("." + module.pending_states.join(",.")); | 150 | var pending_requests = td_request_list.filter('.PENDING'); |
564 | 72 | if (pending.size() === 0) { | 151 | var td_build_list = table_node.all('td.build_status'); |
565 | 152 | var pending_builds = td_build_list.filter( | ||
566 | 153 | "." + module.pending_states.join(",.")); | ||
567 | 154 | if (pending_requests.size() === 0 && pending_builds.size() === 0) { | ||
568 | 73 | return null; | 155 | return null; |
569 | 74 | } | 156 | } |
570 | 75 | 157 | ||
579 | 76 | var snap_build_ids = []; | 158 | var request_ids = []; |
580 | 77 | Y.each(pending, function(node) { | 159 | Y.each(pending_requests, function(node) { |
581 | 78 | var elem_id = node.ancestor().get('id'); | 160 | var elem_id = node.ancestor().get('id'); |
582 | 79 | var snap_build_id = elem_id.replace('build-', ''); | 161 | var request_id = elem_id.replace('request-', ''); |
583 | 80 | snap_build_ids.push(snap_build_id); | 162 | request_ids.push(request_id); |
584 | 81 | }); | 163 | }); |
585 | 82 | 164 | ||
586 | 83 | return {snap_build_ids: snap_build_ids}; | 165 | var build_ids = []; |
587 | 166 | Y.each(pending_builds, function(node) { | ||
588 | 167 | var elem_id = node.ancestor().get('id'); | ||
589 | 168 | var build_id = elem_id.replace('build-', ''); | ||
590 | 169 | build_ids.push(build_id); | ||
591 | 170 | }); | ||
592 | 171 | |||
593 | 172 | return {request_ids: request_ids, build_ids: build_ids}; | ||
594 | 84 | }; | 173 | }; |
595 | 85 | 174 | ||
596 | 86 | module.stopUpdatesCheck = function(table_node) { | 175 | module.stopUpdatesCheck = function(table_node) { |
601 | 87 | // Stop updating when there aren't any builds to update | 176 | // Stop updating when there aren't any build requests or builds to |
602 | 88 | var td_list = table_node.all('td.build_status'); | 177 | // update. |
603 | 89 | var pending = td_list.filter("." + module.pending_states.join(",.")); | 178 | var td_request_list = table_node.all('td.request_status'); |
604 | 90 | return (pending.size() === 0); | 179 | var pending_requests = td_request_list.filter('.PENDING'); |
605 | 180 | var td_build_list = table_node.all('td.build_status'); | ||
606 | 181 | var pending_builds = td_build_list.filter( | ||
607 | 182 | "." + module.pending_states.join(",.")); | ||
608 | 183 | return pending_requests.size() === 0 && pending_builds.size() === 0; | ||
609 | 91 | }; | 184 | }; |
610 | 92 | 185 | ||
611 | 93 | module.config = { | 186 | module.config = { |
612 | 94 | uri: null, | 187 | uri: null, |
614 | 95 | api_method_name: 'getBuildSummariesForSnapBuildIds', | 188 | api_method_name: 'getBuildSummaries', |
615 | 96 | lp_client: null, | 189 | lp_client: null, |
616 | 97 | domUpdateFunction: module.domUpdate, | 190 | domUpdateFunction: module.domUpdate, |
617 | 98 | parameterEvaluatorFunction: module.parameterEvaluator, | 191 | parameterEvaluatorFunction: module.parameterEvaluator, |
618 | 99 | 192 | ||
619 | === modified file 'lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.html' | |||
620 | --- lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.html 2017-08-31 13:35:55 +0000 | |||
621 | +++ lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.html 2018-09-13 15:15:44 +0000 | |||
622 | @@ -1,6 +1,6 @@ | |||
623 | 1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
624 | 2 | <!-- | 2 | <!-- |
626 | 3 | Copyright 2016 Canonical Ltd. This software is licensed under the | 3 | Copyright 2016-2018 Canonical Ltd. This software is licensed under the |
627 | 4 | GNU Affero General Public License version 3 (see the file LICENSE). | 4 | GNU Affero General Public License version 3 (see the file LICENSE). |
628 | 5 | --> | 5 | --> |
629 | 6 | 6 | ||
630 | @@ -62,19 +62,10 @@ | |||
631 | 62 | </tr> | 62 | </tr> |
632 | 63 | </thead> | 63 | </thead> |
633 | 64 | <tbody> | 64 | <tbody> |
647 | 65 | <tr id="build-1"> | 65 | <tr id="request-1"> |
648 | 66 | <td class="build_status NEEDSBUILD"> | 66 | <td class="request_status PENDING"> |
649 | 67 | <img width="14" height="14" alt="[NEEDSBUILD]" title="Needs building" src="/@@/build-needed" /> | 67 | <img width="14" height="14" alt="[PENDING]" title="Pending" src="/@@/build-needed" /> |
650 | 68 | <a href="snap/+build/1">Needs building</a> | 68 | Pending build request |
638 | 69 | </td> | ||
639 | 70 | <td class="datebuilt"> | ||
640 | 71 | in 1 minute (estimated) | ||
641 | 72 | </td> | ||
642 | 73 | <td> | ||
643 | 74 | <a class="sprite distribution" href="/ubuntu/hoary/i386">i386</a> | ||
644 | 75 | </td> | ||
645 | 76 | <td> | ||
646 | 77 | <a href="/ubuntu" class="sprite distribution">Primary Archive for Ubuntu Linux</a> | ||
651 | 78 | </td> | 69 | </td> |
652 | 79 | </tr> | 70 | </tr> |
653 | 80 | <tr id="build-2"> | 71 | <tr id="build-2"> |
654 | @@ -94,6 +85,21 @@ | |||
655 | 94 | <a href="/ubuntu" class="sprite distribution">Primary Archive for Ubuntu Linux</a> | 85 | <a href="/ubuntu" class="sprite distribution">Primary Archive for Ubuntu Linux</a> |
656 | 95 | </td> | 86 | </td> |
657 | 96 | </tr> | 87 | </tr> |
658 | 88 | <tr id="build-1"> | ||
659 | 89 | <td class="build_status NEEDSBUILD"> | ||
660 | 90 | <img width="14" height="14" alt="[NEEDSBUILD]" title="Needs building" src="/@@/build-needed" /> | ||
661 | 91 | <a href="snap/+build/1">Needs building</a> | ||
662 | 92 | </td> | ||
663 | 93 | <td class="datebuilt"> | ||
664 | 94 | in 1 minute (estimated) | ||
665 | 95 | </td> | ||
666 | 96 | <td> | ||
667 | 97 | <a class="sprite distribution" href="/ubuntu/hoary/i386">i386</a> | ||
668 | 98 | </td> | ||
669 | 99 | <td> | ||
670 | 100 | <a href="/ubuntu" class="sprite distribution">Primary Archive for Ubuntu Linux</a> | ||
671 | 101 | </td> | ||
672 | 102 | </tr> | ||
673 | 97 | </tbody> | 103 | </tbody> |
674 | 98 | </table> | 104 | </table> |
675 | 99 | 105 | ||
676 | 100 | 106 | ||
677 | === modified file 'lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.js' | |||
678 | --- lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.js 2017-08-31 13:35:55 +0000 | |||
679 | +++ lib/lp/snappy/javascript/tests/test_snap.update_build_statuses.js 2018-09-13 15:15:44 +0000 | |||
680 | @@ -1,4 +1,4 @@ | |||
682 | 1 | /* Copyright 2016 Canonical Ltd. This software is licensed under the | 1 | /* Copyright 2016-2018 Canonical Ltd. This software is licensed under the |
683 | 2 | * GNU Affero General Public License version 3 (see the file LICENSE). */ | 2 | * GNU Affero General Public License version 3 (see the file LICENSE). */ |
684 | 3 | 3 | ||
685 | 4 | YUI.add('lp.snappy.snap.update_build_statuses.test', function (Y) { | 4 | YUI.add('lp.snappy.snap.update_build_statuses.test', function (Y) { |
686 | @@ -10,13 +10,42 @@ | |||
687 | 10 | name: 'lp.snappy.snap.update_build_statuses_tests', | 10 | name: 'lp.snappy.snap.update_build_statuses_tests', |
688 | 11 | 11 | ||
689 | 12 | setUp: function () { | 12 | setUp: function () { |
692 | 13 | this.table = Y.one('table#latest-builds-listing'); | 13 | // Clone the table from the test data so that we can reliably |
693 | 14 | this.tr_build_1 = Y.one('tr#build-1'); | 14 | // restore it. |
694 | 15 | this.table = Y.one('table#latest-builds-listing').cloneNode(true); | ||
695 | 16 | this.tbody = this.table.one('tbody'); | ||
696 | 17 | this.tr_request_1 = this.tbody.one('tr#request-1'); | ||
697 | 18 | this.tr_build_1 = this.tbody.one('tr#build-1'); | ||
698 | 15 | this.td_status = this.tr_build_1.one('td.build_status'); | 19 | this.td_status = this.tr_build_1.one('td.build_status'); |
699 | 16 | this.td_datebuilt = this.tr_build_1.one("td.datebuilt"); | 20 | this.td_datebuilt = this.tr_build_1.one("td.datebuilt"); |
703 | 17 | this.td_status_class = this.td_status.getAttribute("class"); | 21 | }, |
704 | 18 | this.td_status_img = this.td_status.one("img"); | 22 | |
705 | 19 | this.td_status_a = this.td_status.one("a"); | 23 | assert_node_matches: function(expected, node) { |
706 | 24 | Y.each(expected, function(value, key) { | ||
707 | 25 | if (key === "tag") { | ||
708 | 26 | Y.Assert.areEqual( | ||
709 | 27 | value, node.get("tagName").toLowerCase()); | ||
710 | 28 | } else if (key === "attrs") { | ||
711 | 29 | Y.each(value, function(attr_value, attr_key) { | ||
712 | 30 | Y.Assert.areEqual( | ||
713 | 31 | attr_value, node.getAttribute(attr_key)); | ||
714 | 32 | }); | ||
715 | 33 | } else if (key === "text") { | ||
716 | 34 | Y.Assert.areEqual(value, node.get("text").trim()); | ||
717 | 35 | } else if (key === "children") { | ||
718 | 36 | var children = []; | ||
719 | 37 | node.get("children").each(function(child) { | ||
720 | 38 | children.push(child); | ||
721 | 39 | }); | ||
722 | 40 | Y.Array.each(Y.Array.zip(value, children), function(item) { | ||
723 | 41 | Y.Assert.isObject(item[0]); | ||
724 | 42 | Y.Assert.isObject(item[1]); | ||
725 | 43 | this.assert_node_matches(item[0], item[1]); | ||
726 | 44 | }, this); | ||
727 | 45 | } else { | ||
728 | 46 | Y.Assert.fail("unhandled key " + key); | ||
729 | 47 | } | ||
730 | 48 | }, this); | ||
731 | 20 | }, | 49 | }, |
732 | 21 | 50 | ||
733 | 22 | test_dom_updater_plugin_attached: function() { | 51 | test_dom_updater_plugin_attached: function() { |
734 | @@ -32,167 +61,354 @@ | |||
735 | 32 | 61 | ||
736 | 33 | test_parameter_evaluator: function() { | 62 | test_parameter_evaluator: function() { |
737 | 34 | // parameterEvaluator should return an object with the ids of | 63 | // parameterEvaluator should return an object with the ids of |
739 | 35 | // builds in pending states. | 64 | // build requests and builds in pending states. |
740 | 36 | var params = module.parameterEvaluator(this.table); | 65 | var params = module.parameterEvaluator(this.table); |
741 | 37 | Y.lp.testing.assert.assert_equal_structure( | 66 | Y.lp.testing.assert.assert_equal_structure( |
743 | 38 | {snap_build_ids: ["1"]}, params); | 67 | {request_ids: ["1"], build_ids: ["1"]}, params); |
744 | 39 | }, | 68 | }, |
745 | 40 | 69 | ||
746 | 41 | test_parameter_evaluator_empty: function() { | 70 | test_parameter_evaluator_empty: function() { |
747 | 42 | // parameterEvaluator should return empty if no builds remaining | 71 | // parameterEvaluator should return empty if no builds remaining |
748 | 43 | // in pending states. | 72 | // in pending states. |
749 | 73 | this.tr_request_1.remove(); | ||
750 | 44 | this.td_status.setAttribute("class", "build_status FULLYBUILT"); | 74 | this.td_status.setAttribute("class", "build_status FULLYBUILT"); |
751 | 45 | var params = module.parameterEvaluator(this.table); | 75 | var params = module.parameterEvaluator(this.table); |
752 | 46 | Y.Assert.isNull(params); | 76 | Y.Assert.isNull(params); |
753 | 47 | // reset td class to the original value | ||
754 | 48 | this.td_status.setAttribute("class", this.td_status_class); | ||
755 | 49 | }, | 77 | }, |
756 | 50 | 78 | ||
757 | 51 | test_stop_updates_check: function() { | 79 | test_stop_updates_check: function() { |
761 | 52 | // stopUpdatesCheck should return false if pending builds exist. | 80 | // stopUpdatesCheck should return false if pending build |
762 | 53 | Y.Assert.isFalse(module.stopUpdatesCheck(this.table)); | 81 | // requests or pending builds exist. |
763 | 54 | // stopUpdatesCheck should return true if no pending builds exist. | 82 | Y.Assert.isFalse(module.stopUpdatesCheck(this.table)); |
764 | 83 | this.tr_request_1.one('td.request_status') | ||
765 | 84 | .setAttribute('class', 'request_status COMPLETED'); | ||
766 | 85 | Y.Assert.isFalse(module.stopUpdatesCheck(this.table)); | ||
767 | 86 | // stopUpdatesCheck should return true if no pending build | ||
768 | 87 | // requests or pending builds exist. | ||
769 | 55 | this.td_status.setAttribute("class", "build_status FULLYBUILT"); | 88 | this.td_status.setAttribute("class", "build_status FULLYBUILT"); |
770 | 56 | Y.Assert.isTrue(module.stopUpdatesCheck(this.table)); | 89 | Y.Assert.isTrue(module.stopUpdatesCheck(this.table)); |
771 | 90 | this.tr_request_1.remove(); | ||
772 | 91 | Y.Assert.isTrue(module.stopUpdatesCheck(this.table)); | ||
773 | 57 | for (var i = 0; i < module.pending_states.length; i++) { | 92 | for (var i = 0; i < module.pending_states.length; i++) { |
774 | 58 | this.td_status.setAttribute( | 93 | this.td_status.setAttribute( |
775 | 59 | "class", "build_status " + module.pending_states[i]); | 94 | "class", "build_status " + module.pending_states[i]); |
776 | 60 | Y.Assert.isFalse(module.stopUpdatesCheck(this.table)); | 95 | Y.Assert.isFalse(module.stopUpdatesCheck(this.table)); |
777 | 61 | } | 96 | } |
832 | 62 | // reset td class to the original value | 97 | }, |
833 | 63 | this.td_status.setAttribute("class", this.td_status_class); | 98 | |
834 | 64 | }, | 99 | test_update_build_request_status_dom_completed: function() { |
835 | 65 | 100 | var data = { | |
836 | 66 | test_update_build_status_dom_building: function() { | 101 | "requests": { |
837 | 67 | var original_a_href = this.td_status_a.get("href"); | 102 | "1": { |
838 | 68 | var data = { | 103 | "status": "COMPLETED", |
839 | 69 | "1": { | 104 | "error_message": null, |
840 | 70 | "status": "BUILDING", | 105 | "builds": [ |
841 | 71 | "build_log_url": null, | 106 | { |
842 | 72 | "when_complete_estimate": true, | 107 | "self_link": "/~max/+snap/snap/+build/3", |
843 | 73 | "buildstate": "Currently building", | 108 | "id": 3, |
844 | 74 | "build_log_size": null, | 109 | "distro_arch_series_link": |
845 | 75 | "when_complete": "in 1 minute" | 110 | "/ubuntu/hoary/amd64", |
846 | 76 | } | 111 | "architecture_tag": "amd64", |
847 | 77 | }; | 112 | "archive_link": |
848 | 78 | module.domUpdate(this.table, data); | 113 | '<a href="/ubuntu" ' + |
849 | 79 | Y.Assert.areEqual( | 114 | 'class="sprite distribution">Primary ' + |
850 | 80 | "build_status BUILDING", this.td_status.getAttribute("class")); | 115 | 'Archive for Ubuntu Linux</a>', |
851 | 81 | Y.Assert.areEqual( | 116 | "status": "NEEDSBUILD", |
852 | 82 | "Currently building", this.td_status.get("text").trim()); | 117 | "build_log_url": null, |
853 | 83 | Y.Assert.areEqual("[BUILDING]", this.td_status_img.get("alt")); | 118 | "when_complete_estimate": false, |
854 | 84 | Y.Assert.areEqual( | 119 | "buildstate": "Needs building", |
855 | 85 | "Currently building", this.td_status_img.get("title")); | 120 | "build_log_size": null, |
856 | 86 | Y.Assert.areEqual( | 121 | "when_complete": null |
857 | 87 | "file:///@@/processing", this.td_status_img.get("src")); | 122 | }, |
858 | 88 | Y.Assert.areEqual("14", this.td_status_img.get("width")); | 123 | { |
859 | 89 | Y.Assert.areEqual(original_a_href, this.td_status_a.get("href")); | 124 | "self_link": "/~max/+snap/snap/+build/4", |
860 | 90 | }, | 125 | "id": 4, |
861 | 91 | 126 | "distro_arch_series_link": | |
862 | 92 | test_update_build_status_dom_building: function() { | 127 | "/ubuntu/hoary/i386", |
863 | 93 | var original_a_href = this.td_status_a.get("href"); | 128 | "architecture_tag": "i386", |
864 | 94 | var data = { | 129 | "archive_link": |
865 | 95 | "1": { | 130 | '<a href="/ubuntu" ' + |
866 | 96 | "status": "BUILDING", | 131 | 'class="sprite distribution">Primary ' + |
867 | 97 | "build_log_url": null, | 132 | 'Archive for Ubuntu Linux</a>', |
868 | 98 | "when_complete_estimate": true, | 133 | "status": "BUILDING", |
869 | 99 | "buildstate": "Currently building", | 134 | "build_log_url": null, |
870 | 100 | "build_log_size": null, | 135 | "when_complete_estimate": true, |
871 | 101 | "when_complete": "in 1 minute" | 136 | "buildstate": "Currently building", |
872 | 102 | } | 137 | "build_log_size": null, |
873 | 103 | }; | 138 | "when_complete": "in 1 minute" |
874 | 104 | module.domUpdate(this.table, data); | 139 | } |
875 | 105 | Y.Assert.areEqual( | 140 | ] |
876 | 106 | "build_status BUILDING", this.td_status.getAttribute("class")); | 141 | } |
877 | 107 | Y.Assert.areEqual( | 142 | }, |
878 | 108 | "Currently building", this.td_status.get("text").trim()); | 143 | "builds": {} |
879 | 109 | Y.Assert.areEqual("[BUILDING]", this.td_status_img.get("alt")); | 144 | }; |
880 | 110 | Y.Assert.areEqual( | 145 | module.domUpdate(this.table, data); |
881 | 111 | "Currently building", this.td_status_img.get("title")); | 146 | Y.ArrayAssert.itemsAreEqual( |
882 | 112 | Y.Assert.areEqual( | 147 | ["build-4", "build-3", "build-2", "build-1"], |
883 | 113 | "file:///@@/processing", this.td_status_img.get("src")); | 148 | this.tbody.get("children").get("id")); |
884 | 114 | Y.Assert.areEqual("14", this.td_status_img.get("width")); | 149 | this.assert_node_matches({ |
885 | 115 | Y.Assert.areEqual(original_a_href, this.td_status_a.get("href")); | 150 | "tag": "tr", |
886 | 151 | "attrs": {"id": "build-3"}, | ||
887 | 152 | "children": [ | ||
888 | 153 | { | ||
889 | 154 | "tag": "td", | ||
890 | 155 | "attrs": {"class": "build_status NEEDSBUILD"}, | ||
891 | 156 | "children": [ | ||
892 | 157 | { | ||
893 | 158 | "tag": "img", | ||
894 | 159 | "attrs": { | ||
895 | 160 | "alt": "[NEEDSBUILD]", | ||
896 | 161 | "title": "Needs building", | ||
897 | 162 | "src": "/@@/build-needed", | ||
898 | 163 | "width": "14" | ||
899 | 164 | } | ||
900 | 165 | }, | ||
901 | 166 | { | ||
902 | 167 | "tag": "a", | ||
903 | 168 | "attrs": {"href": "/~max/+snap/snap/+build/3"}, | ||
904 | 169 | "text": "Needs building" | ||
905 | 170 | } | ||
906 | 171 | ] | ||
907 | 172 | }, | ||
908 | 173 | { | ||
909 | 174 | "tag": "td", | ||
910 | 175 | "attrs": {"class": "datebuilt"}, | ||
911 | 176 | "text": "", | ||
912 | 177 | "children": [] | ||
913 | 178 | }, | ||
914 | 179 | { | ||
915 | 180 | "tag": "td", | ||
916 | 181 | "children": [{ | ||
917 | 182 | "tag": "a", | ||
918 | 183 | "attrs": { | ||
919 | 184 | "class": "sprite distribution", | ||
920 | 185 | "href": "/ubuntu/hoary/amd64" | ||
921 | 186 | }, | ||
922 | 187 | "text": "amd64" | ||
923 | 188 | }] | ||
924 | 189 | }, | ||
925 | 190 | { | ||
926 | 191 | "tag": "td", | ||
927 | 192 | "children": [{ | ||
928 | 193 | "tag": "a", | ||
929 | 194 | "attrs": { | ||
930 | 195 | "class": "sprite distribution", | ||
931 | 196 | "href": "/ubuntu" | ||
932 | 197 | }, | ||
933 | 198 | "text": "Primary Archive for Ubuntu Linux" | ||
934 | 199 | }] | ||
935 | 200 | } | ||
936 | 201 | ] | ||
937 | 202 | }, this.tbody.one("tr#build-3")); | ||
938 | 203 | this.assert_node_matches({ | ||
939 | 204 | "tag": "tr", | ||
940 | 205 | "attrs": {"id": "build-4"}, | ||
941 | 206 | "children": [ | ||
942 | 207 | { | ||
943 | 208 | "tag": "td", | ||
944 | 209 | "attrs": {"class": "build_status BUILDING"}, | ||
945 | 210 | "children": [ | ||
946 | 211 | { | ||
947 | 212 | "tag": "img", | ||
948 | 213 | "attrs": { | ||
949 | 214 | "alt": "[BUILDING]", | ||
950 | 215 | "title": "Currently building", | ||
951 | 216 | "src": "/@@/processing", | ||
952 | 217 | "width": "14" | ||
953 | 218 | } | ||
954 | 219 | }, | ||
955 | 220 | { | ||
956 | 221 | "tag": "a", | ||
957 | 222 | "attrs": {"href": "/~max/+snap/snap/+build/4"}, | ||
958 | 223 | "text": "Currently building" | ||
959 | 224 | } | ||
960 | 225 | ] | ||
961 | 226 | }, | ||
962 | 227 | { | ||
963 | 228 | "tag": "td", | ||
964 | 229 | "attrs": {"class": "datebuilt"}, | ||
965 | 230 | "text": "in 1 minute (estimated)", | ||
966 | 231 | "children": [] | ||
967 | 232 | }, | ||
968 | 233 | { | ||
969 | 234 | "tag": "td", | ||
970 | 235 | "children": [{ | ||
971 | 236 | "tag": "a", | ||
972 | 237 | "attrs": { | ||
973 | 238 | "class": "sprite distribution", | ||
974 | 239 | "href": "/ubuntu/hoary/i386" | ||
975 | 240 | }, | ||
976 | 241 | "text": "i386" | ||
977 | 242 | }] | ||
978 | 243 | }, | ||
979 | 244 | { | ||
980 | 245 | "tag": "td", | ||
981 | 246 | "children": [{ | ||
982 | 247 | "tag": "a", | ||
983 | 248 | "attrs": { | ||
984 | 249 | "class": "sprite distribution", | ||
985 | 250 | "href": "/ubuntu" | ||
986 | 251 | }, | ||
987 | 252 | "text": "Primary Archive for Ubuntu Linux" | ||
988 | 253 | }] | ||
989 | 254 | } | ||
990 | 255 | ] | ||
991 | 256 | }, this.tbody.one("tr#build-4")); | ||
992 | 257 | }, | ||
993 | 258 | |||
994 | 259 | test_update_build_request_status_dom_failed: function() { | ||
995 | 260 | var data = { | ||
996 | 261 | "requests": { | ||
997 | 262 | "1": { | ||
998 | 263 | "status": "FAILED", | ||
999 | 264 | "error_message": "Something went wrong", | ||
1000 | 265 | "builds": [] | ||
1001 | 266 | } | ||
1002 | 267 | }, | ||
1003 | 268 | "builds": {} | ||
1004 | 269 | }; | ||
1005 | 270 | module.domUpdate(this.table, data); | ||
1006 | 271 | Y.ArrayAssert.itemsAreEqual( | ||
1007 | 272 | ["build-2", "build-1"], this.tbody.get("children").get("id")); | ||
1008 | 273 | }, | ||
1009 | 274 | |||
1010 | 275 | test_update_build_status_dom_building: function() { | ||
1011 | 276 | var original_a_href = this.td_status.one("a").getAttribute("href"); | ||
1012 | 277 | var data = { | ||
1013 | 278 | "requests": {}, | ||
1014 | 279 | "builds": { | ||
1015 | 280 | "1": { | ||
1016 | 281 | "status": "BUILDING", | ||
1017 | 282 | "build_log_url": null, | ||
1018 | 283 | "when_complete_estimate": true, | ||
1019 | 284 | "buildstate": "Currently building", | ||
1020 | 285 | "build_log_size": null, | ||
1021 | 286 | "when_complete": "in 1 minute" | ||
1022 | 287 | } | ||
1023 | 288 | } | ||
1024 | 289 | }; | ||
1025 | 290 | module.domUpdate(this.table, data); | ||
1026 | 291 | this.assert_node_matches({ | ||
1027 | 292 | "attrs": {"class": "build_status BUILDING"}, | ||
1028 | 293 | "text": "Currently building", | ||
1029 | 294 | "children": [ | ||
1030 | 295 | { | ||
1031 | 296 | "tag": "img", | ||
1032 | 297 | "attrs": { | ||
1033 | 298 | "alt": "[BUILDING]", | ||
1034 | 299 | "title": "Currently building", | ||
1035 | 300 | "src": "/@@/processing", | ||
1036 | 301 | "width": "14" | ||
1037 | 302 | } | ||
1038 | 303 | }, | ||
1039 | 304 | { | ||
1040 | 305 | "tag": "a", | ||
1041 | 306 | "attrs": {"href": original_a_href} | ||
1042 | 307 | } | ||
1043 | 308 | ] | ||
1044 | 309 | }, this.td_status); | ||
1045 | 116 | }, | 310 | }, |
1046 | 117 | 311 | ||
1047 | 118 | test_update_build_status_dom_failedtobuild: function() { | 312 | test_update_build_status_dom_failedtobuild: function() { |
1049 | 119 | var original_a_href = this.td_status_a.get("href"); | 313 | var original_a_href = this.td_status.one("a").getAttribute("href"); |
1050 | 120 | var data = { | 314 | var data = { |
1058 | 121 | "1": { | 315 | "requests": {}, |
1059 | 122 | "status": "FAILEDTOBUILD", | 316 | "builds": { |
1060 | 123 | "build_log_url": null, | 317 | "1": { |
1061 | 124 | "when_complete_estimate": false, | 318 | "status": "FAILEDTOBUILD", |
1062 | 125 | "buildstate": "Failed to build", | 319 | "build_log_url": null, |
1063 | 126 | "build_log_size": null, | 320 | "when_complete_estimate": false, |
1064 | 127 | "when_complete": "1 minute ago" | 321 | "buildstate": "Failed to build", |
1065 | 322 | "build_log_size": null, | ||
1066 | 323 | "when_complete": "1 minute ago" | ||
1067 | 324 | } | ||
1068 | 128 | } | 325 | } |
1069 | 129 | }; | 326 | }; |
1070 | 130 | module.domUpdate(this.table, data); | 327 | module.domUpdate(this.table, data); |
1084 | 131 | Y.Assert.areEqual( | 328 | this.assert_node_matches({ |
1085 | 132 | "build_status FAILEDTOBUILD", | 329 | "attrs": {"class": "build_status FAILEDTOBUILD"}, |
1086 | 133 | this.td_status.getAttribute("class")); | 330 | "text": "Failed to build", |
1087 | 134 | Y.Assert.areEqual( | 331 | "children": [ |
1088 | 135 | "Failed to build", this.td_status.get("text").trim()); | 332 | { |
1089 | 136 | Y.Assert.areEqual( | 333 | "tag": "img", |
1090 | 137 | "[FAILEDTOBUILD]", this.td_status_img.get("alt")); | 334 | "attrs": { |
1091 | 138 | Y.Assert.areEqual( | 335 | "alt": "[FAILEDTOBUILD]", |
1092 | 139 | "Failed to build", this.td_status_img.get("title")); | 336 | "title": "Failed to build", |
1093 | 140 | Y.Assert.areEqual( | 337 | "src": "/@@/build-failed", |
1094 | 141 | "file:///@@/build-failed", this.td_status_img.get("src")); | 338 | "width": "16" |
1095 | 142 | Y.Assert.areEqual("16", this.td_status_img.get("width")); | 339 | } |
1096 | 143 | Y.Assert.areEqual(original_a_href, this.td_status_a.get("href")); | 340 | }, |
1097 | 341 | { | ||
1098 | 342 | "tag": "a", | ||
1099 | 343 | "attrs": {"href": original_a_href} | ||
1100 | 344 | } | ||
1101 | 345 | ] | ||
1102 | 346 | }, this.td_status); | ||
1103 | 144 | }, | 347 | }, |
1104 | 145 | 348 | ||
1105 | 146 | test_update_build_status_dom_chrootwait: function() { | 349 | test_update_build_status_dom_chrootwait: function() { |
1107 | 147 | var original_a_href = this.td_status_a.get("href"); | 350 | var original_a_href = this.td_status.one("a").getAttribute("href"); |
1108 | 148 | var data = { | 351 | var data = { |
1116 | 149 | "1": { | 352 | "requests": {}, |
1117 | 150 | "status": "CHROOTWAIT", | 353 | "builds": { |
1118 | 151 | "build_log_url": null, | 354 | "1": { |
1119 | 152 | "when_complete_estimate": false, | 355 | "status": "CHROOTWAIT", |
1120 | 153 | "buildstate": "Chroot problem", | 356 | "build_log_url": null, |
1121 | 154 | "build_log_size": null, | 357 | "when_complete_estimate": false, |
1122 | 155 | "when_complete": "1 minute ago" | 358 | "buildstate": "Chroot problem", |
1123 | 359 | "build_log_size": null, | ||
1124 | 360 | "when_complete": "1 minute ago" | ||
1125 | 361 | } | ||
1126 | 156 | } | 362 | } |
1127 | 157 | }; | 363 | }; |
1128 | 158 | module.domUpdate(this.table, data); | 364 | module.domUpdate(this.table, data); |
1141 | 159 | Y.Assert.areEqual( | 365 | this.assert_node_matches({ |
1142 | 160 | "build_status CHROOTWAIT", | 366 | "attrs": {"class": "build_status CHROOTWAIT"}, |
1143 | 161 | this.td_status.getAttribute("class")); | 367 | "text": "Chroot problem", |
1144 | 162 | Y.Assert.areEqual( | 368 | "children": [ |
1145 | 163 | "Chroot problem", this.td_status.get("text").trim()); | 369 | { |
1146 | 164 | Y.Assert.areEqual("[CHROOTWAIT]", this.td_status_img.get("alt")); | 370 | "tag": "img", |
1147 | 165 | Y.Assert.areEqual( | 371 | "attrs": { |
1148 | 166 | "Chroot problem", this.td_status_img.get("title")); | 372 | "alt": "[CHROOTWAIT]", |
1149 | 167 | Y.Assert.areEqual( | 373 | "title": "Chroot problem", |
1150 | 168 | "file:///@@/build-chrootwait", this.td_status_img.get("src")); | 374 | "src": "/@@/build-chrootwait", |
1151 | 169 | Y.Assert.areEqual("14", this.td_status_img.get("width")); | 375 | "width": "14" |
1152 | 170 | Y.Assert.areEqual(original_a_href, this.td_status_a.get("href")); | 376 | } |
1153 | 377 | }, | ||
1154 | 378 | { | ||
1155 | 379 | "tag": "a", | ||
1156 | 380 | "attrs": {"href": original_a_href} | ||
1157 | 381 | } | ||
1158 | 382 | ] | ||
1159 | 383 | }, this.td_status); | ||
1160 | 171 | }, | 384 | }, |
1161 | 172 | 385 | ||
1162 | 173 | test_update_build_date_dom: function() { | 386 | test_update_build_date_dom: function() { |
1163 | 174 | var data = { | 387 | var data = { |
1171 | 175 | "1": { | 388 | "requests": {}, |
1172 | 176 | "status": "NEEDSBUILD", | 389 | "builds": { |
1173 | 177 | "build_log_url": "/+build/1/+files/build1.txt.gz", | 390 | "1": { |
1174 | 178 | "when_complete_estimate": true, | 391 | "status": "NEEDSBUILD", |
1175 | 179 | "buildstate": "Needs building", | 392 | "build_log_url": "/+build/1/+files/build1.txt.gz", |
1176 | 180 | "build_log_size": 12345, | 393 | "when_complete_estimate": true, |
1177 | 181 | "when_complete": "in 30 seconds" | 394 | "buildstate": "Needs building", |
1178 | 395 | "build_log_size": 12345, | ||
1179 | 396 | "when_complete": "in 30 seconds" | ||
1180 | 397 | } | ||
1181 | 182 | } | 398 | } |
1182 | 183 | }; | 399 | }; |
1183 | 184 | module.domUpdate(this.table, data); | 400 | module.domUpdate(this.table, data); |
1195 | 185 | Y.Assert.areEqual( | 401 | this.assert_node_matches({ |
1196 | 186 | "in 30 seconds (estimated) buildlog (12345 bytes)", | 402 | "text": "in 30 seconds (estimated) buildlog (12345 bytes)", |
1197 | 187 | this.td_datebuilt.get("text").trim()); | 403 | "children": [{ |
1198 | 188 | var td_datebuilt_a = this.td_datebuilt.one("a"); | 404 | "tag": "a", |
1199 | 189 | Y.Assert.isNotNull(td_datebuilt_a); | 405 | "attrs": { |
1200 | 190 | Y.Assert.areEqual("buildlog", td_datebuilt_a.get("text").trim()); | 406 | "class": "sprite download", |
1201 | 191 | Y.Assert.areEqual( | 407 | "href": data["builds"]["1"].build_log_url |
1202 | 192 | "sprite download", td_datebuilt_a.getAttribute("class")); | 408 | }, |
1203 | 193 | Y.Assert.areEqual( | 409 | "text": "buildlog" |
1204 | 194 | "file://" + data["1"].build_log_url, | 410 | }] |
1205 | 195 | td_datebuilt_a.get("href")); | 411 | }, this.td_datebuilt); |
1206 | 196 | } | 412 | } |
1207 | 197 | })); | 413 | })); |
1208 | 198 | 414 | ||
1209 | 199 | 415 | ||
1210 | === modified file 'lib/lp/snappy/model/snap.py' | |||
1211 | --- lib/lp/snappy/model/snap.py 2018-09-10 11:18:42 +0000 | |||
1212 | +++ lib/lp/snappy/model/snap.py 2018-09-13 15:15:44 +0000 | |||
1213 | @@ -45,7 +45,10 @@ | |||
1214 | 45 | from zope.security.interfaces import Unauthorized | 45 | from zope.security.interfaces import Unauthorized |
1215 | 46 | from zope.security.proxy import removeSecurityProxy | 46 | from zope.security.proxy import removeSecurityProxy |
1216 | 47 | 47 | ||
1218 | 48 | from lp.app.browser.tales import DateTimeFormatterAPI | 48 | from lp.app.browser.tales import ( |
1219 | 49 | ArchiveFormatterAPI, | ||
1220 | 50 | DateTimeFormatterAPI, | ||
1221 | 51 | ) | ||
1222 | 49 | from lp.app.enums import PRIVATE_INFORMATION_TYPES | 52 | from lp.app.enums import PRIVATE_INFORMATION_TYPES |
1223 | 50 | from lp.app.errors import ( | 53 | from lp.app.errors import ( |
1224 | 51 | IncompatibleArguments, | 54 | IncompatibleArguments, |
1225 | @@ -119,7 +122,13 @@ | |||
1226 | 119 | LibraryFileContent, | 122 | LibraryFileContent, |
1227 | 120 | ) | 123 | ) |
1228 | 121 | from lp.services.openid.adapters.openid import CurrentOpenIDEndPoint | 124 | from lp.services.openid.adapters.openid import CurrentOpenIDEndPoint |
1229 | 125 | from lp.services.propertycache import ( | ||
1230 | 126 | cachedproperty, | ||
1231 | 127 | get_property_cache, | ||
1232 | 128 | ) | ||
1233 | 129 | from lp.services.webapp.authorization import precache_permission_for_objects | ||
1234 | 122 | from lp.services.webapp.interfaces import ILaunchBag | 130 | from lp.services.webapp.interfaces import ILaunchBag |
1235 | 131 | from lp.services.webapp.publisher import canonical_url | ||
1236 | 123 | from lp.services.webhooks.interfaces import IWebhookSet | 132 | from lp.services.webhooks.interfaces import IWebhookSet |
1237 | 124 | from lp.services.webhooks.model import WebhookTargetMixin | 133 | from lp.services.webhooks.model import WebhookTargetMixin |
1238 | 125 | from lp.snappy.adapters.buildarch import determine_architectures_to_build | 134 | from lp.snappy.adapters.buildarch import determine_architectures_to_build |
1239 | @@ -178,11 +187,21 @@ | |||
1240 | 178 | """ | 187 | """ |
1241 | 179 | 188 | ||
1242 | 180 | def __init__(self, snap, id): | 189 | def __init__(self, snap, id): |
1243 | 181 | self._job = getUtility(ISnapRequestBuildsJobSource).getBySnapAndID( | ||
1244 | 182 | snap, id) | ||
1245 | 183 | self.snap = snap | 190 | self.snap = snap |
1246 | 184 | self.id = id | 191 | self.id = id |
1247 | 185 | 192 | ||
1248 | 193 | @classmethod | ||
1249 | 194 | def fromJob(cls, job): | ||
1250 | 195 | """See `ISnapBuildRequest`.""" | ||
1251 | 196 | request = cls(job.snap, job.job_id) | ||
1252 | 197 | get_property_cache(request)._job = job | ||
1253 | 198 | return request | ||
1254 | 199 | |||
1255 | 200 | @cachedproperty | ||
1256 | 201 | def _job(self): | ||
1257 | 202 | job_source = getUtility(ISnapRequestBuildsJobSource) | ||
1258 | 203 | return job_source.getBySnapAndID(self.snap, self.id) | ||
1259 | 204 | |||
1260 | 186 | @property | 205 | @property |
1261 | 187 | def date_requested(self): | 206 | def date_requested(self): |
1262 | 188 | """See `ISnapBuildRequest`.""" | 207 | """See `ISnapBuildRequest`.""" |
1263 | @@ -215,6 +234,11 @@ | |||
1264 | 215 | """See `ISnapBuildRequest`.""" | 234 | """See `ISnapBuildRequest`.""" |
1265 | 216 | return self._job.builds | 235 | return self._job.builds |
1266 | 217 | 236 | ||
1267 | 237 | @property | ||
1268 | 238 | def archive(self): | ||
1269 | 239 | """See `ISnapBuildRequest`.""" | ||
1270 | 240 | return self._job.archive | ||
1271 | 241 | |||
1272 | 218 | 242 | ||
1273 | 219 | @implementer(ISnap, IHasOwner) | 243 | @implementer(ISnap, IHasOwner) |
1274 | 220 | class Snap(Storm, WebhookTargetMixin): | 244 | class Snap(Storm, WebhookTargetMixin): |
1275 | @@ -643,6 +667,15 @@ | |||
1276 | 643 | """See `ISnap`.""" | 667 | """See `ISnap`.""" |
1277 | 644 | return SnapBuildRequest(self, job_id) | 668 | return SnapBuildRequest(self, job_id) |
1278 | 645 | 669 | ||
1279 | 670 | @property | ||
1280 | 671 | def pending_build_requests(self): | ||
1281 | 672 | """See `ISnap`.""" | ||
1282 | 673 | job_source = getUtility(ISnapRequestBuildsJobSource) | ||
1283 | 674 | # The returned jobs are ordered by descending ID. | ||
1284 | 675 | jobs = job_source.findBySnap( | ||
1285 | 676 | self, statuses=(JobStatus.WAITING, JobStatus.RUNNING)) | ||
1286 | 677 | return [SnapBuildRequest.fromJob(job) for job in jobs] | ||
1287 | 678 | |||
1288 | 646 | def _getBuilds(self, filter_term, order_by): | 679 | def _getBuilds(self, filter_term, order_by): |
1289 | 647 | """The actual query to get the builds.""" | 680 | """The actual query to get the builds.""" |
1290 | 648 | query_args = [ | 681 | query_args = [ |
1291 | @@ -673,6 +706,10 @@ | |||
1292 | 673 | order_by = Desc(SnapBuild.id) | 706 | order_by = Desc(SnapBuild.id) |
1293 | 674 | builds = self._getBuilds(filter_term, order_by) | 707 | builds = self._getBuilds(filter_term, order_by) |
1294 | 675 | 708 | ||
1295 | 709 | # The user can obviously see this snap, and Snap._getBuilds ensures | ||
1296 | 710 | # that they can see the relevant archive for each build as well. | ||
1297 | 711 | precache_permission_for_objects(None, "launchpad.View", builds) | ||
1298 | 712 | |||
1299 | 676 | # Prefetch data to keep DB query count constant | 713 | # Prefetch data to keep DB query count constant |
1300 | 677 | lfas = load_related(LibraryFileAlias, builds, ["log_id"]) | 714 | lfas = load_related(LibraryFileAlias, builds, ["log_id"]) |
1301 | 678 | load_related(LibraryFileContent, lfas, ["contentID"]) | 715 | load_related(LibraryFileContent, lfas, ["contentID"]) |
1302 | @@ -698,6 +735,66 @@ | |||
1303 | 698 | } | 735 | } |
1304 | 699 | return result | 736 | return result |
1305 | 700 | 737 | ||
1306 | 738 | def getBuildSummaries(self, request_ids=None, build_ids=None, user=None): | ||
1307 | 739 | """See `ISnap`.""" | ||
1308 | 740 | all_build_ids = [] | ||
1309 | 741 | result = {"requests": {}, "builds": {}} | ||
1310 | 742 | |||
1311 | 743 | if request_ids: | ||
1312 | 744 | job_source = getUtility(ISnapRequestBuildsJobSource) | ||
1313 | 745 | jobs = job_source.findBySnap(self, job_ids=request_ids) | ||
1314 | 746 | requests = [SnapBuildRequest.fromJob(job) for job in jobs] | ||
1315 | 747 | builds_by_request = job_source.findBuildsForJobs(jobs, user=user) | ||
1316 | 748 | for builds in builds_by_request.values(): | ||
1317 | 749 | # It's safe to remove the proxy here, because the IDs will | ||
1318 | 750 | # go through Snap._getBuilds which checks visibility. This | ||
1319 | 751 | # saves an Archive query per build in the security adapter. | ||
1320 | 752 | all_build_ids.extend( | ||
1321 | 753 | [removeSecurityProxy(build).id for build in builds]) | ||
1322 | 754 | else: | ||
1323 | 755 | requests = [] | ||
1324 | 756 | |||
1325 | 757 | if build_ids: | ||
1326 | 758 | all_build_ids.extend(build_ids) | ||
1327 | 759 | |||
1328 | 760 | all_build_summaries = self.getBuildSummariesForSnapBuildIds( | ||
1329 | 761 | all_build_ids) | ||
1330 | 762 | |||
1331 | 763 | for request in requests: | ||
1332 | 764 | build_summaries = [] | ||
1333 | 765 | for build in sorted( | ||
1334 | 766 | builds_by_request[request.id], key=attrgetter("id"), | ||
1335 | 767 | reverse=True): | ||
1336 | 768 | if build.id in all_build_summaries: | ||
1337 | 769 | # Include enough information for | ||
1338 | 770 | # snap.update_build_statuses.js to populate new build | ||
1339 | 771 | # rows. | ||
1340 | 772 | build_summary = { | ||
1341 | 773 | "self_link": canonical_url( | ||
1342 | 774 | build, path_only_if_possible=True), | ||
1343 | 775 | "id": build.id, | ||
1344 | 776 | "distro_arch_series_link": canonical_url( | ||
1345 | 777 | build.distro_arch_series, | ||
1346 | 778 | path_only_if_possible=True), | ||
1347 | 779 | "architecture_tag": ( | ||
1348 | 780 | build.distro_arch_series.architecturetag), | ||
1349 | 781 | "archive_link": ArchiveFormatterAPI( | ||
1350 | 782 | build.archive).link(None), | ||
1351 | 783 | } | ||
1352 | 784 | build_summary.update(all_build_summaries[build.id]) | ||
1353 | 785 | build_summaries.append(build_summary) | ||
1354 | 786 | result["requests"][request.id] = { | ||
1355 | 787 | "status": request.status.name, | ||
1356 | 788 | "error_message": request.error_message, | ||
1357 | 789 | "builds": build_summaries, | ||
1358 | 790 | } | ||
1359 | 791 | |||
1360 | 792 | for build_id in (build_ids or []): | ||
1361 | 793 | if build_id in all_build_summaries: | ||
1362 | 794 | result["builds"][build_id] = all_build_summaries[build_id] | ||
1363 | 795 | |||
1364 | 796 | return result | ||
1365 | 797 | |||
1366 | 701 | @property | 798 | @property |
1367 | 702 | def builds(self): | 799 | def builds(self): |
1368 | 703 | """See `ISnap`.""" | 800 | """See `ISnap`.""" |
1369 | 704 | 801 | ||
1370 | === modified file 'lib/lp/snappy/model/snapjob.py' | |||
1371 | --- lib/lp/snappy/model/snapjob.py 2018-09-10 11:18:42 +0000 | |||
1372 | +++ lib/lp/snappy/model/snapjob.py 2018-09-13 15:15:44 +0000 | |||
1373 | @@ -12,12 +12,15 @@ | |||
1374 | 12 | 'SnapRequestBuildsJob', | 12 | 'SnapRequestBuildsJob', |
1375 | 13 | ] | 13 | ] |
1376 | 14 | 14 | ||
1377 | 15 | from itertools import chain | ||
1378 | 16 | |||
1379 | 15 | from lazr.delegates import delegate_to | 17 | from lazr.delegates import delegate_to |
1380 | 16 | from lazr.enum import ( | 18 | from lazr.enum import ( |
1381 | 17 | DBEnumeratedType, | 19 | DBEnumeratedType, |
1382 | 18 | DBItem, | 20 | DBItem, |
1383 | 19 | ) | 21 | ) |
1384 | 20 | from storm.locals import ( | 22 | from storm.locals import ( |
1385 | 23 | Desc, | ||
1386 | 21 | Int, | 24 | Int, |
1387 | 22 | JSON, | 25 | JSON, |
1388 | 23 | Reference, | 26 | Reference, |
1389 | @@ -29,11 +32,14 @@ | |||
1390 | 29 | implementer, | 32 | implementer, |
1391 | 30 | provider, | 33 | provider, |
1392 | 31 | ) | 34 | ) |
1393 | 35 | from zope.security.proxy import removeSecurityProxy | ||
1394 | 32 | 36 | ||
1395 | 33 | from lp.app.errors import NotFoundError | 37 | from lp.app.errors import NotFoundError |
1396 | 34 | from lp.registry.interfaces.person import IPersonSet | 38 | from lp.registry.interfaces.person import IPersonSet |
1397 | 35 | from lp.registry.interfaces.pocket import PackagePublishingPocket | 39 | from lp.registry.interfaces.pocket import PackagePublishingPocket |
1398 | 36 | from lp.services.config import config | 40 | from lp.services.config import config |
1399 | 41 | from lp.services.database.bulk import load_related | ||
1400 | 42 | from lp.services.database.decoratedresultset import DecoratedResultSet | ||
1401 | 37 | from lp.services.database.enumcol import EnumCol | 43 | from lp.services.database.enumcol import EnumCol |
1402 | 38 | from lp.services.database.interfaces import ( | 44 | from lp.services.database.interfaces import ( |
1403 | 39 | IMasterStore, | 45 | IMasterStore, |
1404 | @@ -58,7 +64,10 @@ | |||
1405 | 58 | ISnapRequestBuildsJobSource, | 64 | ISnapRequestBuildsJobSource, |
1406 | 59 | ) | 65 | ) |
1407 | 60 | from lp.snappy.model.snapbuild import SnapBuild | 66 | from lp.snappy.model.snapbuild import SnapBuild |
1409 | 61 | from lp.soyuz.model.archive import Archive | 67 | from lp.soyuz.model.archive import ( |
1410 | 68 | Archive, | ||
1411 | 69 | get_enabled_archive_filter, | ||
1412 | 70 | ) | ||
1413 | 62 | 71 | ||
1414 | 63 | 72 | ||
1415 | 64 | class SnapJobType(DBEnumeratedType): | 73 | class SnapJobType(DBEnumeratedType): |
1416 | @@ -188,6 +197,30 @@ | |||
1417 | 188 | return job | 197 | return job |
1418 | 189 | 198 | ||
1419 | 190 | @classmethod | 199 | @classmethod |
1420 | 200 | def findBySnap(cls, snap, statuses=None, job_ids=None): | ||
1421 | 201 | """See `ISnapRequestBuildsJobSource`.""" | ||
1422 | 202 | clauses = [ | ||
1423 | 203 | SnapJob.snap == snap, | ||
1424 | 204 | SnapJob.job_type == cls.class_job_type, | ||
1425 | 205 | ] | ||
1426 | 206 | if statuses is not None: | ||
1427 | 207 | clauses.extend([ | ||
1428 | 208 | SnapJob.job == Job.id, | ||
1429 | 209 | Job._status.is_in(statuses), | ||
1430 | 210 | ]) | ||
1431 | 211 | if job_ids is not None: | ||
1432 | 212 | clauses.append(SnapJob.job_id.is_in(job_ids)) | ||
1433 | 213 | snap_jobs = IStore(SnapJob).find(SnapJob, *clauses).order_by( | ||
1434 | 214 | Desc(SnapJob.job_id)) | ||
1435 | 215 | |||
1436 | 216 | def preload_jobs(rows): | ||
1437 | 217 | load_related(Job, rows, ["job_id"]) | ||
1438 | 218 | |||
1439 | 219 | return DecoratedResultSet( | ||
1440 | 220 | snap_jobs, lambda snap_job: cls(snap_job), | ||
1441 | 221 | pre_iter_hook=preload_jobs) | ||
1442 | 222 | |||
1443 | 223 | @classmethod | ||
1444 | 191 | def getBySnapAndID(cls, snap, job_id): | 224 | def getBySnapAndID(cls, snap, job_id): |
1445 | 192 | """See `ISnapRequestBuildsJobSource`.""" | 225 | """See `ISnapRequestBuildsJobSource`.""" |
1446 | 193 | snap_job = IStore(SnapJob).find( | 226 | snap_job = IStore(SnapJob).find( |
1447 | @@ -201,6 +234,31 @@ | |||
1448 | 201 | (job_id, snap)) | 234 | (job_id, snap)) |
1449 | 202 | return cls(snap_job) | 235 | return cls(snap_job) |
1450 | 203 | 236 | ||
1451 | 237 | @classmethod | ||
1452 | 238 | def findBuildsForJobs(cls, jobs, user=None): | ||
1453 | 239 | """See `ISnapRequestBuildsJobSource`.""" | ||
1454 | 240 | build_ids = { | ||
1455 | 241 | job.job_id: removeSecurityProxy(job).metadata.get("builds") or [] | ||
1456 | 242 | for job in jobs} | ||
1457 | 243 | all_build_ids = set(chain.from_iterable(build_ids.values())) | ||
1458 | 244 | if all_build_ids: | ||
1459 | 245 | all_builds = { | ||
1460 | 246 | build.id: build for build in IStore(SnapBuild).find( | ||
1461 | 247 | SnapBuild, | ||
1462 | 248 | SnapBuild.id.is_in(all_build_ids), | ||
1463 | 249 | SnapBuild.archive_id == Archive.id, | ||
1464 | 250 | Archive._enabled == True, | ||
1465 | 251 | get_enabled_archive_filter( | ||
1466 | 252 | user, include_public=True, include_subscribed=True)) | ||
1467 | 253 | } | ||
1468 | 254 | else: | ||
1469 | 255 | all_builds = {} | ||
1470 | 256 | return { | ||
1471 | 257 | job.job_id: [ | ||
1472 | 258 | all_builds[build_id] for build_id in build_ids[job.job_id] | ||
1473 | 259 | if build_id in all_builds] | ||
1474 | 260 | for job in jobs} | ||
1475 | 261 | |||
1476 | 204 | def getOperationDescription(self): | 262 | def getOperationDescription(self): |
1477 | 205 | return "requesting builds of %s" % self.snap.name | 263 | return "requesting builds of %s" % self.snap.name |
1478 | 206 | 264 | ||
1479 | @@ -261,11 +319,11 @@ | |||
1480 | 261 | def builds(self): | 319 | def builds(self): |
1481 | 262 | """See `ISnapRequestBuildsJob`.""" | 320 | """See `ISnapRequestBuildsJob`.""" |
1482 | 263 | build_ids = self.metadata.get("builds") | 321 | build_ids = self.metadata.get("builds") |
1486 | 264 | if build_ids is None: | 322 | if build_ids: |
1484 | 265 | return EmptyResultSet() | ||
1485 | 266 | else: | ||
1487 | 267 | return IStore(SnapBuild).find( | 323 | return IStore(SnapBuild).find( |
1488 | 268 | SnapBuild, SnapBuild.id.is_in(build_ids)) | 324 | SnapBuild, SnapBuild.id.is_in(build_ids)) |
1489 | 325 | else: | ||
1490 | 326 | return EmptyResultSet() | ||
1491 | 269 | 327 | ||
1492 | 270 | @builds.setter | 328 | @builds.setter |
1493 | 271 | def builds(self, builds): | 329 | def builds(self, builds): |
1494 | 272 | 330 | ||
1495 | === modified file 'lib/lp/snappy/templates/snap-index.pt' | |||
1496 | --- lib/lp/snappy/templates/snap-index.pt 2018-04-30 16:48:47 +0000 | |||
1497 | +++ lib/lp/snappy/templates/snap-index.pt 2018-09-13 15:15:44 +0000 | |||
1498 | @@ -156,6 +156,18 @@ | |||
1499 | 156 | </tr> | 156 | </tr> |
1500 | 157 | </thead> | 157 | </thead> |
1501 | 158 | <tbody> | 158 | <tbody> |
1502 | 159 | <tal:snap-build-requests repeat="request context/pending_build_requests"> | ||
1503 | 160 | <tr tal:attributes="id string:request-${request/id}"> | ||
1504 | 161 | <td colspan="3" | ||
1505 | 162 | tal:attributes="class string:request_status ${request/status/name}"> | ||
1506 | 163 | <span tal:replace="structure request/image:icon"/> | ||
1507 | 164 | <tal:title replace="request/status/title"/> build request | ||
1508 | 165 | </td> | ||
1509 | 166 | <td> | ||
1510 | 167 | <tal:archive replace="structure request/archive/fmt:link"/> | ||
1511 | 168 | </td> | ||
1512 | 169 | </tr> | ||
1513 | 170 | </tal:snap-build-requests> | ||
1514 | 159 | <tal:snap-builds repeat="build view/builds"> | 171 | <tal:snap-builds repeat="build view/builds"> |
1515 | 160 | <tr tal:attributes="id string:build-${build/id}"> | 172 | <tr tal:attributes="id string:build-${build/id}"> |
1516 | 161 | <td tal:attributes="class string:build_status ${build/status/name}"> | 173 | <td tal:attributes="class string:build_status ${build/status/name}"> |
1517 | 162 | 174 | ||
1518 | === modified file 'lib/lp/snappy/tests/test_snap.py' | |||
1519 | --- lib/lp/snappy/tests/test_snap.py 2018-09-10 11:18:42 +0000 | |||
1520 | +++ lib/lp/snappy/tests/test_snap.py 2018-09-13 15:15:44 +0000 | |||
1521 | @@ -12,6 +12,7 @@ | |||
1522 | 12 | timedelta, | 12 | timedelta, |
1523 | 13 | ) | 13 | ) |
1524 | 14 | import json | 14 | import json |
1525 | 15 | from operator import attrgetter | ||
1526 | 15 | from textwrap import dedent | 16 | from textwrap import dedent |
1527 | 16 | from urlparse import urlsplit | 17 | from urlparse import urlsplit |
1528 | 17 | 18 | ||
1529 | @@ -176,7 +177,9 @@ | |||
1530 | 176 | self.assertThat( | 177 | self.assertThat( |
1531 | 177 | self.factory.makeSnap(), | 178 | self.factory.makeSnap(), |
1532 | 178 | DoesNotSnapshot( | 179 | DoesNotSnapshot( |
1534 | 179 | ["builds", "completed_builds", "pending_builds"], ISnapView)) | 180 | ["pending_build_requests", |
1535 | 181 | "builds", "completed_builds", "pending_builds"], | ||
1536 | 182 | ISnapView)) | ||
1537 | 180 | 183 | ||
1538 | 181 | def test_initial_date_last_modified(self): | 184 | def test_initial_date_last_modified(self): |
1539 | 182 | # The initial value of date_last_modified is date_created. | 185 | # The initial value of date_last_modified is date_created. |
1540 | @@ -424,7 +427,8 @@ | |||
1541 | 424 | snap=Equals(snap), | 427 | snap=Equals(snap), |
1542 | 425 | status=Equals(SnapBuildRequestStatus.PENDING), | 428 | status=Equals(SnapBuildRequestStatus.PENDING), |
1543 | 426 | error_message=Is(None), | 429 | error_message=Is(None), |
1545 | 427 | builds=AfterPreprocessing(set, MatchesSetwise()))) | 430 | builds=AfterPreprocessing(set, MatchesSetwise()), |
1546 | 431 | archive=Equals(snap.distro_series.main_archive))) | ||
1547 | 428 | [job] = getUtility(ISnapRequestBuildsJobSource).iterReady() | 432 | [job] = getUtility(ISnapRequestBuildsJobSource).iterReady() |
1548 | 429 | self.assertThat(job, MatchesStructure( | 433 | self.assertThat(job, MatchesStructure( |
1549 | 430 | job_id=Equals(request.id), | 434 | job_id=Equals(request.id), |
1550 | @@ -744,6 +748,172 @@ | |||
1551 | 744 | 1, 5) | 748 | 1, 5) |
1552 | 745 | self.assertThat(recorder2, HasQueryCount.byEquality(recorder1)) | 749 | self.assertThat(recorder2, HasQueryCount.byEquality(recorder1)) |
1553 | 746 | 750 | ||
1554 | 751 | def test_getBuildSummaries(self): | ||
1555 | 752 | snap1 = self.factory.makeSnap() | ||
1556 | 753 | snap2 = self.factory.makeSnap() | ||
1557 | 754 | request11 = self.factory.makeSnapBuildRequest(snap=snap1) | ||
1558 | 755 | request12 = self.factory.makeSnapBuildRequest(snap=snap1) | ||
1559 | 756 | request2 = self.factory.makeSnapBuildRequest(snap=snap2) | ||
1560 | 757 | self.factory.makeSnapBuildRequest() | ||
1561 | 758 | build11 = self.factory.makeSnapBuild(snap=snap1) | ||
1562 | 759 | build12 = self.factory.makeSnapBuild(snap=snap1) | ||
1563 | 760 | build2 = self.factory.makeSnapBuild(snap=snap2) | ||
1564 | 761 | self.factory.makeSnapBuild() | ||
1565 | 762 | summary1 = snap1.getBuildSummaries( | ||
1566 | 763 | request_ids=[request11.id, request12.id], | ||
1567 | 764 | build_ids=[build11.id, build12.id]) | ||
1568 | 765 | summary2 = snap2.getBuildSummaries( | ||
1569 | 766 | request_ids=[request2.id], build_ids=[build2.id]) | ||
1570 | 767 | request_summary_matcher = MatchesDict({ | ||
1571 | 768 | "status": Equals("PENDING"), | ||
1572 | 769 | "error_message": Is(None), | ||
1573 | 770 | "builds": Equals([]), | ||
1574 | 771 | }) | ||
1575 | 772 | build_summary_matcher = MatchesDict({ | ||
1576 | 773 | "status": Equals("NEEDSBUILD"), | ||
1577 | 774 | "buildstate": Equals("Needs building"), | ||
1578 | 775 | "when_complete": Is(None), | ||
1579 | 776 | "when_complete_estimate": Is(False), | ||
1580 | 777 | "build_log_url": Is(None), | ||
1581 | 778 | "build_log_size": Is(None), | ||
1582 | 779 | }) | ||
1583 | 780 | self.assertThat(summary1, MatchesDict({ | ||
1584 | 781 | "requests": MatchesDict({ | ||
1585 | 782 | request11.id: request_summary_matcher, | ||
1586 | 783 | request12.id: request_summary_matcher, | ||
1587 | 784 | }), | ||
1588 | 785 | "builds": MatchesDict({ | ||
1589 | 786 | build11.id: build_summary_matcher, | ||
1590 | 787 | build12.id: build_summary_matcher, | ||
1591 | 788 | }), | ||
1592 | 789 | })) | ||
1593 | 790 | self.assertThat(summary2, MatchesDict({ | ||
1594 | 791 | "requests": MatchesDict({request2.id: request_summary_matcher}), | ||
1595 | 792 | "builds": MatchesDict({build2.id: build_summary_matcher}), | ||
1596 | 793 | })) | ||
1597 | 794 | |||
1598 | 795 | def test_getBuildSummaries_empty_input(self): | ||
1599 | 796 | snap = self.factory.makeSnap() | ||
1600 | 797 | self.factory.makeSnapBuildRequest(snap=snap) | ||
1601 | 798 | self.assertEqual( | ||
1602 | 799 | {"requests": {}, "builds": {}}, | ||
1603 | 800 | snap.getBuildSummaries(request_ids=None, build_ids=None)) | ||
1604 | 801 | self.assertEqual( | ||
1605 | 802 | {"requests": {}, "builds": {}}, | ||
1606 | 803 | snap.getBuildSummaries(request_ids=[], build_ids=[])) | ||
1607 | 804 | self.assertEqual( | ||
1608 | 805 | {"requests": {}, "builds": {}}, | ||
1609 | 806 | snap.getBuildSummaries(request_ids=(), build_ids=())) | ||
1610 | 807 | |||
1611 | 808 | def test_getBuildSummaries_not_matching_snap(self): | ||
1612 | 809 | # getBuildSummaries does not return information for other snaps. | ||
1613 | 810 | snap1 = self.factory.makeSnap() | ||
1614 | 811 | snap2 = self.factory.makeSnap() | ||
1615 | 812 | self.factory.makeSnapBuildRequest(snap=snap1) | ||
1616 | 813 | self.factory.makeSnapBuild(snap=snap1) | ||
1617 | 814 | request2 = self.factory.makeSnapBuildRequest(snap=snap2) | ||
1618 | 815 | build2 = self.factory.makeSnapBuild(snap=snap2) | ||
1619 | 816 | summary1 = snap1.getBuildSummaries( | ||
1620 | 817 | request_ids=[request2.id], build_ids=[build2.id]) | ||
1621 | 818 | self.assertEqual({"requests": {}, "builds": {}}, summary1) | ||
1622 | 819 | |||
1623 | 820 | def test_getBuildSummaries_request_error_message_field(self): | ||
1624 | 821 | # The error_message field for a build request should be None unless | ||
1625 | 822 | # the build request failed. | ||
1626 | 823 | snap = self.factory.makeSnap() | ||
1627 | 824 | request = self.factory.makeSnapBuildRequest(snap=snap) | ||
1628 | 825 | self.assertIsNone(request.error_message) | ||
1629 | 826 | summary = snap.getBuildSummaries(request_ids=[request.id]) | ||
1630 | 827 | self.assertIsNone(summary["requests"][request.id]["error_message"]) | ||
1631 | 828 | job = removeSecurityProxy(request)._job | ||
1632 | 829 | removeSecurityProxy(job).error_message = "Boom" | ||
1633 | 830 | summary = snap.getBuildSummaries(request_ids=[request.id]) | ||
1634 | 831 | self.assertEqual( | ||
1635 | 832 | "Boom", summary["requests"][request.id]["error_message"]) | ||
1636 | 833 | |||
1637 | 834 | def test_getBuildSummaries_request_builds_field(self): | ||
1638 | 835 | # The builds field should be an empty list unless the build request | ||
1639 | 836 | # has completed and produced builds. | ||
1640 | 837 | self.useFixture(GitHostingFixture(blob=dedent("""\ | ||
1641 | 838 | architectures: | ||
1642 | 839 | - build-on: mips64el | ||
1643 | 840 | - build-on: riscv64 | ||
1644 | 841 | """))) | ||
1645 | 842 | job = self.makeRequestBuildsJob(["mips64el", "riscv64", "sh4"]) | ||
1646 | 843 | snap = job.snap | ||
1647 | 844 | request = snap.getBuildRequest(job.job_id) | ||
1648 | 845 | self.assertEqual([], list(request.builds)) | ||
1649 | 846 | summary = snap.getBuildSummaries(request_ids=[request.id]) | ||
1650 | 847 | self.assertEqual([], summary["requests"][request.id]["builds"]) | ||
1651 | 848 | with person_logged_in(job.requester): | ||
1652 | 849 | with dbuser(config.ISnapRequestBuildsJobSource.dbuser): | ||
1653 | 850 | JobRunner([job]).runAll() | ||
1654 | 851 | summary = snap.getBuildSummaries(request_ids=[request.id]) | ||
1655 | 852 | expected_snap_url = "/~%s/+snap/%s" % (snap.owner.name, snap.name) | ||
1656 | 853 | builds = sorted(request.builds, key=attrgetter("id"), reverse=True) | ||
1657 | 854 | expected_builds = [ | ||
1658 | 855 | { | ||
1659 | 856 | "self_link": expected_snap_url + "/+build/%d" % build.id, | ||
1660 | 857 | "id": build.id, | ||
1661 | 858 | "distro_arch_series_link": "/%s/%s/%s" % ( | ||
1662 | 859 | snap.distro_series.distribution.name, | ||
1663 | 860 | snap.distro_series.name, | ||
1664 | 861 | build.distro_arch_series.architecturetag), | ||
1665 | 862 | "architecture_tag": build.distro_arch_series.architecturetag, | ||
1666 | 863 | "archive_link": ( | ||
1667 | 864 | '<a href="/%s" class="sprite distribution">%s</a>' % ( | ||
1668 | 865 | build.archive.distribution.name, | ||
1669 | 866 | build.archive.displayname)), | ||
1670 | 867 | "status": "NEEDSBUILD", | ||
1671 | 868 | "buildstate": "Needs building", | ||
1672 | 869 | "when_complete": None, | ||
1673 | 870 | "when_complete_estimate": False, | ||
1674 | 871 | "build_log_url": None, | ||
1675 | 872 | "build_log_size": None, | ||
1676 | 873 | } for build in builds] | ||
1677 | 874 | self.assertEqual( | ||
1678 | 875 | expected_builds, summary["requests"][request.id]["builds"]) | ||
1679 | 876 | |||
1680 | 877 | def test_getBuildSummaries_query_count(self): | ||
1681 | 878 | # The DB query count remains constant regardless of the number of | ||
1682 | 879 | # requests and the number of builds resulting from them. | ||
1683 | 880 | self.useFixture(GitHostingFixture(blob=dedent("""\ | ||
1684 | 881 | architectures: | ||
1685 | 882 | - build-on: mips64el | ||
1686 | 883 | - build-on: riscv64 | ||
1687 | 884 | """))) | ||
1688 | 885 | job = self.makeRequestBuildsJob(["mips64el", "riscv64", "sh4"]) | ||
1689 | 886 | snap = job.snap | ||
1690 | 887 | request_ids = [] | ||
1691 | 888 | build_ids = [] | ||
1692 | 889 | |||
1693 | 890 | def create_items(): | ||
1694 | 891 | request = self.factory.makeSnapBuildRequest( | ||
1695 | 892 | snap=snap, archive=self.factory.makeArchive()) | ||
1696 | 893 | request_ids.append(request.id) | ||
1697 | 894 | job = removeSecurityProxy(request)._job | ||
1698 | 895 | with person_logged_in(snap.owner.teamowner): | ||
1699 | 896 | # Using the normal job runner interferes with SQL statement | ||
1700 | 897 | # recording, so we run the job by hand. | ||
1701 | 898 | job.start() | ||
1702 | 899 | job.run() | ||
1703 | 900 | job.complete() | ||
1704 | 901 | # XXX cjwatson 2018-06-20: Queued builds with | ||
1705 | 902 | # BuildQueueStatus.WAITING incur extra queries per build due to | ||
1706 | 903 | # estimating start times. For the moment, we dodge this by | ||
1707 | 904 | # starting the builds. | ||
1708 | 905 | for build in job.builds: | ||
1709 | 906 | build.buildqueue_record.markAsBuilding( | ||
1710 | 907 | self.factory.makeBuilder()) | ||
1711 | 908 | build_ids.append(self.factory.makeSnapBuild( | ||
1712 | 909 | snap=snap, archive=self.factory.makeArchive()).id) | ||
1713 | 910 | |||
1714 | 911 | recorder1, recorder2 = record_two_runs( | ||
1715 | 912 | lambda: snap.getBuildSummaries( | ||
1716 | 913 | request_ids=request_ids, build_ids=build_ids), | ||
1717 | 914 | create_items, 1, 5) | ||
1718 | 915 | self.assertThat(recorder2, HasQueryCount.byEquality(recorder1)) | ||
1719 | 916 | |||
1720 | 747 | 917 | ||
1721 | 748 | class TestSnapDeleteWithBuilds(TestCaseWithFactory): | 918 | class TestSnapDeleteWithBuilds(TestCaseWithFactory): |
1722 | 749 | 919 | ||
1723 | 750 | 920 | ||
1724 | === modified file 'lib/lp/testing/factory.py' | |||
1725 | --- lib/lp/testing/factory.py 2018-08-23 09:30:24 +0000 | |||
1726 | +++ lib/lp/testing/factory.py 2018-09-13 15:15:44 +0000 | |||
1727 | @@ -4728,6 +4728,19 @@ | |||
1728 | 4728 | IStore(snap).flush() | 4728 | IStore(snap).flush() |
1729 | 4729 | return snap | 4729 | return snap |
1730 | 4730 | 4730 | ||
1731 | 4731 | def makeSnapBuildRequest(self, snap=None, requester=None, archive=None, | ||
1732 | 4732 | pocket=PackagePublishingPocket.UPDATES, | ||
1733 | 4733 | channels=None): | ||
1734 | 4734 | """Make a new SnapBuildRequest.""" | ||
1735 | 4735 | if snap is None: | ||
1736 | 4736 | snap = self.makeSnap() | ||
1737 | 4737 | if requester is None: | ||
1738 | 4738 | requester = snap.owner.teamowner | ||
1739 | 4739 | if archive is None: | ||
1740 | 4740 | archive = snap.distro_series.main_archive | ||
1741 | 4741 | return snap.requestBuilds( | ||
1742 | 4742 | requester, archive, pocket, channels=channels) | ||
1743 | 4743 | |||
1744 | 4731 | def makeSnapBuild(self, requester=None, registrant=None, snap=None, | 4744 | def makeSnapBuild(self, requester=None, registrant=None, snap=None, |
1745 | 4732 | archive=None, distroarchseries=None, pocket=None, | 4745 | archive=None, distroarchseries=None, pocket=None, |
1746 | 4733 | channels=None, date_created=DEFAULT, | 4746 | channels=None, date_created=DEFAULT, |