]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: genericxml2xml: Add testing of backup XML files
authorPeter Krempa <pkrempa@redhat.com>
Tue, 3 Dec 2019 12:49:04 +0000 (13:49 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 10 Dec 2019 11:41:56 +0000 (12:41 +0100)
Now that the parser and formatter are in place we can exercise it on
the test files.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/Makefile.am
tests/domainbackupxml2xmlout/backup-pull-seclabel.xml [new file with mode: 0644]
tests/domainbackupxml2xmlout/backup-pull.xml [new file with mode: 0644]
tests/domainbackupxml2xmlout/backup-push-seclabel.xml [new file with mode: 0644]
tests/domainbackupxml2xmlout/backup-push.xml [new file with mode: 0644]
tests/domainbackupxml2xmlout/empty.xml [new file with mode: 0644]
tests/genericxml2xmltest.c
tests/virschematest.c

index 9e825163e57b99cc55387b27cdcbdc24c0361ae8..d3f467fca4d43f76c2127f7378a3e391a7b019ba 100644 (file)
@@ -92,6 +92,7 @@ EXTRA_DIST = \
        cputestdata \
        domaincapsdata \
        domainbackupxml2xmlin \
+       domainbackupxml2xmlout \
        domainconfdata \
        domainschemadata \
        fchostdata \
diff --git a/tests/domainbackupxml2xmlout/backup-pull-seclabel.xml b/tests/domainbackupxml2xmlout/backup-pull-seclabel.xml
new file mode 100644 (file)
index 0000000..c631c9b
--- /dev/null
@@ -0,0 +1,18 @@
+<domainbackup mode='pull'>
+  <incremental>1525889631</incremental>
+  <server transport='tcp' name='localhost' port='10809'/>
+  <disks>
+    <disk name='vda' backup='yes' type='file'>
+      <driver type='qcow2'/>
+      <scratch file='/path/to/file'>
+        <seclabel model='dac' relabel='no'/>
+      </scratch>
+    </disk>
+    <disk name='vdb' backup='yes' type='block'>
+      <driver type='qcow2'/>
+      <scratch dev='/dev/block'>
+        <seclabel model='dac' relabel='no'/>
+      </scratch>
+    </disk>
+  </disks>
+</domainbackup>
diff --git a/tests/domainbackupxml2xmlout/backup-pull.xml b/tests/domainbackupxml2xmlout/backup-pull.xml
new file mode 100644 (file)
index 0000000..24fce9c
--- /dev/null
@@ -0,0 +1,10 @@
+<domainbackup mode='pull'>
+  <incremental>1525889631</incremental>
+  <server transport='tcp' name='localhost' port='10809'/>
+  <disks>
+    <disk name='vda' backup='yes' type='file'>
+      <scratch file='/path/to/file'/>
+    </disk>
+    <disk name='hda' backup='no'/>
+  </disks>
+</domainbackup>
diff --git a/tests/domainbackupxml2xmlout/backup-push-seclabel.xml b/tests/domainbackupxml2xmlout/backup-push-seclabel.xml
new file mode 100644 (file)
index 0000000..9986889
--- /dev/null
@@ -0,0 +1,17 @@
+<domainbackup mode='push'>
+  <incremental>1525889631</incremental>
+  <disks>
+    <disk name='vda' backup='yes' type='file'>
+      <driver type='raw'/>
+      <target file='/path/to/file'>
+        <seclabel model='dac' relabel='no'/>
+      </target>
+    </disk>
+    <disk name='vdb' backup='yes' type='block'>
+      <driver type='qcow2'/>
+      <target dev='/dev/block'>
+        <seclabel model='dac' relabel='no'/>
+      </target>
+    </disk>
+  </disks>
+</domainbackup>
diff --git a/tests/domainbackupxml2xmlout/backup-push.xml b/tests/domainbackupxml2xmlout/backup-push.xml
new file mode 100644 (file)
index 0000000..1997c81
--- /dev/null
@@ -0,0 +1,10 @@
+<domainbackup mode='push'>
+  <incremental>1525889631</incremental>
+  <disks>
+    <disk name='vda' backup='yes' type='file'>
+      <driver type='raw'/>
+      <target file='/path/to/file'/>
+    </disk>
+    <disk name='hda' backup='no'/>
+  </disks>
+</domainbackup>
diff --git a/tests/domainbackupxml2xmlout/empty.xml b/tests/domainbackupxml2xmlout/empty.xml
new file mode 100644 (file)
index 0000000..b1ba495
--- /dev/null
@@ -0,0 +1 @@
+<domainbackup mode='push'/>
index 0d04413712698b1a2660698c3701d16607c4c125..1376221ef8b5fc5d22601769f0915c46143fe6ad 100644 (file)
@@ -8,6 +8,7 @@
 #include "testutils.h"
 #include "internal.h"
 #include "virstring.h"
+#include "conf/backup_conf.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -44,6 +45,41 @@ testCompareXMLToXMLHelper(const void *data)
 }
 
 
