Merge lp:~larryprice/libertine/lxd-etc-hosts into lp:libertine

Proposed by Larry Price
Status: Merged
Approved by: Christopher Townsend
Approved revision: 403
Merged at revision: 422
Proposed branch: lp:~larryprice/libertine/lxd-etc-hosts
Merge into: lp:libertine
Prerequisite: lp:~larryprice/libertine/lxd-destroy-bugs
Diff against target: 48 lines (+15/-2)
1 file modified
python/libertine/LxdContainer.py (+15/-2)
To merge this branch: bzr merge lp:~larryprice/libertine/lxd-etc-hosts
Reviewer Review Type Date Requested Status
Libertine CI Bot continuous-integration Approve
Christopher Townsend Approve
Review via email: mp+318400@code.launchpad.net

Commit message

Add container hostname to /etc/hosts in lxd containers.

Description of the change

Add container hostname to /etc/hosts in lxd containers.

I noticed a non-fatal error when running commands in lxd containers with `sudo -E -u $USER` complaining about not being able to resolve the hostname $CONTAINER_NAME. in this MP, I add the container hostname to /etc/hosts in the container if necessary during creation.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:403
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/419/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/786
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/649
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/649
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/649
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/649
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/796
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/777
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/777/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/777
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/777/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/777
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/777/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/777
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/777/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/419/rebuild

review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

+1

review: Approve
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Reapproving due to intermittent test failure.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'python/libertine/LxdContainer.py'
2--- python/libertine/LxdContainer.py 2017-02-24 15:27:34 +0000
3+++ python/libertine/LxdContainer.py 2017-02-27 19:49:06 +0000
4@@ -192,7 +192,7 @@
5
6 host_path = os.path.join(host_root, filepath.lstrip("/"))
7 if not os.path.exists(host_path):
8- utils.get_logger().warning("Syncing file: {}:{}".format(filepath, host_path))
9+ utils.get_logger().info("Syncing file: {}:{}".format(filepath, host_path))
10 os.makedirs(os.path.dirname(host_path), exist_ok=True)
11 with open(host_path, 'wb') as f:
12 f.write(container.files.get(filepath))
13@@ -237,7 +237,7 @@
14 if broken_container_links[i] == container_link_endpoints[i] or container_link_endpoints[i].startswith(root_path):
15 continue # link wasn't found
16
17- host_linkpath = "{}/{}".format(root_path, container_link_endpoints[i])
18+ host_linkpath = os.path.join(root_path, container_link_endpoints[i].lstrip('/'))
19 if not os.path.exists(host_linkpath):
20 os.makedirs(os.path.dirname(host_linkpath), exist_ok=True)
21 with open(host_linkpath, 'wb') as f:
22@@ -351,6 +351,18 @@
23 _lxd_save(container, 'Saving bind mounts for container \'{}\' raised:'.format(container.name))
24
25
26+def _setup_etc_hosts(container):
27+ self_host = '127.0.1.1 %s' % container.name
28+ hosts = container.files.get("/etc/hosts")
29+
30+ lines = [line for line in hosts.decode('utf-8').split('\n')]
31+ found = [line for line in lines if line == self_host]
32+ if len(found) == 0:
33+ lines.insert(1, self_host)
34+
35+ container.files.put("/etc/hosts", '\n'.join(lines).encode('utf-8'))
36+
37+
38 def update_libertine_profile(client):
39 try:
40 profile = client.profiles.get('libertine')
41@@ -416,6 +428,7 @@
42 self._create_libertine_user_data_dir()
43
44 _setup_bind_mount_service(self._container, uid, username)
45+ _setup_etc_hosts(self._container)
46
47 if multiarch and self.architecture == 'amd64':
48 utils.get_logger().info("Adding i386 multiarch support to container '{}'".format(self.container_id))

Subscribers

People subscribed via source and target branches