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

Proposed by Colin Watson
Status: Merged
Merged at revision: 268
Proposed branch: lp:~cjwatson/launchpad-buildd/livefs-lxd
Merge into: lp:launchpad-buildd
Prerequisite: lp:~cjwatson/launchpad-buildd/snap-lxd
Diff against target: 133 lines (+31/-10)
6 files modified
debian/changelog (+1/-0)
lpbuildd/livefs.py (+1/-0)
lpbuildd/target/build_livefs.py (+4/-1)
lpbuildd/target/lxd.py (+7/-0)
lpbuildd/target/tests/test_lxd.py (+15/-3)
lpbuildd/tests/test_livefs.py (+3/-6)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/livefs-lxd
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+329662@code.launchpad.net

Commit message

Switch livefs builds to the LXD backend.

Description of the change

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.)

To post a comment you must log in.
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 2017-08-26 09:54:56 +0000
3+++ debian/changelog 2017-08-26 09:54:56 +0000
4@@ -26,6 +26,7 @@
5 * Convert buildsnap to the new Operation framework and add unit tests.
6 * Add a LXD backend.
7 * Switch snap builds to the LXD backend.
8+ * Switch livefs builds to the LXD backend.
9
10 -- Colin Watson <cjwatson@ubuntu.com> Tue, 25 Jul 2017 23:07:58 +0100
11
12
13=== modified file 'lpbuildd/livefs.py'
14--- lpbuildd/livefs.py 2017-08-22 16:37:25 +0000
15+++ lpbuildd/livefs.py 2017-08-26 09:54:56 +0000
16@@ -23,6 +23,7 @@
17 class LiveFilesystemBuildManager(DebianBuildManager):
18 """Build a live filesystem."""
19
20+ backend_name = "lxd"
21 initial_build_state = LiveFilesystemBuildState.BUILD_LIVEFS
22
23 def initiate(self, files, chroot, extra_args):
24
25=== modified file 'lpbuildd/target/build_livefs.py'
26--- lpbuildd/target/build_livefs.py 2017-08-22 16:37:25 +0000
27+++ lpbuildd/target/build_livefs.py 2017-08-26 09:54:56 +0000
28@@ -80,7 +80,10 @@
29 self.backend.run(["/bin/sh", "-c", command], echo=echo)
30
31 def install(self):
32- self.backend.run(["apt-get", "-y", "install", "livecd-rootfs"])
33+ deps = ["livecd-rootfs"]
34+ if self.args.backend == "lxd":
35+ deps.extend(["snapd", "fuse", "squashfuse"])
36+ self.backend.run(["apt-get", "-y", "install"] + deps)
37 if self.args.arch == "i386":
38 self.backend.run([
39 "apt-get", "-y", "--no-install-recommends", "install",
40
41=== modified file 'lpbuildd/target/lxd.py'
42--- lpbuildd/target/lxd.py 2017-08-26 09:46:32 +0000
43+++ lpbuildd/target/lxd.py 2017-08-26 09:54:56 +0000
44@@ -282,6 +282,13 @@
45 "source": {"type": "image", "alias": self.alias},
46 }, wait=True)
47
48+ with tempfile.NamedTemporaryFile(mode="w+b") as hosts_file:
49+ self.copy_out("/etc/hosts", hosts_file.name)
50+ hosts_file.seek(0, os.SEEK_END)
51+ print("\n127.0.1.1\t%s" % self.name, file=hosts_file)
52+ hosts_file.flush()
53+ os.fchmod(hosts_file.fileno(), 0o644)
54+ self.copy_in(hosts_file.name, "/etc/hosts")
55 with tempfile.NamedTemporaryFile(mode="w+") as hostname_file:
56 print(self.name, file=hostname_file)
57 hostname_file.flush()
58
59=== modified file 'lpbuildd/target/tests/test_lxd.py'
60--- lpbuildd/target/tests/test_lxd.py 2017-08-26 09:46:32 +0000
61+++ lpbuildd/target/tests/test_lxd.py 2017-08-26 09:54:56 +0000
62@@ -138,6 +138,11 @@
63 client.containers.get.return_value = container
64 container.start.side_effect = (
65 lambda wait=False: setattr(container, "status_code", LXD_RUNNING))
66+ files_api = container.api.files
67+ files_api._api_endpoint = "/1.0/containers/lp-xenial-amd64/files"
68+ files_api.session.get.return_value.status_code = 200
69+ files_api.session.get.return_value.iter_content.return_value = (
70+ iter([b"127.0.0.1\tlocalhost\n"]))
71 processes_fixture = self.useFixture(FakeProcesses())
72 processes_fixture.add(lambda _: {}, name="sudo")
73 LXD("1", "xenial", "amd64").start()
74@@ -201,15 +206,22 @@
75 "profiles": ["default", "lpbuildd"],
76 "source": {"type": "image", "alias": "lp-xenial-amd64"},
77 }, wait=True)
78- container.api.files.post.assert_any_call(
79+ files_api.session.get.assert_called_once_with(
80+ "/1.0/containers/lp-xenial-amd64/files",
81+ params={"path": "/etc/hosts"}, stream=True)
82+ files_api.post.assert_any_call(
83+ params={"path": "/etc/hosts"},
84+ data=b"127.0.0.1\tlocalhost\n\n127.0.1.1\tlp-xenial-amd64\n",
85+ headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
86+ files_api.post.assert_any_call(
87 params={"path": "/etc/hostname"},
88 data=b"lp-xenial-amd64\n",
89 headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
90- container.api.files.post.assert_any_call(
91+ files_api.post.assert_any_call(
92 params={"path": "/etc/resolv.conf"},
93 data=b"host resolv.conf\n",
94 headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0644"})
95- container.api.files.post.assert_any_call(
96+ files_api.post.assert_any_call(
97 params={"path": "/usr/local/sbin/policy-rc.d"},
98 data=policy_rc_d.encode("UTF-8"),
99 headers={"X-LXD-uid": 0, "X-LXD-gid": 0, "X-LXD-mode": "0755"})
100
101=== modified file 'lpbuildd/tests/test_livefs.py'
102--- lpbuildd/tests/test_livefs.py 2017-08-22 16:37:25 +0000
103+++ lpbuildd/tests/test_livefs.py 2017-08-26 09:54:56 +0000
104@@ -77,8 +77,7 @@
105 expected_command = [
106 "sharepath/slavebin/in-target", "in-target",
107 "buildlivefs",
108- "--backend=chroot", "--series=saucy", "--arch=i386",
109- self.buildid,
110+ "--backend=lxd", "--series=saucy", "--arch=i386", self.buildid,
111 "--project", "ubuntu",
112 ]
113 self.assertEqual(expected_command, self.buildmanager.commands[-1])
114@@ -102,8 +101,7 @@
115 expected_command = [
116 "sharepath/slavebin/in-target", "in-target",
117 "scan-for-processes",
118- "--backend=chroot", "--series=saucy", "--arch=i386",
119- self.buildid,
120+ "--backend=lxd", "--series=saucy", "--arch=i386", self.buildid,
121 ]
122 self.assertEqual(
123 LiveFilesystemBuildState.BUILD_LIVEFS, self.getState())
124@@ -120,8 +118,7 @@
125 expected_command = [
126 "sharepath/slavebin/in-target", "in-target",
127 "umount-chroot",
128- "--backend=chroot", "--series=saucy", "--arch=i386",
129- self.buildid,
130+ "--backend=lxd", "--series=saucy", "--arch=i386", self.buildid,
131 ]
132 self.assertEqual(LiveFilesystemBuildState.UMOUNT, self.getState())
133 self.assertEqual(expected_command, self.buildmanager.commands[-1])

Subscribers

People subscribed via source and target branches

to all changes: