3 # lxc: linux Container library
6 # Serge Hallyn <serge.hallyn@ubuntu.com>
8 # This is a test script for the lxc-user-nic program
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.
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.
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
26 s
=`mktemp -d /tmp/lxctest-XXXXXX`
30 verify_unchanged_number
() {
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"
44 lxc-destroy
-n lxctestb || true
45 lxc-destroy
-n lxctestb2 || true
47 [ $DONE -eq 1 ] && echo "PASS" ||
echo "FAIL"
51 verify_unchanged_number lxc.net
.0.
type "network defs"
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"
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
82 cat > $s/1.conf
<< EOF
84 lxc.net.0.link = lxcbr0
87 # Simple nic with hwaddr; verify hwaddr changed
88 cat > $s/2.conf
<< EOF
90 lxc.net.0.link = lxcbr0
93 # No nics, but nic from include
94 cat > $s/1.include
<< EOF
96 lxc.net.0.link = lxcbr0
97 lxc.hook.start = /bin/bash
99 cat > $s/3.conf
<< EOF
100 lxc.include = $s/1.include
103 # No nics, one clone hook in /bin
104 cat > $s/4.conf
<< EOF
105 lxc.hook.start = /bin/bash
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
115 # No nics, one clone hook in $container
116 cat > $s/5.conf
<< EOF
117 lxc.hook.start = $CONTAINER_PATH/x1
120 CONTAINER2_PATH
="${CONTAINER_PATH}2"
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
130 # verify hwaddr, if any changed
132 # verify hooks are correct
134 lxc-destroy
-n lxctestb2 || true
135 lxc-destroy
-n lxctestb || true
136 testnum
=$
((testnum
+1))