[libvirt] [PATCH 0/2] test_driver: implement the remaining ManagedSave APIs

Ilias Stamatis (2): test_driver: implement virDomainManagedSaveGetXMLDesc test_driver: implement virDomainManagedSaveDefineXML src/test/test_driver.c | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) -- 2.22.0

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@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

On Wed, Aug 07, 2019 at 06:56:35PM +0200, Ilias Stamatis wrote:
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.
True, however...
This way we also make sure that we don't touch the real host's filesystem.
Signed-off-by: Ilias Stamatis <stamatis.iliass@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);
...^this won't fly, because this function is supposed to return the XML valid at the time the managedsave was performed. If you e.g. attach a disk to the inactive XML in the meantime, your changes will mean that managedsave-dumpxml will return the current config along with the new attached disk, which is incorrect, so you indeed need to make use of the private data. Because of ^this I think there's no need to review patch 2 at the moment. Regards, Erik

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8715d6c0d6..360bdef373 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7633,6 +7633,43 @@ testDomainManagedSaveGetXMLDesc(virDomainPtr dom, } +static int +testDomainManagedSaveDefineXML(virDomainPtr dom, + const char *dxml, + unsigned int flags) +{ + virDomainObjPtr vm = NULL; + virDomainDefPtr newdef = NULL; + testDriverPtr privconn = dom->conn->privateData; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | + VIR_DOMAIN_SAVE_RUNNING | + VIR_DOMAIN_SAVE_PAUSED, -1); + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (vm->hasManagedSave == false) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("domain does not have managed save image")); + goto cleanup; + } + + if ((newdef = virDomainDefParseString(dxml, privconn->caps, privconn->xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) + goto cleanup; + + virDomainDefFree(vm->def); + vm->def = newdef; + + ret = 0; + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) { @@ -9055,6 +9092,7 @@ static virHypervisorDriver testHypervisorDriver = { .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */ .domainManagedSave = testDomainManagedSave, /* 1.1.4 */ .domainManagedSaveGetXMLDesc = testDomainManagedSaveGetXMLDesc, /* 5.7.0 */ + .domainManagedSaveDefineXML = testDomainManagedSaveDefineXML, /* 5.7.0 */ .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */ .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */ .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */ -- 2.22.0
participants (2)
-
Erik Skultety
-
Ilias Stamatis