Merge lp:~cjwatson/launchpad/snap-auto-builds-oops into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18751
Proposed branch: lp:~cjwatson/launchpad/snap-auto-builds-oops
Merge into: lp:launchpad
Diff against target: 103 lines (+59/-22)
2 files modified
lib/lp/snappy/model/snap.py (+29/-22)
lib/lp/snappy/tests/test_snap.py (+30/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-auto-builds-oops
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+353094@code.launchpad.net

Commit message

Tolerate failures to get snapcraft.yaml in SnapSet.makeAutoBuilds.

Description of the change

We already handled failures to request builds for each individual architecture, but not failure to work out which architectures to build.

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
=== modified file 'lib/lp/snappy/model/snap.py'
--- lib/lp/snappy/model/snap.py 2018-08-06 14:42:30 +0000
+++ lib/lp/snappy/model/snap.py 2018-08-14 14:42:38 +0000
@@ -565,29 +565,36 @@
565 allow_failures=False, fetch_snapcraft_yaml=True,565 allow_failures=False, fetch_snapcraft_yaml=True,
566 logger=None):566 logger=None):
567 """See `ISnap`."""567 """See `ISnap`."""
568 if fetch_snapcraft_yaml:568 try:
569 try:569 if fetch_snapcraft_yaml:
570 snapcraft_data = removeSecurityProxy(570 try:
571 getUtility(ISnapSet).getSnapcraftYaml(self))571 snapcraft_data = removeSecurityProxy(
572 except CannotFetchSnapcraftYaml as e:572 getUtility(ISnapSet).getSnapcraftYaml(self))
573 if not e.unsupported_remote:573 except CannotFetchSnapcraftYaml as e:
574 raise574 if not e.unsupported_remote:
575 # The only reason we can't fetch the file is because we575 raise
576 # don't support fetching from this repository's host. In576 # The only reason we can't fetch the file is because we
577 # this case the best thing is to fall back to building for577 # don't support fetching from this repository's host.
578 # all supported architectures.578 # In this case the best thing is to fall back to
579 # building for all supported architectures.
580 snapcraft_data = {}
581 else:
579 snapcraft_data = {}582 snapcraft_data = {}
580 else:583 # Sort by Processor.id for determinism. This is chosen to be
581 snapcraft_data = {}584 # the same order as in BinaryPackageBuildSet.createForSource, to
582 # Sort by Processor.id for determinism. This is chosen to be the585 # minimise confusion.
583 # same order as in BinaryPackageBuildSet.createForSource, to586 supported_arches = OrderedDict(
584 # minimise confusion.587 (das.architecturetag, das) for das in sorted(
585 supported_arches = OrderedDict(588 self.getAllowedArchitectures(),
586 (das.architecturetag, das) for das in sorted(589 key=attrgetter("processor.id")))
587 self.getAllowedArchitectures(),590 architectures_to_build = determine_architectures_to_build(
588 key=attrgetter("processor.id")))591 snapcraft_data, supported_arches.keys())
589 architectures_to_build = determine_architectures_to_build(592 except Exception as e:
590 snapcraft_data, supported_arches.keys())593 if not allow_failures:
594 raise
595 elif logger is not None:
596 logger.exception(" - %s/%s: %s", self.owner.name, self.name, e)
597 return []
591598
592 builds = []599 builds = []
593 for build_instance in architectures_to_build:600 for build_instance in architectures_to_build:
594601
=== modified file 'lib/lp/snappy/tests/test_snap.py'
--- lib/lp/snappy/tests/test_snap.py 2018-08-06 14:42:30 +0000
+++ lib/lp/snappy/tests/test_snap.py 2018-08-14 14:42:38 +0000
@@ -1441,6 +1441,36 @@
1441 self.assertEqual(1441 self.assertEqual(
1442 expected_log_entries, logger.getLogBuffer().splitlines())1442 expected_log_entries, logger.getLogBuffer().splitlines())
14431443
1444 def test_makeAutoBuilds_tolerates_failures(self):
1445 # If requesting builds of one snap fails, ISnapSet.makeAutoBuilds
1446 # just logs the problem and carries on to the next.
1447 das1, snap1 = self.makeAutoBuildableSnap(is_stale=True)
1448 das2, snap2 = self.makeAutoBuildableSnap(is_stale=True)
1449 logger = BufferLogger()
1450 self.useFixture(GitHostingFixture()).getBlob.failure = (
1451 GitRepositoryBlobNotFound("dummy", "snap/snapcraft.yaml"))
1452 self.assertEqual(
1453 [], getUtility(ISnapSet).makeAutoBuilds(logger=logger))
1454 # The u'...' here is a little odd, but that's how KeyError (and thus
1455 # NotFoundError) stringifies.
1456 expected_log_entries = [
1457 "DEBUG Scheduling builds of snap package %s/%s" % (
1458 snap1.owner.name, snap1.name),
1459 "ERROR - %s/%s: u'Cannot find snapcraft.yaml in %s'" % (
1460 snap1.owner.name, snap1.name, snap1.git_ref.unique_name),
1461 "DEBUG Scheduling builds of snap package %s/%s" % (
1462 snap2.owner.name, snap2.name),
1463 "ERROR - %s/%s: u'Cannot find snapcraft.yaml in %s'" % (
1464 snap2.owner.name, snap2.name, snap2.git_ref.unique_name),
1465 ]
1466 self.assertThat(
1467 logger.getLogBuffer().splitlines(),
1468 # Ignore ordering differences, since ISnapSet.makeAutoBuilds
1469 # might process the two snaps in either order.
1470 MatchesSetwise(*(Equals(entry) for entry in expected_log_entries)))
1471 self.assertFalse(snap1.is_stale)
1472 self.assertFalse(snap2.is_stale)
1473
1444 def test_makeAutoBuilds_with_older_build(self):1474 def test_makeAutoBuilds_with_older_build(self):
1445 # If a previous build is not recent and the snap package is stale,1475 # If a previous build is not recent and the snap package is stale,
1446 # ISnapSet.makeAutoBuilds requests builds.1476 # ISnapSet.makeAutoBuilds requests builds.