mirror of https://gitee.com/openkylin/libvirt.git
qemuhotplugtest: Compare domain XML after device hotplug
We need to make sure a device is properly added/removed (or not) to a domain definition to check that a hotplug API did not lie to us.
This commit is contained in:
parent
8d4189d504
commit
ac5255f914
tests
|
@ -52,7 +52,7 @@ struct qemuHotplugTestData {
|
|||
static int
|
||||
qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
|
||||
virDomainObjPtr *vm,
|
||||
const char *filename)
|
||||
const char *domxml)
|
||||
{
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = NULL;
|
||||
|
@ -60,11 +60,11 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
|
|||
if (!(*vm = virDomainObjNew(xmlopt)))
|
||||
goto cleanup;
|
||||
|
||||
if (!((*vm)->def = virDomainDefParseFile(filename,
|
||||
driver.caps,
|
||||
driver.xmlopt,
|
||||
QEMU_EXPECTED_VIRT_TYPES,
|
||||
0)))
|
||||
if (!((*vm)->def = virDomainDefParseString(domxml,
|
||||
driver.caps,
|
||||
driver.xmlopt,
|
||||
QEMU_EXPECTED_VIRT_TYPES,
|
||||
0)))
|
||||
goto cleanup;
|
||||
|
||||
priv = (*vm)->privateData;
|
||||
|
@ -149,6 +149,32 @@ testQemuHotplugUpdate(virDomainObjPtr vm,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
testQemuHotplugCheckResult(virDomainObjPtr vm,
|
||||
const char *expected,
|
||||
bool fail)
|
||||
{
|
||||
char *actual;
|
||||
int ret;
|
||||
|
||||
actual = virDomainDefFormat(vm->def, VIR_DOMAIN_XML_SECURE);
|
||||
if (!actual)
|
||||
return -1;
|
||||
|
||||
if (STREQ(expected, actual)) {
|
||||
if (fail && virTestGetVerbose())
|
||||
fprintf(stderr, "domain XML should not match the expected result\n");
|
||||
ret = 0;
|
||||
} else {
|
||||
if (!fail)
|
||||
virtTestDifference(stderr, expected, actual);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
VIR_FREE(actual);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
testQemuHotplug(const void *data)
|
||||
{
|
||||
|
@ -156,7 +182,10 @@ testQemuHotplug(const void *data)
|
|||
struct qemuHotplugTestData *test = (struct qemuHotplugTestData *) data;
|
||||
char *domain_filename = NULL;
|
||||
char *device_filename = NULL;
|
||||
char *result_filename = NULL;
|
||||
char *domain_xml = NULL;
|
||||
char *device_xml = NULL;
|
||||
char *result_xml = NULL;
|
||||
const char *const *tmp;
|
||||
bool fail = test->fail;
|
||||
bool keep = test->keep;
|
||||
|
@ -169,7 +198,19 @@ testQemuHotplug(const void *data)
|
|||
if (virAsprintf(&domain_filename, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
|
||||
abs_srcdir, test->domain_filename) < 0 ||
|
||||
virAsprintf(&device_filename, "%s/qemuhotplugtestdata/qemuhotplug-%s.xml",
|
||||
abs_srcdir, test->device_filename) < 0)
|
||||
abs_srcdir, test->device_filename) < 0 ||
|
||||
virAsprintf(&result_filename,
|
||||
"%s/qemuhotplugtestdata/qemuhotplug-%s+%s.xml",
|
||||
abs_srcdir, test->domain_filename,
|
||||
test->device_filename) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(domain_filename, &domain_xml) < 0 ||
|
||||
virtTestLoadFile(device_filename, &device_xml) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (test->action != UPDATE &&
|
||||
virtTestLoadFile(result_filename, &result_xml) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(caps = virQEMUDriverGetCapabilities(&driver, false)))
|
||||
|
@ -178,13 +219,10 @@ testQemuHotplug(const void *data)
|
|||
if (test->vm) {
|
||||
vm = test->vm;
|
||||
} else {
|
||||
if (qemuHotplugCreateObjects(driver.xmlopt, &vm, domain_filename) < 0)
|
||||
if (qemuHotplugCreateObjects(driver.xmlopt, &vm, domain_xml) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virtTestLoadFile(device_filename, &device_xml) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(dev = virDomainDeviceDefParse(device_xml, vm->def,
|
||||
caps, driver.xmlopt, 0)))
|
||||
goto cleanup;
|
||||
|
@ -218,10 +256,14 @@ testQemuHotplug(const void *data)
|
|||
switch (test->action) {
|
||||
case ATTACH:
|
||||
ret = testQemuHotplugAttach(vm, dev);
|
||||
if (ret == 0 || fail)
|
||||
ret = testQemuHotplugCheckResult(vm, result_xml, fail);
|
||||
break;
|
||||
|
||||
case DETACH:
|
||||
ret = testQemuHotplugDetach(vm, dev);
|
||||
if (ret == 0 || fail)
|
||||
ret = testQemuHotplugCheckResult(vm, domain_xml, fail);
|
||||
break;
|
||||
|
||||
case UPDATE:
|
||||
|
@ -231,7 +273,10 @@ testQemuHotplug(const void *data)
|
|||
cleanup:
|
||||
VIR_FREE(domain_filename);
|
||||
VIR_FREE(device_filename);
|
||||
VIR_FREE(result_filename);
|
||||
VIR_FREE(domain_xml);
|
||||
VIR_FREE(device_xml);
|
||||
VIR_FREE(result_xml);
|
||||
/* don't dispose test monitor with VM */
|
||||
if (priv)
|
||||
priv->mon = NULL;
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
<domain type='kvm' id='2'>
|
||||
<name>f17</name>
|
||||
<uuid>a1cd52eb-d37f-4717-fc6e-972f0774f4c9</uuid>
|
||||
<memory unit='KiB'>1048576</memory>
|
||||
<currentMemory unit='KiB'>1048576</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<resource>
|
||||
<partition>/machine</partition>
|
||||
</resource>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-1.4'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<pm>
|
||||
<suspend-to-mem enabled='yes'/>
|
||||
<suspend-to-disk enabled='yes'/>
|
||||
</pm>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' cache='none'/>
|
||||
<source file='/var/lib/libvirt/images/f17.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<alias name='virtio-disk0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw' cache='none'/>
|
||||
<source file='/home/user/tmp/Fedora-17-x86_64-Live-KDE.iso'/>
|
||||
<target dev='hdc' bus='ide'/>
|
||||
<readonly/>
|
||||
<alias name='ide0-1-0'/>
|
||||
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='ide' index='0'>
|
||||
<alias name='ide0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='usb' index='0'>
|
||||
<alias name='usb0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'>
|
||||
<alias name='pci0'/>
|
||||
</controller>
|
||||
<controller type='virtio-serial' index='0'>
|
||||
<alias name='virtio-serial0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
||||
</controller>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:ea:35:6f'/>
|
||||
<source network='default'/>
|
||||
<target dev='vnet0'/>
|
||||
<model type='virtio'/>
|
||||
<bandwidth>
|
||||
<inbound average='4000' peak='8000' floor='200' burst='1024'/>
|
||||
<outbound average='4000' peak='8000' burst='1024'/>
|
||||
</bandwidth>
|
||||
<alias name='net0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</interface>
|
||||
<serial type='pty'>
|
||||
<source path='/dev/pts/22'/>
|
||||
<target type='isa-serial' port='0'/>
|
||||
<alias name='serial0'/>
|
||||
</serial>
|
||||
<serial type='pty'>
|
||||
<source path='/dev/pts/25'/>
|
||||
<target port='0'/>
|
||||
<alias name='serial1'/>
|
||||
</serial>
|
||||
<serial type='tcp'>
|
||||
<source mode='bind' host='0.0.0.0' service='2445'/>
|
||||
<protocol type='raw'/>
|
||||
<target port='1'/>
|
||||
<alias name='serial2'/>
|
||||
</serial>
|
||||
<console type='pty' tty='/dev/pts/22'>
|
||||
<source path='/dev/pts/22'/>
|
||||
<target type='serial' port='0'/>
|
||||
<alias name='serial0'/>
|
||||
</console>
|
||||
<console type='pty'>
|
||||
<source path='/dev/pts/26'/>
|
||||
<target type='virtio' port='1'/>
|
||||
<alias name='console1'/>
|
||||
</console>
|
||||
<channel type='unix'>
|
||||
<source mode='bind' path='/var/lib/libvirt/qemu/f17x86_64.agent'/>
|
||||
<target type='virtio' name='org.qemu.guest_agent.0'/>
|
||||
<alias name='channel0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='1'/>
|
||||
</channel>
|
||||
<input type='tablet' bus='usb'>
|
||||
<alias name='input0'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>
|
||||
<listen type='address' address='0.0.0.0'/>
|
||||
</graphics>
|
||||
<sound model='ich6'>
|
||||
<alias name='sound0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</sound>
|
||||
<video>
|
||||
<model type='cirrus' vram='9216' heads='1'/>
|
||||
<alias name='video0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
<memballoon model='virtio'>
|
||||
<alias name='balloon0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
<seclabel type='static' model='dac' relabel='no'>
|
||||
<label>root:root</label>
|
||||
</seclabel>
|
||||
</domain>
|
Loading…
Reference in New Issue