lxc-test-ubuntu revision 45997a79453b22713f06b6216767bd446703e439
dae00a0203dc968ada4b4241dfbcd937974140e2vboxsync#!/bin/sh
0a987c833e0517dc4efefc14229d96dec62e0965vboxsync
2dfda90468c5653309a3e93423313e0ec0e627a2vboxsync# lxc-test-ubuntu: some tests of ubuntu-specific features of lxc.
2dfda90468c5653309a3e93423313e0ec0e627a2vboxsync# Some features of lxc - networking and LSM configuration for instance -
2dfda90468c5653309a3e93423313e0ec0e627a2vboxsync# are generally configured by the distro packages. This program
cb172d105a87f41489b1553fbd99ec97932609ffvboxsync# tests the Ubuntu configuration.
965aac4e5f942cc0ff08644b8de0394e0712cd79vboxsync
965aac4e5f942cc0ff08644b8de0394e0712cd79vboxsync# These require the ubuntu lxc package to be installed.
965aac4e5f942cc0ff08644b8de0394e0712cd79vboxsync
965aac4e5f942cc0ff08644b8de0394e0712cd79vboxsync# General lxc functionality testing does not belong here.
e42e8ed08e4b2bd2ebb1b160fea921788e1a54a5vboxsync
1912cc6de0895859536e62695e7a5b7810a07f1fvboxsync# This program is free software; you can redistribute it and/or
3baadeafd9922582dad9b32431362e6296417dd8vboxsync# modify it under the terms of the GNU Lesser General Public
00e8340a60924420ea08462899c5815a685c78b2vboxsync# License as published by the Free Software Foundation; either
2da06c2eb59b63010b1998799c719272c0be0f99vboxsync# version 2.1 of the License, or (at your option) any later version.
0700964a23df46033c8149ee10ce643cd3677061vboxsync
0700964a23df46033c8149ee10ce643cd3677061vboxsync# This library is distributed in the hope that it will be useful,
868d6eb6308a75913b9c494558832732e7539b0evboxsync# but WITHOUT ANY WARRANTY; without even the implied warranty of
868d6eb6308a75913b9c494558832732e7539b0evboxsync# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
868d6eb6308a75913b9c494558832732e7539b0evboxsync# Lesser General Public License for more details.
868d6eb6308a75913b9c494558832732e7539b0evboxsync
# 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 1
fi
if [ "$(id -u)" != "0" ]; then
echo "ERROR: Must run as root."
exit 1
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=$(lxc-info -i -n $name -H | head -n 1)
[ -z "$lxcip" ] || break
sleep 1
done
[ -n "$lxcip" ] || FAIL "to start networking in $template container"
if echo "${lxcip}" | grep -q ":"; then
ping6 -c 1 $lxcip || FAIL "to ping $template container"
else
ping -c 1 $lxcip || FAIL "to ping $template container"
fi
# Check apparmor
lxcpid=`lxc-info -n $name -p -H`
aa=`cat /proc/$lxcpid/attr/current`
if [ "$aa" != "lxc-container-default-with-nesting (enforce)" -a \
"$aa" != "lxc-container-default-cgns (enforce)" -a \
"$aa" != "lxc-container-default (enforce)" ]; then
FAIL " to correctly set apparmor profile (profile is \"$aa\")"
fi
lxc-stop -n $name -k
lxc-destroy -n $name
done
exit 0