1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

test: Allow specifying domainsnapshot XML

The user can pass it as a <test:domainsnapshot> subelement of a <domain>.
This commit is contained in:
Cole Robinson 2013-08-07 10:57:55 -04:00
parent 56ff156d15
commit 1d24185284

View File

@ -162,12 +162,24 @@ struct _testDomainNamespaceDef {
int runstate; int runstate;
bool transient; bool transient;
bool hasManagedSave; bool hasManagedSave;
unsigned int num_snap_nodes;
xmlNodePtr *snap_nodes;
}; };
static void static void
testDomainDefNamespaceFree(void *data) testDomainDefNamespaceFree(void *data)
{ {
testDomainNamespaceDefPtr nsdata = data; testDomainNamespaceDefPtr nsdata = data;
size_t i;
if (!nsdata)
return;
for (i = 0; i < nsdata->num_snap_nodes; i++)
xmlFreeNode(nsdata->snap_nodes[i]);
VIR_FREE(nsdata->snap_nodes);
VIR_FREE(nsdata); VIR_FREE(nsdata);
} }
@ -178,7 +190,9 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED,
void **data) void **data)
{ {
testDomainNamespaceDefPtr nsdata = NULL; testDomainNamespaceDefPtr nsdata = NULL;
int tmp; xmlNodePtr *nodes = NULL;
int tmp, n;
size_t i;
unsigned int tmpuint; unsigned int tmpuint;
if (xmlXPathRegisterNs(ctxt, BAD_CAST "test", if (xmlXPathRegisterNs(ctxt, BAD_CAST "test",
@ -192,6 +206,25 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED,
if (VIR_ALLOC(nsdata) < 0) if (VIR_ALLOC(nsdata) < 0)
return -1; return -1;
n = virXPathNodeSet("./test:domainsnapshot", ctxt, &nodes);
if (n < 0)
goto error;
if (n && VIR_ALLOC_N(nsdata->snap_nodes, n) < 0)
goto error;
for (i = 0; i < n; i++) {
xmlNodePtr newnode = xmlCopyNode(nodes[i], 1);
if (!newnode) {
virReportOOMError();
goto error;
}
nsdata->snap_nodes[nsdata->num_snap_nodes] = newnode;
nsdata->num_snap_nodes++;
}
VIR_FREE(nodes);
tmp = virXPathBoolean("boolean(./test:transient)", ctxt); tmp = virXPathBoolean("boolean(./test:transient)", ctxt);
if (tmp == -1) { if (tmp == -1) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid transient")); virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid transient"));
@ -237,6 +270,7 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED,
return 0; return 0;
error: error:
VIR_FREE(nodes);
testDomainDefNamespaceFree(nsdata); testDomainDefNamespaceFree(nsdata);
return -1; return -1;
} }
@ -932,6 +966,63 @@ error:
return -1; return -1;
} }
static int
testParseDomainSnapshots(testConnPtr privconn,
virDomainObjPtr domobj,
const char *file,
xmlXPathContextPtr ctxt)
{
size_t i;
int ret = -1;
testDomainNamespaceDefPtr nsdata = domobj->def->namespaceData;
xmlNodePtr *nodes = nsdata->snap_nodes;
for (i = 0; i < nsdata->num_snap_nodes; i++) {
virDomainSnapshotObjPtr snap;
virDomainSnapshotDefPtr def;
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
"domainsnapshot");
if (!node)
goto error;
def = virDomainSnapshotDefParseNode(ctxt->doc, node,
privconn->caps,
privconn->xmlopt,
1 << VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_SNAPSHOT_PARSE_DISKS |
VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL |
VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE);
if (!def)
goto error;
if (!(snap = virDomainSnapshotAssignDef(domobj->snapshots, def))) {
virDomainSnapshotDefFree(def);
goto error;
}
if (def->current) {
if (domobj->current_snapshot) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("more than one snapshot claims to be active"));
goto error;
}
domobj->current_snapshot = snap;
}
}
if (virDomainSnapshotUpdateRelations(domobj->snapshots) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Snapshots have inconsistent relations for "
"domain %s"), domobj->def->name);
goto error;
}
ret = 0;
error:
return ret;
}
static int static int
testParseDomains(testConnPtr privconn, testParseDomains(testConnPtr privconn,
const char *file, const char *file,
@ -970,6 +1061,11 @@ testParseDomains(testConnPtr privconn,
goto error; goto error;
} }
if (testParseDomainSnapshots(privconn, obj, file, ctxt) < 0) {
virObjectUnlock(obj);
goto error;
}
nsdata = def->namespaceData; nsdata = def->namespaceData;
obj->persistent = !nsdata->transient; obj->persistent = !nsdata->transient;
obj->hasManagedSave = nsdata->hasManagedSave; obj->hasManagedSave = nsdata->hasManagedSave;