lxc-test-ubuntu revision 45997a79453b22713f06b6216767bd446703e439
176N/A#!/bin/sh
176N/A
176N/A# lxc-test-ubuntu: some tests of ubuntu-specific features of lxc.
176N/A# Some features of lxc - networking and LSM configuration for instance -
176N/A# are generally configured by the distro packages. This program
176N/A# tests the Ubuntu configuration.
176N/A
176N/A# These require the ubuntu lxc package to be installed.
176N/A
176N/A# General lxc functionality testing does not belong here.
176N/A
176N/A# This program is free software; you can redistribute it and/or
176N/A# modify it under the terms of the GNU Lesser General Public
176N/A# License as published by the Free Software Foundation; either
176N/A# version 2.1 of the License, or (at your option) any later version.
176N/A
176N/A# This library is distributed in the hope that it will be useful,
176N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
873N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
176N/A# Lesser General Public License for more details.
176N/A
176N/A# You should have received a copy of the GNU Lesser General Public
176N/A# License along with this library; if not, write to the Free Software
176N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
873N/A
176N/Aset -e
176N/A
176N/AFAIL() {
176N/A echo -n "Failed " >&2
176N/A echo "$*" >&2
176N/A exit 1
176N/A}
176N/A
176N/A# Only run on a normally configured ubuntu lxc system
176N/Aif [ ! -d /sys/class/net/lxcbr0 ]; then
176N/A echo "lxcbr0 is not configured."
176N/A exit 1
176N/Afi
176N/Aif [ "$(id -u)" != "0" ]; then
176N/A echo "ERROR: Must run as root."
176N/A exit 1
176N/Afi
176N/A
176N/Afor template in ubuntu ubuntu-cloud; do
176N/A # need a different name for each container so dnsmasq doesn't
176N/A # mess us up with its caching
176N/A if which uuidgen 2>&1 > /dev/null; then
176N/A name=$(uuidgen)
176N/A else
176N/A name=lxc-test-$template
176N/A fi
176N/A
176N/A lxc-create -t $template -n $name || FAIL "creating $template container"
176N/A lxc-start -n $name -d || FAIL "starting $template container"
176N/A lxc-wait -n $name -s RUNNING || FAIL "waiting for $template container to run"
176N/A
176N/A for tries in `seq 1 20`; do
176N/A lxcip=$(lxc-info -i -n $name -H | head -n 1)
176N/A [ -z "$lxcip" ] || break
176N/A sleep 1
176N/A done
176N/A [ -n "$lxcip" ] || FAIL "to start networking in $template container"
176N/A
176N/A if echo "${lxcip}" | grep -q ":"; then
176N/A ping6 -c 1 $lxcip || FAIL "to ping $template container"
176N/A else
176N/A ping -c 1 $lxcip || FAIL "to ping $template container"
176N/A fi
176N/A
176N/A # 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