lxc-test-autostart revision b7aa56b85ca96f321ef6aadb60a28f8c16bec44d
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# lxc: linux Container library
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Stéphane Graber <stgraber@ubuntu.com>
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# This is a test script for lxc-autostart
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# This library is free software; you can redistribute it and/or
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# modify it under the terms of the GNU Lesser General Public
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# License as published by the Free Software Foundation; either
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# version 2.1 of the License, or (at your option) any later version.
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# This library is distributed in the hope that it will be useful,
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# but WITHOUT ANY WARRANTY; without even the implied warranty of
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Lesser General Public License for more details.
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# You should have received a copy of the GNU Lesser General Public
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# License along with this library; if not, write to the Free Software
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber lxc-destroy -n $CONTAINER_NAME >/dev/null 2>&1 || true
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber if [ $DONE -eq 0 ]; then
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Create a container
fd2b7320e3562450111b5adaabcb7f6b9c8d9d13Stéphane Graberlxc-create -t download -n $CONTAINER_NAME -- -d ubuntu -r trusty -a $ARCH
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane GraberCONTAINER_PATH=$(dirname $(lxc-info -n $CONTAINER_NAME -c lxc.rootfs -H))
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Grabercp $CONTAINER_PATH/config $CONTAINER_PATH/config.bak
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Ensure it's not in lxc-autostart
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberlxc-autostart -L | grep -q $CONTAINER_NAME && \
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber (echo "Container shouldn't be auto-started" && exit 1)
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Mark it as auto-started and re-check
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberecho "lxc.start.auto = 1" >> $CONTAINER_PATH/config
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberlxc-autostart -L | grep -q $CONTAINER_NAME || \
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber (echo "Container should be auto-started" && exit 1)
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Put it in a test group and set a delay
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberecho "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberecho "lxc.start.delay = 5" >> $CONTAINER_PATH/config
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Check that everything looks good
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberif [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberlxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't start" && exit 1)
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberlxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't restart" && exit 1)
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graber# Shut it down
48356bbfdf8f277c5fe65287d76b7d891ca40964Stéphane Graberlxc-wait -n $CONTAINER_NAME -t 120 -s STOPPED || (echo "Container didn't stop" && exit 1)
45794802f13e5db18b5d7acb45169e1f4e8b70b2Stéphane Graberlxc-wait -n $CONTAINER_NAME -t 60 -s STOPPED || (echo "Container didn't die" && exit 1)