← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad-buildd/bionic into lp:launchpad-buildd

 

Colin Watson has proposed merging lp:~cjwatson/launchpad-buildd/bionic into lp:launchpad-buildd.

Commit message:
Fix various failures when running on bionic.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/bionic/+merge/376513
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad-buildd/bionic into lp:launchpad-buildd.
=== modified file 'debian/changelog'
--- debian/changelog	2019-11-26 20:44:13 +0000
+++ debian/changelog	2019-12-09 11:22:21 +0000
@@ -1,3 +1,10 @@
+launchpad-buildd (184) UNRELEASED; urgency=medium
+
+  * Adjust sbuildrc to handle various changes in bionic's sbuild.
+  * Configure LXD when creating a target rather than in the postinst.
+
+ -- Colin Watson <cjwatson@xxxxxxxxxx>  Mon, 09 Dec 2019 10:58:32 +0000
+
 launchpad-buildd (183) xenial; urgency=medium
 
   [ Michael Hudson-Doyle ]

=== modified file 'debian/postinst'
--- debian/postinst	2018-02-27 14:06:36 +0000
+++ debian/postinst	2019-12-09 11:22:21 +0000
@@ -106,12 +106,6 @@
 	    fi
 	fi
 
-	# Configure LXD if necessary
-	if [ ! -e /var/lib/lxd/server.key ]; then
-	    lxd init --auto || true
-	    sudo -Hu "$USER" lxc list >/dev/null || true
-	fi
-
 	;;
     abort-upgrade|abort-remove|abort-deconfigure)
 

=== modified file 'lpbuildd/target/lxd.py'
--- lpbuildd/target/lxd.py	2019-11-26 20:28:31 +0000
+++ lpbuildd/target/lxd.py	2019-12-09 11:22:21 +0000
@@ -188,8 +188,17 @@
                 if fileptr is not None:
                     fileptr.close()
 
+    def _init(self):
+        """Configure LXD if necessary."""
+        if not os.path.exists("/var/lib/lxd/server.key"):
+            subprocess.check_call(["sudo", "lxd", "init", "--auto"])
+            # Generate a LXD client certificate for the buildd user.
+            with open("/dev/null", "w") as devnull:
+                subprocess.call(["lxc", "list"], stdout=devnull)
+
     def create(self, image_path, image_type):
         """See `Backend`."""
+        self._init()
         self.remove_image()
 
         # This is a lot of data to shuffle around in Python, but there

=== modified file 'lpbuildd/target/tests/test_lxd.py'
--- lpbuildd/target/tests/test_lxd.py	2019-11-26 20:28:31 +0000
+++ lpbuildd/target/tests/test_lxd.py	2019-12-09 11:22:21 +0000
@@ -190,6 +190,11 @@
         self.assertThat(hello, HasPermissions("0755"))
 
     def test_create_from_chroot(self):
+        fs_fixture = self.useFixture(FakeFilesystem())
+        fs_fixture.add("/var/lib/lxd")
+        processes_fixture = self.useFixture(FakeProcesses())
+        processes_fixture.add(lambda _: {}, name="sudo")
+        processes_fixture.add(lambda _: {}, name="lxc")
         tmp = self.useFixture(TempDir()).path
         source_tarball_path = os.path.join(tmp, "source.tar.bz2")
         self.make_chroot_tarball(source_tarball_path)
@@ -200,6 +205,12 @@
         client.images.create.return_value = image
         LXD("1", "xenial", "amd64").create(source_tarball_path, "chroot")
 
+        self.assertThat(
+            [proc._args["args"] for proc in processes_fixture.procs],
+            MatchesListwise([
+                Equals(["sudo", "lxd", "init", "--auto"]),
+                Equals(["lxc", "list"]),
+                ]))
         client.images.create.assert_called_once_with(mock.ANY, wait=True)
         with io.BytesIO(client.images.create.call_args[0][0]) as f:
             with tarfile.open(fileobj=f) as tar:
@@ -209,16 +220,53 @@
             "lp-xenial-amd64", "lp-xenial-amd64")
 
     def test_create_from_lxd(self):
-        tmp = self.useFixture(TempDir()).path
-        source_image_path = os.path.join(tmp, "source.tar.gz")
-        self.make_lxd_image(source_image_path)
-        self.useFixture(MockPatch("pylxd.Client"))
-        client = pylxd.Client()
-        client.images.all.return_value = []
-        image = mock.MagicMock()
-        client.images.create.return_value = image
-        LXD("1", "xenial", "amd64").create(source_image_path, "lxd")
-
+        fs_fixture = self.useFixture(FakeFilesystem())
+        fs_fixture.add("/var/lib/lxd")
+        processes_fixture = self.useFixture(FakeProcesses())
+        processes_fixture.add(lambda _: {}, name="sudo")
+        processes_fixture.add(lambda _: {}, name="lxc")
+        tmp = self.useFixture(TempDir()).path
+        source_image_path = os.path.join(tmp, "source.tar.gz")
+        self.make_lxd_image(source_image_path)
+        self.useFixture(MockPatch("pylxd.Client"))
+        client = pylxd.Client()
+        client.images.all.return_value = []
+        image = mock.MagicMock()
+        client.images.create.return_value = image
+        LXD("1", "xenial", "amd64").create(source_image_path, "lxd")
+
+        self.assertThat(
+            [proc._args["args"] for proc in processes_fixture.procs],
+            MatchesListwise([
+                Equals(["sudo", "lxd", "init", "--auto"]),
+                Equals(["lxc", "list"]),
+                ]))
+        client.images.create.assert_called_once_with(mock.ANY, wait=True)
+        with io.BytesIO(client.images.create.call_args[0][0]) as f:
+            with tarfile.open(fileobj=f) as tar:
+                with closing(tar.extractfile("rootfs/bin/hello")) as hello:
+                    self.assertEqual("hello\n", hello.read())
+        image.add_alias.assert_called_once_with(
+            "lp-xenial-amd64", "lp-xenial-amd64")
+
+    def test_create_with_already_initialized_lxd(self):
+        fs_fixture = self.useFixture(FakeFilesystem())
+        fs_fixture.add("/var/lib/lxd")
+        os.makedirs("/var/lib/lxd")
+        with open("/var/lib/lxd/server.key", "w"):
+            pass
+        processes_fixture = self.useFixture(FakeProcesses())
+        tmp = self.useFixture(TempDir()).path
+        source_image_path = os.path.join(tmp, "source.tar.gz")
+        self.make_lxd_image(source_image_path)
+        self.useFixture(MockPatch("pylxd.Client"))
+        client = pylxd.Client()
+        client.images.all.return_value = []
+        image = mock.MagicMock()
+        client.images.create.return_value = image
+        LXD("1", "xenial", "amd64").create(source_image_path, "lxd")
+
+        self.assertEqual([], processes_fixture.procs)
         client.images.create.assert_called_once_with(mock.ANY, wait=True)
         with io.BytesIO(client.images.create.call_args[0][0]) as f:
             with tarfile.open(fileobj=f) as tar:

=== modified file 'sbuildrc'
--- sbuildrc	2017-07-18 15:55:57 +0000
+++ sbuildrc	2019-12-09 11:22:21 +0000
@@ -6,6 +6,9 @@
 chomp $fqdn;
 $maintainer_name="Launchpad Build Daemon <buildd\@$fqdn>";
 
+# Don't build architecture-independent packages unless explicitly requested.
+$build_arch_all = 0;
+
 # launchpad-buildd does this before sbuild.
 $apt_update = 0;
 $apt_distupgrade = 0;
@@ -42,4 +45,8 @@
 # is measured by output to the log file.
 $stalled_pkg_timeout = 150;
 
+# Disable some interactive niceties.
+$run_lintian = 0;
+$bd_uninstallable_explainer = '';
+
 $sbuild_mode="buildd";