Convert the individual XML documents into one big XML document
in the format expected by the non-default test://$PATH URI, and
use the same internal helpers for assembling the driver contents.
---
src/test/test_driver.c | 142 +++++++++++++------------------------------------
1 file changed, 37 insertions(+), 105 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e0d3e60..3f3e405 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -407,7 +407,8 @@ testDriverNew(void)
}
-static const char *defaultDomainXML =
+static const char *defaultConnXML =
+"<node>"
"<domain type='test'>"
" <name>test</name>"
" <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>"
@@ -417,10 +418,8 @@ static const char *defaultDomainXML =
" <os>"
" <type>hvm</type>"
" </os>"
-"</domain>";
-
-
-static const char *defaultNetworkXML =
+"</domain>"
+""
"<network>"
" <name>default</name>"
" <uuid>dd8fe884-6c02-601e-7551-cca97df1c5df</uuid>"
@@ -431,9 +430,8 @@ static const char *defaultNetworkXML =
" <range start='192.168.122.2'
end='192.168.122.254'/>"
" </dhcp>"
" </ip>"
-"</network>";
-
-static const char *defaultInterfaceXML =
+"</network>"
+""
"<interface type=\"ethernet\" name=\"eth1\">"
" <start mode=\"onboot\"/>"
" <mac address=\"aa:bb:cc:dd:ee:ff\"/>"
@@ -442,16 +440,34 @@ static const char *defaultInterfaceXML =
" <ip address=\"192.168.0.5\" prefix=\"24\"/>"
" <route gateway=\"192.168.0.1\"/>"
" </protocol>"
-"</interface>";
-
-static const char *defaultPoolXML =
+"</interface>"
+""
"<pool type='dir'>"
" <name>default-pool</name>"
" <uuid>dfe224cb-28fb-8dd0-c4b2-64eb3f0f4566</uuid>"
" <target>"
" <path>/default-pool</path>"
" </target>"
-"</pool>";
+"</pool>"
+""
+"<device>"
+" <name>computer</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>"
+"</node>";
+
static const char *defaultPoolSourcesLogicalXML =
"<sources>\n"
@@ -476,24 +492,6 @@ static const char *defaultPoolSourcesNetFSXML =
" </source>\n"
"</sources>\n";
-static const char *defaultNodeXML =
-"<device>"
-" <name>computer</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>";
-
static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull);
static const unsigned long long defaultPoolAlloc;
@@ -1239,16 +1237,8 @@ testOpenDefault(virConnectPtr conn)
{
int u;
testDriverPtr privconn = NULL;
- virDomainDefPtr domdef = NULL;
- virDomainObjPtr domobj = NULL;
- virNetworkDefPtr netdef = NULL;
- virNetworkObjPtr netobj = NULL;
- virInterfaceDefPtr interfacedef = NULL;
- virInterfaceObjPtr interfaceobj = NULL;
- virStoragePoolDefPtr pooldef = NULL;
- virStoragePoolObjPtr poolobj = NULL;
- virNodeDeviceDefPtr nodedef = NULL;
- virNodeDeviceObjPtr nodeobj = NULL;
+ xmlDocPtr doc = NULL;
+ xmlXPathContextPtr ctxt = NULL;
virMutexLock(&defaultLock);
if (defaultConnections++) {
@@ -1284,84 +1274,26 @@ testOpenDefault(virConnectPtr conn)
if (!(privconn->caps = testBuildCapabilities(conn)))
goto error;
- if (!(domdef = virDomainDefParseString(defaultDomainXML,
- privconn->caps,
- privconn->xmlopt,
- VIR_DOMAIN_DEF_PARSE_INACTIVE)))
+ if (!(doc = virXMLParseStringCtxt(defaultConnXML,
+ _("(test driver)"), &ctxt)))
goto error;
- if (testDomainGenerateIfnames(domdef) < 0)
- goto error;
- if (!(domobj = virDomainObjListAdd(privconn->domains,
- domdef,
- privconn->xmlopt,
- 0, NULL)))
+ if (testOpenParse(privconn, NULL, ctxt) < 0)
goto error;
- domdef = NULL;
-
- domobj->persistent = 1;
- if (testDomainStartState(privconn, domobj,
- VIR_DOMAIN_RUNNING_BOOTED) < 0) {
- virObjectUnlock(domobj);
- goto error;
- }
-
- virObjectUnlock(domobj);
-
- if (!(netdef = virNetworkDefParseString(defaultNetworkXML)))
- goto error;
- if (!(netobj = virNetworkAssignDef(privconn->networks, netdef, 0))) {
- virNetworkDefFree(netdef);
- goto error;
- }
- netobj->active = 1;
- virNetworkObjEndAPI(&netobj);
-
- if (!(interfacedef = virInterfaceDefParseString(defaultInterfaceXML)))
- goto error;
- if (!(interfaceobj = virInterfaceAssignDef(&privconn->ifaces, interfacedef)))
{
- virInterfaceDefFree(interfacedef);
- goto error;
- }
- interfaceobj->active = 1;
- virInterfaceObjUnlock(interfaceobj);
-
- if (!(pooldef = virStoragePoolDefParseString(defaultPoolXML)))
- goto error;
-
- if (!(poolobj = virStoragePoolObjAssignDef(&privconn->pools,
- pooldef))) {
- virStoragePoolDefFree(pooldef);
- goto error;
- }
-
- if (testStoragePoolObjSetDefaults(poolobj) == -1) {
- virStoragePoolObjUnlock(poolobj);
- goto error;
- }
- poolobj->active = 1;
- virStoragePoolObjUnlock(poolobj);
-
- /* Init default node device */
- if (!(nodedef = virNodeDeviceDefParseString(defaultNodeXML, 0, NULL)))
- goto error;
- if (!(nodeobj = virNodeDeviceAssignDef(&privconn->devs,
- nodedef))) {
- virNodeDeviceDefFree(nodedef);
- goto error;
- }
- virNodeDeviceObjUnlock(nodeobj);
defaultConn = privconn;
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doc);
virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_SUCCESS;
error:
testDriverFree(privconn);
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doc);
conn->privateData = NULL;
- virDomainDefFree(domdef);
defaultConnections--;
virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_ERROR;
--
2.7.4