Here's a rebased patch from a month or two ago. It's only fixing and adding tests, so I'll commit it momentarily. Dan Berrange noticed that daemon-conf could interfere with existing domains, so the latter patch below makes it use the new log-setting and unix_sock_dir-setting config options as well as the option to select a per-test PID file. >From efee209a2adf6f2478de26fe25c73bd4c38316ea Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@xxxxxxxxxx> Date: Thu, 8 Jan 2009 20:18:17 +0100 Subject: [PATCH 1/2] add two tests * tests/libvirtd-pool: New file. Exercise the new unix_sock_dir option * tests/libvirtd-fail: New file. * tests/Makefile.am (test_scripts): Add libvirtd-fail and libvirtd-pool. *** empty log message *** --- tests/Makefile.am | 2 + tests/libvirtd-fail | 21 +++++++++++++++++ tests/libvirtd-pool | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 0 deletions(-) create mode 100755 tests/libvirtd-fail create mode 100755 tests/libvirtd-pool diff --git a/tests/Makefile.am b/tests/Makefile.am index b40785f..11ffe76 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -81,7 +81,9 @@ test_scripts += \ daemon-conf \ define-dev-segfault \ int-overflow \ + libvirtd-fail \ libvirtd-net-persist \ + libvirtd-pool \ read-bufsiz \ read-non-seekable \ start \ diff --git a/tests/libvirtd-fail b/tests/libvirtd-fail new file mode 100755 index 0000000..92b82c4 --- /dev/null +++ b/tests/libvirtd-fail @@ -0,0 +1,21 @@ +#!/bin/sh +# Ensure that libvirt fails when given nonexistent --config=FILE + +if test "$VERBOSE" = yes; then + set -x + libvirtd --version +fi + +test -z "$srcdir" && srcdir=$(pwd) +test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. +. "$srcdir/test-lib.sh" + +fail=0 + +libvirtd --config=no-such-file > log 2>&1 && fail=1 +cat <<\EOF > exp +Failed to open file 'no-such-file': No such file or directory +EOF + +compare exp log || fail=1 +exit $fail diff --git a/tests/libvirtd-pool b/tests/libvirtd-pool new file mode 100755 index 0000000..370f3b1 --- /dev/null +++ b/tests/libvirtd-pool @@ -0,0 +1,63 @@ +#!/bin/sh +# Get coverage of libvirtd's config-parsing code. + +if test "$VERBOSE" = yes; then + set -x + libvirtd --version + virsh --version +fi + +test -z "$srcdir" && srcdir=$(pwd) +test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. +. "$srcdir/test-lib.sh" + +fail=0 + +pwd=$(pwd) || fail=1 +sock_dir="$pwd" +cat > conf <<EOF || fail=1 +unix_sock_dir = "$sock_dir" +log_outputs = "3:file:$pwd/log" +EOF + +libvirtd --config=conf > libvirtd-log 2>&1 & pid=$! +sleep 1 + +url="qemu:///session?socket=@$sock_dir/libvirt-sock" +virsh --connect "$url" \ + pool-define-as P dir src-host /src/path /src/dev S /target-path > out 2>&1 \ + || fail=1 +virsh --connect "$url" pool-dumpxml P >> out 2>&1 || fail=1 + +# remove random uuid +sed 's/<uuid>.*/-/' out > k && mv k out || fail=1 + +kill $pid + +cat <<EOF > pool-list-exp +Pool P defined + +<pool type='dir'> + <name>P</name> + - + <capacity>0</capacity> + <allocation>0</allocation> + <available>0</available> + <source> + </source> + <target> + <path>/target-path</path> + <permissions> + <mode>0700</mode> + <owner>500</owner> + <group>500</group> + </permissions> + </target> +</pool> + +EOF + +compare pool-list-exp out || fail=1 +compare /dev/null libvirtd-log || fail=1 + +exit $fail -- 1.6.2.rc1.285.gc5f54 >From e94ab9fcb3e5e1c180308d638956cfc05078df1e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@xxxxxxxxxx> Date: Tue, 13 Jan 2009 10:54:41 +0100 Subject: [PATCH 2/2] tests: further isolate a test that runs libvirtd * tests/daemon-conf: Specify a non-default socket directory. Specify test-specific log directory and pid file, too. --- tests/daemon-conf | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/tests/daemon-conf b/tests/daemon-conf index 7a53eff..a5e86ae 100755 --- a/tests/daemon-conf +++ b/tests/daemon-conf @@ -67,8 +67,18 @@ done # Run with the unmodified config file. sleep_secs=2 + +# Be careful to specify a non-default socket directory: +sed 's,^unix_sock_dir.*,unix_sock_dir="'"$(pwd)"'",' tmp.conf > k || fail=1 +mv k tmp.conf || fail=1 + +# Also, specify a test-specific log directory: +sed 's,^log_outputs.*,log_outputs="3:file:'"$(pwd)/log"'",' tmp.conf > k \ + || fail=1 +mv k tmp.conf || fail=1 + printf "running libvirtd with a valid config file ($sleep_secs seconds)\n" 1>&2 -libvirtd --config=tmp.conf > log 2>&1 & pid=$! +libvirtd --pid-file=pid-file --config=tmp.conf > log 2>&1 & pid=$! sleep $sleep_secs kill $pid -- 1.6.2.rc1.285.gc5f54 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list