[lxc-devel] [PATCH 1/1] add basic lxc-test-ubuntu

Stéphane Graber stgraber at ubuntu.com
Wed Oct 2 20:17:45 UTC 2013


On Wed, Oct 02, 2013 at 02:21:47PM -0500, Serge Hallyn wrote:
> Quoting Stéphane Graber (stgraber at ubuntu.com):
> > On Wed, Oct 02, 2013 at 01:11:12PM -0500, Serge Hallyn wrote:
> > > >From the file comments:
> > > 
> > > """
> > > 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.
> > > """
> > > 
> > > Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> > 
> > So I guess that means we'll need to get our packages to build with
> > --enable-tests and then find a way to get autopkgtest to use
> > lxc-test-ubuntu so we don't need to duplicate this in the packaging.
> 
> Should we have the tests moved into a separate  lxc-tests package?
> 
> (And while we're at it put lxc-init into its own package?)

Yeah, I think it'd be reasonable to add the following packages for 14.04:
 - lxc-init
 - lxc-tests
 - liblua5.X-lxc

As far as I know all the required dependencies to do that are in main,
so I'll try to remember to do that for the daily builds and then get
that included in the distro when 14.04 opens.

> 
> > Overall, looks good, just one comment inline further down.
> > 
> > > ---
> > >  configure.ac              |  1 +
> > >  src/tests/Makefile.am     |  4 +++
> > >  src/tests/lxc-test-ubuntu | 86 +++++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 91 insertions(+)
> > >  create mode 100644 src/tests/lxc-test-ubuntu
> > > 
> > > diff --git a/configure.ac b/configure.ac
> > > index 92a4690..d7f2f03 100644
> > > --- a/configure.ac
> > > +++ b/configure.ac
> > > @@ -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])
> > > diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
> > > index 479facc..ef65958 100644
> > > --- a/src/tests/Makefile.am
> > > +++ b/src/tests/Makefile.am
> > > @@ -36,6 +36,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
> > > index 0000000..efe9d0f
> > > --- /dev/null
> > > +++ b/src/tests/lxc-test-ubuntu
> > > @@ -0,0 +1,86 @@
> > > +#!/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
> > > +
> > > +haveexpect=1
> > > +if ! which expect 2>&1 > /dev/null; then
> > > +	echo "Expect is not installed;  skipping some tests"
> > > +	haveexpect=0
> > > +fi
> > > +
> > > +lxcbrip=`ifconfig lxcbr0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'`
> > > +
> > > +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 5`; do
> > > +		lxcip=`host $name $lxcbrip | tail -1 | awk '{print $NF}'`
> > > +		echo "$lxcip" | grep NXDOMAIN 2>&1 > /dev/null || break
> > > +		sleep 1
> > > +	done
> > > +	echo "$lxcip" | grep NXDOMAIN 2>&1 > /dev/null && FAIL "Networking failed to start"
> > 
> > ^ How about using lxc-info -i?
> 
> Oh...  I had tried lxc-list | grep $name | awk '{ print $3 }', but that
> was sometimes giving me wrong info (when I checked too soon after
> starting the container).  I can try lxc-info -i, but note that I'll
> still have to do the loop, presumably checking for -z "$lxcip",
> because of the usual "lxc-wait -s RUNNING != container is doing
> anything useful yet" problem.

Right, just loop on lxc-info -i -n $name until you get an IP.

> 
> > > +	ping -c 1 $lxcip || FAIL "$template container network is not up"
> > > +	# 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 "Apparmor status is incorrect (profile is \"$aa\")"
> > > +	fi
> > > +	lxc-stop -n $name
> > > +	lxc-destroy -n $name
> > > +done
> > > +
> > > +exit 0
> > > -- 
> > > 1.8.3.2
> > > 
> > > 
> > > ------------------------------------------------------------------------------
> > > October Webinars: Code for Performance
> > > Free Intel webinars can help you accelerate application performance.
> > > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
> > > the latest Intel processors and coprocessors. See abstracts and register >
> > > http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
> > > _______________________________________________
> > > Lxc-devel mailing list
> > > Lxc-devel at lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/lxc-devel
> > 
> > -- 
> > Stéphane Graber
> > Ubuntu developer
> > http://www.ubuntu.com
> 
> 

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20131002/1e1007eb/attachment.pgp>


More information about the lxc-devel mailing list