2011-09-22 20:29:00 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2013-04-16 13:41:44 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
|
2011-09-22 20:29:00 +00:00
|
|
|
#ifdef WITH_QEMU
|
|
|
|
|
|
|
|
# include "internal.h"
|
|
|
|
# include "qemu/qemu_conf.h"
|
|
|
|
# include "qemu/qemu_domain.h"
|
|
|
|
# include "testutilsqemu.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
# include "virstring.h"
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2013-06-07 15:10:28 +00:00
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2012-11-28 16:43:10 +00:00
|
|
|
static virQEMUDriver driver;
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2019-04-15 19:49:30 +00:00
|
|
|
enum {
|
|
|
|
TEST_INTERNAL = 1 << 0, /* Test use of INTERNAL parse/format flag */
|
|
|
|
TEST_REDEFINE = 1 << 1, /* Test use of REDEFINE parse flag */
|
snapshot: Don't expose testsuite-only state in snapshot XML
None of the existing drivers actually use the 0-valued 'nostate'
snapshot state; rather, it was a fluke of implementation. In fact,
some drivers, like qemu, actively reject 'nostate' as invalid during a
snapshot redefine. Normally, a driver computes the state post-parse
from the current domain, and thus virDomainSnapshotGetXMLDesc() will
never expose the state. However, since the testsuite lacks any
associated domain to copy state from, and lacks post-parse processing
that normal drivers have, the testsuite output had several spots with
the state, coupled with a regex filter to ignore the oddity.
It is better to follow the lead of other XML defaults, by not
outputting anything during format if post-parse defaults have not been
applied, and rejecting the default value during parsing. The testsuite
needs a bit of an update, by adding another flag for when to simulate
a post-parse action of setting a snapshot state, but none of the
drivers are impacted other than rejecting XML that was previously
already suspicious in nature.
Similarly, don't expose creation time 0 (for now, only possible if a
user redefined a snapshot to claim creation at the Epoch, but also
happens once setting the creation time is deferred to a post-parse
handler).
This is also a step towards cleaning up snapshot_conf.c to separate
its existing post-parse work (namely, setting the creationTime and
default snapshot name) from the pure parsing work, so that we can get
rid of the testsuite hack of regex filtering of the XML and instead
have more accurate testing of our parser/formatter code.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-16 22:44:38 +00:00
|
|
|
TEST_RUNNING = 1 << 2, /* Set snapshot state to running after parse */
|
2019-04-15 19:49:30 +00:00
|
|
|
};
|
|
|
|
|
2011-09-22 20:29:00 +00:00
|
|
|
static int
|
2013-12-04 13:53:24 +00:00
|
|
|
testCompareXMLToXMLFiles(const char *inxml,
|
|
|
|
const char *outxml,
|
|
|
|
const char *uuid,
|
2019-04-15 19:49:30 +00:00
|
|
|
unsigned int flags)
|
2011-09-22 20:29:00 +00:00
|
|
|
{
|
|
|
|
char *inXmlData = NULL;
|
2013-12-04 13:53:24 +00:00
|
|
|
char *outXmlData = NULL;
|
2011-09-22 20:29:00 +00:00
|
|
|
char *actual = NULL;
|
|
|
|
int ret = -1;
|
2019-02-15 20:43:43 +00:00
|
|
|
unsigned int parseflags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
|
|
|
unsigned int formatflags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE;
|
2019-04-15 19:49:30 +00:00
|
|
|
bool cur = false;
|
2019-05-09 14:59:06 +00:00
|
|
|
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
2013-12-04 13:53:24 +00:00
|
|
|
|
2019-04-15 19:49:30 +00:00
|
|
|
if (flags & TEST_INTERNAL) {
|
2019-02-15 20:43:43 +00:00
|
|
|
parseflags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
|
|
|
|
formatflags |= VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL;
|
|
|
|
}
|
2013-12-04 13:53:24 +00:00
|
|
|
|
2019-04-15 19:49:30 +00:00
|
|
|
if (flags & TEST_REDEFINE)
|
2019-02-15 20:43:43 +00:00
|
|
|
parseflags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(inxml, &inXmlData) < 0)
|
2013-12-04 12:49:40 +00:00
|
|
|
goto cleanup;
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(outxml, &outXmlData) < 0)
|
2013-12-04 13:53:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-09-22 20:29:00 +00:00
|
|
|
if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps,
|
2019-08-06 12:19:35 +00:00
|
|
|
driver.xmlopt, NULL, &cur,
|
2019-02-15 20:43:43 +00:00
|
|
|
parseflags)))
|
2013-12-04 12:49:40 +00:00
|
|
|
goto cleanup;
|
2019-04-15 19:49:30 +00:00
|
|
|
if (cur) {
|
|
|
|
if (!(flags & TEST_INTERNAL))
|
|
|
|
goto cleanup;
|
snapshot: Drop virDomainSnapshotDef.current
The only use for the 'current' member of virDomainSnapshotDef was with
the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
<active> element marking whether a particular snapshot definition was
current, and even then, only by the qemu driver on output, and by qemu
and test driver on input. But this duplicates vm->snapshot_current,
and gets in the way of potential simplifications to have qemu store a
single file for all snapshots rather than one file per snapshot. Get
rid of the member by adding a bool* parameter during parse (ignored if
the PARSE_INTERNAL flag is not set), and by adding a new flag during
format (if FORMAT_INTERNAL is set, the value printed in <active>
depends on the new FORMAT_CURRENT).
Then update the qemu driver accordingly, which involves hoisting
assignments to vm->current_snapshot to occur prior to any point where
a snapshot XML file is written (although qemu kept
vm->current_snapshot and snapshot->def_current in sync by the end of
the function, they were not always identical in the middle of
functions, so the shuffling gets a bit interesting). Later patches
will clean up some of that confusing churn to vm->current_snapshot.
Note: even if later patches refactor qemu to no longer use
FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
will always need PARSE_INTERNAL for input (because on upgrade, a new
libvirt still has to parse XML left from a previous libvirt).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-19 03:56:19 +00:00
|
|
|
formatflags |= VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT;
|
2019-04-15 19:49:30 +00:00
|
|
|
}
|
snapshot: Don't expose testsuite-only state in snapshot XML
None of the existing drivers actually use the 0-valued 'nostate'
snapshot state; rather, it was a fluke of implementation. In fact,
some drivers, like qemu, actively reject 'nostate' as invalid during a
snapshot redefine. Normally, a driver computes the state post-parse
from the current domain, and thus virDomainSnapshotGetXMLDesc() will
never expose the state. However, since the testsuite lacks any
associated domain to copy state from, and lacks post-parse processing
that normal drivers have, the testsuite output had several spots with
the state, coupled with a regex filter to ignore the oddity.
It is better to follow the lead of other XML defaults, by not
outputting anything during format if post-parse defaults have not been
applied, and rejecting the default value during parsing. The testsuite
needs a bit of an update, by adding another flag for when to simulate
a post-parse action of setting a snapshot state, but none of the
drivers are impacted other than rejecting XML that was previously
already suspicious in nature.
Similarly, don't expose creation time 0 (for now, only possible if a
user redefined a snapshot to claim creation at the Epoch, but also
happens once setting the creation time is deferred to a post-parse
handler).
This is also a step towards cleaning up snapshot_conf.c to separate
its existing post-parse work (namely, setting the creationTime and
default snapshot name) from the pure parsing work, so that we can get
rid of the testsuite hack of regex filtering of the XML and instead
have more accurate testing of our parser/formatter code.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-16 22:44:38 +00:00
|
|
|
if (flags & TEST_RUNNING) {
|
|
|
|
if (def->state)
|
|
|
|
goto cleanup;
|
|
|
|
def->state = VIR_DOMAIN_RUNNING;
|
|
|
|
}
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2016-02-04 22:55:05 +00:00
|
|
|
if (!(actual = virDomainSnapshotDefFormat(uuid, def, driver.caps,
|
2017-06-01 22:27:33 +00:00
|
|
|
driver.xmlopt,
|
2019-02-15 20:43:43 +00:00
|
|
|
formatflags)))
|
2013-12-04 12:49:40 +00:00
|
|
|
goto cleanup;
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2013-12-04 13:53:24 +00:00
|
|
|
if (STRNEQ(outXmlData, actual)) {
|
2016-05-26 15:01:54 +00:00
|
|
|
virTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml);
|
2013-12-04 12:49:40 +00:00
|
|
|
goto cleanup;
|
2011-09-22 20:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2013-12-04 12:49:40 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(inXmlData);
|
2013-12-04 13:53:24 +00:00
|
|
|
VIR_FREE(outXmlData);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(actual);
|
2011-09-22 20:29:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct testInfo {
|
2013-12-04 13:53:24 +00:00
|
|
|
const char *inxml;
|
|
|
|
const char *outxml;
|
2011-09-22 20:29:00 +00:00
|
|
|
const char *uuid;
|
2019-04-16 13:00:40 +00:00
|
|
|
long long creationTime;
|
2019-04-15 19:49:30 +00:00
|
|
|
unsigned int flags;
|
2011-09-22 20:29:00 +00:00
|
|
|
};
|
2019-04-16 13:00:40 +00:00
|
|
|
static long long mocktime;
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
static int
|
|
|
|
testSnapshotPostParse(virDomainMomentDefPtr def)
|
|
|
|
{
|
|
|
|
if (!mocktime)
|
|
|
|
return 0;
|
|
|
|
if (def->creationTime)
|
|
|
|
return -1;
|
|
|
|
def->creationTime = mocktime;
|
|
|
|
if (!def->name &&
|
|
|
|
virAsprintf(&def->name, "%lld", def->creationTime) < 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-04 12:49:40 +00:00
|
|
|
|
2011-09-22 20:29:00 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLHelper(const void *data)
|
|
|
|
{
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
mocktime = info->creationTime;
|
2013-12-04 13:53:24 +00:00
|
|
|
return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->uuid,
|
2019-04-15 19:49:30 +00:00
|
|
|
info->flags);
|
2011-09-22 20:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2015-09-15 06:16:02 +00:00
|
|
|
if (qemuTestDriverInit(&driver) < 0)
|
2012-03-22 11:33:35 +00:00
|
|
|
return EXIT_FAILURE;
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
virDomainXMLOptionSetMomentPostParse(driver.xmlopt,
|
|
|
|
testSnapshotPostParse);
|
2013-12-04 13:53:24 +00:00
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
# define DO_TEST(prefix, name, inpath, outpath, uuid, time, flags) \
|
2017-11-03 12:09:47 +00:00
|
|
|
do { \
|
|
|
|
const struct testInfo info = {abs_srcdir "/" inpath "/" name ".xml", \
|
2013-12-04 13:53:24 +00:00
|
|
|
abs_srcdir "/" outpath "/" name ".xml", \
|
2019-04-16 13:00:40 +00:00
|
|
|
uuid, time, flags}; \
|
2017-11-03 12:09:47 +00:00
|
|
|
if (virTestRun("SNAPSHOT XML-2-XML " prefix " " name, \
|
|
|
|
testCompareXMLToXMLHelper, &info) < 0) \
|
|
|
|
ret = -1; \
|
2011-09-22 20:29:00 +00:00
|
|
|
} while (0)
|
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
# define DO_TEST_IN(name, uuid) DO_TEST("in->in", name, \
|
2019-07-05 18:24:40 +00:00
|
|
|
"qemudomainsnapshotxml2xmlin", \
|
|
|
|
"qemudomainsnapshotxml2xmlin", \
|
2019-04-16 13:00:40 +00:00
|
|
|
uuid, 0, 0)
|
2013-12-04 13:53:24 +00:00
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
# define DO_TEST_OUT(name, uuid, internal) \
|
2019-07-05 18:24:40 +00:00
|
|
|
DO_TEST("out->out", name, "qemudomainsnapshotxml2xmlout", \
|
|
|
|
"qemudomainsnapshotxml2xmlout", uuid, 0, internal | TEST_REDEFINE)
|
2013-12-04 13:53:24 +00:00
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
# define DO_TEST_INOUT(name, uuid, time, flags) \
|
|
|
|
DO_TEST("in->out", name, \
|
2019-07-05 18:24:40 +00:00
|
|
|
"qemudomainsnapshotxml2xmlin",\
|
|
|
|
"qemudomainsnapshotxml2xmlout",\
|
2019-04-16 13:00:40 +00:00
|
|
|
uuid, time, flags)
|
2013-12-04 13:53:24 +00:00
|
|
|
|
2011-09-22 20:29:00 +00:00
|
|
|
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
|
|
|
|
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
|
|
|
|
* values for these envvars */
|
|
|
|
setenv("PATH", "/bin", 1);
|
|
|
|
|
2019-04-15 19:49:30 +00:00
|
|
|
DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
|
|
|
|
TEST_INTERNAL);
|
|
|
|
DO_TEST_OUT("disk_snapshot_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
|
|
|
|
TEST_INTERNAL);
|
|
|
|
DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
|
|
|
|
TEST_INTERNAL);
|
|
|
|
DO_TEST_OUT("noparent_nodescription_noactive", NULL, 0);
|
|
|
|
DO_TEST_OUT("noparent_nodescription", NULL, TEST_INTERNAL);
|
|
|
|
DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
|
|
|
|
DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
|
|
|
|
DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
|
|
|
|
0);
|
|
|
|
|
2019-04-16 13:00:40 +00:00
|
|
|
DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
|
|
|
|
1386166249, 0);
|
snapshot: Don't expose testsuite-only state in snapshot XML
None of the existing drivers actually use the 0-valued 'nostate'
snapshot state; rather, it was a fluke of implementation. In fact,
some drivers, like qemu, actively reject 'nostate' as invalid during a
snapshot redefine. Normally, a driver computes the state post-parse
from the current domain, and thus virDomainSnapshotGetXMLDesc() will
never expose the state. However, since the testsuite lacks any
associated domain to copy state from, and lacks post-parse processing
that normal drivers have, the testsuite output had several spots with
the state, coupled with a regex filter to ignore the oddity.
It is better to follow the lead of other XML defaults, by not
outputting anything during format if post-parse defaults have not been
applied, and rejecting the default value during parsing. The testsuite
needs a bit of an update, by adding another flag for when to simulate
a post-parse action of setting a snapshot state, but none of the
drivers are impacted other than rejecting XML that was previously
already suspicious in nature.
Similarly, don't expose creation time 0 (for now, only possible if a
user redefined a snapshot to claim creation at the Epoch, but also
happens once setting the creation time is deferred to a post-parse
handler).
This is also a step towards cleaning up snapshot_conf.c to separate
its existing post-parse work (namely, setting the creationTime and
default snapshot name) from the pure parsing work, so that we can get
rid of the testsuite hack of regex filtering of the XML and instead
have more accurate testing of our parser/formatter code.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-16 22:44:38 +00:00
|
|
|
DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
|
2019-04-16 13:00:40 +00:00
|
|
|
1272917631, TEST_RUNNING);
|
|
|
|
DO_TEST_INOUT("external_vm", NULL, 1555419243, 0);
|
|
|
|
DO_TEST_INOUT("disk_snapshot", NULL, 1555419243, 0);
|
|
|
|
DO_TEST_INOUT("disk_driver_name_null", NULL, 1555419243, 0);
|
2018-06-05 14:02:11 +00:00
|
|
|
DO_TEST_INOUT("disk-seclabel", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 581484660, 0);
|
2013-12-04 17:31:39 +00:00
|
|
|
|
|
|
|
DO_TEST_IN("name_and_description", NULL);
|
|
|
|
DO_TEST_IN("description_only", NULL);
|
|
|
|
DO_TEST_IN("name_only", NULL);
|
|
|
|
|
2015-09-15 06:16:02 +00:00
|
|
|
qemuTestDriverFree(&driver);
|
2011-09-22 20:29:00 +00:00
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2011-09-22 20:29:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|
2011-09-22 20:29:00 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_QEMU */
|