mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0093-v2v-handle-subfolders-in-ova-files.patch

e76f14
From a9c07400e8ac1bca21f6d55c311b2e64f12c27eb Mon Sep 17 00:00:00 2001
e76f14
From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com>
e76f14
Date: Mon, 23 May 2016 15:31:46 +0200
e76f14
Subject: [PATCH] v2v: handle subfolders in ova files
0d20ef
e76f14
Some ova files like those produced by SUSE Studio have their ovf, mf
e76f14
and other files inside a folder rather than at the root of the
e76f14
tarball. Consider the paths relative to the ovf and mf files to cover
e76f14
this case too.
e76f14
e76f14
(cherry picked from commit 9de9300e8b7a99fa06e290f20ef1aaa1eb6f7431)
0d20ef
---
e76f14
 v2v/Makefile.am                        |   1 +
e76f14
 v2v/input_ova.ml                       |   6 +-
e76f14
 v2v/test-v2v-i-ova-subfolders.expected |  17 ++++
e76f14
 v2v/test-v2v-i-ova-subfolders.ovf      | 138 +++++++++++++++++++++++++++++++++
e76f14
 v2v/test-v2v-i-ova-subfolders.sh       |  65 ++++++++++++++++
e76f14
 5 files changed, 225 insertions(+), 2 deletions(-)
e76f14
 create mode 100644 v2v/test-v2v-i-ova-subfolders.expected
e76f14
 create mode 100644 v2v/test-v2v-i-ova-subfolders.ovf
e76f14
 create mode 100755 v2v/test-v2v-i-ova-subfolders.sh
0d20ef
0d20ef
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
e76f14
index 2d52ab8..8354560 100644
0d20ef
--- a/v2v/Makefile.am
0d20ef
+++ b/v2v/Makefile.am
e76f14
@@ -285,6 +285,7 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test
0d20ef
 TESTS = \
e76f14
 	test-v2v-i-ova-formats.sh \
e76f14
 	test-v2v-i-ova-gz.sh \
e76f14
+	test-v2v-i-ova-subfolders.sh \
e76f14
 	test-v2v-i-ova-two-disks.sh \
e76f14
 	test-v2v-copy-to-local.sh \
e76f14
 	test-v2v-bad-networks-and-bridges.sh
e76f14
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
e76f14
index 28dafe6..0a4dfd5 100644
e76f14
--- a/v2v/input_ova.ml
e76f14
+++ b/v2v/input_ova.ml
e76f14
@@ -134,13 +134,14 @@ object
e76f14
     let rex = Str.regexp "SHA1(\\(.*\\))=\\([0-9a-fA-F]+\\)\r?" in
