[PATCH 06/10] test: Wire up managed save APIs

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

 



Also add a <hasmanagedsave> element to set this data when starting
the connection.
---
 src/test/test_driver.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++-
 tests/virshtest.c      |   2 +-
 2 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 3775906..09260ba 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -504,6 +504,7 @@ testDomainStartState(testConnPtr privconn,
         goto cleanup;
     }
 
+    dom->hasManagedSave = false;
     ret = 0;
 cleanup:
     if (ret < 0)
@@ -940,6 +941,7 @@ testParseDomains(testConnPtr privconn,
     for (i = 0; i < num; i++) {
         unsigned int runstate;
         bool transient;
+        bool hasManagedSave;
         virDomainDefPtr def;
         xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "domain");
         if (!node)
@@ -951,6 +953,9 @@ testParseDomains(testConnPtr privconn,
             goto error;
         if (testParseXMLObjectBool(ctxt, node, "transient", &transient) < 0)
             goto error;
+        if (testParseXMLObjectBool(ctxt, node,
+                                   "hasmanagedsave", &hasManagedSave) < 0)
+            goto error;
 
         if (testNodeUnlinkCustomXML(ctxt, node) < 0)
             goto error;
@@ -982,6 +987,7 @@ testParseDomains(testConnPtr privconn,
             testDomainShutdownState(NULL, obj, 0);
         }
         virDomainObjSetState(obj, runstate, 0);
+        obj->hasManagedSave = hasManagedSave;
 
         virObjectUnlock(obj);
     }
@@ -2817,7 +2823,7 @@ static int testDomainUndefineFlags(virDomainPtr domain,
     virDomainEventPtr event = NULL;
     int ret = -1;
 
-    virCheckFlags(0, -1);
+    virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE, -1);
 
     testDriverLock(privconn);
     privdom = virDomainObjListFindByName(privconn->domains,
@@ -2828,6 +2834,15 @@ static int testDomainUndefineFlags(virDomainPtr domain,
         goto cleanup;
     }
 
+    if (privdom->hasManagedSave &&
+        !(flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("Refusing to undefine while domain managed "
+                         "save image exists"));
+        goto cleanup;
+    }
+    privdom->hasManagedSave = false;
+
     event = virDomainEventNewFromObj(privdom,
                                      VIR_DOMAIN_EVENT_UNDEFINED,
                                      VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
@@ -5952,6 +5967,111 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED,
 }
 
 
+static int
+testDomainManagedSave(virDomainPtr dom, unsigned int flags)
+{
+    testConnPtr privconn = dom->conn->privateData;
+    virDomainObjPtr vm = NULL;
+    virDomainEventPtr event = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
+                  VIR_DOMAIN_SAVE_RUNNING |
+                  VIR_DOMAIN_SAVE_PAUSED, -1);
+
+    testDriverLock(privconn);
+    vm = virDomainObjListFindByName(privconn->domains, dom->name);
+    testDriverUnlock(privconn);
+
+    if (vm == NULL) {
+        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto cleanup;
+    }
+
+    if (!virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is not running"));
+        goto cleanup;
+    }
+
+    if (!vm->persistent) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("cannot do managed save for transient domain"));
+        goto cleanup;
+    }
+
+    testDomainShutdownState(dom, vm, VIR_DOMAIN_SHUTOFF_SAVED);
+    event = virDomainEventNewFromObj(vm,
+                                     VIR_DOMAIN_EVENT_STOPPED,
+                                     VIR_DOMAIN_EVENT_STOPPED_SAVED);
+    vm->hasManagedSave = true;
+
+    ret = 0;
+cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    if (event) {
+        testDriverLock(privconn);
+        testDomainEventQueue(privconn, event);
+        testDriverUnlock(privconn);
+    }
+
+    return ret;
+}
+
+
+static int
+testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    testConnPtr privconn = dom->conn->privateData;
+    virDomainObjPtr vm;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    testDriverLock(privconn);
+
+    vm = virDomainObjListFindByName(privconn->domains, dom->name);
+    if (vm == NULL) {
+        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto cleanup;
+    }
+
+    ret = vm->hasManagedSave;
+cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    testDriverUnlock(privconn);
+    return ret;
+}
+
+static int
+testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
+{
+    testConnPtr privconn = dom->conn->privateData;
+    virDomainObjPtr vm;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    testDriverLock(privconn);
+
+    vm = virDomainObjListFindByName(privconn->domains, dom->name);
+    if (vm == NULL) {
+        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto cleanup;
+    }
+
+    vm->hasManagedSave = false;
+    ret = 0;
+cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    testDriverUnlock(privconn);
+    return ret;
+}
+
+
 static virDriver testDriver = {
     .no = VIR_DRV_TEST,
     .name = "Test",
@@ -6022,6 +6142,9 @@ static virDriver testDriver = {
     .connectIsAlive = testConnectIsAlive, /* 0.9.8 */
     .nodeGetCPUMap = testNodeGetCPUMap, /* 1.0.0 */
     .domainScreenshot = testDomainScreenshot, /* 1.0.5 */
+    .domainManagedSave = testDomainManagedSave, /* 1.1.2 */
+    .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.2 */
+    .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.2 */
 };
 
 static virNetworkDriver testNetworkDriver = {
diff --git a/tests/virshtest.c b/tests/virshtest.c
index ca35bb0..fe255d3 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -34,7 +34,7 @@ Max memory:     261072 KiB\n\
 Used memory:    131072 KiB\n\
 Persistent:     yes\n\
 Autostart:      disable\n\
-Managed save:   unknown\n\
+Managed save:   no\n\
 \n";
 static const char *domuuid_fc4 = DOM_UUID "\n\n";
 static const char *domid_fc4 = "2\n\n";
-- 
1.8.3.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]