Debian Codegraph @

src/tests/lxc-test-automount

raw
1 #!/bin/bash
2
3 # SPDX-License-Identifier: LGPL-2.1+
4
5 # lxc: linux Container library
6
7 # At the moment this only tests cgroup automount. Testing proc and
8 # sys automounts would be worthwhile.
9
10 [ -f /proc/self/ns/cgroup ] && exit 0
11
12 # cgmanager doesn't do the same cgroup filesystem mounting
13 cgm ping && exit 0
14
15 set -ex
16
17 cleanup() {
18 set +e
19 rmdir /sys/fs/cgroup/freezer/xx
20 lxc-destroy -n lxc-test-automount -f
21 if [ $PHASE != "done" ]; then
22 echo "automount test failed at $PHASE"
23 exit 1
24 fi
25 echo "automount test passed"
26 exit 0
27 }
28
29 PHASE=setup
30 trap cleanup EXIT
31
32 rmdir /sys/fs/cgroup/freezer/xx || true
33 lxc-destroy -n lxc-test-automount -f || true
34 lxc-create -t busybox -n lxc-test-automount
35
36 PHASE=no-cgroup
37 echo "Starting phase $PHASE"
38 config=/var/lib/lxc/lxc-test-automount/config
39 sed -i '/lxc.mount.auto/d' $config
40 echo "lxc.mount.auto = proc:mixed sys:mixed" >> $config
41
42 lxc-start -n lxc-test-automount
43 pid=$(lxc-info -n lxc-test-automount -p -H)
44 cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
45 notfound=0
46 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
47 [ $notfound -ne 0 ]
48
49 # Tests are as follows:
50 # 1. check that freezer controller is mounted
51 # 2. check that it is cgroupfs for cgroup-full (/cgroup.procs exists) or
52 # tmpfs for cgroup
53 # 3. check that root cgroup dir is readonly or not (try mkdir)
54 # 4. check that the container's cgroup dir is readonly or not
55 # 5. check that the container's cgroup dir is cgroupfs (/cgroup.procs exists)
56
57 lxc-stop -n lxc-test-automount -k
58 PHASE=cgroup:mixed
59 echo "Starting phase $PHASE"
60 sed -i '/lxc.mount.auto/d' $config
61 echo "lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed" >> $config
62 lxc-start -n lxc-test-automount
63 pid=$(lxc-info -n lxc-test-automount -p -H)
64 notfound=0
65 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
66 [ $notfound -ne 1 ]
67 notfound=0
68 stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
69 [ $notfound -ne 0 ]
70 ro=0
71 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
72 [ $ro -ne 0 ]
73 ro=0
74 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
75 [ $ro -ne 1 ]
76 notfound=0
77 stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
78 [ $notfound -ne 1 ]
79
80 lxc-stop -n lxc-test-automount -k
81 PHASE=cgroup:ro
82 echo "Starting phase $PHASE"
83 sed -i '/lxc.mount.auto/d' $config
84 echo "lxc.mount.auto = cgroup:ro proc:mixed sys:mixed" >> $config
85 lxc-start -n lxc-test-automount
86 pid=$(lxc-info -n lxc-test-automount -p -H)
87 cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
88 notfound=0
89 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
90 [ $notfound -ne 1 ]
91 notfound=0
92 stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
93 [ $notfound -ne 0 ]
94 ro=0
95 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
96 [ $ro -ne 0 ]
97 ro=0
98 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
99 [ $ro -ne 1 ]
100 notfound=0
101 stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
102 [ $notfound -ne 1 ]
103
104 lxc-stop -n lxc-test-automount -k
105 PHASE=cgroup:rw
106 echo "Starting phase $PHASE"
107 sed -i '/lxc.mount.auto/d' $config
108 echo "lxc.mount.auto = cgroup:rw proc:mixed sys:mixed" >> $config
109 lxc-start -n lxc-test-automount
110 pid=$(lxc-info -n lxc-test-automount -p -H)
111 cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
112 notfound=0
113 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
114 [ $notfound -ne 1 ]
115 notfound=0
116 stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
117 [ $notfound -ne 0 ]
118 ro=0
119 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
120 [ $ro -ne 1 ]
121 rmdir /proc/$pid/root/sys/fs/cgroup/freezer/xx
122 ro=0
123 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
124 [ $ro -ne 1 ]
125 notfound=0
126 stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
127 [ $notfound -ne 1 ]
128
129 # cgroup-full
130
131 lxc-stop -n lxc-test-automount -k
132 PHASE=cgroup-full:mixed
133 echo "Starting phase $PHASE"
134 sed -i '/lxc.mount.auto/d' $config
135 echo "lxc.mount.auto = cgroup-full:mixed proc:mixed sys:mixed" >> $config
136 lxc-start -n lxc-test-automount
137 pid=$(lxc-info -n lxc-test-automount -p -H)
138 cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
139 notfound=0
140 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
141 [ $notfound -ne 1 ]
142 notfound=0
143 stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
144 [ $notfound -ne 1 ]
145 ro=0
146 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
147 [ $ro -ne 0 ]
148 ro=0
149 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
150 [ $ro -ne 1 ]
151 rmdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx
152 notfound=0
153 stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
154 [ $notfound -ne 1 ]
155
156 lxc-stop -n lxc-test-automount -k
157 PHASE=cgroup-full:ro
158 echo "Starting phase $PHASE"
159 sed -i '/lxc.mount.auto/d' $config
160 echo "lxc.mount.auto = cgroup-full:ro proc:mixed sys:mixed" >> $config
161 lxc-start -n lxc-test-automount
162 pid=$(lxc-info -n lxc-test-automount -p -H)
163 cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
164 notfound=0
165 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
166 [ $notfound -ne 1 ]
167 notfound=0
168 stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
169 [ $notfound -ne 1 ]
170 ro=0
171 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
172 [ $ro -ne 0 ]
173 ro=0
174 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xy || ro=1
175 [ $ro -ne 0 ]
176 notfound=0
177 stat /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
178 [ $notfound -ne 1 ]
179
180 lxc-stop -n lxc-test-automount -k
181 PHASE=cgroup-full:rw
182 echo "Starting phase $PHASE"
183 sed -i '/lxc.mount.auto/d' $config
184 echo "lxc.mount.auto = cgroup-full:rw proc:mixed sys:mixed" >> $config
185 lxc-start -n lxc-test-automount
186 pid=$(lxc-info -n lxc-test-automount -p -H)
187 cg=$(awk -F: '/freezer/ { print $3 }' /proc/$pid/cgroup)
188 notfound=0
189 stat /proc/$pid/root/sys/fs/cgroup/freezer || notfound=1
190 [ $notfound -ne 1 ]
191 notfound=0
192 stat /proc/$pid/root/sys/fs/cgroup/freezer/cgroup.procs || notfound=1
193 [ $notfound -ne 1 ]
194 ro=0
195 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/xx || ro=1
196 [ $ro -ne 1 ]
197 rmdir /proc/$pid/root/sys/fs/cgroup/freezer/xx
198 ro=0
199 mkdir /proc/$pid/root/sys/fs/cgroup/freezer/$cg/xx || ro=1
200 [ $ro -ne 1 ]
201 notfound=0
202 /proc/$pid/root/sys/fs/cgroup/freezer/$cg/cgroup.procs || notfound=1
203 [ $notfound -eq 1 ]
204
205 PHASE=done