Debian Codegraph @

debian/tests/lxc-tests

raw
1 #!/bin/sh
2 # Environment
3
4 if [ ! -d /sys/fs/cgroup/memory ]; then
5 if [ ! "$AUTOPKGTEST_REBOOT_MARK" = "lxc-prepare" ]; then
6 sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/ s/GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 cgroup_enable=memory swapaccount=1"/' /etc/default/grub
7 update-grub2
8 /tmp/autopkgtest-reboot lxc-prepare
9 fi
10 fi
11
12 set -eu
13
14 if [ -f /run/container_type ] || (type systemd-detect-virt >/dev/null 2>&1 && systemd-detect-virt --container >/dev/null 2>&1); then
15 # If running tests within a container, we need to tweak a couple things first.
16 # Running the tests within a VM is preferred, but isn't currently possible on ci.d.n.
17 # This seems to be a good compromise to greatly expand lxc's autopkgtests.
18
19 # First, 'disable' apparmor in the autopkgtest container, otherwise lxc gets tripped
20 # up. Ideally we would mount /sys/kernel/security into the container, which would
21 # then allow lxc to properly get apparmor information. But we then run into issues
22 # where lxc within the container attempts to generate/change apparmor profiles but
23 # fails. So instead, act as if there was no apparmor support.
24 mount -o bind /dev/null /sys/module/apparmor/parameters/enabled
25
26 # Allow lxc-net to start in the container. The service definition prevents its start
27 # if running in a lxc container, but we need it to create the lxcbr0 network interface
28 # that is expected by the tests.
29 sed -i -e 's/ConditionVirtualization=!lxc//' /usr/lib/systemd/system/lxc-net.service
30 systemctl daemon-reload
31 fi
32
33 unset TMPDIR
34
35 TEST_PASS=0
36 TEST_FAIL=0
37 TEST_IGNORED=0
38
39 IGNORE_LIST=""
40
41 # Helper functions
42 pass() {
43 TEST_PASS=$((${TEST_PASS}+1))
44 echo "PASS: $1"
45 }
46
47 fail() {
48 for entry in $IGNORE_LIST; do
49 if [ "$entry" = "$2" ]; then
50 ignore $1
51 return
52 fi
53 done
54
55 TEST_FAIL=$((${TEST_FAIL}+1))
56 echo "FAIL: $1"
57
58 if [ -f "$3" ]; then
59 echo "---"
60 cat $3
61 echo "---"
62 fi
63 }
64
65 ignore() {
66 TEST_IGNORED=$((${TEST_IGNORED}+1))
67 echo "IGNORED: $*"
68 }
69
70 summary() {
71 echo ""
72 echo "SUMMARY: pass=$TEST_PASS, fail=$TEST_FAIL, ignored=$TEST_IGNORED"
73 }
74
75 # prepare network features, they are disabled by default on Debian
76 # but we want to test them
77 echo USE_LXC_BRIDGE=true > /etc/default/lxc-net
78 service lxc-net restart
79
80 cat <<EOF >/etc/lxc/default.conf
81 lxc.net.0.type = veth
82 lxc.net.0.link = lxcbr0
83 lxc.net.0.flags = up
84 lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
85 EOF
86
87 modprobe overlay || true
88
89 # since gnupg2 and dirmngr fetching keys after bootup fails in the first seconds
90 # most probably this is due to entropy in the VM, so lets just wait
91 sleep 30
92
93 # The actual tests
94 ## Default testsuite
95 for testbin in /usr/bin/lxc-test-*; do
96 STRING="lxc-tests: $testbin"
97 [ ! -x "$testbin" ] && continue
98
99 # Some tests can't be run standalone
100 [ "$testbin" = "/usr/bin/lxc-test-may-control" ] && continue
101
102 # Skip some tests when running in a container
103 if [ -f /run/container_type ] || (type systemd-detect-virt >/dev/null 2>&1 && systemd-detect-virt --container >/dev/null 2>&1); then
104 [ "$testbin" = "/usr/bin/lxc-test-apparmor" ] && \
105 ignore "$STRING" && continue
106
107 [ "$testbin" = "/usr/bin/lxc-test-apparmor-mount" ] && \
108 ignore "$STRING" && continue
109
110 [ "$testbin" = "/usr/bin/lxc-test-device-add-remove" ] && \
111 ignore "$STRING" && continue
112
113 [ "$testbin" = "/usr/bin/lxc-test-reboot" ] && \
114 ignore "$STRING" && continue
115
116 # This test fails in the salsa CI runners, but it's hard to
117 # automatically determine if we're in a CI runner or not, so
118 # always skip it for now when running in a container.
119 [ "$testbin" = "/usr/bin/lxc-test-cgpath" ] && \
120 ignore "$STRING" && continue
121
122 # openvswitch seems to hang attempting to setup a bridge
123 # within a container.
124 [ "$testbin" = "/usr/bin/lxc-test-usernic-2" ] && \
125 ignore "$STRING" && continue
126
127 # The following two tests only work in privileged containers,
128 # but randomly fail when run on ci.d.n. I've not been able to
129 # reproduce locally, so for now don't run them in a container.
130 [ "$testbin" = "/usr/bin/lxc-test-unpriv" ] && \
131 ignore "$STRING" && continue
132
133 [ "$testbin" = "/usr/bin/lxc-test-usernic" ] && \
134 ignore "$STRING" && continue
135 fi
136
137 # Skip some tests on old kernels
138 if [ ! -f /proc/self/uid_map ] || [ ! -f /etc/subuid ] || \
139 [ ! -f /etc/subgid ]; then
140 [ "$testbin" = "/usr/bin/lxc-test-unpriv" ] && \
141 ignore "$STRING" && continue
142
143 [ "$testbin" = "/usr/bin/lxc-test-usernic" ] && \
144 ignore "$STRING" && continue
145 fi
146
147 # Skip overlay tests when kernel has no overlay support
148 if ! grep -q overlay /proc/filesystems; then
149 [ "$testbin" = "/usr/bin/lxc-test-cloneconfig" ] && \
150 ignore "$STRING" && continue
151 fi
152
153 OUT=$(mktemp)
154 $testbin >$OUT 2>&1 && pass "$STRING" || fail "$STRING" "$testbin" "$OUT"
155 rm $OUT
156 done
157
158 # Test summary
159 summary
160
161 [ "$TEST_FAIL" != "0" ] && exit 1
162
163 exit 0