]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/lxc-test-automount
src/tests: Fix container creation errors
[mirror_lxc.git] / src / tests / lxc-test-automount
CommitLineData
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
28cgm ping && exit 0
29
8aa1044f
SH
30set -ex
31
32cleanup() {
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
44PHASE=setup
45trap cleanup EXIT
46
47rmdir /sys/fs/cgroup/freezer/xx || true
48lxc-destroy -n lxc-test-automount -f || true
49lxc-create -t busybox -n lxc-test-automount
50
51PHASE=no-cgroup
52echo "Starting phase $PHASE"
53config=/var/lib/lxc/lxc-test-automount/config
54sed -i '/lxc.mount.auto/d' $config
55echo "lxc.mount.auto = proc:mixed sys:mixed" >> $config
56
57lxc-start -n lxc-test-automount
ac46b356
DH
58pid=$(lxc-info -n lxc-test-automount -p -H)
59cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
8aa1044f
SH
60notfound=0
61stat /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
72lxc-stop -n lxc-test-automount -k
73PHASE=cgroup:mixed
74echo "Starting phase $PHASE"
75sed -i '/lxc.mount.auto/d' $config
76echo "lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed" >> $config
77lxc-start -n lxc-test-automount
ac46b356 78pid=$(lxc-info -n lxc-test-automount -p -H)
8aa1044f
SH
79notfound=0
80stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
81[ $notfound -ne 1 ]
82notfound=0
83stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
84[ $notfound -ne 0 ]
85ro=0
86mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
87[ $ro -ne 0 ]
88ro=0
89mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
90[ $ro -ne 1 ]
91notfound=0
92stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
93[ $notfound -ne 1 ]
94
95lxc-stop -n lxc-test-automount -k
96PHASE=cgroup:ro
97echo "Starting phase $PHASE"
98sed -i '/lxc.mount.auto/d' $config
99echo "lxc.mount.auto = cgroup:ro proc:mixed sys:mixed" >> $config
100lxc-start -n lxc-test-automount
ac46b356
DH
101pid=$(lxc-info -n lxc-test-automount -p -H)
102cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
8aa1044f
SH
103notfound=0
104stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
105[ $notfound -ne 1 ]
106notfound=0
107stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
108[ $notfound -ne 0 ]
109ro=0
110mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
111[ $ro -ne 0 ]
112ro=0
113mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
114[ $ro -ne 1 ]
115notfound=0
116stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
117[ $notfound -ne 1 ]
118
119lxc-stop -n lxc-test-automount -k
120PHASE=cgroup:rw
121echo "Starting phase $PHASE"
122sed -i '/lxc.mount.auto/d' $config
123echo "lxc.mount.auto = cgroup:rw proc:mixed sys:mixed" >> $config
124lxc-start -n lxc-test-automount
ac46b356
DH
125pid=$(lxc-info -n lxc-test-automount -p -H)
126cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
8aa1044f
SH
127notfound=0
128stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
129[ $notfound -ne 1 ]
130notfound=0
131stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
132[ $notfound -ne 0 ]
133ro=0
134mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
135[ $ro -ne 1 ]
136rmdir /proc/$pid/root/sys/fs/cgroup/freezer/xx
137ro=0
138mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
139[ $ro -ne 1 ]
140notfound=0
141stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
142[ $notfound -ne 1 ]
143
144# cgroup-full
145
146lxc-stop -n lxc-test-automount -k
147PHASE=cgroup-full:mixed
148echo "Starting phase $PHASE"
149sed -i '/lxc.mount.auto/d' $config
150echo "lxc.mount.auto = cgroup-full:mixed proc:mixed sys:mixed" >> $config
151lxc-start -n lxc-test-automount
ac46b356
DH
152pid=$(lxc-info -n lxc-test-automount -p -H)
153cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
8aa1044f
SH
154notfound=0
155stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
156[ $notfound -ne 1 ]
157notfound=0
158stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
159[ $notfound -ne 1 ]
160ro=0
161mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
162[ $ro -ne 0 ]
163ro=0
164mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
165[ $ro -ne 1 ]
166rmdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx
167notfound=0
168stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
169[ $notfound -ne 1 ]
170
171lxc-stop -n lxc-test-automount -k
172PHASE=cgroup-full:ro
173echo "Starting phase $PHASE"
174sed -i '/lxc.mount.auto/d' $config
175echo "lxc.mount.auto = cgroup-full:ro proc:mixed sys:mixed" >> $config
176lxc-start -n lxc-test-automount
ac46b356
DH
177pid=$(lxc-info -n lxc-test-automount -p -H)
178cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
8aa1044f
SH
179notfound=0
180stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
181[ $notfound -ne 1 ]
182notfound=0
183stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
184[ $notfound -ne 1 ]
185ro=0
186mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
187[ $ro -ne 0 ]
188ro=0
189mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xy || ro=1
190[ $ro -ne 0 ]
191notfound=0
192stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
193[ $notfound -ne 1 ]
194
195lxc-stop -n lxc-test-automount -k
196PHASE=cgroup-full:rw
197echo "Starting phase $PHASE"
198sed -i '/lxc.mount.auto/d' $config
199echo "lxc.mount.auto = cgroup-full:rw proc:mixed sys:mixed" >> $config
200lxc-start -n lxc-test-automount
ac46b356
DH
201pid=$(lxc-info -n lxc-test-automount -p -H)
202cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
8aa1044f
SH
203notfound=0
204stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
205[ $notfound -ne 1 ]
206notfound=0
207stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
208[ $notfound -ne 1 ]
209ro=0
210mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
211[ $ro -ne 1 ]
212rmdir /proc/$pid/root/sys/fs/cgroup/freezer/xx
213ro=0
214mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
215[ $ro -ne 1 ]
216notfound=0
217/proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
218[ $notfound -eq 1 ]
219
220PHASE=done