/src/util/virkeymaps.h
/tests/*.log
/tests/cputest
+/tests/domainsnapshotxml2xmltest
/tests/hashtest
/tests/jsontest
/tests/networkxml2argvtest
return ret;
}
-char *virDomainSnapshotDefFormat(char *domain_uuid,
+char *virDomainSnapshotDefFormat(const char *domain_uuid,
virDomainSnapshotDefPtr def,
unsigned int flags,
int internal)
virDomainDiskSnapshotTypeToString(disk->snapshot));
if (disk->file || disk->driverType) {
virBufferAddLit(&buf, ">\n");
- if (disk->file)
- virBufferEscapeString(&buf, " <source file='%s'/>\n",
- disk->file);
if (disk->driverType)
virBufferEscapeString(&buf, " <driver type='%s'/>\n",
disk->driverType);
+ if (disk->file)
+ virBufferEscapeString(&buf, " <source file='%s'/>\n",
+ disk->file);
virBufferAddLit(&buf, " </disk>\n");
} else {
virBufferAddLit(&buf, "/>\n");
return NULL;
}
virBufferAdjustIndent(&buf, -2);
- } else {
+ } else if (domain_uuid) {
virBufferAddLit(&buf, " <domain>\n");
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid);
virBufferAddLit(&buf, " </domain>\n");
unsigned int expectedVirtTypes,
unsigned int flags);
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
-char *virDomainSnapshotDefFormat(char *domain_uuid,
+char *virDomainSnapshotDefFormat(const char *domain_uuid,
virDomainSnapshotDefPtr def,
unsigned int flags,
int internal);
xmconfigtest xencapstest statstest reconnect
endif
if WITH_QEMU
-check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest qemuargv2xmltest qemuhelptest
+check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
+ qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest
endif
if WITH_OPENVZ
endif
if WITH_QEMU
-TESTS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest qemuargv2xmltest qemuhelptest
-TESTS += nwfilterxml2xmltest
+TESTS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest qemuargv2xmltest \
+ qemuhelptest domainsnapshotxml2xmltest nwfilterxml2xmltest
endif
if WITH_OPENVZ
qemuhelptest_SOURCES = qemuhelptest.c testutils.c testutils.h
qemuhelptest_LDADD = $(qemu_LDADDS) $(LDADDS)
+
+domainsnapshotxml2xmltest_SOURCES = \
+ domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \
+ testutils.c testutils.h
+domainsnapshotxml2xmltest_LDADD = $(qemu_LDADDS) $(LDADDS)
else
-EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuxmlnstest.c qemuargv2xmltest.c qemuhelptest.c testutilsqemu.c testutilsqemu.h
+EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
+ qemuxmlnstest.c qemuhelptest.c domainsnapshotxml2xmltest.c \
+ testutilsqemu.c testutilsqemu.h
endif
if WITH_OPENVZ
<domainsnapshot>
<name>my snap name</name>
<description>!@#$%^</description>
+ <state>running</state>
<parent>
<name>earlier_snap</name>
</parent>
- <state>running</state>
<creationTime>1272917631</creationTime>
<domain>
<uuid>9d37b878-a7cc-9f9a-b78f-49b3abad25a8</uuid>
<domainsnapshot>
<name>my snap name</name>
<description>!@#$%^</description>
+ <state>disk-snapshot</state>
<parent>
<name>earlier_snap</name>
</parent>
- <state>disk-snapshot</state>
<creationTime>1272917631</creationTime>
<disks>
<disk name='hda' snapshot='no'/>
<source file='/path/to/generated5'/>
</disk>
</disks>
-<domain type='qemu'>
- <name>QEMUGuest1</name>
- <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
- <memory>219100</memory>
- <currentMemory>219100</currentMemory>
- <vcpu cpuset='1-4,8-20,525'>1</vcpu>
- <os>
- <type arch='i686' machine='pc'>hvm</type>
- <boot dev='hd'/>
- </os>
- <clock offset='utc'/>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>destroy</on_crash>
- <devices>
- <emulator>/usr/bin/qemu</emulator>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest1'/>
- <target dev='hda' bus='ide'/>
- <address type='drive' controller='0' bus='0' unit='0'/>
- </disk>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest2'/>
- <target dev='hdb' bus='ide'/>
- <address type='drive' controller='0' bus='1' unit='0'/>
- </disk>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest3'/>
- <target dev='hdc' bus='ide'/>
- <address type='drive' controller='0' bus='2' unit='0'/>
- </disk>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest4'/>
- <target dev='hdd' bus='ide'/>
- <address type='drive' controller='0' bus='3' unit='0'/>
- </disk>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest5'/>
- <target dev='hde' bus='ide'/>
- <address type='drive' controller='0' bus='4' unit='0'/>
- </disk>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest6'/>
- <target dev='hdf' bus='ide'/>
- <address type='drive' controller='0' bus='5' unit='0'/>
- </disk>
- <controller type='ide' index='0'/>
- <memballoon model='virtio'/>
- </devices>
-</domain>
+ <domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory>219100</memory>
+ <currentMemory>219100</currentMemory>
+ <vcpu cpuset='1-4,8-20,525'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' unit='0'/>
+ </disk>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest2'/>
+ <target dev='hdb' bus='ide'/>
+ <address type='drive' controller='0' bus='1' unit='0'/>
+ </disk>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest3'/>
+ <target dev='hdc' bus='ide'/>
+ <address type='drive' controller='0' bus='2' unit='0'/>
+ </disk>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest4'/>
+ <target dev='hdd' bus='ide'/>
+ <address type='drive' controller='0' bus='3' unit='0'/>
+ </disk>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest5'/>
+ <target dev='hde' bus='ide'/>
+ <address type='drive' controller='0' bus='4' unit='0'/>
+ </disk>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest6'/>
+ <target dev='hdf' bus='ide'/>
+ <address type='drive' controller='0' bus='5' unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'/>
+ </devices>
+ </domain>
<active>1</active>
</domainsnapshot>
<domainsnapshot>
<name>my snap name</name>
<description>!@#$%^</description>
+ <state>running</state>
<parent>
<name>earlier_snap</name>
</parent>
- <state>running</state>
<creationTime>1272917631</creationTime>
-<domain type='qemu'>
- <name>QEMUGuest1</name>
- <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
- <memory>219100</memory>
- <currentMemory>219100</currentMemory>
- <vcpu cpuset='1-4,8-20,525'>1</vcpu>
- <os>
- <type arch='i686' machine='pc'>hvm</type>
- <boot dev='hd'/>
- </os>
- <clock offset='utc'/>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>destroy</on_crash>
- <devices>
- <emulator>/usr/bin/qemu</emulator>
- <disk type='block' device='disk'>
- <source dev='/dev/HostVG/QEMUGuest1'/>
- <target dev='hda' bus='ide'/>
- <address type='drive' controller='0' bus='0' unit='0'/>
- </disk>
- <controller type='ide' index='0'/>
- <memballoon model='virtio'/>
- </devices>
-</domain>
+ <domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory>219100</memory>
+ <currentMemory>219100</currentMemory>
+ <vcpu cpuset='1-4,8-20,525'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'/>
+ </devices>
+ </domain>
<active>1</active>
</domainsnapshot>
--- /dev/null
+#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 struct qemud_driver 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:
+ free(inXmlData);
+ 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:
+ 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);
+
+ virCapabilitiesFree(driver.caps);
+
+ return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+VIRT_TEST_MAIN(mymain)
+
+#else
+
+int
+main(void)
+{
+ return EXIT_AM_SKIP;
+}
+
+#endif /* WITH_QEMU */