/usr/bin/lxc-test-cloneconfig is in lxc-tests 2.0.7-0ubuntu1~16.04.2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | #!/bin/bash
# lxc: linux Container library
# Authors:
# Serge Hallyn <serge.hallyn@ubuntu.com>
#
# This is a test script for the lxc-user-nic program
# 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
set -e
s=`mktemp -d /tmp/lxctest-XXXXXX`
DONE=0
verify_unchanged_number() {
key=$1
desc=$2
n1=`grep ^$key $CONTAINER_PATH/config | wc -l`
n2=`grep ^$key $CONTAINER2_PATH/config | wc -l`
if [ $n1 -ne $n2 ]; then
echo "Test $testnum failed"
echo "unequal number of $desc"
echo "Original has $n1, clone has $n2"
false
fi
}
cleanup() {
lxc-destroy -n lxctestb || true
lxc-destroy -n lxctestb2 || true
rm -rf $s
[ $DONE -eq 1 ] && echo "PASS" || echo "FAIL"
}
verify_numnics() {
verify_unchanged_number lxc.network.type "network defs"
}
verify_hwaddr() {
verify_unchanged_number lxc.network.hwaddr "hwaddr defs"
grep ^lxc.network.hwaddr $CONTAINER_PATH/config | while read line; do
addr=`echo $line | awk -F= { print $2 }`
echo "looking for $addr in $CONTAINER2_PATH/config"
if grep -q $addr $CONTAINER2_PATH/config; then
echo "Test $testnum failed"
echo "hwaddr $addr was not changed"
false
fi
done
}
verify_hooks() {
verify_unchanged_number lxc.hook "hooks"
grep ^lxc.hook $CONTAINER_PATH/config | while read line; do
nline=${line/$CONTAINER_PATH/$CONTAINER2_PATH}
if ! grep -q "$nline" $CONTAINER2_PATH/config; then
echo "Test $testnum failed"
echo "Failed to find $nline in:"
cat $CONTAINER2_PATH/config
fi
done
}
trap cleanup EXIT
# Simple nic
cat > $s/1.conf << EOF
lxc.network.type = veth
lxc.network.link = lxcbr0
EOF
# Simple nic with hwaddr; verify hwaddr changed
cat > $s/2.conf << EOF
lxc.network.type = veth
lxc.network.link = lxcbr0
EOF
# No nics, but nic from include
cat > $s/1.include << EOF
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.hook.start = /bin/bash
EOF
cat > $s/3.conf << EOF
lxc.include = $s/1.include
EOF
# No nics, one clone hook in /bin
cat > $s/4.conf << EOF
lxc.hook.start = /bin/bash
EOF
# Figure out container dirname
# We need this in 5.conf
lxc-destroy -n lxctestb || true
lxc-create -t busybox -n lxctestb
CONTAINER_PATH=$(dirname $(lxc-info -n lxctestb -c lxc.rootfs -H))
lxc-destroy -n lxctestb
# No nics, one clone hook in $container
cat > $s/5.conf << EOF
lxc.hook.start = $CONTAINER_PATH/x1
EOF
CONTAINER2_PATH="${CONTAINER_PATH}2"
testnum=1
for f in $s/*.conf; do
echo "Test $testnum starting ($f)"
lxc-create -t busybox -f $f -n lxctestb
touch $CONTAINER_PATH/x1
lxc-copy -s -n lxctestb -N lxctestb2
# verify that # nics did not change
verify_numnics
# verify hwaddr, if any changed
verify_hwaddr
# verify hooks are correct
verify_hooks
lxc-destroy -n lxctestb2 || true
lxc-destroy -n lxctestb || true
testnum=$((testnum+1))
done
DONE=1
|