mirror of https://github.com/apache/cloudstack.git
kvm: fix NPE while import KVM VMs from other hosts (#8720)
This commit is contained in:
parent
e86363be8e
commit
a7ec8738a2
|
|
@ -419,6 +419,9 @@ public class LibvirtDomainXMLParser {
|
|||
}
|
||||
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
if (eElement == null) {
|
||||
return null;
|
||||
}
|
||||
NodeList tagNodeList = eElement.getElementsByTagName(tag);
|
||||
if (tagNodeList == null || tagNodeList.getLength() == 0) {
|
||||
return null;
|
||||
|
|
@ -426,14 +429,20 @@ public class LibvirtDomainXMLParser {
|
|||
|
||||
NodeList nlList = tagNodeList.item(0).getChildNodes();
|
||||
|
||||
if (nlList == null || nlList.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Node nValue = nlList.item(0);
|
||||
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
if (eElement == null) {
|
||||
return null;
|
||||
}
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
if (tag == null || tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element)tagNode.item(0);
|
||||
|
|
|
|||
|
|
@ -259,4 +259,126 @@ public class LibvirtDomainXMLParserTest extends TestCase {
|
|||
assertEquals(WatchDogDef.WatchDogModel.I6300ESB, watchDogs.get(0).getModel());
|
||||
assertEquals(WatchDogDef.WatchDogAction.RESET, watchDogs.get(0).getAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomainXMLParserWithoutModelName() {
|
||||
String xml = "<domain type='kvm'>\n" +
|
||||
" <name>testkiran</name>\n" +
|
||||
" <uuid>aafaaabc-8657-4efc-9c52-3422d4e04088</uuid>\n" +
|
||||
" <memory unit='KiB'>2097152</memory>\n" +
|
||||
" <currentMemory unit='KiB'>2097152</currentMemory>\n" +
|
||||
" <vcpu placement='static'>2</vcpu>\n" +
|
||||
" <os>\n" +
|
||||
" <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>\n" +
|
||||
" <boot dev='hd'/>\n" +
|
||||
" </os>\n" +
|
||||
" <features>\n" +
|
||||
" <acpi/>\n" +
|
||||
" <apic/>\n" +
|
||||
" </features>\n" +
|
||||
" <cpu mode='host-model' check='partial'>\n" +
|
||||
" <model fallback='allow'/>\n" +
|
||||
" </cpu>\n" +
|
||||
" <clock offset='utc'>\n" +
|
||||
" <timer name='rtc' tickpolicy='catchup'/>\n" +
|
||||
" <timer name='pit' tickpolicy='delay'/>\n" +
|
||||
" <timer name='hpet' present='no'/>\n" +
|
||||
" </clock>\n" +
|
||||
" <on_poweroff>destroy</on_poweroff>\n" +
|
||||
" <on_reboot>restart</on_reboot>\n" +
|
||||
" <on_crash>destroy</on_crash>\n" +
|
||||
" <pm>\n" +
|
||||
" <suspend-to-mem enabled='no'/>\n" +
|
||||
" <suspend-to-disk enabled='no'/>\n" +
|
||||
" </pm>\n" +
|
||||
" <devices>\n" +
|
||||
" <emulator>/usr/libexec/qemu-kvm</emulator>\n" +
|
||||
" <disk type='file' device='disk'>\n" +
|
||||
" <driver name='qemu' type='qcow2'/>\n" +
|
||||
" <source file='/var/lib/libvirt/images/ubuntu-22.04.qcow2'/>\n" +
|
||||
" <target dev='vda' bus='virtio'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>\n" +
|
||||
" </disk>\n" +
|
||||
" <disk type='file' device='disk'>\n" +
|
||||
" <driver name='qemu' type='qcow2'/>\n" +
|
||||
" <source file='/var/lib/libvirt/images/testkiran.qcow2'/>\n" +
|
||||
" <target dev='vdb' bus='virtio'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>\n" +
|
||||
" </disk>\n" +
|
||||
" <controller type='usb' index='0' model='ich9-ehci1'>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>\n" +
|
||||
" </controller>\n" +
|
||||
" <controller type='usb' index='0' model='ich9-uhci1'>\n" +
|
||||
" <master startport='0'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>\n" +
|
||||
" </controller>\n" +
|
||||
" <controller type='usb' index='0' model='ich9-uhci2'>\n" +
|
||||
" <master startport='2'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>\n" +
|
||||
" </controller>\n" +
|
||||
" <controller type='usb' index='0' model='ich9-uhci3'>\n" +
|
||||
" <master startport='4'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>\n" +
|
||||
" </controller>\n" +
|
||||
" <controller type='pci' index='0' model='pci-root'/>\n" +
|
||||
" <controller type='virtio-serial' index='0'>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>\n" +
|
||||
" </controller>\n" +
|
||||
" <interface type='network'>\n" +
|
||||
" <mac address='52:54:00:09:73:b8'/>\n" +
|
||||
" <source network='default'/>\n" +
|
||||
" <model type='virtio'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>\n" +
|
||||
" </interface>\n" +
|
||||
" <serial type='pty'>\n" +
|
||||
" <target type='isa-serial' port='0'>\n" +
|
||||
" <model name='isa-serial'/>\n" +
|
||||
" </target>\n" +
|
||||
" </serial>\n" +
|
||||
" <console type='pty'>\n" +
|
||||
" <target type='serial' port='0'/>\n" +
|
||||
" </console>\n" +
|
||||
" <channel type='spicevmc'>\n" +
|
||||
" <target type='virtio' name='com.redhat.spice.0'/>\n" +
|
||||
" <address type='virtio-serial' controller='0' bus='0' port='1'/>\n" +
|
||||
" </channel>\n" +
|
||||
" <input type='tablet' bus='usb'>\n" +
|
||||
" <address type='usb' bus='0' port='1'/>\n" +
|
||||
" </input>\n" +
|
||||
" <input type='mouse' bus='ps2'/>\n" +
|
||||
" <input type='keyboard' bus='ps2'/>\n" +
|
||||
" <graphics type='vnc' port='-1' autoport='yes'>\n" +
|
||||
" <listen type='address'/>\n" +
|
||||
" </graphics>\n" +
|
||||
" <graphics type='spice' autoport='yes'>\n" +
|
||||
" <listen type='address'/>\n" +
|
||||
" <image compression='off'/>\n" +
|
||||
" </graphics>\n" +
|
||||
" <sound model='ich6'>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>\n" +
|
||||
" </sound>\n" +
|
||||
" <video>\n" +
|
||||
" <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>\n" +
|
||||
" </video>\n" +
|
||||
" <redirdev bus='usb' type='spicevmc'>\n" +
|
||||
" <address type='usb' bus='0' port='2'/>\n" +
|
||||
" </redirdev>\n" +
|
||||
" <redirdev bus='usb' type='spicevmc'>\n" +
|
||||
" <address type='usb' bus='0' port='3'/>\n" +
|
||||
" </redirdev>\n" +
|
||||
" <memballoon model='virtio'>\n" +
|
||||
" <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>\n" +
|
||||
" </memballoon>\n" +
|
||||
" </devices>\n" +
|
||||
"</domain>";
|
||||
|
||||
LibvirtDomainXMLParser libvirtDomainXMLParser = new LibvirtDomainXMLParser();
|
||||
try {
|
||||
libvirtDomainXMLParser.parseDomainXML(xml);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Got exception " + e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue