← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:backend-capabilities into launchpad-buildd:master with ~cjwatson/launchpad-buildd:lpcraft as a prerequisite.

Commit message:
Express backend capabilities as attributes of Backend

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/413899

At present there's only one of these capabilities, namely `supports_snapd`.  This is cleaner than having target commands test the backend name.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:backend-capabilities into launchpad-buildd:master.
diff --git a/lpbuildd/target/backend.py b/lpbuildd/target/backend.py
index fb00dd4..244c38b 100644
--- a/lpbuildd/target/backend.py
+++ b/lpbuildd/target/backend.py
@@ -29,6 +29,8 @@ def check_path_escape(buildd_path, path_to_check):
 class Backend:
     """A backend implementation for the environment where we run builds."""
 
+    supports_snapd = False
+
     def __init__(self, build_id, series=None, arch=None):
         self.build_id = build_id
         self.series = series
diff --git a/lpbuildd/target/build_charm.py b/lpbuildd/target/build_charm.py
index 1bdd807..c6c370f 100644
--- a/lpbuildd/target/build_charm.py
+++ b/lpbuildd/target/build_charm.py
@@ -54,7 +54,7 @@ class BuildCharm(BuilderProxyOperationMixin, VCSOperationMixin,
         if self.args.proxy_url:
             deps.extend(self.proxy_deps)
             self.install_git_proxy()
-        if self.args.backend == "lxd":
+        if self.backend.supports_snapd:
             # udev is installed explicitly to work around
             # https://bugs.launchpad.net/snapd/+bug/1731519.
             for dep in "snapd", "fuse", "squashfuse", "udev":
@@ -67,7 +67,7 @@ class BuildCharm(BuilderProxyOperationMixin, VCSOperationMixin,
             "python3-setuptools",
             ])
         self.backend.run(["apt-get", "-y", "install"] + deps)
-        if self.args.backend in ("lxd", "fake"):
+        if self.backend.supports_snapd:
             self.snap_store_set_proxy()
         for snap_name in self.core_snap_names:
             if snap_name in self.args.channels:
diff --git a/lpbuildd/target/build_livefs.py b/lpbuildd/target/build_livefs.py
index 00707ae..8881e33 100644
--- a/lpbuildd/target/build_livefs.py
+++ b/lpbuildd/target/build_livefs.py
@@ -83,14 +83,14 @@ class BuildLiveFS(SnapStoreOperationMixin, Operation):
 
     def install(self):
         deps = ["livecd-rootfs"]
-        if self.args.backend == "lxd":
+        if self.backend.supports_snapd:
             # udev is installed explicitly to work around
             # https://bugs.launchpad.net/snapd/+bug/1731519.
             for dep in "snapd", "fuse", "squashfuse", "udev":
                 if self.backend.is_package_available(dep):
                     deps.append(dep)
         self.backend.run(["apt-get", "-y", "install"] + deps)
-        if self.args.backend in ("lxd", "fake"):
+        if self.backend.supports_snapd:
             self.snap_store_set_proxy()
         if self.args.locale is not None:
             self.backend.run([
diff --git a/lpbuildd/target/build_oci.py b/lpbuildd/target/build_oci.py
index 896c5a0..3bfccd0 100644
--- a/lpbuildd/target/build_oci.py
+++ b/lpbuildd/target/build_oci.py
@@ -77,7 +77,7 @@ class BuildOCI(BuilderProxyOperationMixin, VCSOperationMixin,
         deps.extend(self.vcs_deps)
         deps.extend(["docker.io"])
         self.backend.run(["apt-get", "-y", "install"] + deps)
-        if self.args.backend in ("lxd", "fake"):
+        if self.backend.supports_snapd:
             self.snap_store_set_proxy()
         self.backend.run(["systemctl", "restart", "docker"])
         # The docker snap can't see /build, so we have to do our work under
diff --git a/lpbuildd/target/build_snap.py b/lpbuildd/target/build_snap.py
index 09032e5..96cecd1 100644
--- a/lpbuildd/target/build_snap.py
+++ b/lpbuildd/target/build_snap.py
@@ -107,7 +107,7 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
         if self.args.proxy_url:
             deps.extend(self.proxy_deps)
             self.install_git_proxy()
-        if self.args.backend == "lxd":
+        if self.backend.supports_snapd:
             # udev is installed explicitly to work around
             # https://bugs.launchpad.net/snapd/+bug/1731519.
             for dep in "snapd", "fuse", "squashfuse", "udev":
@@ -121,7 +121,7 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
         else:
             deps.append("snapcraft")
         self.backend.run(["apt-get", "-y", "install"] + deps)
-        if self.args.backend in ("lxd", "fake"):
+        if self.backend.supports_snapd:
             self.snap_store_set_proxy()
         for snap_name in self.core_snap_names:
             if snap_name in self.args.channels:
diff --git a/lpbuildd/target/lxd.py b/lpbuildd/target/lxd.py
index 163176d..24e48fe 100644
--- a/lpbuildd/target/lxd.py
+++ b/lpbuildd/target/lxd.py
@@ -93,6 +93,8 @@ class LXDException(Exception):
 
 class LXD(Backend):
 
+    supports_snapd = True
+
     # Architecture mapping
     arches = {
         "amd64": "x86_64",
diff --git a/lpbuildd/target/run_ci.py b/lpbuildd/target/run_ci.py
index e74cbc7..1fb6b0f 100644
--- a/lpbuildd/target/run_ci.py
+++ b/lpbuildd/target/run_ci.py
@@ -40,13 +40,13 @@ class RunCIPrepare(BuilderProxyOperationMixin, VCSOperationMixin,
         if self.args.proxy_url:
             deps.extend(self.proxy_deps)
             self.install_git_proxy()
-        if self.args.backend == "lxd":
+        if self.backend.supports_snapd:
             for dep in "snapd", "fuse", "squashfuse":
                 if self.backend.is_package_available(dep):
                     deps.append(dep)
         deps.extend(self.vcs_deps)
         self.backend.run(["apt-get", "-y", "install"] + deps)
-        if self.args.backend in ("lxd", "fake"):
+        if self.backend.supports_snapd:
             self.snap_store_set_proxy()
         for snap_name, channel in sorted(self.args.channels.items()):
             if snap_name not in ("lxd", "lpcraft"):
diff --git a/lpbuildd/tests/fakebuilder.py b/lpbuildd/tests/fakebuilder.py
index 4013c4b..a00c168 100644
--- a/lpbuildd/tests/fakebuilder.py
+++ b/lpbuildd/tests/fakebuilder.py
@@ -138,6 +138,8 @@ class FakeBuilder:
 
 class FakeBackend(Backend):
 
+    supports_snapd = True
+
     def __init__(self, *args, **kwargs):
         super(FakeBackend, self).__init__(*args, **kwargs)
         fake_methods = (
@@ -148,6 +150,7 @@ class FakeBackend(Backend):
         for fake_method in fake_methods:
             setattr(self, fake_method, FakeMethod())
         self.backend_fs = {}
+        self.available_packages = set()
 
     def _add_inode(self, path, contents, full_mode):
         path = os.path.normpath(path)
@@ -221,6 +224,9 @@ class FakeBackend(Backend):
             for backend_path, (_, mode) in self.backend_fs.items()
             if match(backend_path, mode)]
 
+    def is_package_available(self, package):
+        return package in self.available_packages
+
 
 class UncontainedBackend(Backend):
     """A partial backend implementation with no containment."""

Follow ups