Merge lp:~cjwatson/launchpad/snap-daily-builds-request-builds into lp:launchpad
- snap-daily-builds-request-builds
- Merge into devel
Proposed by
Colin Watson
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 18740 | ||||
Proposed branch: | lp:~cjwatson/launchpad/snap-daily-builds-request-builds | ||||
Merge into: | lp:launchpad | ||||
Prerequisite: | lp:~cjwatson/launchpad/git-ref-remote-blob | ||||
Diff against target: |
353 lines (+128/-54) 4 files modified
lib/lp/snappy/adapters/buildarch.py (+4/-4) lib/lp/snappy/interfaces/snap.py (+14/-1) lib/lp/snappy/model/snap.py (+28/-36) lib/lp/snappy/tests/test_snap.py (+82/-13) |
||||
To merge this branch: | bzr merge lp:~cjwatson/launchpad/snap-daily-builds-request-builds | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email: mp+348187@code.launchpad.net |
Commit message
Make automatic builds of snaps honour build-on architectures.
Description of the change
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/snappy/adapters/buildarch.py' | |||
2 | --- lib/lp/snappy/adapters/buildarch.py 2018-06-14 17:11:56 +0000 | |||
3 | +++ lib/lp/snappy/adapters/buildarch.py 2018-07-30 09:08:46 +0000 | |||
4 | @@ -122,12 +122,12 @@ | |||
5 | 122 | 122 | ||
6 | 123 | 123 | ||
7 | 124 | def determine_architectures_to_build(snapcraft_data, supported_arches): | 124 | def determine_architectures_to_build(snapcraft_data, supported_arches): |
9 | 125 | """Return a set of architectures to build based on snapcraft.yaml. | 125 | """Return a list of architectures to build based on snapcraft.yaml. |
10 | 126 | 126 | ||
11 | 127 | :param snapcraft_data: A parsed snapcraft.yaml. | 127 | :param snapcraft_data: A parsed snapcraft.yaml. |
12 | 128 | :param supported_arches: An ordered list of all architecture tags that | 128 | :param supported_arches: An ordered list of all architecture tags that |
13 | 129 | we can create builds for. | 129 | we can create builds for. |
15 | 130 | :return: a set of `SnapBuildInstance`s. | 130 | :return: a list of `SnapBuildInstance`s. |
16 | 131 | """ | 131 | """ |
17 | 132 | architectures_list = snapcraft_data.get("architectures") | 132 | architectures_list = snapcraft_data.get("architectures") |
18 | 133 | 133 | ||
19 | @@ -162,10 +162,10 @@ | |||
20 | 162 | if duplicates: | 162 | if duplicates: |
21 | 163 | raise DuplicateBuildOnError(duplicates) | 163 | raise DuplicateBuildOnError(duplicates) |
22 | 164 | 164 | ||
24 | 165 | architectures_to_build = set() | 165 | architectures_to_build = [] |
25 | 166 | for arch in architectures: | 166 | for arch in architectures: |
26 | 167 | try: | 167 | try: |
28 | 168 | architectures_to_build.add( | 168 | architectures_to_build.append( |
29 | 169 | SnapBuildInstance(arch, supported_arches)) | 169 | SnapBuildInstance(arch, supported_arches)) |
30 | 170 | except UnsupportedBuildOnError: | 170 | except UnsupportedBuildOnError: |
31 | 171 | # Snaps are allowed to declare that they build on architectures | 171 | # Snaps are allowed to declare that they build on architectures |
32 | 172 | 172 | ||
33 | === modified file 'lib/lp/snappy/interfaces/snap.py' | |||
34 | --- lib/lp/snappy/interfaces/snap.py 2018-06-18 16:42:43 +0000 | |||
35 | +++ lib/lp/snappy/interfaces/snap.py 2018-07-30 09:08:46 +0000 | |||
36 | @@ -406,6 +406,7 @@ | |||
37 | 406 | """ | 406 | """ |
38 | 407 | 407 | ||
39 | 408 | def requestBuildsFromJob(requester, archive, pocket, channels=None, | 408 | def requestBuildsFromJob(requester, archive, pocket, channels=None, |
40 | 409 | allow_failures=False, fetch_snapcraft_yaml=True, | ||
41 | 409 | logger=None): | 410 | logger=None): |
42 | 410 | """Synchronous part of `Snap.requestBuilds`. | 411 | """Synchronous part of `Snap.requestBuilds`. |
43 | 411 | 412 | ||
44 | @@ -416,6 +417,13 @@ | |||
45 | 416 | :param pocket: The pocket that should be targeted. | 417 | :param pocket: The pocket that should be targeted. |
46 | 417 | :param channels: A dictionary mapping snap names to channels to use | 418 | :param channels: A dictionary mapping snap names to channels to use |
47 | 418 | for these builds. | 419 | for these builds. |
48 | 420 | :param allow_failures: If True, log exceptions other than "already | ||
49 | 421 | pending" from individual build requests; if False, raise them to | ||
50 | 422 | the caller. | ||
51 | 423 | :param fetch_snapcraft_yaml: If True, fetch snapcraft.yaml from the | ||
52 | 424 | appropriate branch or repository and use it to decide which | ||
53 | 425 | builds to request; if False, fall back to building for all | ||
54 | 426 | supported architectures. | ||
55 | 419 | :param logger: An optional logger. | 427 | :param logger: An optional logger. |
56 | 420 | :return: A sequence of `ISnapBuild` instances. | 428 | :return: A sequence of `ISnapBuild` instances. |
57 | 421 | """ | 429 | """ |
58 | @@ -474,12 +482,17 @@ | |||
59 | 474 | @operation_returns_collection_of(Interface) | 482 | @operation_returns_collection_of(Interface) |
60 | 475 | @export_write_operation() | 483 | @export_write_operation() |
61 | 476 | @operation_for_version("devel") | 484 | @operation_for_version("devel") |
63 | 477 | def requestAutoBuilds(allow_failures=False, logger=None): | 485 | def requestAutoBuilds(allow_failures=False, fetch_snapcraft_yaml=False, |
64 | 486 | logger=None): | ||
65 | 478 | """Create and return automatic builds for this snap package. | 487 | """Create and return automatic builds for this snap package. |
66 | 479 | 488 | ||
67 | 480 | :param allow_failures: If True, log exceptions other than "already | 489 | :param allow_failures: If True, log exceptions other than "already |
68 | 481 | pending" from individual build requests; if False, raise them to | 490 | pending" from individual build requests; if False, raise them to |
69 | 482 | the caller. | 491 | the caller. |
70 | 492 | :param fetch_snapcraft_yaml: If True, fetch snapcraft.yaml from the | ||
71 | 493 | appropriate branch or repository and use it to decide which | ||
72 | 494 | builds to request; if False, fall back to building for all | ||
73 | 495 | supported architectures. | ||
74 | 483 | :param logger: An optional logger. | 496 | :param logger: An optional logger. |
75 | 484 | :raises CannotRequestAutoBuilds: if no auto_build_archive or | 497 | :raises CannotRequestAutoBuilds: if no auto_build_archive or |
76 | 485 | auto_build_pocket is set. | 498 | auto_build_pocket is set. |
77 | 486 | 499 | ||
78 | === modified file 'lib/lp/snappy/model/snap.py' | |||
79 | --- lib/lp/snappy/model/snap.py 2018-07-13 09:17:40 +0000 | |||
80 | +++ lib/lp/snappy/model/snap.py 2018-07-30 09:08:46 +0000 | |||
81 | @@ -552,18 +552,22 @@ | |||
82 | 552 | return self.getBuildRequest(job.job_id) | 552 | return self.getBuildRequest(job.job_id) |
83 | 553 | 553 | ||
84 | 554 | def requestBuildsFromJob(self, requester, archive, pocket, channels=None, | 554 | def requestBuildsFromJob(self, requester, archive, pocket, channels=None, |
85 | 555 | allow_failures=False, fetch_snapcraft_yaml=True, | ||
86 | 555 | logger=None): | 556 | logger=None): |
87 | 556 | """See `ISnap`.""" | 557 | """See `ISnap`.""" |
98 | 557 | try: | 558 | if fetch_snapcraft_yaml: |
99 | 558 | snapcraft_data = removeSecurityProxy( | 559 | try: |
100 | 559 | getUtility(ISnapSet).getSnapcraftYaml(self)) | 560 | snapcraft_data = removeSecurityProxy( |
101 | 560 | except CannotFetchSnapcraftYaml as e: | 561 | getUtility(ISnapSet).getSnapcraftYaml(self)) |
102 | 561 | if not e.unsupported_remote: | 562 | except CannotFetchSnapcraftYaml as e: |
103 | 562 | raise | 563 | if not e.unsupported_remote: |
104 | 563 | # The only reason we can't fetch the file is because we don't | 564 | raise |
105 | 564 | # support fetching from this repository's host. In this case | 565 | # The only reason we can't fetch the file is because we |
106 | 565 | # the best thing is to fall back to building for all supported | 566 | # don't support fetching from this repository's host. In |
107 | 566 | # architectures. | 567 | # this case the best thing is to fall back to building for |
108 | 568 | # all supported architectures. | ||
109 | 569 | snapcraft_data = {} | ||
110 | 570 | else: | ||
111 | 567 | snapcraft_data = {} | 571 | snapcraft_data = {} |
112 | 568 | # Sort by Processor.id for determinism. This is chosen to be the | 572 | # Sort by Processor.id for determinism. This is chosen to be the |
113 | 569 | # same order as in BinaryPackageBuildSet.createForSource, to | 573 | # same order as in BinaryPackageBuildSet.createForSource, to |
114 | @@ -589,11 +593,18 @@ | |||
115 | 589 | builds.append(build) | 593 | builds.append(build) |
116 | 590 | except SnapBuildAlreadyPending as e: | 594 | except SnapBuildAlreadyPending as e: |
117 | 591 | pass | 595 | pass |
118 | 596 | except Exception as e: | ||
119 | 597 | if not allow_failures: | ||
120 | 598 | raise | ||
121 | 599 | elif logger is not None: | ||
122 | 600 | logger.exception( | ||
123 | 601 | " - %s/%s/%s: %s", | ||
124 | 602 | self.owner.name, self.name, arch, e) | ||
125 | 592 | return builds | 603 | return builds |
126 | 593 | 604 | ||
128 | 594 | def requestAutoBuilds(self, allow_failures=False, logger=None): | 605 | def requestAutoBuilds(self, allow_failures=False, |
129 | 606 | fetch_snapcraft_yaml=False, logger=None): | ||
130 | 595 | """See `ISnap`.""" | 607 | """See `ISnap`.""" |
131 | 596 | builds = [] | ||
132 | 597 | if self.auto_build_archive is None: | 608 | if self.auto_build_archive is None: |
133 | 598 | raise CannotRequestAutoBuilds("auto_build_archive") | 609 | raise CannotRequestAutoBuilds("auto_build_archive") |
134 | 599 | if self.auto_build_pocket is None: | 610 | if self.auto_build_pocket is None: |
135 | @@ -603,29 +614,10 @@ | |||
136 | 603 | logger.debug( | 614 | logger.debug( |
137 | 604 | "Scheduling builds of snap package %s/%s", | 615 | "Scheduling builds of snap package %s/%s", |
138 | 605 | self.owner.name, self.name) | 616 | self.owner.name, self.name) |
162 | 606 | for arch in self.getAllowedArchitectures(): | 617 | return self.requestBuildsFromJob( |
163 | 607 | try: | 618 | self.owner, self.auto_build_archive, self.auto_build_pocket, |
164 | 608 | build = self.requestBuild( | 619 | channels=self.auto_build_channels, allow_failures=allow_failures, |
165 | 609 | self.owner, self.auto_build_archive, arch, | 620 | fetch_snapcraft_yaml=fetch_snapcraft_yaml, logger=logger) |
143 | 610 | self.auto_build_pocket, self.auto_build_channels) | ||
144 | 611 | if logger is not None: | ||
145 | 612 | logger.debug( | ||
146 | 613 | " - %s/%s/%s: Build requested.", | ||
147 | 614 | self.owner.name, self.name, arch.architecturetag) | ||
148 | 615 | builds.append(build) | ||
149 | 616 | except SnapBuildAlreadyPending as e: | ||
150 | 617 | if logger is not None: | ||
151 | 618 | logger.warning( | ||
152 | 619 | " - %s/%s/%s: %s", | ||
153 | 620 | self.owner.name, self.name, arch.architecturetag, e) | ||
154 | 621 | except Exception as e: | ||
155 | 622 | if not allow_failures: | ||
156 | 623 | raise | ||
157 | 624 | elif logger is not None: | ||
158 | 625 | logger.exception( | ||
159 | 626 | " - %s/%s/%s: %s", | ||
160 | 627 | self.owner.name, self.name, arch.architecturetag, e) | ||
161 | 628 | return builds | ||
166 | 629 | 621 | ||
167 | 630 | def getBuildRequest(self, job_id): | 622 | def getBuildRequest(self, job_id): |
168 | 631 | """See `ISnap`.""" | 623 | """See `ISnap`.""" |
169 | @@ -1113,7 +1105,7 @@ | |||
170 | 1113 | builds = [] | 1105 | builds = [] |
171 | 1114 | for snap in snaps: | 1106 | for snap in snaps: |
172 | 1115 | builds.extend(snap.requestAutoBuilds( | 1107 | builds.extend(snap.requestAutoBuilds( |
174 | 1116 | allow_failures=True, logger=logger)) | 1108 | allow_failures=True, fetch_snapcraft_yaml=True, logger=logger)) |
175 | 1117 | return builds | 1109 | return builds |
176 | 1118 | 1110 | ||
177 | 1119 | def detachFromBranch(self, branch): | 1111 | def detachFromBranch(self, branch): |
178 | 1120 | 1112 | ||
179 | === modified file 'lib/lp/snappy/tests/test_snap.py' | |||
180 | --- lib/lp/snappy/tests/test_snap.py 2018-06-18 16:42:43 +0000 | |||
181 | +++ lib/lp/snappy/tests/test_snap.py 2018-07-30 09:08:46 +0000 | |||
182 | @@ -1285,9 +1285,10 @@ | |||
183 | 1285 | def makeAutoBuildableSnap(self, **kwargs): | 1285 | def makeAutoBuildableSnap(self, **kwargs): |
184 | 1286 | processor = self.factory.makeProcessor(supports_virtualized=True) | 1286 | processor = self.factory.makeProcessor(supports_virtualized=True) |
185 | 1287 | das = self.makeBuildableDistroArchSeries(processor=processor) | 1287 | das = self.makeBuildableDistroArchSeries(processor=processor) |
186 | 1288 | [git_ref] = self.factory.makeGitRefs() | ||
187 | 1288 | snap = self.factory.makeSnap( | 1289 | snap = self.factory.makeSnap( |
188 | 1289 | distroseries=das.distroseries, processors=[das.processor], | 1290 | distroseries=das.distroseries, processors=[das.processor], |
190 | 1290 | auto_build=True, **kwargs) | 1291 | git_ref=git_ref, auto_build=True, **kwargs) |
191 | 1291 | return das, snap | 1292 | return das, snap |
192 | 1292 | 1293 | ||
193 | 1293 | def test_makeAutoBuilds(self): | 1294 | def test_makeAutoBuilds(self): |
194 | @@ -1296,7 +1297,11 @@ | |||
195 | 1296 | self.assertEqual([], getUtility(ISnapSet).makeAutoBuilds()) | 1297 | self.assertEqual([], getUtility(ISnapSet).makeAutoBuilds()) |
196 | 1297 | das, snap = self.makeAutoBuildableSnap(is_stale=True) | 1298 | das, snap = self.makeAutoBuildableSnap(is_stale=True) |
197 | 1298 | logger = BufferLogger() | 1299 | logger = BufferLogger() |
199 | 1299 | [build] = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | 1300 | with GitHostingFixture(blob=dedent("""\ |
200 | 1301 | architectures: | ||
201 | 1302 | - build-on: %s | ||
202 | 1303 | """) % das.architecturetag): | ||
203 | 1304 | [build] = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | ||
204 | 1300 | self.assertThat(build, MatchesStructure.byEquality( | 1305 | self.assertThat(build, MatchesStructure.byEquality( |
205 | 1301 | requester=snap.owner, snap=snap, distro_arch_series=das, | 1306 | requester=snap.owner, snap=snap, distro_arch_series=das, |
206 | 1302 | status=BuildStatus.NEEDSBUILD, | 1307 | status=BuildStatus.NEEDSBUILD, |
207 | @@ -1319,7 +1324,11 @@ | |||
208 | 1319 | requester=snap.owner, snap=snap, archive=snap.auto_build_archive, | 1324 | requester=snap.owner, snap=snap, archive=snap.auto_build_archive, |
209 | 1320 | distroarchseries=das) | 1325 | distroarchseries=das) |
210 | 1321 | logger = BufferLogger() | 1326 | logger = BufferLogger() |
212 | 1322 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | 1327 | with GitHostingFixture(blob=dedent("""\ |
213 | 1328 | architectures: | ||
214 | 1329 | - build-on: %s | ||
215 | 1330 | """) % das.architecturetag): | ||
216 | 1331 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | ||
217 | 1323 | self.assertEqual([], builds) | 1332 | self.assertEqual([], builds) |
218 | 1324 | self.assertEqual([], logger.getLogBuffer().splitlines()) | 1333 | self.assertEqual([], logger.getLogBuffer().splitlines()) |
219 | 1325 | 1334 | ||
220 | @@ -1340,7 +1349,13 @@ | |||
221 | 1340 | channels={"snapcraft": "stable"}) | 1349 | channels={"snapcraft": "stable"}) |
222 | 1341 | 1350 | ||
223 | 1342 | logger = BufferLogger() | 1351 | logger = BufferLogger() |
225 | 1343 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | 1352 | snapcraft_yaml = dedent("""\ |
226 | 1353 | architectures: | ||
227 | 1354 | - build-on: %s | ||
228 | 1355 | - build-on: %s | ||
229 | 1356 | """) % (das1.architecturetag, das2.architecturetag) | ||
230 | 1357 | with GitHostingFixture(blob=snapcraft_yaml): | ||
231 | 1358 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | ||
232 | 1344 | self.assertThat(builds, MatchesSetwise( | 1359 | self.assertThat(builds, MatchesSetwise( |
233 | 1345 | MatchesStructure( | 1360 | MatchesStructure( |
234 | 1346 | requester=Equals(snap1.owner), snap=Equals(snap1), | 1361 | requester=Equals(snap1.owner), snap=Equals(snap1), |
235 | @@ -1369,14 +1384,19 @@ | |||
236 | 1369 | removeSecurityProxy(snap).is_stale = True | 1384 | removeSecurityProxy(snap).is_stale = True |
237 | 1370 | IStore(snap).flush() | 1385 | IStore(snap).flush() |
238 | 1371 | logger = BufferLogger() | 1386 | logger = BufferLogger() |
240 | 1372 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | 1387 | with GitHostingFixture(blob=snapcraft_yaml): |
241 | 1388 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | ||
242 | 1373 | self.assertEqual([], builds) | 1389 | self.assertEqual([], builds) |
243 | 1374 | self.assertEqual([], logger.getLogBuffer().splitlines()) | 1390 | self.assertEqual([], logger.getLogBuffer().splitlines()) |
244 | 1375 | 1391 | ||
245 | 1376 | def test_makeAutoBuilds_skips_non_stale_snaps(self): | 1392 | def test_makeAutoBuilds_skips_non_stale_snaps(self): |
246 | 1377 | # ISnapSet.makeAutoBuilds skips snap packages that are not stale. | 1393 | # ISnapSet.makeAutoBuilds skips snap packages that are not stale. |
247 | 1378 | das, snap = self.makeAutoBuildableSnap(is_stale=False) | 1394 | das, snap = self.makeAutoBuildableSnap(is_stale=False) |
249 | 1379 | self.assertEqual([], getUtility(ISnapSet).makeAutoBuilds()) | 1395 | with GitHostingFixture(blob=dedent("""\ |
250 | 1396 | architectures: | ||
251 | 1397 | - build-on: %s | ||
252 | 1398 | """) % das.architecturetag): | ||
253 | 1399 | self.assertEqual([], getUtility(ISnapSet).makeAutoBuilds()) | ||
254 | 1380 | 1400 | ||
255 | 1381 | def test_makeAutoBuilds_skips_pending(self): | 1401 | def test_makeAutoBuilds_skips_pending(self): |
256 | 1382 | # ISnapSet.makeAutoBuilds skips snap packages that already have | 1402 | # ISnapSet.makeAutoBuilds skips snap packages that already have |
257 | @@ -1389,14 +1409,15 @@ | |||
258 | 1389 | distroarchseries=das, | 1409 | distroarchseries=das, |
259 | 1390 | date_created=datetime.now(pytz.UTC) - timedelta(days=1)) | 1410 | date_created=datetime.now(pytz.UTC) - timedelta(days=1)) |
260 | 1391 | logger = BufferLogger() | 1411 | logger = BufferLogger() |
262 | 1392 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | 1412 | with GitHostingFixture(blob=dedent("""\ |
263 | 1413 | architectures: | ||
264 | 1414 | - build-on: %s | ||
265 | 1415 | """) % das.architecturetag): | ||
266 | 1416 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | ||
267 | 1393 | self.assertEqual([], builds) | 1417 | self.assertEqual([], builds) |
268 | 1394 | expected_log_entries = [ | 1418 | expected_log_entries = [ |
269 | 1395 | "DEBUG Scheduling builds of snap package %s/%s" % ( | 1419 | "DEBUG Scheduling builds of snap package %s/%s" % ( |
270 | 1396 | snap.owner.name, snap.name), | 1420 | snap.owner.name, snap.name), |
271 | 1397 | "WARNING - %s/%s/%s: An identical build of this snap package " | ||
272 | 1398 | "is already pending." % ( | ||
273 | 1399 | snap.owner.name, snap.name, das.architecturetag), | ||
274 | 1400 | ] | 1421 | ] |
275 | 1401 | self.assertEqual( | 1422 | self.assertEqual( |
276 | 1402 | expected_log_entries, logger.getLogBuffer().splitlines()) | 1423 | expected_log_entries, logger.getLogBuffer().splitlines()) |
277 | @@ -1410,7 +1431,11 @@ | |||
278 | 1410 | distroarchseries=das, | 1431 | distroarchseries=das, |
279 | 1411 | date_created=datetime.now(pytz.UTC) - timedelta(days=1), | 1432 | date_created=datetime.now(pytz.UTC) - timedelta(days=1), |
280 | 1412 | status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=1)) | 1433 | status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=1)) |
282 | 1413 | builds = getUtility(ISnapSet).makeAutoBuilds() | 1434 | with GitHostingFixture(blob=dedent("""\ |
283 | 1435 | architectures: | ||
284 | 1436 | - build-on: %s | ||
285 | 1437 | """) % das.architecturetag): | ||
286 | 1438 | builds = getUtility(ISnapSet).makeAutoBuilds() | ||
287 | 1414 | self.assertEqual(1, len(builds)) | 1439 | self.assertEqual(1, len(builds)) |
288 | 1415 | 1440 | ||
289 | 1416 | def test_makeAutoBuilds_with_older_and_newer_builds(self): | 1441 | def test_makeAutoBuilds_with_older_and_newer_builds(self): |
290 | @@ -1423,7 +1448,11 @@ | |||
291 | 1423 | archive=snap.auto_build_archive, distroarchseries=das, | 1448 | archive=snap.auto_build_archive, distroarchseries=das, |
292 | 1424 | date_created=datetime.now(pytz.UTC) - timediff, | 1449 | date_created=datetime.now(pytz.UTC) - timediff, |
293 | 1425 | status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=1)) | 1450 | status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=1)) |
295 | 1426 | self.assertEqual([], getUtility(ISnapSet).makeAutoBuilds()) | 1451 | with GitHostingFixture(blob=dedent("""\ |
296 | 1452 | architectures: | ||
297 | 1453 | - build-on: %s | ||
298 | 1454 | """) % das.architecturetag): | ||
299 | 1455 | self.assertEqual([], getUtility(ISnapSet).makeAutoBuilds()) | ||
300 | 1427 | 1456 | ||
301 | 1428 | def test_makeAutoBuilds_with_recent_build_from_different_archive(self): | 1457 | def test_makeAutoBuilds_with_recent_build_from_different_archive(self): |
302 | 1429 | # If a snap package has been built recently but from an archive | 1458 | # If a snap package has been built recently but from an archive |
303 | @@ -1434,9 +1463,49 @@ | |||
304 | 1434 | requester=snap.owner, snap=snap, distroarchseries=das, | 1463 | requester=snap.owner, snap=snap, distroarchseries=das, |
305 | 1435 | date_created=datetime.now(pytz.UTC) - timedelta(minutes=30), | 1464 | date_created=datetime.now(pytz.UTC) - timedelta(minutes=30), |
306 | 1436 | status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=1)) | 1465 | status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=1)) |
308 | 1437 | builds = getUtility(ISnapSet).makeAutoBuilds() | 1466 | with GitHostingFixture(blob=dedent("""\ |
309 | 1467 | architectures: | ||
310 | 1468 | - build-on: %s | ||
311 | 1469 | """) % das.architecturetag): | ||
312 | 1470 | builds = getUtility(ISnapSet).makeAutoBuilds() | ||
313 | 1438 | self.assertEqual(1, len(builds)) | 1471 | self.assertEqual(1, len(builds)) |
314 | 1439 | 1472 | ||
315 | 1473 | def test_makeAutoBuilds_honours_explicit_architectures(self): | ||
316 | 1474 | # ISnapSet.makeAutoBuilds honours an explicit list of architectures | ||
317 | 1475 | # in the snap's snapcraft.yaml. | ||
318 | 1476 | das1, snap = self.makeAutoBuildableSnap(is_stale=True) | ||
319 | 1477 | das2 = self.makeBuildableDistroArchSeries( | ||
320 | 1478 | distroseries=das1.distroseries, | ||
321 | 1479 | processor=self.factory.makeProcessor(supports_virtualized=True)) | ||
322 | 1480 | das3 = self.makeBuildableDistroArchSeries( | ||
323 | 1481 | distroseries=das1.distroseries, | ||
324 | 1482 | processor=self.factory.makeProcessor(supports_virtualized=True)) | ||
325 | 1483 | snap.setProcessors([das1.processor, das2.processor, das3.processor]) | ||
326 | 1484 | logger = BufferLogger() | ||
327 | 1485 | with GitHostingFixture(blob=dedent("""\ | ||
328 | 1486 | architectures: | ||
329 | 1487 | - build-on: %s | ||
330 | 1488 | - build-on: %s | ||
331 | 1489 | """) % (das1.architecturetag, das2.architecturetag)): | ||
332 | 1490 | builds = getUtility(ISnapSet).makeAutoBuilds(logger=logger) | ||
333 | 1491 | self.assertThat(set(builds), MatchesSetwise(*[ | ||
334 | 1492 | MatchesStructure.byEquality( | ||
335 | 1493 | requester=snap.owner, snap=snap, distro_arch_series=das, | ||
336 | 1494 | status=BuildStatus.NEEDSBUILD) | ||
337 | 1495 | for das in (das1, das2) | ||
338 | 1496 | ])) | ||
339 | 1497 | expected_log_entries = [ | ||
340 | 1498 | "DEBUG Scheduling builds of snap package %s/%s" % ( | ||
341 | 1499 | snap.owner.name, snap.name), | ||
342 | 1500 | "DEBUG - %s/%s/%s: Build requested." % ( | ||
343 | 1501 | snap.owner.name, snap.name, das1.architecturetag), | ||
344 | 1502 | "DEBUG - %s/%s/%s: Build requested." % ( | ||
345 | 1503 | snap.owner.name, snap.name, das2.architecturetag), | ||
346 | 1504 | ] | ||
347 | 1505 | self.assertEqual( | ||
348 | 1506 | expected_log_entries, logger.getLogBuffer().splitlines()) | ||
349 | 1507 | self.assertFalse(snap.is_stale) | ||
350 | 1508 | |||
351 | 1440 | def test_detachFromBranch(self): | 1509 | def test_detachFromBranch(self): |
352 | 1441 | # ISnapSet.detachFromBranch clears the given Bazaar branch from all | 1510 | # ISnapSet.detachFromBranch clears the given Bazaar branch from all |
353 | 1442 | # Snaps. | 1511 | # Snaps. |