test: Support loading node device info from file/XML

Also add some XML examples.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2009-10-02 10:05:17 -04:00
parent 7165bef132
commit e22f2f5c9c
4 changed files with 75 additions and 1 deletions

View File

@ -0,0 +1,16 @@
<device>
<name>File_test_device</name>
<capability type='system'>
<hardware>
<vendor>Libvirt</vendor>
<version>Test driver</version>
<serial>123456</serial>
<uuid>11111111-2222-3333-4444-555555555555</uuid>
</hardware>
<firmware>
<vendor>Libvirt</vendor>
<version>Test Driver</version>
<release_date>01/22/2007</release_date>
</firmware>
</capability>
</device>

View File

@ -14,6 +14,7 @@
<pool file="testpool.xml">
<volume file="testvol.xml"/>
</pool>
<device file="testdev.xml"/>
<cpu>
<mhz>6000</mhz>

View File

@ -97,6 +97,25 @@
</dhcp>
</ip>
</network>
<device>
<name>File_test_device</name>
<capability type='system'>
<hardware>
<vendor>Libvirt</vendor>
<version>Test driver</version>
<serial>123456</serial>
<uuid>11111111-2222-3333-4444-555555555555</uuid>
</hardware>
<firmware>
<vendor>Libvirt</vendor>
<version>Test Driver</version>
<release_date>01/22/2007</release_date>
</firmware>
</capability>
</device>
<cpu>
<mhz>6000</mhz>
<model>i986</model>

View File

@ -547,7 +547,8 @@ static int testOpenFromFile(virConnectPtr conn,
char *str;
xmlDocPtr xml = NULL;
xmlNodePtr root = NULL;
xmlNodePtr *domains = NULL, *networks = NULL, *ifaces = NULL, *pools = NULL;
xmlNodePtr *domains = NULL, *networks = NULL, *ifaces = NULL,
*pools = NULL, *devs = NULL;
xmlXPathContextPtr ctxt = NULL;
virNodeInfoPtr nodeInfo;
virNetworkObjPtr net;
@ -841,6 +842,43 @@ static int testOpenFromFile(virConnectPtr conn,
}
VIR_FREE(pools);
ret = virXPathNodeSet(conn, "/node/device", ctxt, &devs);
if (ret < 0) {
testError(NULL, VIR_ERR_XML_ERROR, "%s", _("node device list"));
goto error;
}
for (i = 0 ; i < ret ; i++) {
virNodeDeviceDefPtr def;
virNodeDeviceObjPtr dev;
char *relFile = virXMLPropString(devs[i], "file");
if (relFile != NULL) {
char *absFile = testBuildFilename(file, relFile);
VIR_FREE(relFile);
if (!absFile) {
testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
_("resolving device filename"));
goto error;
}
def = virNodeDeviceDefParseFile(conn, absFile, 0);
VIR_FREE(absFile);
if (!def)
goto error;
} else {
if ((def = virNodeDeviceDefParseNode(conn, xml, devs[i], 0)) == NULL)
goto error;
}
if (!(dev = virNodeDeviceAssignDef(conn, &privconn->devs, def))) {
virNodeDeviceDefFree(def);
goto error;
}
virNodeDeviceObjUnlock(dev);
}
VIR_FREE(devs);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml);
testDriverUnlock(privconn);