Add tests for the new Qemu namespace XML.

Thanks to DV for knocking together the Relax-NG changes
quickly for me.

Changes since v1:
 - Change the domain.rng to correspond to the new schema
 - Don't allocate caps->ns in testQemuCapsInit since it is a static table

Changes since v2:
 - Change domain.rng to add restrictions on allowed environment names

Changes since v3:
 - Remove a bogus comment in the tests

Signed-off-by: Chris Lalancette <clalance@redhat.com>
This commit is contained in:
Chris Lalancette 2010-04-20 17:22:49 -04:00
parent 337d201ef2
commit a71be01f04
10 changed files with 118 additions and 8 deletions

View File

@ -41,6 +41,9 @@
<optional>
<ref name="seclabel"/>
</optional>
<optional>
<ref name='qemucmdline'/>
</optional>
</interleave>
</element>
</define>
@ -1680,6 +1683,31 @@
</optional>
</define>
<!--
Optional hypervisor extensions in their own namespace:
QEmu
-->
<define name="qemucmdline">
<element name="commandline" ns="http://libvirt.org/schemas/domain/qemu/1.0">
<zeroOrMore>
<element name="arg">
<attribute name='value'/>
</element>
</zeroOrMore>
<zeroOrMore>
<element name="env">
<attribute name='name'>
<ref name="filter-param-name"/>
</attribute>
<optional>
<attribute name='value'/>
</optional>
<empty/>
</element>
</zeroOrMore>
</element>
</define>
<!--
Type library

View File

@ -552,7 +552,7 @@ static void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
virDomainObjUnref(obj);
}
static void qemuDomainDefNamespaceFree(void *nsdata)
void qemuDomainDefNamespaceFree(void *nsdata)
{
qemuDomainCmdlineDefPtr cmd = nsdata;
unsigned int i;
@ -572,10 +572,10 @@ static void qemuDomainDefNamespaceFree(void *nsdata)
VIR_FREE(cmd);
}
static int qemuDomainDefNamespaceParse(xmlDocPtr xml,
xmlNodePtr root,
xmlXPathContextPtr ctxt,
void **data)
int qemuDomainDefNamespaceParse(xmlDocPtr xml,
xmlNodePtr root,
xmlXPathContextPtr ctxt,
void **data)
{
qemuDomainCmdlineDefPtr cmd = NULL;
xmlNsPtr ns;
@ -685,8 +685,8 @@ error:
return -1;
}
static int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
void *nsdata)
int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
void *nsdata)
{
qemuDomainCmdlineDefPtr cmd = nsdata;
unsigned int i;
@ -709,7 +709,7 @@ static int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
return 0;
}
static const char *qemuDomainDefNamespaceHref(void)
const char *qemuDomainDefNamespaceHref(void)
{
return "xmlns:qemu='" QEMU_NAMESPACE_HREF "'";
}

View File

@ -27,6 +27,8 @@
# include <config.h>
# include <libxml/xpath.h>
# include "internal.h"
# if HAVE_LINUX_KVM_H
@ -49,4 +51,13 @@
int qemuRegister(void);
void qemuDomainDefNamespaceFree(void *nsdata);
int qemuDomainDefNamespaceParse(xmlDocPtr xml,
xmlNodePtr root,
xmlXPathContextPtr ctxt,
void **data);
int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
void *nsdata);
const char *qemuDomainDefNamespaceHref(void);
#endif /* QEMUD_DRIVER_H */

View File

@ -228,6 +228,8 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000");
DO_TEST("qemu-ns-no-env", 0);
free(driver.stateDir);
virCapabilitiesFree(driver.caps);

View File

@ -0,0 +1 @@
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -unknown parameter

View File

@ -0,0 +1,29 @@
<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219200</memory>
<currentMemory>219200</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<memballoon model='virtio'/>
</devices>
<qemu:commandline>
<qemu:arg value='-unknown'/>
<qemu:arg value='parameter'/>
</qemu:commandline>
</domain>

View File

@ -0,0 +1 @@
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test NS=ns BAR= /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -unknown parameter

View File

@ -0,0 +1,30 @@
<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219200</memory>
<currentMemory>219200</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
<qemu:commandline>
<qemu:arg value='-unknown'/>
<qemu:arg value='parameter'/>
<qemu:env name='NS' value='ns'/>
<qemu:env name='BAR'/>
</qemu:commandline>
</domain>

View File

@ -370,6 +370,8 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000");
DO_TEST("qemu-ns", 0);
free(driver.stateDir);
virCapabilitiesFree(driver.caps);

View File

@ -7,6 +7,7 @@
# include "testutils.h"
# include "memory.h"
# include "cpu_conf.h"
# include "qemu/qemu_driver.h"
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
@ -100,6 +101,11 @@ virCapsPtr testQemuCapsInit(void) {
(machines = testQemuAllocMachines(&nmachines)) == NULL)
goto cleanup;
caps->ns.parse = qemuDomainDefNamespaceParse;
caps->ns.free = qemuDomainDefNamespaceFree;
caps->ns.format = qemuDomainDefNamespaceFormatXML;
caps->ns.href = qemuDomainDefNamespaceHref;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
"/usr/bin/qemu", NULL,
nmachines, machines)) == NULL)