Merge ~andrey-fedoseev/launchpad:snap-base-features into launchpad:master

Proposed by Andrey Fedoseev
Status: Merged
Approved by: Andrey Fedoseev
Approved revision: 4a8d2ebed4b8d4c991da24aa305a2af3c6102cd5
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~andrey-fedoseev/launchpad:snap-base-features
Merge into: launchpad:master
Diff against target: 109 lines (+23/-8)
3 files modified
lib/lp/snappy/adapters/buildarch.py (+8/-2)
lib/lp/snappy/adapters/tests/test_buildarch.py (+14/-5)
lib/lp/snappy/model/snap.py (+1/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+431544@code.launchpad.net

Commit message

Use `SnapBase.features` in `snapcraft.yaml` parser

to determine whether duplicate build-on values are allowed instead of relying on snap base name

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Andrey Fedoseev (andrey-fedoseev) :
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/snappy/adapters/buildarch.py b/lib/lp/snappy/adapters/buildarch.py
2index 102eb74..eb87a7d 100644
3--- a/lib/lp/snappy/adapters/buildarch.py
4+++ b/lib/lp/snappy/adapters/buildarch.py
5@@ -9,6 +9,8 @@ from collections import Counter
6 from typing import Any, Dict, List, Optional, Union
7
8 from lp.services.helpers import english_list
9+from lp.snappy.interfaces.snapbase import SnapBaseFeature
10+from lp.snappy.model.snapbase import SnapBase
11
12
13 class SnapArchitecturesParserError(Exception):
14@@ -146,7 +148,7 @@ class SnapBuildInstance:
15
16
17 def determine_architectures_to_build(
18- snap_base: Optional[str],
19+ snap_base: Optional[SnapBase],
20 snapcraft_data: Dict[str, Any],
21 supported_arches: List[str],
22 ) -> List[SnapBuildInstance]:
23@@ -184,7 +186,11 @@ def determine_architectures_to_build(
24 SnapArchitecture(build_on=a) for a in supported_arches
25 ]
26
27- if snap_base not in {"core22"}:
28+ allow_duplicate_build_on = (
29+ snap_base
30+ and snap_base.features.get(SnapBaseFeature.ALLOW_DUPLICATE_BUILD_ON)
31+ ) or False
32+ if not allow_duplicate_build_on:
33 # Ensure that multiple `build-on` items don't include the same
34 # architecture; this is ambiguous and forbidden by snapcraft prior
35 # to core22. Checking this here means that we don't get duplicate
36diff --git a/lib/lp/snappy/adapters/tests/test_buildarch.py b/lib/lp/snappy/adapters/tests/test_buildarch.py
37index db52baf..8a9ef2e 100644
38--- a/lib/lp/snappy/adapters/tests/test_buildarch.py
39+++ b/lib/lp/snappy/adapters/tests/test_buildarch.py
40@@ -11,7 +11,9 @@ from lp.snappy.adapters.buildarch import (
41 UnsupportedBuildOnError,
42 determine_architectures_to_build,
43 )
44-from lp.testing import TestCase
45+from lp.snappy.interfaces.snapbase import SnapBaseFeature
46+from lp.testing import TestCase, TestCaseWithFactory
47+from lp.testing.layers import ZopelessDatabaseLayer
48
49
50 class TestSnapArchitecture(WithScenarios, TestCase):
51@@ -174,11 +176,12 @@ class TestSnapBuildInstanceError(TestCase):
52 self.assertEqual(["amd64"], raised.build_on)
53
54
55-class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
56-
57+class TestDetermineArchitecturesToBuild(WithScenarios, TestCaseWithFactory):
58 # Scenarios taken from the architectures document:
59 # https://forum.snapcraft.io/t/architectures/4972
60
61+ layer = ZopelessDatabaseLayer
62+
63 scenarios = [
64 (
65 "none",
66@@ -396,6 +399,9 @@ class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
67 (
68 "multiple build-for for the same build-on",
69 {
70+ "snap_base_features": {
71+ SnapBaseFeature.ALLOW_DUPLICATE_BUILD_ON: True
72+ },
73 "architectures": [
74 {"build-on": "amd64", "build-for": ["amd64"]},
75 {"build-on": "amd64", "build-for": ["i386"]},
76@@ -418,7 +424,9 @@ class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
77 (
78 "multiple build-for for the same build-on: old base",
79 {
80- "snap_base": "core20",
81+ "snap_base_features": {
82+ SnapBaseFeature.ALLOW_DUPLICATE_BUILD_ON: False
83+ },
84 "architectures": [
85 {"build-on": "amd64", "build-for": ["amd64"]},
86 {"build-on": "amd64", "build-for": ["i386"]},
87@@ -431,7 +439,8 @@ class TestDetermineArchitecturesToBuild(WithScenarios, TestCase):
88
89 def test_parser(self):
90 snapcraft_data = {"architectures": self.architectures}
91- snap_base = getattr(self, "snap_base", "core22")
92+ snap_base_features = getattr(self, "snap_base_features", {})
93+ snap_base = self.factory.makeSnapBase(features=snap_base_features)
94 if hasattr(self, "expected_exception"):
95 self.assertRaises(
96 self.expected_exception,
97diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
98index 7728ecf..e60040f 100644
99--- a/lib/lp/snappy/model/snap.py
100+++ b/lib/lp/snappy/model/snap.py
101@@ -1009,7 +1009,7 @@ class Snap(Storm, WebhookTargetMixin):
102 )
103 )
104 architectures_to_build = determine_architectures_to_build(
105- snap_base.name if snap_base is not None else None,
106+ snap_base,
107 snapcraft_data,
108 list(supported_arches.keys()),
109 )

Subscribers

People subscribed via source and target branches

to status/vote changes: