2007-12-11 21:20:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Get coverage of libvirtd's config-parsing code.
|
|
|
|
|
2008-12-01 15:04:28 +00:00
|
|
|
if test "$VERBOSE" = yes; then
|
|
|
|
set -x
|
|
|
|
libvirtd --version
|
|
|
|
fi
|
|
|
|
|
2007-12-11 21:20:13 +00:00
|
|
|
# Boilerplate code to set up a test directory, cd into it,
|
|
|
|
# and to ensure we remove it upon completion.
|
|
|
|
this_test_() { echo "./$0" | sed 's,.*/,,'; }
|
|
|
|
t_=$(this_test_)-$$
|
|
|
|
init_cwd_=$(pwd)
|
|
|
|
trap 'st=$?; d='"$t_"';
|
|
|
|
cd '"$init_cwd_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0
|
|
|
|
trap '(exit $?); exit $?' 1 2 13 15
|
|
|
|
mkdir "$t_" || fail=1
|
|
|
|
cd "$t_" || fail=1
|
|
|
|
|
2008-12-01 15:04:28 +00:00
|
|
|
conf="$abs_top_srcdir/qemud/libvirtd.conf"
|
|
|
|
|
|
|
|
# Ensure that each commented out PARAMETER = VALUE line has the expected form.
|
|
|
|
grep '[a-z_] *= *[^ ]' "$conf" | grep -vE '^#[a-z_]+ = ' \
|
|
|
|
&& { echo "$0: found unexpected lines (above) in $conf" 1>&2; exit 1; }
|
|
|
|
|
2007-12-11 21:20:13 +00:00
|
|
|
# Start with the sample libvirtd.conf file, uncommenting all real directives.
|
2008-12-01 15:04:28 +00:00
|
|
|
sed -n 's/^#\([^ #]\)/\1/p' "$conf" > tmp.conf
|
2007-12-11 21:20:13 +00:00
|
|
|
|
|
|
|
# Iterate through that list of directives, corrupting one RHS at a
|
|
|
|
# time and running libvirtd with the resulting config. Each libvirtd
|
|
|
|
# invocation must fail.
|
|
|
|
n=$(wc -l < tmp.conf)
|
|
|
|
i=1
|
|
|
|
while :; do
|
|
|
|
param_name=$(sed -n "$i"'s/ = .*//p' tmp.conf)
|
2008-12-01 15:04:28 +00:00
|
|
|
printf "testing with corrupted config: $param_name\n" 1>&2
|
2007-12-11 21:20:13 +00:00
|
|
|
rhs=$(sed -n "$i"'s/.* = \(.*\)/\1/p' tmp.conf)
|
|
|
|
f=in$i.conf
|
2008-12-01 15:04:28 +00:00
|
|
|
case $rhs in
|
|
|
|
# Change an RHS that starts with '"' or '[' to "3".
|
|
|
|
[[\"]*) sed "$i"'s/ = [["].*/ = 3/' tmp.conf > $f;;
|
|
|
|
# Change an RHS that starts with a digit to the string '"foo"'.
|
|
|
|
[0-9]*) sed "$i"'s/ = [0-9].*/ = "foo"/' tmp.conf > $f;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Run libvirtd, expecting it to fail.
|
2007-12-11 21:20:13 +00:00
|
|
|
libvirtd --config=$f 2> err && fail=1
|
2008-12-01 15:04:28 +00:00
|
|
|
|
2007-12-11 21:20:13 +00:00
|
|
|
case $rhs in
|
|
|
|
# '"'*) msg='should be a string';;
|
|
|
|
'"'*) msg='invalid type: got long; expected string';;
|
2008-12-01 15:04:28 +00:00
|
|
|
[0-9]*) msg='invalid type: got string; expected long';;
|
2007-12-11 21:20:13 +00:00
|
|
|
'['*) msg='must be a string or list of strings';;
|
|
|
|
*) echo "unexpected RHS: $rhs" 1>&2; fail=1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
test $i = $n && break
|
|
|
|
|
2008-12-12 16:11:50 +00:00
|
|
|
# Filter out some ignorable diagnostics.
|
|
|
|
sed \
|
|
|
|
-e '/^Cannot set group when not running as root$/d' \
|
|
|
|
-e '/^libnuma: Warning: .sys not mounted or no numa system/d' \
|
|
|
|
err > k && mv k err
|
2007-12-11 21:20:13 +00:00
|
|
|
|
|
|
|
printf '%s\n\n' "remoteReadConfigFile: $f: $param_name: $msg" > expected-err
|
|
|
|
diff -u expected-err err || fail=1
|
|
|
|
|
|
|
|
i=$(expr $i + 1)
|
|
|
|
done
|
|
|
|
|
|
|
|
# Run with the unmodified config file.
|
2008-12-01 15:04:28 +00:00
|
|
|
sleep_secs=2
|
|
|
|
printf "running libvirtd with a valid config file ($sleep_secs seconds)\n" 1>&2
|
2007-12-11 21:20:13 +00:00
|
|
|
libvirtd --config=tmp.conf > log 2>&1 & pid=$!
|
2008-12-01 15:04:28 +00:00
|
|
|
sleep $sleep_secs
|
2007-12-11 21:20:13 +00:00
|
|
|
kill $pid
|
|
|
|
|
|
|
|
# Expect an orderly shut-down and successful exit.
|
|
|
|
wait $pid || fail=1
|
|
|
|
|
|
|
|
# "cat log" would print this for non-root:
|
|
|
|
# Cannot set group when not running as root
|
|
|
|
# Shutting down on signal 15
|
|
|
|
# And normally, we'd require that output, but obviously
|
|
|
|
# it'd be different for root.
|
|
|
|
|
|
|
|
exit $fail
|