[libvirt] [PATCH 1/2] test_driver: implement virDomainManagedSaveGetXMLDesc

Ilias Stamatis stamatis.iliass at gmail.com
Wed Aug 7 16:56:35 UTC 2019


The managedSave APIs according to the documentation are supposed to
operate on a disk file. However, this might not be appropriate in the
case of the test driver since:

* It's better if the test driver keeps all its state in memory only and
doesn't affect the host in any way.

* The test driver, apart from "emulating" the domains, it additionally
"emulates" a fake physical host. Every time we start a new test
connection that sort of means that a new physical host is created as
well. And this fake host isn't necessarily the same.

What we can do instead is operating on the already existing domain
definitions. So along as a connection remains open, a domain can
preserve the managed state between different shutdown / create calls.
When the test connection closes this means that the fake host is
destroyed as well, hence no other state is preserved after that.

This way we also make sure that we don't touch the real host's
filesystem.

Signed-off-by: Ilias Stamatis <stamatis.iliass at gmail.com>
---
 src/test/test_driver.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6f18baa265..8715d6c0d6 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -7606,6 +7606,33 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags)
 }


+static char *
+testDomainManagedSaveGetXMLDesc(virDomainPtr dom,
+                                unsigned int flags)
+{
+    virDomainObjPtr vm;
+    testDriverPtr privconn = dom->conn->privateData;
+    char *ret = NULL;
+
+    virCheckFlags(VIR_DOMAIN_SAVE_IMAGE_XML_SECURE, NULL);
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        return NULL;
+
+    if (vm->hasManagedSave == false) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("domain does not have managed save image"));
+        goto cleanup;
+    }
+
+    ret = virDomainDefFormat(vm->def, privconn->caps, VIR_DOMAIN_DEF_FORMAT_SECURE);
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 static int
 testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
 {
@@ -9027,6 +9054,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainSendProcessSignal = testDomainSendProcessSignal, /* 5.5.0 */
     .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */
     .domainManagedSave = testDomainManagedSave, /* 1.1.4 */
+    .domainManagedSaveGetXMLDesc = testDomainManagedSaveGetXMLDesc, /* 5.7.0 */
     .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */
     .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */
     .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */
--
2.22.0




More information about the libvir-list mailing list