]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/lxc-test-cloneconfig
tests: use busybox in lxc-test-usernic.in
[mirror_lxc.git] / src / tests / lxc-test-cloneconfig
1 #!/bin/bash
2
3 # lxc: linux Container library
4
5 # Authors:
6 # Serge Hallyn <serge.hallyn@ubuntu.com>
7 #
8 # This is a test script for the lxc-user-nic program
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
24 set -e
25
26 s=`mktemp -d /tmp/lxctest-XXXXXX`
27
28 DONE=0
29
30 verify_unchanged_number() {
31 key=$1
32 desc=$2
33 n1=`grep ^$key $CONTAINER_PATH/config | wc -l`
34 n2=`grep ^$key $CONTAINER2_PATH/config | wc -l`
35 if [ $n1 -ne $n2 ]; then
36 echo "Test $testnum failed"
37 echo "unequal number of $desc"
38 echo "Original has $n1, clone has $n2"
39 false
40 fi
41 }
42
43 cleanup() {
44 lxc-destroy -n lxctestb || true
45 lxc-destroy -n lxctestb2 || true
46 rm -rf $s
47 [ $DONE -eq 1 ] && echo "PASS" || echo "FAIL"
48 }
49
50 verify_numnics() {
51 verify_unchanged_number lxc.net.0.type "network defs"
52 }
53
54 verify_hwaddr() {
55 verify_unchanged_number lxc.net.0.hwaddr "hwaddr defs"
56 grep ^lxc.net.0.hwaddr $CONTAINER_PATH/config | while read line; do
57 addr=`echo $line | awk -F= { print $2 }`
58 echo "looking for $addr in $CONTAINER2_PATH/config"
59 if grep -q $addr $CONTAINER2_PATH/config; then
60 echo "Test $testnum failed"
61 echo "hwaddr $addr was not changed"
62 false
63 fi
64 done
65 }
66
67 verify_hooks() {
68 verify_unchanged_number lxc.hook "hooks"
69 grep ^lxc.hook $CONTAINER_PATH/config | while read line; do
70 nline=${line/$CONTAINER_PATH/$CONTAINER2_PATH}
71 if ! grep -q "$nline" $CONTAINER2_PATH/config; then
72 echo "Test $testnum failed"
73 echo "Failed to find $nline in:"
74 cat $CONTAINER2_PATH/config
75 fi
76 done
77 }
78
79 trap cleanup EXIT
80
81 # Simple nic
82 cat > $s/1.conf << EOF
83 lxc.net.0.type = veth
84 lxc.net.0.link = lxcbr0
85 EOF
86
87 # Simple nic with hwaddr; verify hwaddr changed
88 cat > $s/2.conf << EOF
89 lxc.net.0.type = veth
90 lxc.net.0.link = lxcbr0
91 EOF
92
93 # No nics, but nic from include
94 cat > $s/1.include << EOF
95 lxc.net.0.type = veth
96 lxc.net.0.link = lxcbr0
97 lxc.hook.start = /bin/bash
98 EOF
99 cat > $s/3.conf << EOF
100 lxc.include = $s/1.include
101 EOF
102
103 # No nics, one clone hook in /bin
104 cat > $s/4.conf << EOF
105 lxc.hook.start = /bin/bash
106 EOF
107
108 # Figure out container dirname
109 # We need this in 5.conf
110 lxc-destroy -n lxctestb || true
111 lxc-create -t busybox -n lxctestb -B dir
112 CONTAINER_PATH=$(dirname $(lxc-info -n lxctestb -c lxc.rootfs.path -H) | sed 's/dir://')
113 lxc-destroy -n lxctestb
114
115 # No nics, one clone hook in $container
116 cat > $s/5.conf << EOF
117 lxc.hook.start = $CONTAINER_PATH/x1
118 EOF
119
120 CONTAINER2_PATH="${CONTAINER_PATH}2"
121
122 testnum=1
123 for f in $s/*.conf; do
124 echo "Test $testnum starting ($f)"
125 lxc-create -t busybox -f $f -n lxctestb
126 touch $CONTAINER_PATH/x1
127 lxc-copy -s -n lxctestb -N lxctestb2
128 # verify that # nics did not change
129 verify_numnics
130 # verify hwaddr, if any changed
131 verify_hwaddr
132 # verify hooks are correct
133 verify_hooks
134 lxc-destroy -n lxctestb2 || true
135 lxc-destroy -n lxctestb || true
136 testnum=$((testnum+1))
137 done
138
139 DONE=1