lxc-test-ubuntu revision 025f59ab98217b7e9caf6d3ac7e910853d95f621
2N/A#!/bin/sh
2N/A
2N/A# lxc-test-ubuntu: some tests of ubuntu-specific features of lxc.
2N/A# Some features of lxc - networking and LSM configuration for instance -
2N/A# are generally configured by the distro packages. This program
2N/A# tests the Ubuntu configuration.
2N/A
2N/A# These require the ubuntu lxc package to be installed.
2N/A
2N/A# General lxc functionality testing does not belong here.
2N/A
2N/A# This program is free software; you can redistribute it and/or
2N/A# modify it under the terms of the GNU Lesser General Public
2N/A# License as published by the Free Software Foundation; either
2N/A# version 2.1 of the License, or (at your option) any later version.
2N/A
2N/A# This library is distributed in the hope that it will be useful,
2N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2N/A# Lesser General Public License for more details.
58N/A
2N/A# You should have received a copy of the GNU Lesser General Public
2N/A# License along with this library; if not, write to the Free Software
2N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2N/A
23N/A
23N/Aset -e
23N/A
23N/AFAIL() {
23N/A echo -n "Failed " >&2
32N/A echo "$*" >&2
32N/A exit 1
32N/A}
34N/A
32N/A# Only run on a normally configured ubuntu lxc system
34N/Aif [ ! -d /sys/class/net/lxcbr0 ]; then
32N/A echo "lxcbr0 is not configured."
32N/A exit 0
58N/Afi
32N/Aif [ "$(id -u)" != "0" ]; then
225N/A echo "Must run as root."
225N/A exit 0
225N/Afi
225N/Aif ! which host 2>&1 > /dev/null; then
225N/A echo "'host' program not found. Please install bind9-host"
225N/A exit 0
225N/Afi
225N/A
225N/Afor template in ubuntu ubuntu-cloud; do
225N/A # need a different name for each container so dnsmasq doesn't
2N/A # mess us up with its caching
38N/A if which uuidgen 2>&1 > /dev/null; then
38N/A name=$(uuidgen)
38N/A else
38N/A name=lxc-test-$template
38N/A fi
38N/A lxc-create -t $template -n $name || FAIL "creating $template container"
38N/A lxc-start -n $name -d || FAIL "starting $template container"
83N/A lxc-wait -n $name -s RUNNING || FAIL "waiting for $template container to run"
83N/A for tries in `seq 1 20`; do
99N/A lxcip=`sudo lxc-info -i -n $name | awk -F: '{ print $2 }' | awk '{ print $1}' | head -1`
2N/A [ -z "$lxcip" ] || break
92N/A sleep 1
92N/A done
92N/A [ -n "$lxcip" ] || FAIL "to start networking in $template container"
2N/A
2N/A ping -c 1 $lxcip || FAIL "to ping $template container"
313N/A # Check apparmor
2N/A lxcpid=`lxc-info -n $name -p | awk -F: '{ print $2 }' | awk '{ print $1}'`
34N/A aa=`cat /proc/$lxcpid/attr/current`
2N/A if [ "$aa" != "lxc-container-default-with-nesting (enforce)" ]; then
313N/A FAIL " to correctly set apparmor profile (profile is \"$aa\")"
313N/A fi
313N/A lxc-stop -n $name
34N/A lxc-destroy -n $name
2N/Adone
313N/A
53N/Aexit 0
34N/A