[libvirt] tweak a format string and add a test

I'm about to commit these (like what I already posted, but now the test kills libvirtd):
From 944052f2287f1a07034be16ea08d620c55eecd6e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 2 Mar 2009 14:46:20 +0100 Subject: [PATCH 1/2] virsh: tweak a format string to avoid emitting trailing space
* src/virsh.c (cmdNetworkList): Change format not to right-pad with spaces, as that would have required a trailing blank in an expected output file. --- src/virsh.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/virsh.c b/src/virsh.c index 8ae79c5..c23fdda 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -2596,7 +2596,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) qsort(&inactiveNames[0], maxinactive, sizeof(char*), namesorter); } } - vshPrintExtra(ctl, "%-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart")); + vshPrintExtra(ctl, "%-20s %-10s %s\n", _("Name"), _("State"), _("Autostart")); vshPrintExtra(ctl, "-----------------------------------------\n"); for (i = 0; i < maxactive; i++) { -- 1.6.2.rc1.285.gc5f54
From dfeac0d70dce4a84ee5d70553ec3929bdbeab0c4 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 2 Mar 2009 14:32:59 +0100 Subject: [PATCH 2/2] tests: test for a recent fix
* tests/libvirtd-net-persist: New file. Test for the "Mark defined networks as persistent" fix. * tests/Makefile.am (test_scripts): Add it. --- tests/Makefile.am | 1 + tests/libvirtd-net-persist | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 0 deletions(-) create mode 100755 tests/libvirtd-net-persist diff --git a/tests/Makefile.am b/tests/Makefile.am index bec4f60..7479e03 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -81,6 +81,7 @@ test_scripts += \ daemon-conf \ define-dev-segfault \ int-overflow \ + libvirtd-net-persist \ read-bufsiz \ read-non-seekable \ start \ diff --git a/tests/libvirtd-net-persist b/tests/libvirtd-net-persist new file mode 100755 index 0000000..50a1ef4 --- /dev/null +++ b/tests/libvirtd-net-persist @@ -0,0 +1,58 @@ +#!/bin/sh +# ensure that net-destroy doesn't make network disappear (persistence-related) + +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 + +cat > net.xml <<EOF || fail=1 +<network> + <name>N</name> + <ip address="192.168.199.1" netmask="255.255.255.0"></ip> +</network> +EOF + +cat > exp <<EOF || fail=1 +Network N defined from net.xml + +Network N destroyed + +Name State Autostart +----------------------------------------- +N inactive no + +EOF + +libvirtd --config=conf > libvirtd-log 2>&1 & pid=$! +sleep 1 + +url="qemu:///session?socket=@$sock_dir/libvirt-sock" +virsh -c "$url" \ + 'net-define net.xml; net-destroy N; net-list --all' > out 2>&1 \ + || fail=1 + +# if libvird's log is empty, sleep for a second before killing it +test -s libvirtd-log || sleep 1 +kill $pid + +compare exp out || fail=1 + +printf "Shutting down network 'N'\n" > log-exp +compare log-exp libvirtd-log || fail=1 + +exit $fail -- 1.6.2.rc1.285.gc5f54

On Mon, Mar 02, 2009 at 07:38:50PM +0100, Jim Meyering wrote:
I'm about to commit these (like what I already posted, but now the test kills libvirtd):
okay, it's always annoying to change virsh output, though, ACK Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Mon, Mar 02, 2009 at 07:38:50PM +0100, Jim Meyering wrote:
I'm about to commit these (like what I already posted, but now the test kills libvirtd):
From 944052f2287f1a07034be16ea08d620c55eecd6e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 2 Mar 2009 14:46:20 +0100 Subject: [PATCH 1/2] virsh: tweak a format string to avoid emitting trailing space
* src/virsh.c (cmdNetworkList): Change format not to right-pad with spaces, as that would have required a trailing blank in an expected output file. --- src/virsh.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/virsh.c b/src/virsh.c index 8ae79c5..c23fdda 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -2596,7 +2596,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) qsort(&inactiveNames[0], maxinactive, sizeof(char*), namesorter); } } - vshPrintExtra(ctl, "%-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart")); + vshPrintExtra(ctl, "%-20s %-10s %s\n", _("Name"), _("State"), _("Autostart")); vshPrintExtra(ctl, "-----------------------------------------\n");
for (i = 0; i < maxactive; i++) { -- 1.6.2.rc1.285.gc5f54
ACK, we already did the same for the 'list' command. I really don't like these kind of tests in here - tests of the live drivers should be part of a separate integration test suite bundle, that's independant of main code releases.
+ +libvirtd --config=conf > libvirtd-log 2>&1 & pid=$! +sleep 1 + +url="qemu:///session?socket=@$sock_dir/libvirt-sock" +virsh -c "$url" \ + 'net-define net.xml; net-destroy N; net-list --all' > out 2>&1 \ + || fail=1
Calling 'net-destroy' doesn't make sense because the network hasn't been started here yet, merely defined as an inactive config. Starting the network would not be a thing you want to do in the test suite, because it may mess with your host networking. The virtual network driver shouldn't be usable under the 'qemu:///session' instance either, because it needs to be running privileged. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Daniel P. Berrange wrote: ...
I really don't like these kind of tests in here - tests of the live drivers should be part of a separate integration test suite bundle, that's independant of main code releases.
As I already mentioned, adding them here is simply a stop-gap measure to ensure we record how to exercise the just-fixed code. I expect to convert them to a more general framework as time permits.
+libvirtd --config=conf > libvirtd-log 2>&1 & pid=$! +sleep 1 + +url="qemu:///session?socket=@$sock_dir/libvirt-sock" +virsh -c "$url" \ + 'net-define net.xml; net-destroy N; net-list --all' > out 2>&1 \ + || fail=1
Calling 'net-destroy' doesn't make sense because the network hasn't been started here yet, merely defined as an inactive config. Starting the network would not be a thing you want to do in the test suite, because it may mess with your host networking. The virtual network driver shouldn't be usable under the 'qemu:///session' instance either, because it needs to be running privileged.
My goal was to exercise the code in question with as simple an example as possible, while remaining non-invasive -- i.e., don't start network, don't require root. If you have a better way, please describe it.
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Jim Meyering