+static int
+testCompareBackupXML(const void *data)
+{
+    const char *testname = data;
+    g_autofree char *xml_in = NULL;
+    g_autofree char *file_in = NULL;
+    g_autofree char *file_out = NULL;
+    g_autoptr(virDomainBackupDef) backup = NULL;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autofree char *actual = NULL;
+
+    file_in = g_strdup_printf("%s/domainbackupxml2xmlin/%s.xml",
+                              abs_srcdir, testname);
+    file_out = g_strdup_printf("%s/domainbackupxml2xmlout/%s.xml",
+                               abs_srcdir, testname);
+
+    if (virFileReadAll(file_in, 1024 * 64, &xml_in) < 0)
+        return -1;
+
+    if (!(backup = virDomainBackupDefParseString(xml_in, xmlopt, 0))) {
+        VIR_TEST_VERBOSE("failed to parse backup def '%s'", file_in);
+        return -1;
+    }
+
+    if (virDomainBackupDefFormat(&buf, backup, false) < 0) {
+        VIR_TEST_VERBOSE("failed to format backup def '%s'", file_in);
+        return -1;
+    }
+
+    actual = virBufferContentAndReset(&buf);
+
+    return virTestCompareToFile(actual, file_out);
+}
+
+
 static int
 mymain(void)
 {
@@ -149,6 +185,16 @@ mymain(void)
 
     DO_TEST_DIFFERENT("cputune");
 
+#define DO_TEST_BACKUP(name) \
+    if (virTestRun("QEMU BACKUP XML-2-XML " name, testCompareBackupXML, name) < 0) \
+        ret = -1;
+
+    DO_TEST_BACKUP("empty");
+    DO_TEST_BACKUP("backup-pull");
+    DO_TEST_BACKUP("backup-pull-seclabel");
+    DO_TEST_BACKUP("backup-push");
+    DO_TEST_BACKUP("backup-push-seclabel");
+
     virObjectUnref(caps);
     virObjectUnref(xmlopt);
 
index 5ae2d207d18f5c2ba202a539cdf1b1134eafac10..e4a440afb06becb308ee5534ab687e88e68cb0a3 100644 (file)
@@ -205,7 +205,8 @@ mymain(void)
                 "genericxml2xmloutdata", "xlconfigdata", "libxlxml2domconfigdata",
                 "qemuhotplugtestdomains");
     DO_TEST_DIR("domaincaps.rng", "domaincapsdata");
-    DO_TEST_DIR("domainbackup.rng", "domainbackupxml2xmlin");
+    DO_TEST_DIR("domainbackup.rng", "domainbackupxml2xmlin",
+                "domainbackupxml2xmlout");
     DO_TEST_DIR("domaincheckpoint.rng", "qemudomaincheckpointxml2xmlin",
                 "qemudomaincheckpointxml2xmlout");
     DO_TEST_DIR("domainsnapshot.rng", "qemudomainsnapshotxml2xmlin",