From a9c07400e8ac1bca21f6d55c311b2e64f12c27eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Mon, 23 May 2016 15:31:46 +0200 Subject: [PATCH] v2v: handle subfolders in ova files Some ova files like those produced by SUSE Studio have their ovf, mf and other files inside a folder rather than at the root of the tarball. Consider the paths relative to the ovf and mf files to cover this case too. (cherry picked from commit 9de9300e8b7a99fa06e290f20ef1aaa1eb6f7431) --- v2v/Makefile.am | 1 + v2v/input_ova.ml | 6 +- v2v/test-v2v-i-ova-subfolders.expected | 17 ++++ v2v/test-v2v-i-ova-subfolders.ovf | 138 +++++++++++++++++++++++++++++++++ v2v/test-v2v-i-ova-subfolders.sh | 65 ++++++++++++++++ 5 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 v2v/test-v2v-i-ova-subfolders.expected create mode 100644 v2v/test-v2v-i-ova-subfolders.ovf create mode 100755 v2v/test-v2v-i-ova-subfolders.sh diff --git a/v2v/Makefile.am b/v2v/Makefile.am index 2d52ab8..8354560 100644 --- a/v2v/Makefile.am +++ b/v2v/Makefile.am @@ -285,6 +285,7 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test TESTS = \ test-v2v-i-ova-formats.sh \ test-v2v-i-ova-gz.sh \ + test-v2v-i-ova-subfolders.sh \ test-v2v-i-ova-two-disks.sh \ test-v2v-copy-to-local.sh \ test-v2v-bad-networks-and-bridges.sh diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml index 28dafe6..0a4dfd5 100644 --- a/v2v/input_ova.ml +++ b/v2v/input_ova.ml @@ -134,13 +134,14 @@ object let rex = Str.regexp "SHA1(\\(.*\\))=\\([0-9a-fA-F]+\\)\r?" in List.iter ( fun mf -> + let mf_folder = Filename.dirname mf in let chan = open_in mf in let rec loop () = let line = input_line chan in if Str.string_match rex line 0 then ( let disk = Str.matched_group 1 line in let expected = Str.matched_group 2 line in - let cmd = sprintf "sha1sum %s" (quote (exploded // disk)) in + let cmd = sprintf "sha1sum %s" (quote (mf_folder // disk)) in let out = external_command cmd in match out with | [] -> @@ -159,6 +160,7 @@ object ) mf; (* Parse the ovf file. *) + let ovf_folder = Filename.dirname ovf in let xml = read_whole_file ovf in let doc = Xml.parse_memory xml in @@ -259,7 +261,7 @@ object | Some s -> s in (* Does the file exist and is it readable? *) - let filename = exploded // filename in + let filename = ovf_folder // filename in Unix.access filename [Unix.R_OK]; (* The spec allows the file to be gzip-compressed, in which case diff --git a/v2v/test-v2v-i-ova-subfolders.expected b/v2v/test-v2v-i-ova-subfolders.expected new file mode 100644 index 0000000..7037b9e --- /dev/null +++ b/v2v/test-v2v-i-ova-subfolders.expected @@ -0,0 +1,17 @@ +Source guest information (--print-source option): + + source name: 2K8R2EESP1_2_Medium +hypervisor type: vmware + memory: 1073741824 (bytes) + nr vCPUs: 1 + CPU features: + firmware: uefi + display: + sound: +disks: + subfolder/disk1.vmdk (vmdk) [scsi] +removable media: + CD-ROM [ide] in slot 0 +NICs: + Network "Network adapter 1" + diff --git a/v2v/test-v2v-i-ova-subfolders.ovf b/v2v/test-v2v-i-ova-subfolders.ovf new file mode 100644 index 0000000..4827c7e --- /dev/null +++ b/v2v/test-v2v-i-ova-subfolders.ovf @@ -0,0 +1,138 @@ + + + + + + + Virtual disk information + + + + The list of logical networks + + The PG-VLAN60 network + + + + A virtual machine + 2K8R2EESP1_2_Medium + + The kind of installed guest operating system + Microsoft Windows Server 2008 R2 (64-bit) + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + 2K8R2EESP1_2_Medium + vmx-10 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + 3 + 1 + + + byte * 2^20 + Memory Size + 1024MB of memory + 2 + 4 + 1024 + + + 0 + SCSI Controller + SCSI controller 0 + 3 + lsilogicsas + 6 + + + + 1 + IDE Controller + IDE 1 + 4 + 5 + + + 0 + IDE Controller + IDE 0 + 5 + 5 + + + false + Video card + 6 + 24 + + + + + + + false + VMCI device + 7 + vmware.vmci + 1 + + + + + 0 + false + CD/DVD drive 1 + 8 + 4 + vmware.cdrom.atapi + 15 + + + 0 + Hard disk 1 + ovf:/disk/vmdisk1 + 9 + 3 + 17 + + + + 7 + true + PG-VLAN60 + E1000 ethernet adapter on "PG-VLAN60" + Network adapter 1 + 11 + E1000 + 10 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/v2v/test-v2v-i-ova-subfolders.sh b/v2v/test-v2v-i-ova-subfolders.sh new file mode 100755 index 0000000..a590fcc --- /dev/null +++ b/v2v/test-v2v-i-ova-subfolders.sh @@ -0,0 +1,65 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014 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 files located in a subfolder. + +unset CDPATH +export LANG=C +set -e + +if [ -n "$SKIP_TEST_V2V_I_OVA_SUBFOLDERS_SH" ]; then + echo "$0: test skipped because environment variable is set" + exit 77 +fi + +if [ "$(guestfish get-backend)" = "uml" ]; then + echo "$0: test skipped because UML backend does not support network" + exit 77 +fi + +export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" + +. $srcdir/../test-data/guestfs-hashsums.sh + +d=test-v2v-i-ova-subfolders.d +rm -rf $d +mkdir -p $d/subfolder + +cp test-v2v-i-ova-subfolders.ovf $d/subfolder/ + +pushd $d/subfolder + +truncate -s 10k disk1.vmdk +sha=`do_sha1 disk1.vmdk` +echo -e "SHA1(disk1.vmdk)=$sha\r" > disk1.mf + +cd .. +tar -cf test.ova subfolder +popd + +# Run virt-v2v but only as far as the --print-source stage, and +# normalize the output. +$VG virt-v2v --debug-gc --quiet \ + -i ova $d/test.ova \ + --print-source | +sed 's,[^ \t]*\(subfolder/disk.*\.vmdk\),\1,' > $d/source + +# Check the parsed source is what we expect. +diff -u test-v2v-i-ova-subfolders.expected $d/source + +rm -rf $d -- 1.8.3.1