Merge ~cjwatson/launchpad-buildd:backend-capabilities into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 73e9bd457e2335510a4669d56cc39410f34628a3
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:backend-capabilities
Merge into: launchpad-buildd:master
Prerequisite: ~cjwatson/launchpad-buildd:lpcraft
Diff against target: 155 lines (+19/-9)
8 files modified
lpbuildd/target/backend.py (+2/-0)
lpbuildd/target/build_charm.py (+2/-2)
lpbuildd/target/build_livefs.py (+2/-2)
lpbuildd/target/build_oci.py (+1/-1)
lpbuildd/target/build_snap.py (+2/-2)
lpbuildd/target/lxd.py (+2/-0)
lpbuildd/target/run_ci.py (+2/-2)
lpbuildd/tests/fakebuilder.py (+6/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+413899@code.launchpad.net

Commit message

Express backend capabilities as attributes of Backend

Description of the change

At present there's only one of these capabilities, namely `supports_snapd`. This is cleaner than having target commands test the backend name.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

LGTM (I did not run the tests, as I still face the lxd-agent issue, which at some point I have to spend some time on)

Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lpbuildd/target/backend.py b/lpbuildd/target/backend.py
2index fb00dd4..244c38b 100644
3--- a/lpbuildd/target/backend.py
4+++ b/lpbuildd/target/backend.py
5@@ -29,6 +29,8 @@ def check_path_escape(buildd_path, path_to_check):
6 class Backend:
7 """A backend implementation for the environment where we run builds."""
8
9+ supports_snapd = False
10+
11 def __init__(self, build_id, series=None, arch=None):
12 self.build_id = build_id
13 self.series = series
14diff --git a/lpbuildd/target/build_charm.py b/lpbuildd/target/build_charm.py
15index 1bdd807..c6c370f 100644
16--- a/lpbuildd/target/build_charm.py
17+++ b/lpbuildd/target/build_charm.py
18@@ -54,7 +54,7 @@ class BuildCharm(BuilderProxyOperationMixin, VCSOperationMixin,
19 if self.args.proxy_url:
20 deps.extend(self.proxy_deps)
21 self.install_git_proxy()
22- if self.args.backend == "lxd":
23+ if self.backend.supports_snapd:
24 # udev is installed explicitly to work around
25 # https://bugs.launchpad.net/snapd/+bug/1731519.
26 for dep in "snapd", "fuse", "squashfuse", "udev":
27@@ -67,7 +67,7 @@ class BuildCharm(BuilderProxyOperationMixin, VCSOperationMixin,
28 "python3-setuptools",
29 ])
30 self.backend.run(["apt-get", "-y", "install"] + deps)
31- if self.args.backend in ("lxd", "fake"):
32+ if self.backend.supports_snapd:
33 self.snap_store_set_proxy()
34 for snap_name in self.core_snap_names:
35 if snap_name in self.args.channels:
36diff --git a/lpbuildd/target/build_livefs.py b/lpbuildd/target/build_livefs.py
37index 00707ae..8881e33 100644
38--- a/lpbuildd/target/build_livefs.py
39+++ b/lpbuildd/target/build_livefs.py
40@@ -83,14 +83,14 @@ class BuildLiveFS(SnapStoreOperationMixin, Operation):
41
42 def install(self):
43 deps = ["livecd-rootfs"]
44- if self.args.backend == "lxd":
45+ if self.backend.supports_snapd:
46 # udev is installed explicitly to work around
47 # https://bugs.launchpad.net/snapd/+bug/1731519.
48 for dep in "snapd", "fuse", "squashfuse", "udev":
49 if self.backend.is_package_available(dep):
50 deps.append(dep)
51 self.backend.run(["apt-get", "-y", "install"] + deps)
52- if self.args.backend in ("lxd", "fake"):
53+ if self.backend.supports_snapd:
54 self.snap_store_set_proxy()
55 if self.args.locale is not None:
56 self.backend.run([
57diff --git a/lpbuildd/target/build_oci.py b/lpbuildd/target/build_oci.py
58index 896c5a0..3bfccd0 100644
59--- a/lpbuildd/target/build_oci.py
60+++ b/lpbuildd/target/build_oci.py
61@@ -77,7 +77,7 @@ class BuildOCI(BuilderProxyOperationMixin, VCSOperationMixin,
62 deps.extend(self.vcs_deps)
63 deps.extend(["docker.io"])
64 self.backend.run(["apt-get", "-y", "install"] + deps)
65- if self.args.backend in ("lxd", "fake"):
66+ if self.backend.supports_snapd:
67 self.snap_store_set_proxy()
68 self.backend.run(["systemctl", "restart", "docker"])
69 # The docker snap can't see /build, so we have to do our work under
70diff --git a/lpbuildd/target/build_snap.py b/lpbuildd/target/build_snap.py
71index 09032e5..96cecd1 100644
72--- a/lpbuildd/target/build_snap.py
73+++ b/lpbuildd/target/build_snap.py
74@@ -107,7 +107,7 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
75 if self.args.proxy_url:
76 deps.extend(self.proxy_deps)
77 self.install_git_proxy()
78- if self.args.backend == "lxd":
79+ if self.backend.supports_snapd:
80 # udev is installed explicitly to work around
81 # https://bugs.launchpad.net/snapd/+bug/1731519.
82 for dep in "snapd", "fuse", "squashfuse", "udev":
83@@ -121,7 +121,7 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
84 else:
85 deps.append("snapcraft")
86 self.backend.run(["apt-get", "-y", "install"] + deps)
87- if self.args.backend in ("lxd", "fake"):
88+ if self.backend.supports_snapd:
89 self.snap_store_set_proxy()
90 for snap_name in self.core_snap_names:
91 if snap_name in self.args.channels:
92diff --git a/lpbuildd/target/lxd.py b/lpbuildd/target/lxd.py
93index 163176d..24e48fe 100644
94--- a/lpbuildd/target/lxd.py
95+++ b/lpbuildd/target/lxd.py
96@@ -93,6 +93,8 @@ class LXDException(Exception):
97
98 class LXD(Backend):
99
100+ supports_snapd = True
101+
102 # Architecture mapping
103 arches = {
104 "amd64": "x86_64",
105diff --git a/lpbuildd/target/run_ci.py b/lpbuildd/target/run_ci.py
106index e74cbc7..1fb6b0f 100644
107--- a/lpbuildd/target/run_ci.py
108+++ b/lpbuildd/target/run_ci.py
109@@ -40,13 +40,13 @@ class RunCIPrepare(BuilderProxyOperationMixin, VCSOperationMixin,
110 if self.args.proxy_url:
111 deps.extend(self.proxy_deps)
112 self.install_git_proxy()
113- if self.args.backend == "lxd":
114+ if self.backend.supports_snapd:
115 for dep in "snapd", "fuse", "squashfuse":
116 if self.backend.is_package_available(dep):
117 deps.append(dep)
118 deps.extend(self.vcs_deps)
119 self.backend.run(["apt-get", "-y", "install"] + deps)
120- if self.args.backend in ("lxd", "fake"):
121+ if self.backend.supports_snapd:
122 self.snap_store_set_proxy()
123 for snap_name, channel in sorted(self.args.channels.items()):
124 if snap_name not in ("lxd", "lpcraft"):
125diff --git a/lpbuildd/tests/fakebuilder.py b/lpbuildd/tests/fakebuilder.py
126index 4013c4b..a00c168 100644
127--- a/lpbuildd/tests/fakebuilder.py
128+++ b/lpbuildd/tests/fakebuilder.py
129@@ -138,6 +138,8 @@ class FakeBuilder:
130
131 class FakeBackend(Backend):
132
133+ supports_snapd = True
134+
135 def __init__(self, *args, **kwargs):
136 super(FakeBackend, self).__init__(*args, **kwargs)
137 fake_methods = (
138@@ -148,6 +150,7 @@ class FakeBackend(Backend):
139 for fake_method in fake_methods:
140 setattr(self, fake_method, FakeMethod())
141 self.backend_fs = {}
142+ self.available_packages = set()
143
144 def _add_inode(self, path, contents, full_mode):
145 path = os.path.normpath(path)
146@@ -221,6 +224,9 @@ class FakeBackend(Backend):
147 for backend_path, (_, mode) in self.backend_fs.items()
148 if match(backend_path, mode)]
149
150+ def is_package_available(self, package):
151+ return package in self.available_packages
152+
153
154 class UncontainedBackend(Backend):
155 """A partial backend implementation with no containment."""

Subscribers

People subscribed via source and target branches