From 5fd0910be3b7a942e81f04e17db6658c2c600fab Mon Sep 17 00:00:00 2001 From: Emmanuel Kasper Date: Wed, 13 Sep 2017 16:10:24 +0200 Subject: [PATCH] Add tests for parse_ovf function This includes: * a test script * the manifests generated by exports from a VmWare Workstation * disk images are generated from qemu-img, with a 2KB size (it is possible to inspect the disk images with od -bc they contain a VMDK header and the rest are null characters) --- test/Makefile | 5 +- test/ovf_manifests/Win10-Liz-disk1.vmdk | Bin 0 -> 65536 bytes test/ovf_manifests/Win10-Liz.ovf | 142 ++++++++++++++++++ test/ovf_manifests/Win_2008_R2_two-disks.ovf | 145 +++++++++++++++++++ test/ovf_manifests/disk1.vmdk | Bin 0 -> 65536 bytes test/ovf_manifests/disk2.vmdk | Bin 0 -> 65536 bytes test/run_ovf_tests.pl | 42 ++++++ 7 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 test/ovf_manifests/Win10-Liz-disk1.vmdk create mode 100755 test/ovf_manifests/Win10-Liz.ovf create mode 100755 test/ovf_manifests/Win_2008_R2_two-disks.ovf create mode 100644 test/ovf_manifests/disk1.vmdk create mode 100644 test/ovf_manifests/disk2.vmdk create mode 100755 test/run_ovf_tests.pl diff --git a/test/Makefile b/test/Makefile index 37330cf..6777f4a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,10 @@ all: test -test: test_snapshot +test: test_snapshot test_ovf test_snapshot: run_snapshot_tests.pl ./run_snapshot_tests.pl ./test_get_replicatable_volumes.pl + +test_ovf: run_ovf_tests.pl + ./run_ovf_tests.pl diff --git a/test/ovf_manifests/Win10-Liz-disk1.vmdk b/test/ovf_manifests/Win10-Liz-disk1.vmdk new file mode 100644 index 0000000000000000000000000000000000000000..662354a3d1333a2f6c4364005e53bfe7cd8b9044 GIT binary patch literal 65536 zcmeIvy>HV%7zbeUF`dK)46s{U!a5_FoJCkDB zKRozW{5{ByIY=etVNVcI$B zY@^?CwTN|j)tg?;i)G&AZFqPqoW(5P2K~XUq>9sqVVe!!?y@Y;)^#k~TefEvd2_XU z^M@5mfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk4^iOdL%ftb z5g~`p!f^fB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N p0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK;Zui`~%h>XmtPp literal 0 HcmV?d00001 diff --git a/test/ovf_manifests/Win10-Liz.ovf b/test/ovf_manifests/Win10-Liz.ovf new file mode 100755 index 0000000..46642c0 --- /dev/null +++ b/test/ovf_manifests/Win10-Liz.ovf @@ -0,0 +1,142 @@ + + + + + + + + Virtual disk information + + + + The list of logical networks + + The bridged network + + + + A virtual machine + Win10-Liz + + The kind of installed guest operating system + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + Win10-Liz + vmx-11 + + + hertz * 10^6 + Number of Virtual CPUs + 4 virtual CPU(s) + 1 + 3 + 4 + + + byte * 2^20 + Memory Size + 6144MB of memory + 2 + 4 + 6144 + + + 0 + SATA Controller + sataController0 + 3 + vmware.sata.ahci + 20 + + + 0 + USB Controller (XHCI) + usb3 + 4 + vmware.usb.xhci + 23 + + + 0 + USB Controller (EHCI) + usb + 5 + vmware.usb.ehci + 23 + + + + 0 + SCSI Controller + scsiController0 + 6 + lsilogicsas + 6 + + + true + serial0 + 7 + 21 + + + + 0 + disk0 + ovf:/disk/vmdisk1 + 8 + 6 + 17 + + + 2 + true + bridged + E1000e ethernet adapter on "bridged" + ethernet0 + 9 + E1000e + 10 + + + + false + sound + 10 + vmware.soundcard.hdaudio + 1 + + + false + video + 11 + 24 + + + + false + vmci + 12 + vmware.vmci + 1 + + + 1 + false + cdrom0 + 13 + 3 + 15 + + + + + + + + + \ No newline at end of file diff --git a/test/ovf_manifests/Win_2008_R2_two-disks.ovf b/test/ovf_manifests/Win_2008_R2_two-disks.ovf new file mode 100755 index 0000000..a563aab --- /dev/null +++ b/test/ovf_manifests/Win_2008_R2_two-disks.ovf @@ -0,0 +1,145 @@ + + + + + + + + + Virtual disk information + + + + + The list of logical networks + + The bridged network + + + + A virtual machine + Win_2008-R2x64 + + The kind of installed guest operating system + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + Win_2008-R2x64 + vmx-11 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + 3 + 1 + + + byte * 2^20 + Memory Size + 2048MB of memory + 2 + 4 + 2048 + + + 0 + SATA Controller + sataController0 + 3 + vmware.sata.ahci + 20 + + + 0 + USB Controller (EHCI) + usb + 4 + vmware.usb.ehci + 23 + + + + 0 + SCSI Controller + scsiController0 + 5 + lsilogicsas + 6 + + + true + serial0 + 6 + 21 + + + + 0 + disk0 + ovf:/disk/vmdisk1 + 7 + 5 + 17 + + + 1 + disk1 + ovf:/disk/vmdisk2 + 8 + 5 + 17 + + + 2 + true + bridged + E1000 ethernet adapter on "bridged" + ethernet0 + 9 + E1000 + 10 + + + + false + sound + 10 + vmware.soundcard.hdaudio + 1 + + + false + video + 11 + 24 + + + + false + vmci + 12 + vmware.vmci + 1 + + + 1 + false + cdrom0 + 13 + 3 + 15 + + + + + + + + + + diff --git a/test/ovf_manifests/disk1.vmdk b/test/ovf_manifests/disk1.vmdk new file mode 100644 index 0000000000000000000000000000000000000000..8660602343a1a955f9bcf2e6beaed99316dd8167 GIT binary patch literal 65536 zcmeIvy>HV%7zbeUF`dK)46sz*Sy|tuS*)j3xo%d~*K!`iCRTO1T8@X|%lB-2b2}Q2@{gmi&a1d=x<|K%7N%9q zn|Qfh$8m45TCV10Gb^W)c4ZxVA@tMpzfJp2S{y#m?iwzx)01@a>+{9rJna?j=ZAyM zqPW{FznsOxiSi~-&+HV%7zbeUF`dK)46s)ntf&y(cMe*SJh-aTX?eH9+& z#z!O2Psc@dn~q~OEsJ%%D!&!;7&fu2iq&#-6u$l#k8ZBB&%=0f64qH6mv#5(X4k^B zj9DEow(B_REmq6byr^fzbkeM>VlRY#diJkw-bwTQ2bx{O`BgehC%?a(PtMX_-hBS! zV6(_?yX6%pcd>%ZCj`_<*{eCa6d4SQYmC$1K;F1Lf} zc3v#=CU3(J2jMJcc^4cVA0$#W-ahT}R7ZdS0RjXF5Fl_M z@c!W5Edc@q2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U eAV7cs0RjXF5FkK+009C72oNAZfB=F2DR2*l=VfOA literal 0 HcmV?d00001 diff --git a/test/run_ovf_tests.pl b/test/run_ovf_tests.pl new file mode 100755 index 0000000..b9e4825 --- /dev/null +++ b/test/run_ovf_tests.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use lib qw(..); # prepend .. to @INC so we use the local version of PVE packages + +use FindBin '$Bin'; +use PVE::QemuServer::OVF; +use Test::More; + +use Data::Dumper; + +my $test_manifests = join ('/', $Bin, 'ovf_manifests'); + +my $win2008 = PVE::QemuServer::OVF::parse_ovf("$test_manifests/Win_2008_R2_two-disks.ovf"); +my $win10 = PVE::QemuServer::OVF::parse_ovf("$test_manifests/Win10-Liz.ovf"); + +print "testing disks\n"; + +is($win2008->{disks}->[0]->{disk_address}, 'scsi0', 'multidisk vm has the correct first disk controller'); +is($win2008->{disks}->[0]->{backing_file}, "$test_manifests/disk1.vmdk", 'multidisk vm has the correct first disk backing device'); +is($win2008->{disks}->[0]->{virtual_size}, 2048, 'multidisk vm has the correct first disk size'); + +is($win2008->{disks}->[1]->{disk_address}, 'scsi1', 'multidisk vm has the correct second disk controller'); +is($win2008->{disks}->[1]->{backing_file}, "$test_manifests/disk2.vmdk", 'multidisk vm has the correct second disk backing device'); +is($win2008->{disks}->[1]->{virtual_size}, 2048, 'multidisk vm has the correct second disk size'); + +is($win10->{disks}->[0]->{disk_address}, 'scsi0', 'single disk vm has the correct disk controller'); +is($win10->{disks}->[0]->{backing_file}, "$test_manifests/Win10-Liz-disk1.vmdk", 'single disk vm has the correct disk backing device'); +is($win10->{disks}->[0]->{virtual_size}, 2048, 'single disk vm has the correct size'); + +print "\ntesting vm.conf extraction\n"; + +is($win2008->{qm}->{name}, 'Win2008-R2x64', 'win2008 VM name is correct'); +is($win2008->{qm}->{memory}, '2048', 'win2008 VM memory is correct'); +is($win2008->{qm}->{cores}, '1', 'win2008 VM cores are correct'); + +is($win10->{qm}->{name}, 'Win10-Liz', 'win10 VM name is correct'); +is($win10->{qm}->{memory}, '6144', 'win10 VM memory is correct'); +is($win10->{qm}->{cores}, '4', 'win10 VM cores are correct'); + +done_testing(); -- 2.39.2