]>
Commit | Line | Data |
---|---|---|
8aa1044f SH |
1 | #!/bin/bash |
2 | ||
3 | # lxc: linux Container library | |
4 | ||
5 | # Authors: | |
6 | # Serge Hallyn <serge.hallyn@ubuntu.com> | |
7 | ||
8 | # This library is free software; you can redistribute it and/or | |
9 | # modify it under the terms of the GNU Lesser General Public | |
10 | # License as published by the Free Software Foundation; either | |
11 | # version 2.1 of the License, or (at your option) any later version. | |
12 | ||
13 | # This library is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | # Lesser General Public License for more details. | |
17 | ||
18 | # You should have received a copy of the GNU Lesser General Public | |
19 | # License along with this library; if not, write to the Free Software | |
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | ||
22 | # At the moment this only tests cgroup automount. Testing proc and | |
23 | # sys automounts would be worthwhile. | |
24 | ||
25 | [ -f /proc/self/ns/cgroup ] && exit 0 | |
26 | ||
9ec45e7f SH |
27 | # cgmanager doesn't do the same cgroup filesystem mounting |
28 | cgm ping && exit 0 | |
29 | ||
8aa1044f SH |
30 | set -ex |
31 | ||
32 | cleanup() { | |
33 | set +e | |
34 | rmdir /sys/fs/cgroup/freezer/xx | |
35 | lxc-destroy -n lxc-test-automount -f | |
36 | if [ $PHASE != "done" ]; then | |
37 | echo "automount test failed at $PHASE" | |
38 | exit 1 | |
39 | fi | |
40 | echo "automount test passed" | |
41 | exit 0 | |
42 | } | |
43 | ||
44 | PHASE=setup | |
45 | trap cleanup EXIT | |
46 | ||
47 | rmdir /sys/fs/cgroup/freezer/xx || true | |
48 | lxc-destroy -n lxc-test-automount -f || true | |
49 | lxc-create -t busybox -n lxc-test-automount | |
50 | ||
51 | PHASE=no-cgroup | |
52 | echo "Starting phase $PHASE" | |
53 | config=/var/lib/lxc/lxc-test-automount/config | |
54 | sed -i '/lxc.mount.auto/d' $config | |
55 | echo "lxc.mount.auto = proc:mixed sys:mixed" >> $config | |
56 | ||
57 | lxc-start -n lxc-test-automount | |
58 | pid=`lxc-info -n lxc-test-automount -p -H` | |
59 | cg=`awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup` | |
60 | notfound=0 | |
61 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
62 | [ $notfound -ne 0 ] | |
63 | ||
64 | # Tests are as follows: | |
65 | # 1. check that freezer controller is mounted | |
66 | # 2. check that it is cgroupfs for cgroup-full (/cgroup.procs exists) or | |
67 | # tmpfs for cgroup | |
68 | # 3. check that root cgroup dir is readonly or not (try mkdir) | |
69 | # 4. check that the container's cgroup dir is readonly or not | |
70 | # 5. check that the container's cgroup dir is cgroupfs (/cgroup.procs exists) | |
71 | ||
72 | lxc-stop -n lxc-test-automount -k | |
73 | PHASE=cgroup:mixed | |
74 | echo "Starting phase $PHASE" | |
75 | sed -i '/lxc.mount.auto/d' $config | |
76 | echo "lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed" >> $config | |
77 | lxc-start -n lxc-test-automount | |
78 | pid=`lxc-info -n lxc-test-automount -p -H` | |
79 | notfound=0 | |
80 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
81 | [ $notfound -ne 1 ] | |
82 | notfound=0 | |
83 | stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1 | |
84 | [ $notfound -ne 0 ] | |
85 | ro=0 | |
86 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1 | |
87 | [ $ro -ne 0 ] | |
88 | ro=0 | |
89 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1 | |
90 | [ $ro -ne 1 ] | |
91 | notfound=0 | |
92 | stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1 | |
93 | [ $notfound -ne 1 ] | |
94 | ||
95 | lxc-stop -n lxc-test-automount -k | |
96 | PHASE=cgroup:ro | |
97 | echo "Starting phase $PHASE" | |
98 | sed -i '/lxc.mount.auto/d' $config | |
99 | echo "lxc.mount.auto = cgroup:ro proc:mixed sys:mixed" >> $config | |
100 | lxc-start -n lxc-test-automount | |
101 | pid=`lxc-info -n lxc-test-automount -p -H` | |
102 | cg=`awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup` | |
103 | notfound=0 | |
104 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
105 | [ $notfound -ne 1 ] | |
106 | notfound=0 | |
107 | stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1 | |
108 | [ $notfound -ne 0 ] | |
109 | ro=0 | |
110 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1 | |
111 | [ $ro -ne 0 ] | |
112 | ro=0 | |
113 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1 | |
114 | [ $ro -ne 1 ] | |
115 | notfound=0 | |
116 | stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1 | |
117 | [ $notfound -ne 1 ] | |
118 | ||
119 | lxc-stop -n lxc-test-automount -k | |
120 | PHASE=cgroup:rw | |
121 | echo "Starting phase $PHASE" | |
122 | sed -i '/lxc.mount.auto/d' $config | |
123 | echo "lxc.mount.auto = cgroup:rw proc:mixed sys:mixed" >> $config | |
124 | lxc-start -n lxc-test-automount | |
125 | pid=`lxc-info -n lxc-test-automount -p -H` | |
126 | cg=`awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup` | |
127 | notfound=0 | |
128 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
129 | [ $notfound -ne 1 ] | |
130 | notfound=0 | |
131 | stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1 | |
132 | [ $notfound -ne 0 ] | |
133 | ro=0 | |
134 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1 | |
135 | [ $ro -ne 1 ] | |
136 | rmdir /proc/$pid/root/sys/fs/cgroup/freezer/xx | |
137 | ro=0 | |
138 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1 | |
139 | [ $ro -ne 1 ] | |
140 | notfound=0 | |
141 | stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1 | |
142 | [ $notfound -ne 1 ] | |
143 | ||
144 | # cgroup-full | |
145 | ||
146 | lxc-stop -n lxc-test-automount -k | |
147 | PHASE=cgroup-full:mixed | |
148 | echo "Starting phase $PHASE" | |
149 | sed -i '/lxc.mount.auto/d' $config | |
150 | echo "lxc.mount.auto = cgroup-full:mixed proc:mixed sys:mixed" >> $config | |
151 | lxc-start -n lxc-test-automount | |
152 | pid=`lxc-info -n lxc-test-automount -p -H` | |
153 | cg=`awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup` | |
154 | notfound=0 | |
155 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
156 | [ $notfound -ne 1 ] | |
157 | notfound=0 | |
158 | stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1 | |
159 | [ $notfound -ne 1 ] | |
160 | ro=0 | |
161 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1 | |
162 | [ $ro -ne 0 ] | |
163 | ro=0 | |
164 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1 | |
165 | [ $ro -ne 1 ] | |
166 | rmdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx | |
167 | notfound=0 | |
168 | stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1 | |
169 | [ $notfound -ne 1 ] | |
170 | ||
171 | lxc-stop -n lxc-test-automount -k | |
172 | PHASE=cgroup-full:ro | |
173 | echo "Starting phase $PHASE" | |
174 | sed -i '/lxc.mount.auto/d' $config | |
175 | echo "lxc.mount.auto = cgroup-full:ro proc:mixed sys:mixed" >> $config | |
176 | lxc-start -n lxc-test-automount | |
177 | pid=`lxc-info -n lxc-test-automount -p -H` | |
178 | cg=`awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup` | |
179 | notfound=0 | |
180 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
181 | [ $notfound -ne 1 ] | |
182 | notfound=0 | |
183 | stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1 | |
184 | [ $notfound -ne 1 ] | |
185 | ro=0 | |
186 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1 | |
187 | [ $ro -ne 0 ] | |
188 | ro=0 | |
189 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xy || ro=1 | |
190 | [ $ro -ne 0 ] | |
191 | notfound=0 | |
192 | stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1 | |
193 | [ $notfound -ne 1 ] | |
194 | ||
195 | lxc-stop -n lxc-test-automount -k | |
196 | PHASE=cgroup-full:rw | |
197 | echo "Starting phase $PHASE" | |
198 | sed -i '/lxc.mount.auto/d' $config | |
199 | echo "lxc.mount.auto = cgroup-full:rw proc:mixed sys:mixed" >> $config | |
200 | lxc-start -n lxc-test-automount | |
201 | pid=`lxc-info -n lxc-test-automount -p -H` | |
202 | cg=`awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup` | |
203 | notfound=0 | |
204 | stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1 | |
205 | [ $notfound -ne 1 ] | |
206 | notfound=0 | |
207 | stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1 | |
208 | [ $notfound -ne 1 ] | |
209 | ro=0 | |
210 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1 | |
211 | [ $ro -ne 1 ] | |
212 | rmdir /proc/$pid/root/sys/fs/cgroup/freezer/xx | |
213 | ro=0 | |
214 | mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1 | |
215 | [ $ro -ne 1 ] | |
216 | notfound=0 | |
217 | /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1 | |
218 | [ $notfound -eq 1 ] | |
219 | ||
220 | PHASE=done |