libvirt/tests/domainsnapshotxml2xmltest.c

132 lines
3.4 KiB
C
Raw Normal View History

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#ifdef WITH_QEMU
# include "internal.h"
# include "testutils.h"
# include "qemu/qemu_conf.h"
# include "qemu/qemu_domain.h"
# include "testutilsqemu.h"
static virQEMUDriver driver;
static int
testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
{
char *inXmlData = NULL;
char *actual = NULL;
int ret = -1;
virDomainSnapshotDefPtr def = NULL;
unsigned int flags = (VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE |
VIR_DOMAIN_SNAPSHOT_PARSE_DISKS);
if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
if (internal)
flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps,
QEMU_EXPECTED_VIRT_TYPES,
flags)))
goto fail;
if (!(actual = virDomainSnapshotDefFormat(uuid, def,
VIR_DOMAIN_XML_SECURE,
internal)))
goto fail;
if (STRNEQ(inXmlData, actual)) {
virtTestDifference(stderr, inXmlData, actual);
goto fail;
}
ret = 0;
fail:
VIR_FREE(inXmlData);
VIR_FREE(actual);
virDomainSnapshotDefFree(def);
return ret;
}
struct testInfo {
const char *name;
const char *uuid;
int internal;
};
static int
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data;
char *xml_in = NULL;
int ret = -1;
if (virAsprintf(&xml_in, "%s/domainsnapshotxml2xmlout/%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
ret = testCompareXMLToXMLFiles(xml_in, info->uuid, info->internal);
cleanup:
VIR_FREE(xml_in);
return ret;
}
static int
mymain(void)
{
int ret = 0;
if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
# define DO_TEST(name, uuid, internal) \
do { \
const struct testInfo info = {name, uuid, internal}; \
if (virtTestRun("SNAPSHOT XML-2-XML " name, \
1, testCompareXMLToXMLHelper, &info) < 0) \
ret = -1; \
} while (0)
/* 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);
DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 1);
DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
DO_TEST("noparent_nodescription_noactive", NULL, 0);
DO_TEST("noparent_nodescription", NULL, 1);
DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
snapshot: new XML for external system checkpoint Each <domainsnapshot> can now contain an optional <memory> element that describes how the VM state was handled, similar to disk snapshots. The new element will always appear in output; for back-compat, an input that lacks the element will assume 'no' or 'internal' according to the domain state. Along with this change, it is now possible to pass <disks> in the XML for an offline snapshot; this also needs to be wired up in a future patch, to make it possible to choose internal vs. external on a per-disk basis for each disk in an offline domain. At that point, using the --disk-only flag for an offline domain will be able to work. For some examples below, remember that qemu supports the following snapshot actions: qemu-img: offline external and internal disk savevm: online internal VM and disk migrate: online external VM transaction: online external disk ===== <domainsnapshot> <memory snapshot='no'/> ... </domainsnapshot> implies that there is no VM state saved (mandatory for offline and disk-only snapshots, not possible otherwise); using qemu-img for offline domains and transaction for online. ===== <domainsnapshot> <memory snapshot='internal'/> ... </domainsnapshot> state is saved inside one of the disks (as in qemu's 'savevm' system checkpoint implementation). If needed in the future, we can also add an attribute pointing out _which_ disk saved the internal state; maybe disk='vda'. ===== <domainsnapshot> <memory snapshot='external' file='/path/to/state'/> ... </domainsnapshot> This is not wired up yet, but future patches will allow this to control a combination of 'virsh save /path/to/state' plus disk snapshots from the same point in time. ===== So for 1.0.1 (and later, as needed), I plan to implement this table of combinations, with '*' designating new code and '+' designating existing code reached through new combinations of xml and/or the existing DISK_ONLY flag: domain memory disk disk-only | result ----------------------------------------- offline omit omit any | memory=no disk=int, via qemu-img offline no omit any |+memory=no disk=int, via qemu-img offline omit/no no any | invalid combination (nothing to snapshot) offline omit/no int any |+memory=no disk=int, via qemu-img offline omit/no ext any |*memory=no disk=ext, via qemu-img offline int/ext any any | invalid combination (no memory to save) online omit omit off | memory=int disk=int, via savevm online omit omit on | memory=no disk=default, via transaction online omit no/ext off | unsupported for now online omit no on | invalid combination (nothing to snapshot) online omit ext on | memory=no disk=ext, via transaction online omit int off |+memory=int disk=int, via savevm online omit int on | unsupported for now online no omit any |+memory=no disk=default, via transaction online no no any | invalid combination (nothing to snapshot) online no int any | unsupported for now online no ext any |+memory=no disk=ext, via transaction online int/ext any on | invalid combination (disk-only vs. memory) online int omit off |+memory=int disk=int, via savevm online int no/ext off | unsupported for now online int int off |+memory=int disk=int, via savevm online ext omit off |*memory=ext disk=default, via migrate+trans online ext no off |+memory=ext disk=no, via migrate online ext int off | unsupported for now online ext ext off |*memory=ext disk=ext, via migrate+transaction * docs/schemas/domainsnapshot.rng (memory): New RNG element. * docs/formatsnapshot.html.in: Document it. * src/conf/snapshot_conf.h (virDomainSnapshotDef): New fields. * src/conf/domain_conf.c (virDomainSnapshotDefFree) (virDomainSnapshotDefParseString, virDomainSnapshotDefFormat): Manage new fields. * tests/domainsnapshotxml2xmltest.c: New test. * tests/domainsnapshotxml2xmlin/*.xml: Update existing tests. * tests/domainsnapshotxml2xmlout/*.xml: Likewise.
2012-10-23 15:12:23 +00:00
DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
virObjectUnref(driver.caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIRT_TEST_MAIN(mymain)
#else
# include "testutils.h"
int
main(void)
{
return EXIT_AM_SKIP;
}
#endif /* WITH_QEMU */