Implement the new flags for bulk snapshot dump and redefine. 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
   dumpxml test --snapshots" | sed -n '/<snapshots/,/<.snapshots/p' > list.xml
$ virsh -c test:///default "
   snapshot-list test
   snapshot-create test --redefine-list list.xml
   snapshot-current --name test
   snapshot-list --parent test
"
 Name   Creation Time   State
-------------------------------

Domain snapshot list imported successfully
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).

Signed-off-by: Eric Blake <ebl...@redhat.com>
---
 src/test/test_driver.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index a6a67d42e2..fd0fd6a67a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2628,7 +2628,7 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, 
unsigned int flags)
     virDomainObjPtr privdom;
     char *ret = NULL;

-    virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
+    virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS | VIR_DOMAIN_XML_SNAPSHOTS, 
NULL);

     if (!(privdom = testDomObjFromDomain(domain)))
         return NULL;
@@ -2636,8 +2636,9 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, 
unsigned int flags)
     def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
         privdom->newDef ? privdom->newDef : privdom->def;

-    ret = virDomainDefFormat(def, privconn->caps,
-                             virDomainDefFormatConvertXMLFlags(flags));
+    ret = virDomainDefFormatFull(def, privconn->caps,
+                                 privdom->snapshots, privdom->current_snapshot,
+                                 virDomainDefFormatConvertXMLFlags(flags));

     virDomainObjEndAPI(&privdom);
     return ret;
@@ -6314,6 +6315,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
      * QUIESCE: Nothing to do
      * ATOMIC: Nothing to do
      * LIVE: Nothing to do
+     * REDEFINE_LIST: Implemented
      */
     virCheckFlags(
         VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
@@ -6321,7 +6323,8 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
         VIR_DOMAIN_SNAPSHOT_CREATE_HALT |
         VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE |
         VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC |
-        VIR_DOMAIN_SNAPSHOT_CREATE_LIVE, NULL);
+        VIR_DOMAIN_SNAPSHOT_CREATE_LIVE |
+        VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST, NULL);

     if ((redefine && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)))
         update_current = false;
@@ -6337,6 +6340,18 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
         goto cleanup;
     }

+    if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST) {
+        if (virDomainSnapshotDefParseList(xmlDesc, vm->def->uuid, 
vm->snapshots,
+                                          &vm->current_snapshot, 
privconn->caps,
+                                          privconn->xmlopt, parse_flags) < 0)
+            goto cleanup;
+
+        /* Return is arbitrary, so use the first root */
+        snap = virDomainSnapshotFindByName(vm->snapshots, NULL);
+        snapshot = virGetDomainSnapshot(domain, snap->first_child->def->name);
+        goto cleanup;
+    }
+
     if (!(def = virDomainSnapshotDefParseString(xmlDesc,
                                                 privconn->caps,
                                                 privconn->xmlopt,
@@ -6384,7 +6399,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
     snapshot = virGetDomainSnapshot(domain, snap->def->name);
  cleanup:
     if (vm) {
-        if (snapshot) {
+        if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST)) {
             virDomainSnapshotObjPtr other;
             if (update_current)
                 vm->current_snapshot = snap;
-- 
2.20.1

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

Reply via email to