← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad-buildd/livefs-lxd into lp:launchpad-buildd with lp:~cjwatson/launchpad-buildd/snap-lxd as a prerequisite.

Commit message:
Switch livefs builds to the LXD backend.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/livefs-lxd/+merge/329662

I also fixed a container setup bug in passing: we need to modify /etc/hosts at least a little bit in order to ensure that "hostname -f" works.  (An alternative would be to ensure that /etc/resolv.conf contains "search lxd", but this seems easier for now.)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad-buildd/livefs-lxd into lp:launchpad-buildd.
=== modified file 'debian/changelog'
--- debian/changelog	2017-08-26 09:54:56 +0000
+++ debian/changelog	2017-08-26 09:54:56 +0000
@@ -26,6 +26,7 @@
   * Convert buildsnap to the new Operation framework and add unit tests.
   * Add a LXD backend.
   * Switch snap builds to the LXD backend.
+  * Switch livefs builds to the LXD backend.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 25 Jul 2017 23:07:58 +0100
 

=== modified file 'lpbuildd/livefs.py'
--- lpbuildd/livefs.py	2017-08-22 16:37:25 +0000
+++ lpbuildd/livefs.py	2017-08-26 09:54:56 +0000
@@ -23,6 +23,7 @@
 class LiveFilesystemBuildManager(DebianBuildManager):
     """Build a live filesystem."""
 
+    backend_name = "lxd"
     initial_build_state = LiveFilesystemBuildState.BUILD_LIVEFS
 
     def initiate(self, files, chroot, extra_args):

=== modified file 'lpbuildd/target/build_livefs.py'
--- lpbuildd/target/build_livefs.py	2017-08-22 16:37:25 +0000
+++ lpbuildd/target/build_livefs.py	2017-08-26 09:54:56 +0000
@@ -80,7 +80,10 @@
         self.backend.run(["/bin/sh", "-c", command], echo=echo)
 
     def install(self):
-        self.backend.run(["apt-get", "-y", "install", "livecd-rootfs"])
+        deps = ["livecd-rootfs"]
+        if self.args.backend == "lxd":
+            deps.extend(["snapd", "fuse", "squashfuse"])
+        self.backend.run(["apt-get", "-y", "install"] + deps)
         if self.args.arch == "i386":
             self.backend.run([
                 "apt-get", "-y", "--no-install-recommends", "install",

=== modified file 'lpbuildd/target/lxd.py'
--- lpbuildd/target/lxd.py	2017-08-26 09:46:32 +0000
+++ lpbuildd/target/lxd.py	2017-08-26 09:54:56 +0000
@@ -282,6 +282,13 @@
             "source": {"type": "image", "alias": self.alias},
             }, wait=True)
 
+        with tempfile.NamedTemporaryFile(mode="w+b") as hosts_file:
+            self.copy_out("/etc/hosts", hosts_file.name)
+            hosts_file.seek(0, os.SEEK_END)
+            print("\n127.0.1.1\t%s" % self.name, file=hosts_file)
+            hosts_file.flush()
+            os.fchmod(hosts_file.fileno(), 0o644)
+            self.copy_in(hosts_file.name, "/etc/hosts")
         with tempfile.NamedTemporaryFile(mode="w+") as hostname_file:
             print(self.name, file=hostname_file)
             hostname_file.flush()

=== modified file 'lpbuildd/target/tests/test_lxd.py'
--- lpbuildd/target/tests/test_lxd.py	2017-08-26 09:46:32 +0000
+++ lpbuildd/target/tests/test_lxd.py	2017-08-26 09:54:56 +0000
@@ -138,6 +138,11 @@
         client.containers.get.return_value = container
         container.start.side_effect = (
             lambda wait=False: setattr(container, "status_code", LXD_RUNNING))
+        files_api = container.api.files
+        files_api._api_endpoint = "/1.0/containers/lp-xenial-amd64/files"
+        files_api.session.get.return_value.status_code = 200
+        files_api.session.get.return_value.iter_content.return_value = (
+            iter([b"127.0.0.1\tlocalhost\n"]))
         processes_fixture = self.useFixture(FakeProcesses())
         processes_fixture.add(lambda _: {}, name="sudo")
         LXD("1", "xenial", "amd64").start()
@@ -201,15 +206,22 @@
             "profiles": ["default", "lpbuildd"],
             "source": {"type": "image", "alias": "lp-xenial-amd64"},
             }, wait=True)
-        container.api.files.post.assert_any_call(
+        files_api.session.get.assert_called_once_with(
+            "/1.0/containers/lp-xenial-amd64/files",
+            params={"path": "/etc/hosts"}, stream=True)
+        files_api.post.assert_any_call(
+            params={"path": "/etc/hosts"},
+            data=b"127.0.0.1\tlocalhost\n\n127.0.1.1\tlp-xenial-amd64\n",
+            headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
+        files_api.post.assert_any_call(
             params={"path": "/etc/hostname"},
             data=b"lp-xenial-amd64\n",
             headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
-        container.api.files.post.assert_any_call(
+        files_api.post.assert_any_call(
             params={"path": "/etc/resolv.conf"},
             data=b"host resolv.conf\n",
             headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
-        container.api.files.post.assert_any_call(
+        files_api.post.assert_any_call(
             params={"path": "/usr/local/sbin/policy-rc.d"},
             data=policy_rc_d.encode("UTF-8"),
             headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0755"})

=== modified file 'lpbuildd/tests/test_livefs.py'
--- lpbuildd/tests/test_livefs.py	2017-08-22 16:37:25 +0000
+++ lpbuildd/tests/test_livefs.py	2017-08-26 09:54:56 +0000
@@ -77,8 +77,7 @@
         expected_command = [
             "sharepath/slavebin/in-target", "in-target",
             "buildlivefs",
-            "--backend=chroot", "--series=saucy", "--arch=i386",
-            self.buildid,
+            "--backend=lxd", "--series=saucy", "--arch=i386", self.buildid,
             "--project", "ubuntu",
             ]
         self.assertEqual(expected_command, self.buildmanager.commands[-1])
@@ -102,8 +101,7 @@
         expected_command = [
             "sharepath/slavebin/in-target", "in-target",
             "scan-for-processes",
-            "--backend=chroot", "--series=saucy", "--arch=i386",
-            self.buildid,
+            "--backend=lxd", "--series=saucy", "--arch=i386", self.buildid,
             ]
         self.assertEqual(
             LiveFilesystemBuildState.BUILD_LIVEFS, self.getState())
@@ -120,8 +118,7 @@
         expected_command = [
             "sharepath/slavebin/in-target", "in-target",
             "umount-chroot",
-            "--backend=chroot", "--series=saucy", "--arch=i386",
-            self.buildid,
+            "--backend=lxd", "--series=saucy", "--arch=i386", self.buildid,
             ]
         self.assertEqual(LiveFilesystemBuildState.UMOUNT, self.getState())
         self.assertEqual(expected_command, self.buildmanager.commands[-1])