From 94931821559c53ddd505bf8c34c7131e0b23b3c5 Mon Sep 17 00:00:00 2001 From: Shubha Kulkarni Date: Fri, 18 Nov 2022 16:42:41 -0500 Subject: [PATCH] core: look for InstanceID as well when reading internal ovfs Issue: When attaching SD, VM Import tab doesn't show a VM if VM OVF has 'InstanceID' instead of 'InstanceId' property. The engine log shows the below error. 'Error parsing OVF due to OVF error: ol8-clone: cannot read 'rasd:InstanceId' with value: null'. Ref bug change https://bugzilla.redhat.com/show_bug.cgi?id=1850103 Fix: When reading/parsing VM OVF, check for both values 'InstanceID' and 'InstanceId'. Signed-off-by: Shubha Kulkarni --- .../engine/core/utils/ovf/OvfOvirtReader.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java index 9a4e734ec58..1ca96f60ccd 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java @@ -146,6 +146,17 @@ private XmlNode getNode(XmlNodeList nodeList, String attributeName, String attri return null; } + protected String getInstanceIdValue(XmlNode node) { + XmlNode candidateNode = selectSingleNode(node, "rasd:InstanceId", _xmlNS); + // Some OVFs have InstanceID instead of InstanceId (e.g. generated by Oracle) + // So check for both values in the xml node + if (candidateNode == null) { + candidateNode = selectSingleNode(node, "rasd:InstanceID", _xmlNS); + } + + return candidateNode.innerText; + } + protected void readSnapshotsSection(@SuppressWarnings("unused") XmlNode section) { // The snapshot section only has meaning for VMs, and is overridden in OvfVmReader. } @@ -261,7 +272,7 @@ protected void readDisk(XmlNode node, DiskImage image) { @Override protected VmNetworkInterface getNetworkInterface(XmlNode node) { // prior to 3.0 the instanceId is int , in 3.1 and on this is Guid - String str = selectSingleNode(node, VMD_ID, _xmlNS).innerText; + String str = getInstanceIdValue(node); if (!StringUtils.isNumeric(str)) { // 3.1 and above OVF format final Guid guid = new Guid(str); VmNetworkInterface iface = interfaces.stream().filter(i -> i.getId().equals(guid)).findFirst().orElse(null); @@ -329,7 +340,8 @@ protected void readOsSection(XmlNode section) { @Override protected void readDiskImageItem(XmlNode node) { - final Guid guid = new Guid(selectSingleNode(node, VMD_ID, _xmlNS).innerText); + String str = getInstanceIdValue(node); + final Guid guid = new Guid(str); DiskImage image = _images.stream().filter(d -> d.getImageId().equals(guid)).findFirst().orElse(null); if (image == null) { return;