Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the OvfOvirtReader disk read more robust #890

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ public static Stream<MockConfigDescriptor<?>> 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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
93 changes: 93 additions & 0 deletions backend/manager/modules/bll/src/test/resources/vmOvfData2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version='1.0' encoding='utf-8'?>
<ovf:Envelope xmlns:rasd='http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData' xmlns:vssd='http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ovf='http://schemas.dmtf.org/ovf/envelope/1/' xmlns:ovirt='http://www.ovirt.org/ovf' ovf:version='0.9'>
<!-- generated by virt-v2v 2.3.4rhel=9,release=5.el9 -->
<References>
<File ovf:href='752b9199-8083-4e60-9be2-b2f13f54790f/e562465d-dc03-427f-8cc9-20fc1055424f' ovf:id='e562465d-dc03-427f-8cc9-20fc1055424f' ovf:description='generated by virt-v2v 2.3.4rhel=9,release=5.el9'/>
</References>
<Section xsi:type='ovf:NetworkSection_Type'>
<Info>List of networks</Info>
<Network ovf:name='DPG_VMNetwork'/>
</Section>
<Section xsi:type='ovf:DiskSection_Type'>
<Info>List of Virtual Disks</Info>
<Disk ovf:diskId='e562465d-dc03-427f-8cc9-20fc1055424f' ovf:size='200' ovf:capacity='214748364800' ovf:fileRef='752b9199-8083-4e60-9be2-b2f13f54790f/e562465d-dc03-427f-8cc9-20fc1055424f' ovf:parentRef='' ovf:vm_snapshot_id='84038453-d7da-4dbc-8ecc-8af6b8c7c6e2' ovf:volume-format='RAW' ovf:volume-type='Sparse' ovf:format='http://en.wikipedia.org/wiki/Byte' ovf:disk-interface='IDE' ovf:disk-type='System' ovf:boot='True'/>
</Section>
<Content ovf:id='out' xsi:type='ovf:VirtualSystem_Type'>
<Name>sevenofnine</Name>
<TemplateId>00000000-0000-0000-0000-000000000000</TemplateId>
<TemplateName>Blank</TemplateName>
<Description>generated by virt-v2v 2.3.4rhel=9,release=5.el9</Description>
<Domain/>
<CreationDate>2023/10/26 20:56:35</CreationDate>
<IsInitilized>True</IsInitilized>
<IsAutoSuspend>False</IsAutoSuspend>
<TimeZone/>
<IsStateless>False</IsStateless>
<VmType>1</VmType>
<DefaultDisplayType>2</DefaultDisplayType>
<BiosType>2</BiosType>
<Origin>1</Origin>
<Section ovf:id='4a6237d9-05a0-4d5a-a7b1-ff01764a761f' ovf:required='false' xsi:type='ovf:OperatingSystemSection_Type'>
<Info>Windows Server 2019 Datacenter</Info>
<Description>windows_2019x64</Description>
</Section>
<Section xsi:type='ovf:VirtualHardwareSection_Type'>
<Info>8 CPU, 16384 Memory</Info>
<Item>
<rasd:Caption>8 virtual cpu</rasd:Caption>
<rasd:Description>Number of virtual CPU</rasd:Description>
<rasd:InstanceId>1</rasd:InstanceId>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:num_of_sockets>1</rasd:num_of_sockets>
<rasd:cpu_per_socket>8</rasd:cpu_per_socket>
</Item>
<Item>
<rasd:Caption>16384 MB of memory</rasd:Caption>
<rasd:Description>Memory Size</rasd:Description>
<rasd:InstanceId>2</rasd:InstanceId>
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
<rasd:VirtualQuantity>16384</rasd:VirtualQuantity>
</Item>
<Item>
<rasd:Caption>USB Controller</rasd:Caption>
<rasd:InstanceId>3</rasd:InstanceId>
<rasd:ResourceType>23</rasd:ResourceType>
<rasd:UsbPolicy>Disabled</rasd:UsbPolicy>
</Item>
<Item>
<rasd:Caption>Graphical Controller</rasd:Caption>
<rasd:InstanceId>e183b91f-6e02-4803-b3c7-d7e2a8d8f30e</rasd:InstanceId>
<rasd:ResourceType>20</rasd:ResourceType>
<Type>video</Type>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<Device>vga</Device>
</Item>
<Item>
<rasd:Caption>Drive 1</rasd:Caption>
<rasd:InstanceId>e562465d-dc03-427f-8cc9-20fc1055424f</rasd:InstanceId>
<rasd:ResourceType>17</rasd:ResourceType>
<Type>disk</Type>
<rasd:HostResource>752b9199-8083-4e60-9be2-b2f13f54790f/e562465d-dc03-427f-8cc9-20fc1055424f</rasd:HostResource>
<rasd:Parent>00000000-0000-0000-0000-000000000000</rasd:Parent>
<rasd:Template>00000000-0000-0000-0000-000000000000</rasd:Template>
<rasd:ApplicationList/>
<rasd:StorageId>dfe7c94d-f724-4bbc-9156-d47761f417c6</rasd:StorageId>
<rasd:StoragePoolId>00000000-0000-0000-0000-000000000000</rasd:StoragePoolId>
<rasd:CreationDate>2023/10/26 20:56:35</rasd:CreationDate>
<rasd:LastModified>2023/10/26 20:56:35</rasd:LastModified>
<rasd:last_modified_date>2023/10/26 20:56:35</rasd:last_modified_date>
<BootOrder>1</BootOrder>
</Item>
<Item>
<rasd:InstanceId>ab4bf497-a995-470c-8f4e-91a18c4b74fa</rasd:InstanceId>
<rasd:Caption>Ethernet adapter on DPG_VMNetwork</rasd:Caption>
<rasd:ResourceType>10</rasd:ResourceType>
<rasd:ResourceSubType>1</rasd:ResourceSubType>
<Type>interface</Type>
<rasd:Connection>DPG_VMNetwork</rasd:Connection>
<rasd:Name>eth0</rasd:Name>
</Item>
</Section>
</Content>
</ovf:Envelope>
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}
Expand Down