]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/lxc-test-autostart
spelling: timeout
[mirror_lxc.git] / src / tests / lxc-test-autostart
CommitLineData
45794802
SG
1#!/bin/sh
2
3# lxc: linux Container library
4
5# Authors:
6# Stéphane Graber <stgraber@ubuntu.com>
7#
8# This is a test script for lxc-autostart
9
10# This library is free software; you can redistribute it and/or
11# modify it under the terms of the GNU Lesser General Public
12# License as published by the Free Software Foundation; either
13# version 2.1 of the License, or (at your option) any later version.
14
15# This library is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18# Lesser General Public License for more details.
19
20# You should have received a copy of the GNU Lesser General Public
21# License along with this library; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
24DONE=0
0815a592 25KNOWN_RELEASES="precise trusty xenial yakkety zesty"
45794802
SG
26cleanup() {
27 lxc-destroy -n $CONTAINER_NAME >/dev/null 2>&1 || true
28
29 if [ $DONE -eq 0 ]; then
30 echo "FAIL"
31 exit 1
32 fi
33 echo "PASS"
34}
35
fd2b7320
SG
36ARCH=i386
37if type dpkg >/dev/null 2>&1; then
38 ARCH=$(dpkg --print-architecture)
39fi
40
45794802
SG
41trap cleanup EXIT HUP INT TERM
42set -eu
43
44# Create a container
45CONTAINER_NAME=lxc-test-auto
64ea46c7
PHL
46
47# default release is trusty, or the systems release if recognized
48release=trusty
49if [ -f /etc/lsb-release ]; then
50 . /etc/lsb-release
51 rels=$(ubuntu-distro-info --supported 2>/dev/null) ||
52 rels="$KNOWN_RELEASES"
53 for r in $rels; do
54 [ "$DISTRIB_CODENAME" = "$r" ] && release="$r"
55 done
56fi
57
4b19d742 58lxc-create -t download -n $CONTAINER_NAME -B dir -- -d ubuntu -r $release -a $ARCH
7a96a068 59CONTAINER_PATH=$(dirname $(lxc-info -n $CONTAINER_NAME -c lxc.rootfs.path -H) | sed -e 's/dir://')
45794802
SG
60cp $CONTAINER_PATH/config $CONTAINER_PATH/config.bak
61
62# Ensure it's not in lxc-autostart
63lxc-autostart -L | grep -q $CONTAINER_NAME && \
64 (echo "Container shouldn't be auto-started" && exit 1)
65
66# Mark it as auto-started and re-check
67echo "lxc.start.auto = 1" >> $CONTAINER_PATH/config
68lxc-autostart -L | grep -q $CONTAINER_NAME || \
69 (echo "Container should be auto-started" && exit 1)
70
71# Put it in a test group and set a delay
72echo "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config
73echo "lxc.start.delay = 5" >> $CONTAINER_PATH/config
74
75# Check that everything looks good
76if [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then
77 echo "Invalid autostart setting" && exit 1
78fi
79
80# Start it
81lxc-autostart -g lxc-auto-test
82lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't start" && exit 1)
b7aa56b8 83sleep 5
45794802
SG
84
85# Restart it
86lxc-autostart -g lxc-auto-test -r
87lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't restart" && exit 1)
b7aa56b8 88sleep 5
45794802 89
c6b861ba
SG
90# When shutting down, the container calls sync. If the machine running
91# the test has a massive backlog, it can take minutes for the sync call to
92# finish, causing a test failure.
93# So try to reduce that by flushing everything to disk before we attempt
94# a container shutdown.
95sync
96
45794802 97# Shut it down
c2997f9e 98lxc-autostart -g lxc-auto-test -s -t 120
48356bbf 99lxc-wait -n $CONTAINER_NAME -t 120 -s STOPPED || (echo "Container didn't stop" && exit 1)
45794802
SG
100
101# Kill it
102lxc-autostart -g lxc-auto-test -k
103lxc-wait -n $CONTAINER_NAME -t 60 -s STOPPED || (echo "Container didn't die" && exit 1)
104
105DONE=1