mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
test: Extract common parts of test driver data allocation
This commit is contained in:
parent
8b43335abb
commit
81be22617f
@ -309,24 +309,6 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDomainXMLOptionPtr
|
|
||||||
testBuildXMLConfig(void)
|
|
||||||
{
|
|
||||||
virDomainXMLPrivateDataCallbacks priv = {
|
|
||||||
.alloc = testDomainObjPrivateAlloc,
|
|
||||||
.free = testDomainObjPrivateFree
|
|
||||||
};
|
|
||||||
|
|
||||||
/* All our XML extensions are input only, so we only need to parse */
|
|
||||||
virDomainXMLNamespace ns = {
|
|
||||||
.parse = testDomainDefNamespaceParse,
|
|
||||||
.free = testDomainDefNamespaceFree,
|
|
||||||
};
|
|
||||||
|
|
||||||
return virDomainXMLOptionNew(NULL, &priv, &ns);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virCapsPtr
|
static virCapsPtr
|
||||||
testBuildCapabilities(virConnectPtr conn)
|
testBuildCapabilities(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
@ -402,6 +384,45 @@ testBuildCapabilities(virConnectPtr conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static testDriverPtr
|
||||||
|
testDriverNew(void)
|
||||||
|
{
|
||||||
|
virDomainXMLPrivateDataCallbacks priv = {
|
||||||
|
.alloc = testDomainObjPrivateAlloc,
|
||||||
|
.free = testDomainObjPrivateFree
|
||||||
|
};
|
||||||
|
|
||||||
|
virDomainXMLNamespace ns = {
|
||||||
|
.parse = testDomainDefNamespaceParse,
|
||||||
|
.free = testDomainDefNamespaceFree,
|
||||||
|
};
|
||||||
|
testDriverPtr ret;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(ret) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (virMutexInit(&ret->lock) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("cannot initialize mutex"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, &priv, &ns)) ||
|
||||||
|
!(ret->eventState = virObjectEventStateNew()) ||
|
||||||
|
!(ret->domains = virDomainObjListNew()) ||
|
||||||
|
!(ret->networks = virNetworkObjListNew()))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
ret->nextDomID = 1;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
error:
|
||||||
|
testDriverFree(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *defaultDomainXML =
|
static const char *defaultDomainXML =
|
||||||
"<domain type='test'>"
|
"<domain type='test'>"
|
||||||
" <name>test</name>"
|
" <name>test</name>"
|
||||||
@ -730,24 +751,11 @@ testOpenDefault(virConnectPtr conn)
|
|||||||
return VIR_DRV_OPEN_SUCCESS;
|
return VIR_DRV_OPEN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(privconn) < 0)
|
if (!(privconn = testDriverNew()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virMutexInit(&privconn->lock) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("cannot initialize mutex"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
conn->privateData = privconn;
|
conn->privateData = privconn;
|
||||||
|
|
||||||
if (!(privconn->eventState = virObjectEventStateNew()))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(privconn->domains = virDomainObjListNew()) ||
|
|
||||||
!(privconn->networks = virNetworkObjListNew()))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
|
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
|
||||||
|
|
||||||
/* Numa setup */
|
/* Numa setup */
|
||||||
@ -770,11 +778,6 @@ testOpenDefault(virConnectPtr conn)
|
|||||||
if (!(privconn->caps = testBuildCapabilities(conn)))
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(privconn->xmlopt = testBuildXMLConfig()))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
privconn->nextDomID = 1;
|
|
||||||
|
|
||||||
if (!(domdef = virDomainDefParseString(defaultDomainXML,
|
if (!(domdef = virDomainDefParseString(defaultDomainXML,
|
||||||
privconn->caps,
|
privconn->caps,
|
||||||
privconn->xmlopt,
|
privconn->xmlopt,
|
||||||
@ -1412,31 +1415,15 @@ testOpenFromFile(virConnectPtr conn, const char *file)
|
|||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
testDriverPtr privconn;
|
testDriverPtr privconn;
|
||||||
|
|
||||||
if (VIR_ALLOC(privconn) < 0)
|
if (!(privconn = testDriverNew()))
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
if (virMutexInit(&privconn->lock) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("cannot initialize mutex"));
|
|
||||||
VIR_FREE(privconn);
|
|
||||||
return VIR_DRV_OPEN_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
conn->privateData = privconn;
|
conn->privateData = privconn;
|
||||||
|
|
||||||
if (!(privconn->domains = virDomainObjListNew()) ||
|
|
||||||
!(privconn->networks = virNetworkObjListNew()))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(privconn->caps = testBuildCapabilities(conn)))
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(privconn->xmlopt = testBuildXMLConfig()))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(privconn->eventState = virObjectEventStateNew()))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(doc = virXMLParseFileCtxt(file, &ctxt)))
|
if (!(doc = virXMLParseFileCtxt(file, &ctxt)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -1446,7 +1433,6 @@ testOpenFromFile(virConnectPtr conn, const char *file)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
privconn->nextDomID = 1;
|
|
||||||
privconn->numCells = 0;
|
privconn->numCells = 0;
|
||||||
if (VIR_STRDUP(privconn->path, file) < 0)
|
if (VIR_STRDUP(privconn->path, file) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user