Commit 2bee4565 authored by Antonio Terceiro's avatar Antonio Terceiro

lxc/create-testbed: avoid cleaning up valid containers

Sometimes, the creation of a new testbed fails for various reasons (some
essential package) breaks debootstrap, or something fails to download.
Those failures are already handled by autopkgtest-build-lxc: the old
container is only replaced by the new one in case of success.  In that
case, it's OK for debci to just keep using the older container since it
will be upgraded before running any tests anyway.

The only case where we indeed want to remove containers is when the
customizations needed by debci are not successfully applied.
parent 338a286d
......@@ -75,25 +75,44 @@ container=autopkgtest-${debci_suite}-${debci_arch}
completed=no
container_exists() {
lxc-ls -f | awk "BEGIN { rc = 1 } { if (\$1 == \"$1\") { rc = 0 } } END { exit rc }"
}
container_running() {
lxc-ls -f | awk "BEGIN { rc = 1 } { if (\$1 == \"$1\" && \$2 == \"RUNNING\") { rc = 0 } } END { exit rc }"
}
cleanup_container() {
local c
c="$1"
if container_exists "$c"; then
# is container $c running?
if container_running "$c"; then
lxc-stop --name="$c"
fi
lxc-destroy --name="$c"
fi
}
cleanup() {
if [ "$completed" = yes ]; then return; fi
for c in $container.new $container; do
# does container $c exist?
if lxc-ls -f | awk "BEGIN { rc = 1 } { if (\$1 == \"$c\") { rc = 0 } } END { exit rc }"; then
# is container $c running?
if lxc-ls -f | awk "BEGIN { rc = 1 } { if (\$1 == \"$c\" && \$2 == \"RUNNING\") { rc = 0 } } END { exit rc }"; then
lxc-stop --name="$c"
fi
lxc-destroy --name="$c"
return
fi
done
# autopkgtest-build-lxc can leave this behind in some cases
cleanup_container "${container}.new"
if [ "$created" = yes ]; then
# autopkgtest-build-lxc succeeded, but our customization didn't. we can't
# use the container in such state
cleanup_container "$container"
fi
}
trap cleanup EXIT
created=no
autopkgtest-build-lxc $distro $debci_suite $debci_arch
created=yes
LXC_PATH=$(lxc-config lxc.lxcpath) || LXC_PATH=/var/lib/lxc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment