Merge lp:~bac/lpsetup/nested-lxc into lp:lpsetup

Proposed by Brad Crittenden
Status: Merged
Approved by: Gary Poster
Approved revision: 66
Merged at revision: 63
Proposed branch: lp:~bac/lpsetup/nested-lxc
Merge into: lp:lpsetup
Diff against target: 142 lines (+100/-9)
3 files modified
README.rst (+36/-9)
lpsetup/templates/lxc-with-testing (+58/-0)
lpsetup/tests/integration/test_install_lxc.py (+6/-0)
To merge this branch: bzr merge lp:~bac/lpsetup/nested-lxc
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+116726@code.launchpad.net

Commit message

Make changes to allow nested LXCs for integration testing.

Description of the change

Make changes to allow nested LXCs for integration testing.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Yay!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.rst'
2--- README.rst 2012-07-24 18:27:40 +0000
3+++ README.rst 2012-07-25 18:52:21 +0000
4@@ -86,15 +86,14 @@
5
6 There are two tests provided and each can run in either environment as
7 long as you specify using the '-e' command line option. The tests
8-are:
9-
10-lpsetup/tests/integration/non-lxc.py
11-lpsetup/tests/integration/juju-lxc.py
12-
13-The first only tests the *init-host* command but goes no further.
14-The second tests *install-lxc*. Due to bug 924281 (supposedly
15-*fix-released* but still seen) this test cannot currently be run in an
16-lxc container as it would require an lxc inside an lxc.
17+are in lpsetup/tests/integration.
18+
19+The first, *test_init_host.py*, only tests the *init-host* command but
20+goes no further. The second, *test_install_lxc.py*, tests
21+*install-lxc*. If this test is run against a local LXC environment,
22+some changes need are first required to the host machine where the
23+test will be run. Follow the instruction in the next section before
24+launching the test.
25
26 The tests bootstrap the environment for you and fail if it is already
27 running.
28@@ -106,6 +105,34 @@
29 StrictHostKeyChecking no
30 UserKnownHostsFile /dev/null
31
32+Required changes for using nested LXC containers
33+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
35+In order to get nested LXCs working in precise a few work-arounds are
36+required, mostly relating to apparmor.
37+
38+The description of what needs to be done is at:
39+http://www.stgraber.org/2012/05/04/lxc-in-ubuntu-12-04-lts/
40+
41+For the testing scenario, the host machine must be manually changed
42+once[1] with the following modifications:
43+sudo cp lpsetup/templates/lxc-with-testing /etc/apparmor.d/lxc
44+sudo /etc/init.d/apparmor reload
45+sudo cp /usr/lib/lxc/templates/lxc-ubuntu /usr/lib/lxc/templates/lxc-ubuntu.orig
46+sudo sed -i "s/#lxc.aa_profile = unconfined/lxc.aa_profile = lxc-container-with-nesting/" \
47+ /usr/lib/lxc/templates/lxc-ubuntu
48+
49+Should you want to disallow the apparmor change made to the default
50+ubuntu template:
51+sudo mv /usr/lib/lxc/templates/lxc-ubuntu.orig \
52+ /usr/lib/lxc/templates/lxc-ubuntu
53+
54+The other changes mentioned are handled by the test in the container
55+launched by Juju.
56+
57+[1] If the *lxc* package changes such that the *ubuntu* template is
58+modified, then the last two steps to update the template will be
59+required to be performed again.
60
61 Linting
62 ~~~~~~~
63
64=== added file 'lpsetup/templates/lxc-with-testing'
65--- lpsetup/templates/lxc-with-testing 1970-01-01 00:00:00 +0000
66+++ lpsetup/templates/lxc-with-testing 2012-07-25 18:52:21 +0000
67@@ -0,0 +1,58 @@
68+# Do not load this file. Rather, load /etc/apparmor.d/lxc-containers, which
69+# will source all profiles under /etc/apparmor.d/lxc
70+
71+# {installation_header}
72+
73+profile lxc-container-with-nesting flags=(attach_disconnected,mediate_deleted) {
74+ network,
75+ capability,
76+ file,
77+ umount,
78+
79+ # addition for container nesting
80+ mount -> /sys/fs/cgroup/**,
81+ mount fstype=proc -> /var/cache/lxc/**,
82+ mount fstype=sysfs -> /var/cache/lxc/**,
83+ mount fstype=devpts -> /dev/pts/,
84+ mount -> /usr/lib/lxc/root/,
85+ mount -> /usr/lib/lxc/root/**,
86+ mount /dev/pts/ptmx/ -> /dev/ptmx/,
87+ pivot_root,
88+ change_profile -> lxc-*,
89+
90+ # ignore DENIED message on / remount
91+ deny mount options=(ro, remount) -> /,
92+
93+ # allow tmpfs mounts everywhere
94+ mount fstype=tmpfs,
95+
96+ # allow mqueue mounts everywhere
97+ mount fstype=mqueue,
98+
99+ # allow bind mount of /lib/init/fstab for lxcguest
100+ mount options=(rw, bind) /lib/init/fstab.lxc/ -> /lib/init/fstab/,
101+
102+ # deny writes in /proc/sys/fs but allow fusectl to be mounted
103+ mount fstype=binfmt_misc -> /proc/sys/fs/binfmt_misc/,
104+ deny @{PROC}/sys/fs/** wklx,
105+
106+ # block some other dangerous paths
107+ deny @{PROC}/sysrq-trigger rwklx,
108+ deny @{PROC}/mem rwklx,
109+ deny @{PROC}/kmem rwklx,
110+ deny @{PROC}/sys/kernel/** wklx,
111+
112+ # deny writes in /sys except for /sys/fs/cgroup, also allow
113+ # fusectl, securityfs and debugfs to be mounted there (read-only)
114+ mount fstype=fusectl -> /sys/fs/fuse/connections/,
115+ mount fstype=securityfs -> /sys/kernel/security/,
116+ mount fstype=debugfs -> /sys/kernel/debug/,
117+ deny mount fstype=debugfs -> /var/lib/ureadahead/debugfs/,
118+ mount fstype=proc -> /proc/,
119+ mount fstype=sysfs -> /sys/,
120+ deny /sys/[^f]*/** wklx,
121+ deny /sys/f[^s]*/** wklx,
122+ deny /sys/fs/[^c]*/** wklx,
123+ deny /sys/fs/c[^g]*/** wklx,
124+ deny /sys/fs/cg[^r]*/** wklx,
125+}
126
127=== modified file 'lpsetup/tests/integration/test_install_lxc.py'
128--- lpsetup/tests/integration/test_install_lxc.py 2012-07-25 13:11:25 +0000
129+++ lpsetup/tests/integration/test_install_lxc.py 2012-07-25 18:52:21 +0000
130@@ -73,6 +73,12 @@
131 def set_up(self):
132 super(InstallLXCTest, self).set_up()
133 self.on_remote('cd lpsetup; sudo python setup.py install')
134+ # The installation of `lxc` is redundant as init-lxc does it but
135+ # required to get the nested LXC work-around to work.
136+ self.on_remote('sudo apt-get -y install lxc')
137+ self.on_remote('sudo stop lxc')
138+ self.on_remote('sudo sed -i "s/10.0.3/10.0.4/g" /etc/default/lxc')
139+ self.on_remote('sudo start lxc')
140
141 def do_test(self):
142 """Run an end-to-end integration tests of the LXC lpsetup story."""

Subscribers

People subscribed via source and target branches