]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
add basic lxc-test-ubuntu (v3)
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 3 Oct 2013 03:30:31 +0000 (22:30 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 3 Oct 2013 17:23:07 +0000 (12:23 -0500)
Some features of lxc - networking and LSM configuration for instance -
are generally configured by the distro packages.  This program
tests the Ubuntu configuration.

changelog v2:
  Switch to lxc-info -i to detect ip address as stgraber suggested
  Don't look for 'expect' as I'm not using it yet.
changelog v3:
  Make sure to only read one ip address from container.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
configure.ac
src/tests/Makefile.am
src/tests/lxc-test-ubuntu [new file with mode: 0644]

index 92a4690dcad402a9ededeffc95de0b59f55b98d3..d7f2f03ae5c335e3f8406275b7defca87213a29a 100644 (file)
@@ -51,6 +51,7 @@ case $with_distro in
 esac
 AC_MSG_RESULT([$with_distro])
 AM_CONDITIONAL([HAVE_DEBIAN], [test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu"])
+AM_CONDITIONAL([DISTRO_UBUNTU], [test "x$with_distro" = "xubuntu"])
 
 # Detect the newuidmap tool (required for userns)
 AC_CHECK_PROG([NEWUIDMAP], [newuidmap], [newuidmap])
index d9d5da2915be594777c729cdede74e63bf323dbe..1814c4b5de5303a1f07ef99f4dc94e95fe6b6a54 100644 (file)
@@ -38,6 +38,10 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
 
 bin_SCRIPTS = lxc-test-usernic
 
+if DISTRO_UBUNTU
+bin_SCRIPTS += lxc-test-ubuntu
+endif
+
 endif
 
 EXTRA_DIST = \
diff --git a/src/tests/lxc-test-ubuntu b/src/tests/lxc-test-ubuntu
new file mode 100644 (file)
index 0000000..c6573c1
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+# lxc-test-ubuntu: some tests of ubuntu-specific features of lxc.
+# Some features of lxc - networking and LSM configuration for instance -
+# are generally configured by the distro packages.  This program
+# tests the Ubuntu configuration.
+
+# These require the ubuntu lxc package to be installed.
+
+# General lxc functionality testing does not belong here.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+set -e
+
+FAIL() {
+       echo -n "Failed " >&2
+       echo "$*" >&2
+       exit 1
+}
+
+# Only run on a normally configured ubuntu lxc system
+if [ ! -d /sys/class/net/lxcbr0 ]; then
+       echo "lxcbr0 is not configured."
+       exit 0
+fi
+if [ "$(id -u)" != "0" ]; then
+       echo "Must run as root."
+       exit 0
+fi
+if ! which host 2>&1 > /dev/null; then
+       echo "'host' program not found.  Please install bind9-host"
+       exit 0
+fi
+
+for template in ubuntu ubuntu-cloud; do
+       # need a different name for each container so dnsmasq doesn't
+       # mess us up with its caching
+       if which uuidgen 2>&1 > /dev/null; then
+               name=$(uuidgen)
+       else
+               name=lxc-test-$template
+       fi
+       lxc-create -t $template -n $name || FAIL "creating $template container"
+       lxc-start -n $name -d || FAIL "starting $template container"
+       lxc-wait -n $name -s RUNNING || FAIL "waiting for $template container to run"
+       for tries in `seq 1 20`; do
+               lxcip=`sudo lxc-info -i -n $name | awk -F: '{ print $2 }' | awk '{ print $1}' | head -1`
+               [ -z "$lxcip" ] || break
+               sleep 1
+       done
+       [ -n "$lxcip" ] || FAIL "to start networking in $template container"
+
+       ping -c 1 $lxcip || FAIL "to ping $template container"
+       # Check apparmor
+       lxcpid=`lxc-info -n $name -p | awk -F: '{ print $2 }' | awk '{ print $1}'`
+       aa=`cat /proc/$lxcpid/attr/current`
+       if [ "$aa" != "lxc-container-default-with-nesting (enforce)" ]; then
+               FAIL " to correctly set apparmor profile (profile is \"$aa\")"
+       fi
+       lxc-stop -n $name
+       lxc-destroy -n $name
+done
+
+exit 0