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

Proposed by Colin Watson
Status: Merged
Merged at revision: 336
Proposed branch: lp:~cjwatson/launchpad-buildd/lxd-hostname
Merge into: lp:launchpad-buildd
Diff against target: 129 lines (+39/-5)
3 files modified
debian/changelog (+7/-0)
lpbuildd/target/lxd.py (+6/-2)
lpbuildd/target/tests/test_lxd.py (+26/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/lxd-hostname
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+337127@code.launchpad.net

Commit message

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

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Adam Conrad (adconrad) wrote :

FWIW, this isn't *just* about livecd-rootfs, it's also nice for the build to actually know the hostname for debugging porpoises.

Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2018-01-15 10:08:55 +0000
3+++ debian/changelog 2018-02-04 01:09:37 +0000
4@@ -1,3 +1,10 @@
5+launchpad-buildd (159) UNRELEASED; urgency=medium
6+
7+ * Set the hostname and FQDN of LXD containers to match the host system,
8+ though with an IP address pointing to the container (LP: #1747015).
9+
10+ -- Colin Watson <cjwatson@ubuntu.com> Sun, 04 Feb 2018 00:58:54 +0000
11+
12 launchpad-buildd (158) xenial; urgency=medium
13
14 [ Steve Langasek ]
15
16=== modified file 'lpbuildd/target/lxd.py'
17--- lpbuildd/target/lxd.py 2017-11-13 15:18:07 +0000
18+++ lpbuildd/target/lxd.py 2018-02-04 01:09:37 +0000
19@@ -321,6 +321,10 @@
20 "source": {"type": "image", "alias": self.alias},
21 }, wait=True)
22
23+ hostname = subprocess.check_output(
24+ ["hostname"], universal_newlines=True).rstrip("\n")
25+ fqdn = subprocess.check_output(
26+ ["hostname", "--fqdn"], universal_newlines=True).rstrip("\n")
27 with tempfile.NamedTemporaryFile(mode="w+b") as hosts_file:
28 try:
29 self.copy_out("/etc/hosts", hosts_file.name)
30@@ -328,12 +332,12 @@
31 hosts_file.seek(0, os.SEEK_SET)
32 hosts_file.write(fallback_hosts.encode("UTF-8"))
33 hosts_file.seek(0, os.SEEK_END)
34- print("\n127.0.1.1\t%s" % self.name, file=hosts_file)
35+ print("\n127.0.1.1\t%s %s" % (fqdn, hostname), file=hosts_file)
36 hosts_file.flush()
37 os.fchmod(hosts_file.fileno(), 0o644)
38 self.copy_in(hosts_file.name, "/etc/hosts")
39 with tempfile.NamedTemporaryFile(mode="w+") as hostname_file:
40- print(self.name, file=hostname_file)
41+ print(hostname, file=hostname_file)
42 hostname_file.flush()
43 os.fchmod(hostname_file.fileno(), 0o644)
44 self.copy_in(hostname_file.name, "/etc/hostname")
45
46=== modified file 'lpbuildd/target/tests/test_lxd.py'
47--- lpbuildd/target/tests/test_lxd.py 2017-11-13 15:18:07 +0000
48+++ lpbuildd/target/tests/test_lxd.py 2018-02-04 01:09:37 +0000
49@@ -5,6 +5,7 @@
50
51 __metaclass__ = type
52
53+import argparse
54 from contextlib import closing
55 import io
56 import json
57@@ -74,6 +75,20 @@
58 return response
59
60
61+class FakeHostname:
62+
63+ def __init__(self, hostname, fqdn):
64+ self.hostname = hostname
65+ self.fqdn = fqdn
66+
67+ def __call__(self, proc_args):
68+ parser = argparse.ArgumentParser()
69+ parser.add_argument("--fqdn", action="store_true", default=False)
70+ args = parser.parse_args(proc_args["args"][1:])
71+ output = self.fqdn if args.fqdn else self.hostname
72+ return {"stdout": io.BytesIO((output + "\n").encode("UTF-8"))}
73+
74+
75 class TestLXD(TestCase):
76
77 def make_chroot_tarball(self, output_path):
78@@ -208,6 +223,8 @@
79 processes_fixture = self.useFixture(FakeProcesses())
80 processes_fixture.add(lambda _: {}, name="sudo")
81 processes_fixture.add(lambda _: {}, name="lxc")
82+ processes_fixture.add(
83+ FakeHostname("example", "example.buildd"), name="hostname")
84 LXD("1", "xenial", "amd64").start()
85
86 self.assert_correct_profile()
87@@ -243,6 +260,8 @@
88 "--pid-file=/run/launchpad-buildd/dnsmasq.pid",
89 "--except-interface=lo", "--interface=lpbuilddbr0",
90 "--listen-address=10.10.10.1"]),
91+ Equals(["hostname"]),
92+ Equals(["hostname", "--fqdn"]),
93 Equals(
94 lxc +
95 ["mknod", "-m", "0660", "/dev/loop-control",
96@@ -271,11 +290,13 @@
97 params={"path": "/etc/hosts"}, stream=True)
98 files_api.post.assert_any_call(
99 params={"path": "/etc/hosts"},
100- data=b"127.0.0.1\tlocalhost\n\n127.0.1.1\tlp-xenial-amd64\n",
101+ data=(
102+ b"127.0.0.1\tlocalhost\n\n"
103+ b"127.0.1.1\texample.buildd example\n"),
104 headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
105 files_api.post.assert_any_call(
106 params={"path": "/etc/hostname"},
107- data=b"lp-xenial-amd64\n",
108+ data=b"example\n",
109 headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
110 files_api.post.assert_any_call(
111 params={"path": "/etc/resolv.conf"},
112@@ -322,6 +343,8 @@
113 processes_fixture = self.useFixture(FakeProcesses())
114 processes_fixture.add(lambda _: {}, name="sudo")
115 processes_fixture.add(lambda _: {}, name="lxc")
116+ processes_fixture.add(
117+ FakeHostname("example", "example.buildd"), name="hostname")
118 LXD("1", "xenial", "amd64").start()
119
120 files_api.session.get.assert_any_call(
121@@ -331,7 +354,7 @@
122 params={"path": "/etc/hosts"},
123 data=(
124 fallback_hosts +
125- "\n127.0.1.1\tlp-xenial-amd64\n").encode("UTF-8"),
126+ "\n127.0.1.1\texample.buildd example\n").encode("UTF-8"),
127 headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
128
129 def test_start_with_mounted_dev_conf(self):

Subscribers

People subscribed via source and target branches

to all changes: