Merge ~cjwatson/launchpad:generalise-snap-build-base into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 6a29280462f4f3d3f82bd8f4e356747e9ea06f3a
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:generalise-snap-build-base
Merge into: launchpad:master
Diff against target: 113 lines (+45/-10)
2 files modified
lib/lp/snappy/model/snap.py (+16/-7)
lib/lp/snappy/tests/test_snap.py (+29/-3)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+383436@code.launchpad.net

Commit message

Implement build-base for snaps without base: bare

Description of the change

Sync up our base selection for snap builds with snapcraft:

  https://github.com/snapcore/snapcraft/blob/4.0/snapcraft/internal/meta/snap.py#L161-L181

This makes two significant changes to base selection:

 * `build-base` now wins in all cases, even if the snap does not have `base: bare`;

 * if `build-base` is not set and the snap has `type: base`, then the snap's `name` is used as the base.

If neither of those apply, then the value of `base` is used, as before.

`base: bare` without `build-base` is now an error, while previously the default base would have been used. However, this combination is forbidden by snapcraft at the schema-validation change, so this change shouldn't matter in practice.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) wrote :

looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
2index 229eaa4..4860fad 100644
3--- a/lib/lp/snappy/model/snap.py
4+++ b/lib/lp/snappy/model/snap.py
5@@ -1,4 +1,4 @@
6-# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
7+# Copyright 2015-2020 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 from __future__ import absolute_import, print_function, unicode_literals
11@@ -689,18 +689,27 @@ class Snap(Storm, WebhookTargetMixin):
12 @staticmethod
13 def _findBase(snapcraft_data):
14 """Find a suitable base for a build."""
15+ base = snapcraft_data.get("base")
16+ build_base = snapcraft_data.get("build-base")
17+ name = snapcraft_data.get("name")
18+ snap_type = snapcraft_data.get("type")
19+
20+ # Keep this in sync with
21+ # snapcraft.internal.meta.snap.Snap.get_build_base.
22 snap_base_set = getUtility(ISnapBaseSet)
23- snap_base_name = snapcraft_data.get("base")
24+ if build_base is not None:
25+ snap_base_name = build_base
26+ elif name is not None and snap_type == "base":
27+ snap_base_name = name
28+ else:
29+ snap_base_name = base
30+
31 if isinstance(snap_base_name, bytes):
32 snap_base_name = snap_base_name.decode("UTF-8")
33- if snap_base_name == "bare":
34- snap_base_name = snapcraft_data.get("build-base")
35- if isinstance(snap_base_name, bytes):
36- snap_base_name = snap_base_name.decode("UTF-8")
37 if snap_base_name is not None:
38 return snap_base_set.getByName(snap_base_name), snap_base_name
39 else:
40- return snap_base_set.getDefault(), snap_base_name
41+ return snap_base_set.getDefault(), None
42
43 def _pickDistroSeries(self, snap_base, snap_base_name):
44 """Pick a suitable `IDistroSeries` for a build."""
45diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
46index 809b617..0b712fe 100644
47--- a/lib/lp/snappy/tests/test_snap.py
48+++ b/lib/lp/snappy/tests/test_snap.py
49@@ -1,4 +1,4 @@
50-# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
51+# Copyright 2015-2020 Canonical Ltd. This software is licensed under the
52 # GNU Affero General Public License version 3 (see the file LICENSE).
53
54 """Test snap packages."""
55@@ -564,14 +564,27 @@ class TestSnap(TestCaseWithFactory):
56 self.assertEqual(
57 (snap_base, snap_base.name),
58 Snap._findBase({"base": "bare", "build-base": snap_base.name}))
59+ self.assertEqual(
60+ (snap_base, snap_base.name),
61+ Snap._findBase({"build-base": snap_base.name}))
62+ self.assertEqual(
63+ (snap_base, snap_base.name),
64+ Snap._findBase({"type": "base", "name": snap_base.name}))
65 self.assertRaises(
66 NoSuchSnapBase, Snap._findBase,
67 {"base": "nonexistent"})
68 self.assertRaises(
69 NoSuchSnapBase, Snap._findBase,
70+ {"base": "bare"})
71+ self.assertRaises(
72+ NoSuchSnapBase, Snap._findBase,
73 {"base": "bare", "build-base": "nonexistent"})
74+ self.assertRaises(
75+ NoSuchSnapBase, Snap._findBase,
76+ {"build-base": "nonexistent"})
77 self.assertEqual((None, None), Snap._findBase({}))
78- self.assertEqual((None, None), Snap._findBase({"base": "bare"}))
79+ self.assertEqual(
80+ (None, None), Snap._findBase({"name": snap_bases[0].name}))
81
82 def test__findBase_with_default(self):
83 with admin_logged_in():
84@@ -585,15 +598,28 @@ class TestSnap(TestCaseWithFactory):
85 self.assertEqual(
86 (snap_base, snap_base.name),
87 Snap._findBase({"base": "bare", "build-base": snap_base.name}))
88+ self.assertEqual(
89+ (snap_base, snap_base.name),
90+ Snap._findBase({"build-base": snap_base.name}))
91+ self.assertEqual(
92+ (snap_base, snap_base.name),
93+ Snap._findBase({"type": "base", "name": snap_base.name}))
94 self.assertRaises(
95 NoSuchSnapBase, Snap._findBase,
96 {"base": "nonexistent"})
97 self.assertRaises(
98 NoSuchSnapBase, Snap._findBase,
99+ {"base": "bare"})
100+ self.assertRaises(
101+ NoSuchSnapBase, Snap._findBase,
102 {"base": "bare", "build-base": "nonexistent"})
103+ self.assertRaises(
104+ NoSuchSnapBase, Snap._findBase,
105+ {"build-base": "nonexistent"})
106 self.assertEqual((snap_bases[0], None), Snap._findBase({}))
107 self.assertEqual(
108- (snap_bases[0], None), Snap._findBase({"base": "bare"}))
109+ (snap_bases[0], None),
110+ Snap._findBase({"name": snap_bases[0].name}))
111
112 def makeRequestBuildsJob(self, arch_tags, git_ref=None):
113 distro = self.factory.makeDistribution()

Subscribers

People subscribed via source and target branches

to status/vote changes: