[Libguestfs] [PATCH] v2v: Add extra tests for malformed OVA files.

Richard W.M. Jones rjones at redhat.com
Mon Mar 6 15:08:59 UTC 2017


Test:
 - Bad SHA1 sum
 - Bad SHA256 sum
 - Invalid lines in manifest (x2)
 - Good checksum and manifest

These tests were originally written by Tomáš Golembiovský.  All I have
done is to integrate them into the virt-v2v test suite.
---
 .gitignore                              |  1 +
 v2v/Makefile.am                         | 22 +++++++-
 v2v/test-v2v-i-ova-bad-sha1.sh          | 66 +++++++++++++++++++++++
 v2v/test-v2v-i-ova-bad-sha256.sh        | 66 +++++++++++++++++++++++
 v2v/test-v2v-i-ova-checksums.ovf        | 95 +++++++++++++++++++++++++++++++++
 v2v/test-v2v-i-ova-good-checksums.sh    | 64 ++++++++++++++++++++++
 v2v/test-v2v-i-ova-invalid-manifest1.sh | 65 ++++++++++++++++++++++
 v2v/test-v2v-i-ova-invalid-manifest2.sh | 64 ++++++++++++++++++++++
 8 files changed, 442 insertions(+), 1 deletion(-)
 create mode 100755 v2v/test-v2v-i-ova-bad-sha1.sh
 create mode 100755 v2v/test-v2v-i-ova-bad-sha256.sh
 create mode 100644 v2v/test-v2v-i-ova-checksums.ovf
 create mode 100755 v2v/test-v2v-i-ova-good-checksums.sh
 create mode 100755 v2v/test-v2v-i-ova-invalid-manifest1.sh
 create mode 100755 v2v/test-v2v-i-ova-invalid-manifest2.sh

diff --git a/.gitignore b/.gitignore
index e3b6d7b..7dd49e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -635,6 +635,7 @@ Makefile.in
 /v2v/virt-v2v.1
 /v2v/virt-v2v-copy-to-local
 /v2v/virt-v2v-copy-to-local.1
+/v2v/windows.vmdk
 /website/*.html
 /website/README.txt
 /website/TODO.txt
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 55f7e70..9c685f9 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -256,10 +256,15 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test
 
 TESTS = \
 	test-v2v-docs.sh \
-	test-v2v-i-ova-tar.sh \
+	test-v2v-i-ova-bad-sha1.sh \
+	test-v2v-i-ova-bad-sha256.sh \
 	test-v2v-i-ova-formats.sh \
+	test-v2v-i-ova-good-checksums.sh \
 	test-v2v-i-ova-gz.sh \
+	test-v2v-i-ova-invalid-manifest1.sh \
+	test-v2v-i-ova-invalid-manifest2.sh \
 	test-v2v-i-ova-subfolders.sh \
+	test-v2v-i-ova-tar.sh \
 	test-v2v-i-ova-two-disks.sh \
 	test-v2v-bad-networks-and-bridges.sh
 
@@ -302,6 +307,20 @@ TESTS += \
 endif
 endif ENABLE_APPLIANCE
 
+# The VMDK file is used for some -i ova tests.
+check_DATA = windows.vmdk
+windows.vmdk: ../test-data/phony-guests/windows.img
+	rm -f $@ $@-t
+	if [ -s $< ]; then \
+	    qemu-img convert -f raw $< -O vmdk $@-t; \
+	    mv $@-t $@; \
+	else \
+	    touch $@; \
+	fi
+
+DISTCLEANFILES += \
+	windows.vmdk
+
 check-valgrind:
 	$(MAKE) VG="@VG@" check
 
@@ -355,6 +374,7 @@ EXTRA_DIST += \
 	test-v2v-floppy.sh \
 	test-v2v-floppy.xml \
 	test-v2v-i-disk.sh \
+	test-v2v-i-ova-checksums.ovf \
 	test-v2v-i-ova-formats.expected \
 	test-v2v-i-ova-formats.ovf \
 	test-v2v-i-ova-formats.sh \
diff --git a/v2v/test-v2v-i-ova-bad-sha1.sh b/v2v/test-v2v-i-ova-bad-sha1.sh
new file mode 100755
index 0000000..3724c71
--- /dev/null
+++ b/v2v/test-v2v-i-ova-bad-sha1.sh
@@ -0,0 +1,66 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014-2017 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 -i ova option with a good manifest containing a bad SHA1 checksum.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+skip_if_backend uml
+skip_unless_phony_guest windows.img
+
+if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then
+    echo "$0: test skipped because windows.vmdk was not created"
+    exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools"
+
+d=test-v2v-i-ova-bad-sha1.d
+rm -rf $d
+mkdir $d
+
+pushd $d
+
+# Create the test OVA.
+cp ../test-v2v-i-ova-checksums.ovf test.ovf
+cp ../windows.vmdk disk.vmdk
+echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf
+sha1=`do_sha1 disk.vmdk | tr '0-5' 'a-f'`
+echo "SHA1(disk.vmdk)=" $sha1 >> test.mf
+tar cf test.ova test.ovf disk.vmdk test.mf
+
+# Run virt-v2v but only as far as the --print-source stage.
+# It is expected to fail with an error.
+if $VG virt-v2v --debug-gc --quiet \
+       -i ova test.ova \
+       --print-source >test.out 2>&1; then
+    cat test.out
+    echo "$0: expected virt-v2v to fail, but it succeeded"
+    exit 1
+fi
+cat test.out
+if ! grep "error: checksum of disk disk.vmdk does not match manifest" test.out
+then
+    echo "$0: did not see the expected error in the output of virt-v2v"
+    exit 1
+fi
+
+popd
+rm -rf $d
diff --git a/v2v/test-v2v-i-ova-bad-sha256.sh b/v2v/test-v2v-i-ova-bad-sha256.sh
new file mode 100755
index 0000000..7cd06f5
--- /dev/null
+++ b/v2v/test-v2v-i-ova-bad-sha256.sh
@@ -0,0 +1,66 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014-2017 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 -i ova option with a good manifest containing a bad SHA256 checksum.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+skip_if_backend uml
+skip_unless_phony_guest windows.img
+
+if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then
+    echo "$0: test skipped because windows.vmdk was not created"
+    exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools"
+
+d=test-v2v-i-ova-bad-sha256.d
+rm -rf $d
+mkdir $d
+
+pushd $d
+
+# Create the test OVA.
+cp ../test-v2v-i-ova-checksums.ovf test.ovf
+cp ../windows.vmdk disk.vmdk
+echo "SHA256(test.ovf)=" `do_sha256 test.ovf` > test.mf
+sha256=`do_sha256 disk.vmdk | tr '0-5' 'a-f'`
+echo "SHA256(disk.vmdk)=" $sha256 >> test.mf
+tar cf test.ova test.ovf disk.vmdk test.mf
+
+# Run virt-v2v but only as far as the --print-source stage.
+# It is expected to fail with an error.
+if $VG virt-v2v --debug-gc --quiet \
+       -i ova test.ova \
+       --print-source >test.out 2>&1; then
+    cat test.out
+    echo "$0: expected virt-v2v to fail, but it succeeded"
+    exit 1
+fi
+cat test.out
+if ! grep "error: checksum of disk disk.vmdk does not match manifest" test.out
+then
+    echo "$0: did not see the expected error in the output of virt-v2v"
+    exit 1
+fi
+
+popd
+rm -rf $d
diff --git a/v2v/test-v2v-i-ova-checksums.ovf b/v2v/test-v2v-i-ova-checksums.ovf
new file mode 100644
index 0000000..5bb7f6e
--- /dev/null
+++ b/v2v/test-v2v-i-ova-checksums.ovf
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Envelope xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <References>
+    <File ovf:href="disk.vmdk" ovf:id="file1" ovf:size="4063232" />
+  </References>
+  <DiskSection>
+    <Info>Virtual disk information</Info>
+    <Disk ovf:capacity="512" ovf:capacityAllocationUnits="byte * 2^20" ovf:diskId="vmdisk1" ovf:fileRef="file1" />
+  </DiskSection>
+  <VirtualSystem ovf:id="ova-test">
+    <Info>A virtual machine</Info>
+    <Name>ova-test</Name>
+    <OperatingSystemSection ovf:id="69">
+      <Info>The kind of installed guest operating system</Info>
+      <Description>Microsoft Windows Server 2003 (32-bit)</Description>
+    </OperatingSystemSection>
+    <VirtualHardwareSection>
+      <Info>Virtual hardware requirements</Info>
+      <System>
+        <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
+        <vssd:InstanceID>0</vssd:InstanceID>
+        <vssd:VirtualSystemIdentifier>ova-test</vssd:VirtualSystemIdentifier>
+        <vssd:VirtualSystemType>vmx-08</vssd:VirtualSystemType>
+      </System>
+      <Item>
+        <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
+        <rasd:Description>Number of Virtual CPUs</rasd:Description>
+        <rasd:ElementName>2 virtual CPU(s)</rasd:ElementName>
+        <rasd:InstanceID>1</rasd:InstanceID>
+        <rasd:ResourceType>3</rasd:ResourceType>
+        <rasd:VirtualQuantity>2</rasd:VirtualQuantity>
+      </Item>
+      <Item>
+        <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
+        <rasd:Description>Memory Size</rasd:Description>
+        <rasd:ElementName>4096MB of memory</rasd:ElementName>
+        <rasd:InstanceID>2</rasd:InstanceID>
+        <rasd:ResourceType>4</rasd:ResourceType>
+        <rasd:VirtualQuantity>4096</rasd:VirtualQuantity>
+      </Item>
+      <Item>
+        <rasd:Address>0</rasd:Address>
+        <rasd:Description>SCSI Controller</rasd:Description>
+        <rasd:ElementName>SCSI controller 0</rasd:ElementName>
+        <rasd:InstanceID>3</rasd:InstanceID>
+        <rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>
+        <rasd:ResourceType>6</rasd:ResourceType>
+      </Item>
+      <Item>
+        <rasd:Address>1</rasd:Address>
+        <rasd:Description>IDE Controller</rasd:Description>
+        <rasd:ElementName>IDE 1</rasd:ElementName>
+        <rasd:InstanceID>4</rasd:InstanceID>
+        <rasd:ResourceType>5</rasd:ResourceType>
+      </Item>
+      <Item>
+        <rasd:Address>0</rasd:Address>
+        <rasd:Description>IDE Controller</rasd:Description>
+        <rasd:ElementName>IDE 0</rasd:ElementName>
+        <rasd:InstanceID>5</rasd:InstanceID>
+        <rasd:ResourceType>5</rasd:ResourceType>
+      </Item>
+      <Item ovf:required="false">
+        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
+        <rasd:ElementName>Video card</rasd:ElementName>
+        <rasd:InstanceID>6</rasd:InstanceID>
+        <rasd:ResourceType>24</rasd:ResourceType>
+      </Item>
+      <Item ovf:required="false">
+        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
+        <rasd:ElementName>VMCI device</rasd:ElementName>
+        <rasd:InstanceID>7</rasd:InstanceID>
+        <rasd:ResourceSubType>vmware.vmci</rasd:ResourceSubType>
+        <rasd:ResourceType>1</rasd:ResourceType>
+      </Item>
+      <Item ovf:required="false">
+        <rasd:AddressOnParent>1</rasd:AddressOnParent>
+        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
+        <rasd:ElementName>CD/DVD drive 1</rasd:ElementName>
+        <rasd:InstanceID>8</rasd:InstanceID>
+        <rasd:Parent>4</rasd:Parent>
+        <rasd:ResourceSubType>vmware.cdrom.remotepassthrough</rasd:ResourceSubType>
+        <rasd:ResourceType>15</rasd:ResourceType>
+      </Item>
+      <Item>
+        <rasd:AddressOnParent>0</rasd:AddressOnParent>
+        <rasd:ElementName>Hard disk 1</rasd:ElementName>
+        <rasd:HostResource>ovf:/disk/vmdisk1</rasd:HostResource>
+        <rasd:InstanceID>9</rasd:InstanceID>
+        <rasd:Parent>3</rasd:Parent>
+        <rasd:ResourceType>17</rasd:ResourceType>
+      </Item>
+    </VirtualHardwareSection>
+  </VirtualSystem>
+</Envelope>
diff --git a/v2v/test-v2v-i-ova-good-checksums.sh b/v2v/test-v2v-i-ova-good-checksums.sh
new file mode 100755
index 0000000..6f42701
--- /dev/null
+++ b/v2v/test-v2v-i-ova-good-checksums.sh
@@ -0,0 +1,64 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014-2017 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 -i ova option with good checksums.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+skip_if_backend uml
+skip_unless_phony_guest windows.img
+
+if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then
+    echo "$0: test skipped because windows.vmdk was not created"
+    exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools"
+
+d=test-v2v-i-ova-good-checksums.d
+rm -rf $d
+mkdir $d
+
+pushd $d
+
+# Create the test OVA.
+cp ../test-v2v-i-ova-checksums.ovf test.ovf
+cp ../windows.vmdk disk.vmdk
+echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf
+echo "SHA1(disk.vmdk)=" `do_sha1 disk.vmdk` >> test.mf
+tar cf test.ova test.ovf disk.vmdk test.mf
+
+# Run virt-v2v but only as far as the --print-source stage.
+# It should succeed with no warnings.
+if ! $VG virt-v2v --debug-gc --quiet \
+       -i ova test.ova \
+       --print-source >test.out 2>&1; then
+    cat test.out
+    exit 1
+fi
+cat test.out
+
+if grep -sq "warning: " test.out; then
+    echo "$0: unexpected warning in virt-v2v output: see messages above"
+    exit 1
+fi
+
+popd
+rm -rf $d
diff --git a/v2v/test-v2v-i-ova-invalid-manifest1.sh b/v2v/test-v2v-i-ova-invalid-manifest1.sh
new file mode 100755
index 0000000..f26a9ab
--- /dev/null
+++ b/v2v/test-v2v-i-ova-invalid-manifest1.sh
@@ -0,0 +1,65 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014-2017 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 -i ova option with invalid manifest.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+skip_if_backend uml
+skip_unless_phony_guest windows.img
+
+if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then
+    echo "$0: test skipped because windows.vmdk was not created"
+    exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools"
+
+d=test-v2v-i-ova-invalid-manifest1.d
+rm -rf $d
+mkdir $d
+
+pushd $d
+
+# Create the test OVA.
+cp ../test-v2v-i-ova-checksums.ovf test.ovf
+cp ../windows.vmdk disk.vmdk
+echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf
+echo "SHA1(disk.vmdk)=" `do_sha1 disk.vmdk` >> test.mf
+echo "garbage line" >> test.mf
+tar cf test.ova test.ovf disk.vmdk test.mf
+
+# Run virt-v2v but only as far as the --print-source stage.
+# It should succeed with a warning.
+if ! $VG virt-v2v --debug-gc --quiet \
+       -i ova test.ova \
+       --print-source >test.out 2>&1; then
+    cat test.out
+    exit 1
+fi
+cat test.out
+
+if ! grep -sq "warning: unable to parse line.*garbage" test.out; then
+    echo "$0: did not see the expected warning in the output of virt-v2v"
+    exit 1
+fi
+
+popd
+rm -rf $d
diff --git a/v2v/test-v2v-i-ova-invalid-manifest2.sh b/v2v/test-v2v-i-ova-invalid-manifest2.sh
new file mode 100755
index 0000000..a336e5e
--- /dev/null
+++ b/v2v/test-v2v-i-ova-invalid-manifest2.sh
@@ -0,0 +1,64 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014-2017 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 -i ova option with invalid manifest.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+skip_if_backend uml
+skip_unless_phony_guest windows.img
+
+if [ ! -f windows.vmdk -o ! -s windows.vmdk ]; then
+    echo "$0: test skipped because windows.vmdk was not created"
+    exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools"
+
+d=test-v2v-i-ova-invalid-manifest2.d
+rm -rf $d
+mkdir $d
+
+pushd $d
+
+# Create the test OVA.
+cp ../test-v2v-i-ova-checksums.ovf test.ovf
+cp ../windows.vmdk disk.vmdk
+echo "SHA1(test.ovf)=" `do_sha1 test.ovf` > test.mf
+echo "SHA1(disk.vmdk)=$(do_sha1 disk.vmdk)" >> test.mf
+tar cf test.ova test.ovf disk.vmdk test.mf
+
+# Run virt-v2v but only as far as the --print-source stage.
+# It should succeed with a warning.
+if ! $VG virt-v2v --debug-gc --quiet \
+       -i ova test.ova \
+       --print-source >test.out 2>&1; then
+    cat test.out
+    exit 1
+fi
+cat test.out
+
+if ! grep -sq "warning: unable to parse line" test.out; then
+    echo "$0: did not see the expected warning in the output of virt-v2v"
+    exit 1
+fi
+
+popd
+rm -rf $d
-- 
2.9.3




More information about the Libguestfs mailing list