← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Set the hostname and FQDN of LXD containers to match the host system, though with an IP address pointing to the container.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1747015 in launchpad-buildd: "Propagate hostname to lxd container"
  https://bugs.launchpad.net/launchpad-buildd/+bug/1747015

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

Otherwise we break livecd-rootfs code that, for better or worse, adjusts its behaviour (mainly internal hostnames, I think) depending on whether it's being built on a buildd.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad-buildd/lxd-hostname into lp:launchpad-buildd.
=== modified file 'debian/changelog'
--- debian/changelog	2018-01-15 10:08:55 +0000
+++ debian/changelog	2018-02-04 01:09:37 +0000
@@ -1,3 +1,10 @@
+launchpad-buildd (159) UNRELEASED; urgency=medium
+
+  * Set the hostname and FQDN of LXD containers to match the host system,
+    though with an IP address pointing to the container (LP: #1747015).
+
+ -- Colin Watson <cjwatson@xxxxxxxxxx>  Sun, 04 Feb 2018 00:58:54 +0000
+
 launchpad-buildd (158) xenial; urgency=medium
 
   [ Steve Langasek ]

=== modified file 'lpbuildd/target/lxd.py'
--- lpbuildd/target/lxd.py	2017-11-13 15:18:07 +0000
+++ lpbuildd/target/lxd.py	2018-02-04 01:09:37 +0000
@@ -321,6 +321,10 @@
             "source": {"type": "image", "alias": self.alias},
             }, wait=True)
 
+        hostname = subprocess.check_output(
+            ["hostname"], universal_newlines=True).rstrip("\n")
+        fqdn = subprocess.check_output(
+            ["hostname", "--fqdn"], universal_newlines=True).rstrip("\n")
         with tempfile.NamedTemporaryFile(mode="w+b") as hosts_file:
             try:
                 self.copy_out("/etc/hosts", hosts_file.name)
@@ -328,12 +332,12 @@
                 hosts_file.seek(0, os.SEEK_SET)
                 hosts_file.write(fallback_hosts.encode("UTF-8"))
             hosts_file.seek(0, os.SEEK_END)
-            print("\n127.0.1.1\t%s" % self.name, file=hosts_file)
+            print("\n127.0.1.1\t%s %s" % (fqdn, hostname), 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)
+            print(hostname, file=hostname_file)
             hostname_file.flush()
             os.fchmod(hostname_file.fileno(), 0o644)
             self.copy_in(hostname_file.name, "/etc/hostname")

=== modified file 'lpbuildd/target/tests/test_lxd.py'
--- lpbuildd/target/tests/test_lxd.py	2017-11-13 15:18:07 +0000
+++ lpbuildd/target/tests/test_lxd.py	2018-02-04 01:09:37 +0000
@@ -5,6 +5,7 @@
 
 __metaclass__ = type
 
+import argparse
 from contextlib import closing
 import io
 import json
@@ -74,6 +75,20 @@
         return response
 
 
+class FakeHostname:
+
+    def __init__(self, hostname, fqdn):
+        self.hostname = hostname
+        self.fqdn = fqdn
+
+    def __call__(self, proc_args):
+        parser = argparse.ArgumentParser()
+        parser.add_argument("--fqdn", action="store_true", default=False)
+        args = parser.parse_args(proc_args["args"][1:])
+        output = self.fqdn if args.fqdn else self.hostname
+        return {"stdout": io.BytesIO((output + "\n").encode("UTF-8"))}
+
+
 class TestLXD(TestCase):
 
     def make_chroot_tarball(self, output_path):
@@ -208,6 +223,8 @@
         processes_fixture = self.useFixture(FakeProcesses())
         processes_fixture.add(lambda _: {}, name="sudo")
         processes_fixture.add(lambda _: {}, name="lxc")
+        processes_fixture.add(
+            FakeHostname("example", "example.buildd"), name="hostname")
         LXD("1", "xenial", "amd64").start()
 
         self.assert_correct_profile()
@@ -243,6 +260,8 @@
                  "--pid-file=/run/launchpad-buildd/dnsmasq.pid",
                  "--except-interface=lo", "--interface=lpbuilddbr0",
                  "--listen-address=10.10.10.1"]),
+            Equals(["hostname"]),
+            Equals(["hostname", "--fqdn"]),
             Equals(
                 lxc +
                 ["mknod", "-m", "0660", "/dev/loop-control",
@@ -271,11 +290,13 @@
             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",
+            data=(
+                b"127.0.0.1\tlocalhost\n\n"
+                b"127.0.1.1\texample.buildd example\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",
+            data=b"example\n",
             headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
         files_api.post.assert_any_call(
             params={"path": "/etc/resolv.conf"},
@@ -322,6 +343,8 @@
         processes_fixture = self.useFixture(FakeProcesses())
         processes_fixture.add(lambda _: {}, name="sudo")
         processes_fixture.add(lambda _: {}, name="lxc")
+        processes_fixture.add(
+            FakeHostname("example", "example.buildd"), name="hostname")
         LXD("1", "xenial", "amd64").start()
 
         files_api.session.get.assert_any_call(
@@ -331,7 +354,7 @@
             params={"path": "/etc/hosts"},
             data=(
                 fallback_hosts +
-                "\n127.0.1.1\tlp-xenial-amd64\n").encode("UTF-8"),
+                "\n127.0.1.1\texample.buildd example\n").encode("UTF-8"),
             headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
 
     def test_start_with_mounted_dev_conf(self):


Follow ups