Pino Toscano
2019-May-16 09:08 UTC
[Libguestfs] [PATCH] v2v: -o json: add a simple test for it
Followup of commit f190e08d85556dac293ef15bfeee38e54471570f. --- v2v/Makefile.am | 2 ++ v2v/test-v2v-o-json.sh | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 v2v/test-v2v-o-json.sh diff --git a/v2v/Makefile.am b/v2v/Makefile.am index 39511022e..1c37d20b4 100644 --- a/v2v/Makefile.am +++ b/v2v/Makefile.am @@ -468,6 +468,7 @@ TESTS += \ test-v2v-networks-and-bridges.sh \ test-v2v-no-copy.sh \ test-v2v-o-glance.sh \ + test-v2v-o-json.sh \ test-v2v-o-libvirt.sh \ test-v2v-o-null.sh \ test-v2v-o-openstack.sh \ @@ -628,6 +629,7 @@ EXTRA_DIST += \ test-v2v-networks-and-bridges.xml \ test-v2v-no-copy.sh \ test-v2v-o-glance.sh \ + test-v2v-o-json.sh \ test-v2v-o-libvirt.sh \ test-v2v-o-null.sh \ test-v2v-o-openstack.sh \ diff --git a/v2v/test-v2v-o-json.sh b/v2v/test-v2v-o-json.sh new file mode 100755 index 000000000..71458a1bb --- /dev/null +++ b/v2v/test-v2v-o-json.sh @@ -0,0 +1,58 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2019 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test -o json. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img +skip_unless jq --version + +libvirt_uri="test://$abs_top_builddir/test-data/phony-guests/guests.xml" + +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" + +guestname=windows + +d=test-v2v-o-json.d +rm -rf $d +mkdir $d + +json=$d/$guestname.json + +$VG virt-v2v --debug-gc \ + -i libvirt -ic "$libvirt_uri" windows \ + -o json -os $d -on $guestname + +# Test the disk was created. +test -f $d/$guestname-sda + +# Test the JSON. +test x$(jq -r '.name' $json) = xwindows +test x$(jq -r '.inspect.type' $json) = xwindows +test x$(jq -r '.inspect.distro' $json) = xwindows +test x$(jq -r '.inspect.osinfo' $json) = xwin7 +test $(jq -r '.disks | length' $json) -eq 1 +test $(jq -r '.nics | length' $json) -eq 1 +test $(jq -r '.removables | length' $json) -eq 0 + +# Clean up. +rm -r $d -- 2.21.0
Pino Toscano
2019-May-16 10:06 UTC
Re: [Libguestfs] [PATCH] v2v: -o json: add a simple test for it
On Thursday, May 16, 2019 11:08:23 AM CEST Pino Toscano wrote:> Followup of commit f190e08d85556dac293ef15bfeee38e54471570f. > --- > v2v/Makefile.am | 2 ++ > v2v/test-v2v-o-json.sh | 58 ++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 60 insertions(+) > create mode 100755 v2v/test-v2v-o-json.sh > > diff --git a/v2v/Makefile.am b/v2v/Makefile.am > index 39511022e..1c37d20b4 100644 > --- a/v2v/Makefile.am > +++ b/v2v/Makefile.am > @@ -468,6 +468,7 @@ TESTS += \ > test-v2v-networks-and-bridges.sh \ > test-v2v-no-copy.sh \ > test-v2v-o-glance.sh \ > + test-v2v-o-json.sh \ > test-v2v-o-libvirt.sh \ > test-v2v-o-null.sh \ > test-v2v-o-openstack.sh \ > @@ -628,6 +629,7 @@ EXTRA_DIST += \ > test-v2v-networks-and-bridges.xml \ > test-v2v-no-copy.sh \ > test-v2v-o-glance.sh \ > + test-v2v-o-json.sh \ > test-v2v-o-libvirt.sh \ > test-v2v-o-null.sh \ > test-v2v-o-openstack.sh \ > diff --git a/v2v/test-v2v-o-json.sh b/v2v/test-v2v-o-json.sh > new file mode 100755 > index 000000000..71458a1bb > --- /dev/null > +++ b/v2v/test-v2v-o-json.sh > @@ -0,0 +1,58 @@ > +#!/bin/bash - > +# libguestfs virt-v2v test script > +# Copyright (C) 2019 Red Hat Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 2 of the License, or > +# (at your option) any later version. > +# > +# This program 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 General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program; if not, write to the Free Software > +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > + > +# Test -o json. > + > +set -e > + > +$TEST_FUNCTIONS > +skip_if_skipped > +skip_if_backend uml > +skip_unless_phony_guest windows.img > +skip_unless jq --version > + > +libvirt_uri="test://$abs_top_builddir/test-data/phony-guests/guests.xml" > + > +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" > + > +guestname=windows > + > +d=test-v2v-o-json.d > +rm -rf $d > +mkdir $d > + > +json=$d/$guestname.json > + > +$VG virt-v2v --debug-gc \ > + -i libvirt -ic "$libvirt_uri" windows \ > + -o json -os $d -on $guestname > + > +# Test the disk was created. > +test -f $d/$guestname-sda > + > +# Test the JSON. > +test x$(jq -r '.name' $json) = xwindows > +test x$(jq -r '.inspect.type' $json) = xwindows > +test x$(jq -r '.inspect.distro' $json) = xwindows > +test x$(jq -r '.inspect.osinfo' $json) = xwin7 > +test $(jq -r '.disks | length' $json) -eq 1Consider also the following line at this point: test $(jq -r '.disks[0].file' $json) = $(realpath $d/$guestname-sda) (forgot to save the editor, will not send v2 just for this)> +test $(jq -r '.nics | length' $json) -eq 1 > +test $(jq -r '.removables | length' $json) -eq 0 > + > +# Clean up. > +rm -r $d >-- Pino Toscano
Richard W.M. Jones
2019-May-17 17:06 UTC
Re: [Libguestfs] [PATCH] v2v: -o json: add a simple test for it
ACK, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Seemingly Similar Threads
- Re: [PATCH] v2v: -o json: add a simple test for it
- [PATCH 0/3] tests: Define common test functions.
- [PATCH [WIP] 0/3] tests: Define common test functions.
- [PATCH v2] v2v: -o rhv-upload: test-v2v-o-rhv-upload.sh: add more skip checks
- [PATCH v2 3/3] v2v: tests: test paths for installation of linux guest tools