File: lxc-test-autostart

package info (click to toggle)
lxc 1%3A1.0.6-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 4,800 kB
  • sloc: ansic: 33,735; sh: 11,868; python: 1,223; makefile: 734
file content (92 lines) | stat: -rwxr-xr-x 2,920 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh

# lxc: linux Container library

# Authors:
# St├ęphane Graber <stgraber@ubuntu.com>
#
# This is a test script for lxc-autostart

# This library 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

DONE=0
cleanup() {
	lxc-destroy -n $CONTAINER_NAME >/dev/null 2>&1 || true

	if [ $DONE -eq 0 ]; then
		echo "FAIL"
		exit 1
	fi
	echo "PASS"
}

ARCH=i386
if type dpkg >/dev/null 2>&1; then
	ARCH=$(dpkg --print-architecture)
fi

trap cleanup EXIT HUP INT TERM
set -eu

# Create a container
CONTAINER_NAME=lxc-test-auto
lxc-create -t download -n $CONTAINER_NAME -- -d ubuntu -r trusty -a $ARCH
CONTAINER_PATH=$(dirname $(lxc-info -n $CONTAINER_NAME -c lxc.rootfs -H))
cp $CONTAINER_PATH/config $CONTAINER_PATH/config.bak

# Ensure it's not in lxc-autostart
lxc-autostart -L | grep -q $CONTAINER_NAME && \
    (echo "Container shouldn't be auto-started" && exit 1)

# Mark it as auto-started and re-check
echo "lxc.start.auto = 1" >> $CONTAINER_PATH/config
lxc-autostart -L | grep -q $CONTAINER_NAME || \
    (echo "Container should be auto-started" && exit 1)

# Put it in a test group and set a delay
echo "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config
echo "lxc.start.delay = 5" >> $CONTAINER_PATH/config

# Check that everything looks good
if [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then
    echo "Invalid autostart setting" && exit 1
fi

# Start it
lxc-autostart -g lxc-auto-test
lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't start" && exit 1)
sleep 5

# Restart it
lxc-autostart -g lxc-auto-test -r
lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't restart" && exit 1)
sleep 5

# When shutting down, the container calls sync. If the machine running
# the test has a massive backlog, it can take minutes for the sync call to
# finish, causing a test failure.
# So try to reduce that by flushing everything to disk before we attempt
# a container shutdown.
sync

# Shut it down
lxc-autostart -g lxc-auto-test -s -t 120
lxc-wait -n $CONTAINER_NAME -t 120 -s STOPPED || (echo "Container didn't stop" && exit 1)

# Kill it
lxc-autostart -g lxc-auto-test -k
lxc-wait -n $CONTAINER_NAME -t 60 -s STOPPED || (echo "Container didn't die" && exit 1)

DONE=1