e76f14
     List.iter (
e76f14
       fun mf ->
e76f14
+        let mf_folder = Filename.dirname mf in
e76f14
         let chan = open_in mf in
e76f14
         let rec loop () =
e76f14
           let line = input_line chan in
e76f14
           if Str.string_match rex line 0 then (
e76f14
             let disk = Str.matched_group 1 line in
e76f14
             let expected = Str.matched_group 2 line in
e76f14
-            let cmd = sprintf "sha1sum %s" (quote (exploded // disk)) in
e76f14
+            let cmd = sprintf "sha1sum %s" (quote (mf_folder // disk)) in
e76f14
             let out = external_command cmd in
e76f14
             match out with
e76f14
             | [] ->
e76f14
@@ -159,6 +160,7 @@ object
e76f14
     ) mf;
e76f14
 
e76f14
     (* Parse the ovf file. *)
e76f14
+    let ovf_folder = Filename.dirname ovf in
e76f14
     let xml = read_whole_file ovf in
e76f14
     let doc = Xml.parse_memory xml in
e76f14
 
e76f14
@@ -259,7 +261,7 @@ object
e76f14
             | Some s -> s in
0d20ef
 
e76f14
           (* Does the file exist and is it readable? *)
e76f14
-          let filename = exploded // filename in
e76f14
+          let filename = ovf_folder // filename in
e76f14
           Unix.access filename [Unix.R_OK];
e76f14
 
e76f14
           (* The spec allows the file to be gzip-compressed, in which case
e76f14
diff --git a/v2v/test-v2v-i-ova-subfolders.expected b/v2v/test-v2v-i-ova-subfolders.expected
0d20ef
new file mode 100644
e76f14
index 0000000..7037b9e
0d20ef
--- /dev/null
e76f14
+++ b/v2v/test-v2v-i-ova-subfolders.expected
e76f14
@@ -0,0 +1,17 @@
0d20ef
+Source guest information (--print-source option):
0d20ef
+
0d20ef
+    source name: 2K8R2EESP1_2_Medium
0d20ef
+hypervisor type: vmware
0d20ef
+         memory: 1073741824 (bytes)
0d20ef
+       nr vCPUs: 1
0d20ef
+   CPU features: 
e76f14
+       firmware: uefi
0d20ef
+        display: 
e76f14
+          sound: 
0d20ef
+disks:
e76f14
+	subfolder/disk1.vmdk (vmdk) [scsi]
0d20ef
+removable media:
e76f14
+	CD-ROM [ide] in slot 0
0d20ef
+NICs:
0d20ef
+	Network "Network adapter 1"
0d20ef
+
e76f14
diff --git a/v2v/test-v2v-i-ova-subfolders.ovf b/v2v/test-v2v-i-ova-subfolders.ovf
0d20ef
new file mode 100644
e76f14
index 0000000..4827c7e
0d20ef
--- /dev/null
e76f14
+++ b/v2v/test-v2v-i-ova-subfolders.ovf
0d20ef
@@ -0,0 +1,138 @@
0d20ef
+
0d20ef
+<Envelope vmw:buildId="build-1750787" 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:vmw="http://www.vmware.com/schema/ovf" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
0d20ef
+  <References>
0d20ef
+    <File ovf:href="disk1.vmdk" ovf:id="file1" ovf:size="7804077568"/>
0d20ef
+  </References>
0d20ef
+  <DiskSection>
0d20ef
+    <Info>Virtual disk information</Info>
0d20ef
+    <Disk ovf:capacity="50" ovf:capacityAllocationUnits="byte * 2^30" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" ovf:populatedSize="18975752192"/>
0d20ef
+  </DiskSection>
0d20ef
+  <NetworkSection>
0d20ef
+    <Info>The list of logical networks</Info>
0d20ef
+    <Network ovf:name="PG-VLAN60">
0d20ef
+      <Description>The PG-VLAN60 network</Description>
0d20ef
+    </Network>
0d20ef
+  </NetworkSection>
0d20ef
+  <VirtualSystem ovf:id="2K8R2EESP1_2_Medium">
0d20ef
+    <Info>A virtual machine</Info>
0d20ef
+    <Name>2K8R2EESP1_2_Medium</Name>
0d20ef
+    <OperatingSystemSection ovf:id="103" vmw:osType="windows7Server64Guest">
0d20ef
+      <Info>The kind of installed guest operating system</Info>
0d20ef
+      <Description>Microsoft Windows Server 2008 R2 (64-bit)</Description>
0d20ef
+    </OperatingSystemSection>
0d20ef
+    <VirtualHardwareSection>
0d20ef
+      <Info>Virtual hardware requirements</Info>
0d20ef
+      <System>
0d20ef
+        <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
0d20ef
+        <vssd:InstanceID>0</vssd:InstanceID>
0d20ef
+        <vssd:VirtualSystemIdentifier>2K8R2EESP1_2_Medium</vssd:VirtualSystemIdentifier>
0d20ef
+        <vssd:VirtualSystemType>vmx-10</vssd:VirtualSystemType>
0d20ef
+      </System>
0d20ef
+      <Item>
0d20ef
+        <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
0d20ef
+        <rasd:Description>Number of Virtual CPUs</rasd:Description>
0d20ef
+        <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>1</rasd:InstanceID>
0d20ef
+        <rasd:ResourceType>3</rasd:ResourceType>
0d20ef
+        <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
0d20ef
+      </Item>
0d20ef
+      <Item>
0d20ef
+        <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
0d20ef
+        <rasd:Description>Memory Size</rasd:Description>
0d20ef
+        <rasd:ElementName>1024MB of memory</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>2</rasd:InstanceID>
0d20ef
+        <rasd:ResourceType>4</rasd:ResourceType>
0d20ef
+        <rasd:VirtualQuantity>1024</rasd:VirtualQuantity>
0d20ef
+      </Item>
0d20ef
+      <Item>
0d20ef
+        <rasd:Address>0</rasd:Address>
0d20ef
+        <rasd:Description>SCSI Controller</rasd:Description>
0d20ef
+        <rasd:ElementName>SCSI controller 0</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>3</rasd:InstanceID>
0d20ef
+        <rasd:ResourceSubType>lsilogicsas</rasd:ResourceSubType>
0d20ef
+        <rasd:ResourceType>6</rasd:ResourceType>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="slotInfo.pciSlotNumber" vmw:value="160"/>
0d20ef
+      </Item>
0d20ef
+      <Item>
0d20ef
+        <rasd:Address>1</rasd:Address>
0d20ef
+        <rasd:Description>IDE Controller</rasd:Description>
0d20ef
+        <rasd:ElementName>IDE 1</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>4</rasd:InstanceID>
0d20ef
+        <rasd:ResourceType>5</rasd:ResourceType>
0d20ef
+      </Item>
0d20ef
+      <Item>
0d20ef
+        <rasd:Address>0</rasd:Address>
0d20ef
+        <rasd:Description>IDE Controller</rasd:Description>
0d20ef
+        <rasd:ElementName>IDE 0</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>5</rasd:InstanceID>
0d20ef
+        <rasd:ResourceType>5</rasd:ResourceType>
0d20ef
+      </Item>
0d20ef
+      <Item ovf:required="false">
0d20ef
+        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
0d20ef
+        <rasd:ElementName>Video card</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>6</rasd:InstanceID>
0d20ef
+        <rasd:ResourceType>24</rasd:ResourceType>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="enable3DSupport" vmw:value="false"/>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="use3dRenderer" vmw:value="automatic"/>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="useAutoDetect" vmw:value="true"/>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="videoRamSizeInKB" vmw:value="4096"/>
0d20ef
+      </Item>
0d20ef
+      <Item ovf:required="false">
0d20ef
+        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
0d20ef
+        <rasd:ElementName>VMCI device</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>7</rasd:InstanceID>
0d20ef
+        <rasd:ResourceSubType>vmware.vmci</rasd:ResourceSubType>
0d20ef
+        <rasd:ResourceType>1</rasd:ResourceType>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="allowUnrestrictedCommunication" vmw:value="false"/>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="slotInfo.pciSlotNumber" vmw:value="32"/>
0d20ef
+      </Item>
0d20ef
+      <Item ovf:required="false">
0d20ef
+        <rasd:AddressOnParent>0</rasd:AddressOnParent>
0d20ef
+        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
0d20ef
+        <rasd:ElementName>CD/DVD drive 1</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>8</rasd:InstanceID>
0d20ef
+        <rasd:Parent>4</rasd:Parent>
0d20ef
+        <rasd:ResourceSubType>vmware.cdrom.atapi</rasd:ResourceSubType>
0d20ef
+        <rasd:ResourceType>15</rasd:ResourceType>
0d20ef
+      </Item>
0d20ef
+      <Item>
0d20ef
+        <rasd:AddressOnParent>0</rasd:AddressOnParent>
0d20ef
+        <rasd:ElementName>Hard disk 1</rasd:ElementName>
0d20ef
+        <rasd:HostResource>ovf:/disk/vmdisk1</rasd:HostResource>
0d20ef
+        <rasd:InstanceID>9</rasd:InstanceID>
0d20ef
+        <rasd:Parent>3</rasd:Parent>
0d20ef
+        <rasd:ResourceType>17</rasd:ResourceType>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="backing.writeThrough" vmw:value="false"/>
0d20ef
+      </Item>
0d20ef
+      <Item>
0d20ef
+        <rasd:AddressOnParent>7</rasd:AddressOnParent>
0d20ef
+        <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
0d20ef
+        <rasd:Connection>PG-VLAN60</rasd:Connection>
0d20ef
+        <rasd:Description>E1000 ethernet adapter on "PG-VLAN60"</rasd:Description>
0d20ef
+        <rasd:ElementName>Network adapter 1</rasd:ElementName>
0d20ef
+        <rasd:InstanceID>11</rasd:InstanceID>
0d20ef
+        <rasd:ResourceSubType>E1000</rasd:ResourceSubType>
0d20ef
+        <rasd:ResourceType>10</rasd:ResourceType>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="slotInfo.pciSlotNumber" vmw:value="33"/>
0d20ef
+        <vmw:Config ovf:required="false" vmw:key="wakeOnLanEnabled" vmw:value="true"/>
0d20ef
+      </Item>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="false"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="cpuHotRemoveEnabled" vmw:value="false"/>
e76f14
+      <vmw:Config ovf:required="false" vmw:key="firmware" vmw:value="efi"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="virtualICH7MPresent" vmw:value="false"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="virtualSMCPresent" vmw:value="false"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="false"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="nestedHVEnabled" vmw:value="false"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="powerOpInfo.powerOffType" vmw:value="soft"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="powerOpInfo.resetType" vmw:value="soft"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="powerOpInfo.standbyAction" vmw:value="checkpoint"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="powerOpInfo.suspendType" vmw:value="hard"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="tools.afterPowerOn" vmw:value="true"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="tools.afterResume" vmw:value="true"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="tools.beforeGuestShutdown" vmw:value="true"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="tools.beforeGuestStandby" vmw:value="true"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="tools.syncTimeWithHost" vmw:value="false"/>
0d20ef
+      <vmw:Config ovf:required="false" vmw:key="tools.toolsUpgradePolicy" vmw:value="upgradeAtPowerCycle"/>
0d20ef
+    </VirtualHardwareSection>
0d20ef
+  </VirtualSystem>
0d20ef
+</Envelope>                                 
e76f14
diff --git a/v2v/test-v2v-i-ova-subfolders.sh b/v2v/test-v2v-i-ova-subfolders.sh
0d20ef
new file mode 100755
e76f14
index 0000000..a590fcc
0d20ef
--- /dev/null
e76f14
+++ b/v2v/test-v2v-i-ova-subfolders.sh
e76f14
@@ -0,0 +1,65 @@
0d20ef
+#!/bin/bash -
0d20ef
+# libguestfs virt-v2v test script
0d20ef
+# Copyright (C) 2014 Red Hat Inc.
0d20ef
+#
0d20ef
+# This program is free software; you can redistribute it and/or modify
0d20ef
+# it under the terms of the GNU General Public License as published by
0d20ef
+# the Free Software Foundation; either version 2 of the License, or
0d20ef
+# (at your option) any later version.
0d20ef
+#
0d20ef
+# This program is distributed in the hope that it will be useful,
0d20ef
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+# GNU General Public License for more details.
0d20ef
+#
0d20ef
+# You should have received a copy of the GNU General Public License
0d20ef
+# along with this program; if not, write to the Free Software
0d20ef
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+
e76f14
+# Test -i ova option with files located in a subfolder.
0d20ef
+
0d20ef
+unset CDPATH
0d20ef
+export LANG=C
0d20ef
+set -e
0d20ef
+
e76f14
+if [ -n "$SKIP_TEST_V2V_I_OVA_SUBFOLDERS_SH" ]; then
0d20ef
+    echo "$0: test skipped because environment variable is set"
0d20ef
+    exit 77
0d20ef
+fi
0d20ef
+
0d20ef
+if [ "$(guestfish get-backend)" = "uml" ]; then
0d20ef
+    echo "$0: test skipped because UML backend does not support network"
0d20ef
+    exit 77
0d20ef
+fi
0d20ef
+
e76f14
+export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
e76f14
+
e76f14
+. $srcdir/../test-data/guestfs-hashsums.sh
0d20ef
+
e76f14
+d=test-v2v-i-ova-subfolders.d
0d20ef
+rm -rf $d
e76f14
+mkdir -p $d/subfolder
e76f14
+
e76f14
+cp test-v2v-i-ova-subfolders.ovf $d/subfolder/
0d20ef
+
e76f14
+pushd $d/subfolder
0d20ef
+
0d20ef
+truncate -s 10k disk1.vmdk
e76f14
+sha=`do_sha1 disk1.vmdk`
0d20ef
+echo -e "SHA1(disk1.vmdk)=$sha\r" > disk1.mf
0d20ef
+
e76f14
+cd ..
e76f14
+tar -cf test.ova subfolder
0d20ef
+popd
0d20ef
+
0d20ef
+# Run virt-v2v but only as far as the --print-source stage, and
0d20ef
+# normalize the output.
0d20ef
+$VG virt-v2v --debug-gc --quiet \
0d20ef
+    -i ova $d/test.ova \
0d20ef
+    --print-source |
e76f14
+sed 's,[^ \t]*\(subfolder/disk.*\.vmdk\),\1,' > $d/source
0d20ef
+
0d20ef
+# Check the parsed source is what we expect.
e76f14
+diff -u test-v2v-i-ova-subfolders.expected $d/source
0d20ef
+
0d20ef
+rm -rf $d
0d20ef
-- 
0d20ef
1.8.3.1
0d20ef