[PATCH v4 6/8] test: Implement bulk snapshot operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement the new API calls for bulk snapshot dump and import. The
bulk of the work is already done by the common code.

Since each connection to test:///default restarts at the same
canned state, this can easily be tested with:

$ virsh -c test:///default "
   snapshot-create-as test s1
   snapshot-create-as test s2
   echo witness
   snapshot-dumpxml test --all" | sed '1,/witness/d' > list.xml
$ virsh -c test:///default "
   snapshot-list test
   snapshot-import test list.xml
   snapshot-current --name test
   snapshot-list --parent test
"
 Name   Creation Time   State
-------------------------------

Imported 2 snapshots
s2
 Name   Creation Time               State     Parent
------------------------------------------------------
 s1     2019-02-20 22:26:52 -0600   running
 s2     2019-02-20 22:26:52 -0600   running   s1

The test driver also makes it easy to test input validation, by
modifying list.xml incorrectly (such as trying to attempt circular
dependencies).  Proving that that --topological makes a difference
is a bit harder (since we randomize the hash seed, it is not 100%
reproducible which order you get without it), but I found that
creating snapshots s1, s3, s2 in that order tended to be more likely
to hash in non-topological order without the flag.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/test/test_driver.c | 62 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 02cd4f4d07..085e228873 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1,7 +1,7 @@
 /*
  * test_driver.c: A "mock" hypervisor for use by application unit tests
  *
- * Copyright (C) 2006-2015 Red Hat, Inc.
+ * Copyright (C) 2006-2019 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -6222,6 +6222,36 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
     return xml;
 }

+static char *
+testDomainGetSnapshotsXMLDesc(virDomainPtr domain,
+                              unsigned int flags)
+{
+    virDomainObjPtr vm = NULL;
+    char *xml = NULL;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+    testDriverPtr privconn = domain->conn->privateData;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virCheckFlags(VIR_DOMAIN_GET_SNAPSHOTS_XML_SECURE |
+                  VIR_DOMAIN_GET_SNAPSHOTS_XML_TOPOLOGICAL, NULL);
+
+    if (!(vm = testDomObjFromDomain(domain)))
+        return NULL;
+
+    virUUIDFormat(domain->uuid, uuidstr);
+
+    if (virDomainSnapshotObjListFormat(&buf, uuidstr, vm->snapshots,
+                                       vm->current_snapshot, privconn->caps,
+                                       privconn->xmlopt, flags) < 0)
+        goto cleanup;
+
+    xml = virBufferContentAndReset(&buf);
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return xml;
+}
+
 static int
 testDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
                             unsigned int flags)
@@ -6409,6 +6439,34 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
 }


+static int
+testDomainImportSnapshotsXML(virDomainPtr domain,
+                             const char *xmlDesc,
+                             unsigned int flags)
+{
+    testDriverPtr privconn = domain->conn->privateData;
+    virDomainObjPtr vm = NULL;
+    int ret = -1;
+    unsigned int parse_flags = VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE |
+        VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = testDomObjFromDomain(domain)))
+        return -1;
+
+    ret = virDomainSnapshotObjListParse(xmlDesc,
+                                        vm->def->uuid,
+                                        vm->snapshots,
+                                        &vm->current_snapshot,
+                                        privconn->caps,
+                                        privconn->xmlopt,
+                                        parse_flags);
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 typedef struct _testSnapRemoveData testSnapRemoveData;
 typedef testSnapRemoveData *testSnapRemoveDataPtr;
 struct _testSnapRemoveData {
@@ -6840,6 +6898,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */
     .domainListAllSnapshots = testDomainListAllSnapshots, /* 1.1.4 */
     .domainSnapshotGetXMLDesc = testDomainSnapshotGetXMLDesc, /* 1.1.4 */
+    .domainGetSnapshotsXMLDesc = testDomainGetSnapshotsXMLDesc, /* 5.2.0 */
     .domainSnapshotNumChildren = testDomainSnapshotNumChildren, /* 1.1.4 */
     .domainSnapshotListChildrenNames = testDomainSnapshotListChildrenNames, /* 1.1.4 */
     .domainSnapshotListAllChildren = testDomainSnapshotListAllChildren, /* 1.1.4 */
@@ -6850,6 +6909,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainSnapshotIsCurrent = testDomainSnapshotIsCurrent, /* 1.1.4 */
     .domainSnapshotHasMetadata = testDomainSnapshotHasMetadata, /* 1.1.4 */
     .domainSnapshotCreateXML = testDomainSnapshotCreateXML, /* 1.1.4 */
+    .domainImportSnapshotsXML = testDomainImportSnapshotsXML, /* 5.2.0 */
     .domainRevertToSnapshot = testDomainRevertToSnapshot, /* 1.1.4 */
     .domainSnapshotDelete = testDomainSnapshotDelete, /* 1.1.4 */

-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux