]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/lxc-test-ubuntu
tests: fix get_item tests
[mirror_lxc.git] / src / tests / lxc-test-ubuntu
1 #!/bin/sh
2
3 # lxc-test-ubuntu: some tests of ubuntu-specific features of lxc.
4 # Some features of lxc - networking and LSM configuration for instance -
5 # are generally configured by the distro packages. This program
6 # tests the Ubuntu configuration.
7
8 # These require the ubuntu lxc package to be installed.
9
10 # General lxc functionality testing does not belong here.
11
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU Lesser General Public
14 # License as published by the Free Software Foundation; either
15 # version 2.1 of the License, or (at your option) any later version.
16
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Lesser General Public License for more details.
21
22 # You should have received a copy of the GNU Lesser General Public
23 # License along with this library; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
26 set -e
27
28 FAIL() {
29 echo -n "Failed " >&2
30 echo "$*" >&2
31 exit 1
32 }
33
34 # Only run on a normally configured ubuntu lxc system
35 if [ ! -d /sys/class/net/lxcbr0 ]; then
36 echo "lxcbr0 is not configured."
37 exit 1
38 fi
39 if [ "$(id -u)" != "0" ]; then
40 echo "ERROR: Must run as root."
41 exit 1
42 fi
43
44 for template in ubuntu ubuntu-cloud; do
45 # need a different name for each container so dnsmasq doesn't
46 # mess us up with its caching
47 if which uuidgen 2>&1 > /dev/null; then
48 name=$(uuidgen)
49 else
50 name=lxc-test-$template
51 fi
52
53 lxc-create -t $template -n $name || FAIL "creating $template container"
54 lxc-start -n $name -d || FAIL "starting $template container"
55 lxc-wait -n $name -s RUNNING || FAIL "waiting for $template container to run"
56
57 for tries in `seq 1 20`; do
58 lxcip=$(lxc-info -i -n $name -H | head -n 1)
59 [ -z "$lxcip" ] || break
60 sleep 1
61 done
62 [ -n "$lxcip" ] || FAIL "to start networking in $template container"
63
64 ping -c 1 $lxcip || FAIL "to ping $template container"
65 # Check apparmor
66 lxcpid=`lxc-info -n $name -p -H`
67 aa=`cat /proc/$lxcpid/attr/current`
68 if [ "$aa" != "lxc-container-default-with-nesting (enforce)" -a \
69 "$aa" != "lxc-container-default-cgns (enforce)" -a \
70 "$aa" != "lxc-container-default (enforce)" ]; then
71 FAIL " to correctly set apparmor profile (profile is \"$aa\")"
72 fi
73 lxc-stop -n $name -k
74 lxc-destroy -n $name
75 done
76
77 exit 0