Merge lp:~townsend/libertine/fix-lxc-timezone into lp:libertine

Proposed by Christopher Townsend
Status: Merged
Approved by: Stephen M. Webb
Approved revision: 171
Merged at revision: 172
Proposed branch: lp:~townsend/libertine/fix-lxc-timezone
Merge into: lp:libertine
Diff against target: 63 lines (+27/-2)
2 files modified
data/libertine-lxc.conf (+0/-2)
python/libertine/LxcContainer.py (+27/-0)
To merge this branch: bzr merge lp:~townsend/libertine/fix-lxc-timezone
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Libertine CI Bot continuous-integration Approve
Review via email: mp+285065@code.launchpad.net

Commit message

data/libertine-lxc.conf: Remove the /etc/timezone & /etc/localtime bind-mounts.
python/libertine/LxcContainer.py: Check to see if the LXC's timezone matches the host's timezone, and if not, reconfigure the LXC to match.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) wrote :

The container timezone only gets updated when packages are updated?

review: Needs Information
Revision history for this message
Christopher Townsend (townsend) wrote :

The timezone will be updated a container creation time because it call update_packages(). It will also look to see if the host's timezone has changed when packages are updated as well. I thought it would be a bit heavy handed to check and possibly set the timezone every time the container is started, so I thought putting it in update_packages() was a good compromise.

Revision history for this message
Stephen M. Webb (bregma) wrote :

I suspect there will be complaints about the contained timezone not being correct, but until it's integrated with the changing of the timezone outside of the container somehow this is an acceptable compromise.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/libertine-lxc.conf'
2--- data/libertine-lxc.conf 2015-12-22 19:04:27 +0000
3+++ data/libertine-lxc.conf 2016-02-04 14:23:32 +0000
4@@ -1,7 +1,5 @@
5 lxc.mount.entry = /dev/dri dev/dri none bind,create=dir
6 lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix/ none bind,create=dir
7 lxc.mount.entry = /dev/fuse dev/fuse none bind,optional,create=file
8-lxc.mount.entry = /etc/localtime etc/localtime none bind
9-lxc.mount.entry = /etc/timezone etc/timezone none bind
10 lxc.mount.entry = /usr/lib/locale usr/lib/locale none bind
11 lxc.tty = 0
12
13=== modified file 'python/libertine/LxcContainer.py'
14--- python/libertine/LxcContainer.py 2016-02-02 21:09:07 +0000
15+++ python/libertine/LxcContainer.py 2016-02-04 14:23:32 +0000
16@@ -63,6 +63,13 @@
17 return container
18
19
20+def get_host_timezone():
21+ with open(os.path.join('/', 'etc', 'timezone'), 'r') as fd:
22+ host_timezone = fd.read().strip('\n')
23+
24+ return host_timezone
25+
26+
27 class LibertineLXC(BaseContainer):
28 """
29 A concrete container type implemented using an LXC container.
30@@ -76,6 +83,17 @@
31 def is_running(self):
32 return self.container.running
33
34+ def timezone_needs_update(self):
35+ host_timezone = get_host_timezone()
36+
37+ with open(os.path.join(self.root_path, 'etc', 'timezone'), 'r') as fd:
38+ container_timezone = fd.read().strip('\n')
39+
40+ if host_timezone == container_timezone:
41+ return False
42+ else:
43+ return True
44+
45 def start_container(self):
46 if not self.container.running:
47 if not self.container.start():
48@@ -96,6 +114,15 @@
49 cmd_args = shlex.split(command_string)
50 return self.container.attach_wait(lxc.attach_run_command, cmd_args)
51
52+ def update_packages(self, verbosity=1):
53+ if self.timezone_needs_update():
54+ self.run_in_container("bash -c \'echo \"{}\" >/etc/timezone\'".format(
55+ get_host_timezone()))
56+ self.run_in_container("rm -f /etc/localtime")
57+ self.run_in_container("dpkg-reconfigure -f noninteractive tzdata")
58+
59+ super().update_packages(verbosity)
60+
61 def destroy_libertine_container(self):
62 if self.container.defined:
63 self.container.stop()

Subscribers

People subscribed via source and target branches