diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/exportimport/ImportVMFromConfigurationCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/exportimport/ImportVMFromConfigurationCommandTest.java index 1583a297509..7c451c7a864 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/exportimport/ImportVMFromConfigurationCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/exportimport/ImportVMFromConfigurationCommandTest.java @@ -95,8 +95,10 @@ public static Stream> mockConfiguration() { private final Guid storagePoolId = Guid.newGuid(); private final Guid clusterId = Guid.newGuid(); private static final String VM_OVF_XML_DATA = "src/test/resources/vmOvfData.xml"; + private static final String VM_OVF_XML_DATA2 = "src/test/resources/vmOvfData2.xml"; private static final String OVF_URI = "http://schemas.dmtf.org/ovf/envelope/1/"; private String xmlOvfData; + private String xmlOvfData2; private Cluster cluster; private StoragePool storagePool; @@ -206,12 +208,17 @@ osId, new VmIconIdSizePair(Guid.Empty, Guid.Empty) doReturn(null).when(labelDao).getByName(any()); setXmlOvfData(); + setXmlOvfData2(); } private void setXmlOvfData() throws IOException { xmlOvfData = new String(Files.readAllBytes(Paths.get(VM_OVF_XML_DATA)), StandardCharsets.UTF_8); } + private void setXmlOvfData2() throws IOException { + xmlOvfData2 = new String(Files.readAllBytes(Paths.get(VM_OVF_XML_DATA2)), StandardCharsets.UTF_8); + } + private void appendBiosTypeTag(XmlDocument document, int biosTypeId, Boolean custom) { XmlNode content = document.selectSingleNode("//*/Content"); Element element = document.createElement(BIOS_TYPE); @@ -244,6 +251,20 @@ public void testPositiveImportVmFromConfiguration() { ValidateTestUtils.runAndAssertValidateSuccess(cmd); } + @Test + public void testPositiveImportVmFromConfiguration2() { + initCommand(getOvfEntityData2()); + doReturn(Boolean.TRUE).when(cmd).validateAfterCloneVm(any()); + doReturn(Boolean.TRUE).when(cmd).validateBeforeCloneVm(any()); + when(validator.validateUnregisteredEntity(any())) .thenReturn(ValidationResult.VALID); + when(validator.validateStorageExistForUnregisteredEntity(anyList(), anyBoolean(), any(), any())) + .thenReturn(ValidationResult.VALID); + doReturn(ValidationResult.VALID).when(validator) + .validateStorageExistsForMemoryDisks(anyList(), anyBoolean(), anyMap()); + + ValidateTestUtils.runAndAssertValidateSuccess(cmd); + } + @Test public void testImportVMFromConfigurationWhenStorageDomainIsInMaintenance() { initCommand(getOvfEntityData()); @@ -415,6 +436,14 @@ private OvfEntityData getOvfEntityData() { return ovfEntity; } + private OvfEntityData getOvfEntityData2() { + OvfEntityData ovfEntity = new OvfEntityData(); + ovfEntity.setEntityId(vmId); + ovfEntity.setEntityName("Some VM"); + ovfEntity.setOvfData(xmlOvfData2); + return ovfEntity; + } + protected StorageDomain createStorageDomain() { StorageDomain sd = new StorageDomain(); sd.setId(storageDomainId); diff --git a/backend/manager/modules/bll/src/test/resources/vmOvfData2.xml b/backend/manager/modules/bll/src/test/resources/vmOvfData2.xml new file mode 100644 index 00000000000..fd73650e9e6 --- /dev/null +++ b/backend/manager/modules/bll/src/test/resources/vmOvfData2.xml @@ -0,0 +1,93 @@ + + + + + + +
+ List of networks + +
+
+ List of Virtual Disks + +
+ + sevenofnine + 00000000-0000-0000-0000-000000000000 + Blank + generated by virt-v2v 2.3.4rhel=9,release=5.el9 + + 2023/10/26 20:56:35 + True + False + + False + 1 + 2 + 2 + 1 +
+ Windows Server 2019 Datacenter + windows_2019x64 +
+
+ 8 CPU, 16384 Memory + + 8 virtual cpu + Number of virtual CPU + 1 + 3 + 1 + 8 + + + 16384 MB of memory + Memory Size + 2 + 4 + MegaBytes + 16384 + + + USB Controller + 3 + 23 + Disabled + + + Graphical Controller + e183b91f-6e02-4803-b3c7-d7e2a8d8f30e + 20 + video + 1 + vga + + + Drive 1 + e562465d-dc03-427f-8cc9-20fc1055424f + 17 + disk + 752b9199-8083-4e60-9be2-b2f13f54790f/e562465d-dc03-427f-8cc9-20fc1055424f + 00000000-0000-0000-0000-000000000000 + 00000000-0000-0000-0000-000000000000 + + dfe7c94d-f724-4bbc-9156-d47761f417c6 + 00000000-0000-0000-0000-000000000000 + 2023/10/26 20:56:35 + 2023/10/26 20:56:35 + 2023/10/26 20:56:35 + 1 + + + ab4bf497-a995-470c-8f4e-91a18c4b74fa + Ethernet adapter on DPG_VMNetwork + 10 + 1 + interface + DPG_VMNetwork + eth0 + +
+
+
\ No newline at end of file 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 1ca96f60ccd..e1df7436a4c 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 @@ -260,10 +260,10 @@ public void buildDisk() { protected void readDisk(XmlNode node, DiskImage image) { super.readDisk(node, image); - if (!StringUtils.isEmpty(node.attributes.get("ovf:size").getValue())) { + if (node.attributes.get("ovf:size") != null && !StringUtils.isEmpty(node.attributes.get("ovf:size").getValue())) { image.setSize(convertGigabyteToBytes(Long.parseLong(node.attributes.get("ovf:size").getValue()))); } - if (!StringUtils.isEmpty(node.attributes.get("ovf:actual_size").getValue())) { + if (node.attributes.get("ovf:actual_size") != null && !StringUtils.isEmpty(node.attributes.get("ovf:actual_size").getValue())) { image.setActualSizeInBytes( convertGigabyteToBytes(Long.parseLong(node.attributes.get("ovf:actual_size").getValue()))); }