99cbc7
From c549a110d3705473ab4435bd164a8e48d5da64a1 Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <c549a110d3705473ab4435bd164a8e48d5da64a1@dist-git>
99cbc7
From: John Ferlan <jferlan@redhat.com>
99cbc7
Date: Wed, 3 Apr 2019 09:12:16 -0400
99cbc7
Subject: [PATCH] tests: Introduce tests for storage pool xml to argv checks
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1584663
99cbc7
99cbc7
Similar to qemuxml2argv and storagevolxml2argv, let's create some
99cbc7
tests to ensure that the XML generates a consistent command line.
99cbc7
99cbc7
Using the same list of pools as storagepoolxml2xmltest, start with
99cbc7
the file system tests (fs, netfs, netfs-cifs, netfs-gluster).
99cbc7
99cbc7
Signed-off-by: John Ferlan <jferlan@redhat.com>
99cbc7
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
(cherry picked from commit f2f84b4d4ab289e736e367d2867cf945d17d0b20)
99cbc7
99cbc7
Resolved some build issues:
99cbc7
99cbc7
 * Removed the VIR_FREE defs and used the VIR_FREE for @src. Turns out
99cbc7
   it was unnecessary for @actualCmdline and was removed in commit
99cbc7
   5f02df444beea79ef7c94f923c0c36135102d562
99cbc7
99cbc7
 * Removed VIR_STORAGE_POOL_ISCSI_DIRECT from switch since it's not
99cbc7
   a downstream symbol/option
99cbc7
99cbc7
Signed-off-by: John Ferlan <jferlan@redhat.com>
99cbc7
Message-Id: <20190403131219.16385-5-jferlan@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 tests/Makefile.am                             |  12 ++
99cbc7
 tests/storagepoolxml2argvdata/pool-fs.argv    |   1 +
99cbc7
 .../pool-netfs-cifs.argv                      |   1 +
99cbc7
 .../pool-netfs-gluster.argv                   |   1 +
99cbc7
 tests/storagepoolxml2argvdata/pool-netfs.argv |   1 +
99cbc7
 tests/storagepoolxml2argvtest.c               | 172 ++++++++++++++++++
99cbc7
 6 files changed, 188 insertions(+)
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-fs.argv
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-cifs.argv
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-gluster.argv
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs.argv
99cbc7
 create mode 100644 tests/storagepoolxml2argvtest.c
99cbc7
99cbc7
diff --git a/tests/Makefile.am b/tests/Makefile.am
99cbc7
index a4ebed489a..858076df7b 100644
99cbc7
--- a/tests/Makefile.am
99cbc7
+++ b/tests/Makefile.am
99cbc7
@@ -141,6 +141,7 @@ EXTRA_DIST = \
99cbc7
 	storagepoolschemadata \
99cbc7
 	storagepoolxml2xmlin \
99cbc7
 	storagepoolxml2xmlout \
99cbc7
+	storagepoolxml2argvdata \
99cbc7
 	storagevolschemadata \
99cbc7
 	storagevolxml2argvdata \
99cbc7
 	storagevolxml2xmlin \
99cbc7
@@ -363,6 +364,7 @@ endif WITH_NWFILTER
99cbc7
 
99cbc7
 if WITH_STORAGE
99cbc7
 test_programs += storagevolxml2argvtest
99cbc7
+test_programs += storagepoolxml2argvtest
99cbc7
 test_programs += virstorageutiltest
99cbc7
 endif WITH_STORAGE
99cbc7
 
99cbc7
@@ -901,6 +903,16 @@ storagevolxml2argvtest_LDADD = \
99cbc7
 	../src/libvirt_util.la \
99cbc7
 	$(LDADDS)
99cbc7
 
99cbc7
+storagepoolxml2argvtest_SOURCES = \
99cbc7
+    storagepoolxml2argvtest.c \
99cbc7
+    testutils.c testutils.h
99cbc7
+storagepoolxml2argvtest_LDADD = \
99cbc7
+	$(LIBXML_LIBS) \
99cbc7
+	../src/libvirt_driver_storage_impl.la \
99cbc7
+	../src/libvirt_conf.la \
99cbc7
+	../src/libvirt_util.la \
99cbc7
+	$(LDADDS)
99cbc7
+
99cbc7
 else ! WITH_STORAGE
99cbc7
 EXTRA_DIST += storagevolxml2argvtest.c
99cbc7
 EXTRA_DIST += virstorageutiltest.c
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-fs.argv b/tests/storagepoolxml2argvdata/pool-fs.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..537ce4cee5
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-fs.argv
99cbc7
@@ -0,0 +1 @@
99cbc7
+mount -t ext3 /dev/sda6 /mnt
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-cifs.argv b/tests/storagepoolxml2argvdata/pool-netfs-cifs.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..2fef6f5782
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-netfs-cifs.argv
99cbc7
@@ -0,0 +1 @@
99cbc7
+mount -t cifs //example.com/samba_share /mnt/cifs -o guest
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-gluster.argv b/tests/storagepoolxml2argvdata/pool-netfs-gluster.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..4303d514ef
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-netfs-gluster.argv
99cbc7
@@ -0,0 +1 @@
99cbc7
+mount -t glusterfs example.com:/volume -o direct-io-mode=1 /mnt/gluster
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-netfs.argv b/tests/storagepoolxml2argvdata/pool-netfs.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..04127c5087
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-netfs.argv
99cbc7
@@ -0,0 +1 @@
99cbc7
+mount -t nfs localhost:/var/lib/libvirt/images /mnt
99cbc7
diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c
99cbc7
new file mode 100644
99cbc7
index 0000000000..54bc07b4e1
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvtest.c
99cbc7
@@ -0,0 +1,172 @@
99cbc7
+#include <config.h>
99cbc7
+
99cbc7
+#include "internal.h"
99cbc7
+#include "testutils.h"
99cbc7
+#include "datatypes.h"
99cbc7
+#include "storage/storage_util.h"
99cbc7
+#include "testutilsqemu.h"
99cbc7
+#include "virstring.h"
99cbc7
+
99cbc7
+#define VIR_FROM_THIS VIR_FROM_NONE
99cbc7
+
99cbc7
+
99cbc7
+static int
99cbc7
+testCompareXMLToArgvFiles(bool shouldFail,
99cbc7
+                          const char *poolxml,
99cbc7
+                          const char *cmdline)
99cbc7
+{
99cbc7
+    char *actualCmdline = NULL;
99cbc7
+    char *src = NULL;
99cbc7
+    int ret = -1;
99cbc7
+    virCommandPtr cmd = NULL;
99cbc7
+    virStoragePoolDefPtr def = NULL;
99cbc7
+    virStoragePoolObjPtr pool = NULL;
99cbc7
+
99cbc7
+    if (!(def = virStoragePoolDefParseFile(poolxml)))
99cbc7
+        goto cleanup;
99cbc7
+
99cbc7
+    switch ((virStoragePoolType)def->type) {
99cbc7
+    case VIR_STORAGE_POOL_FS:
99cbc7
+    case VIR_STORAGE_POOL_NETFS:
99cbc7
+        if (!(pool = virStoragePoolObjNew())) {
99cbc7
+            VIR_TEST_DEBUG("pool type %d alloc pool obj fails\n", def->type);
99cbc7
+            virStoragePoolDefFree(def);
99cbc7
+            goto cleanup;
99cbc7
+        }
99cbc7
+        virStoragePoolObjSetDef(pool, def);
99cbc7
+
99cbc7
+        if (!(src = virStorageBackendFileSystemGetPoolSource(pool))) {
99cbc7
+            VIR_TEST_DEBUG("pool type %d has no pool source\n", def->type);
99cbc7
+            goto cleanup;
99cbc7
+        }
99cbc7
+
99cbc7
+        cmd = virStorageBackendFileSystemMountCmd(def, src);
99cbc7
+        break;
99cbc7
+
99cbc7
+    case VIR_STORAGE_POOL_DIR:
99cbc7
+    case VIR_STORAGE_POOL_LOGICAL:
99cbc7
+    case VIR_STORAGE_POOL_DISK:
99cbc7
+    case VIR_STORAGE_POOL_ISCSI:
99cbc7
+    case VIR_STORAGE_POOL_SCSI:
99cbc7
+    case VIR_STORAGE_POOL_MPATH:
99cbc7
+    case VIR_STORAGE_POOL_RBD:
99cbc7
+    case VIR_STORAGE_POOL_SHEEPDOG:
99cbc7
+    case VIR_STORAGE_POOL_GLUSTER:
99cbc7
+    case VIR_STORAGE_POOL_ZFS:
99cbc7
+    case VIR_STORAGE_POOL_VSTORAGE:
99cbc7
+    case VIR_STORAGE_POOL_LAST:
99cbc7
+    default:
99cbc7
+        VIR_TEST_DEBUG("pool type %d has no xml2argv test\n", def->type);
99cbc7
+        goto cleanup;
99cbc7
+    };
99cbc7
+
99cbc7
+    if (!(actualCmdline = virCommandToString(cmd))) {
99cbc7
+        VIR_TEST_DEBUG("pool type %d failed to get commandline\n", def->type);
99cbc7
+        goto cleanup;
99cbc7
+    }
99cbc7
+
99cbc7
+    virTestClearCommandPath(actualCmdline);
99cbc7
+    if (virTestCompareToFile(actualCmdline, cmdline) < 0)
99cbc7
+        goto cleanup;
99cbc7
+
99cbc7
+    ret = 0;
99cbc7
+
99cbc7
+ cleanup:
99cbc7
+    virCommandFree(cmd);
99cbc7
+    VIR_FREE(src);
99cbc7
+    VIR_FREE(actualCmdline);
99cbc7
+    virStoragePoolObjEndAPI(&pool);
99cbc7
+    if (shouldFail) {
99cbc7
+        virResetLastError();
99cbc7
+        ret = 0;
99cbc7
+    }
99cbc7
+    return ret;
99cbc7
+}
99cbc7
+
99cbc7
+struct testInfo {
99cbc7
+    bool shouldFail;
99cbc7
+    const char *pool;
99cbc7
+};
99cbc7
+
99cbc7
+static int
99cbc7
+testCompareXMLToArgvHelper(const void *data)
99cbc7
+{
99cbc7
+    int result = -1;
99cbc7
+    const struct testInfo *info = data;
99cbc7
+    char *poolxml = NULL;
99cbc7
+    char *cmdline = NULL;
99cbc7
+
99cbc7
+    if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
99cbc7
+                    abs_srcdir, info->pool) < 0)
99cbc7
+        goto cleanup;
99cbc7
+
99cbc7
+    if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s.argv",
99cbc7
+                    abs_srcdir, info->pool) < 0 && !info->shouldFail)
99cbc7
+        goto cleanup;
99cbc7
+
99cbc7
+    result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline);
99cbc7
+
99cbc7
+ cleanup:
99cbc7
+    VIR_FREE(poolxml);
99cbc7
+    VIR_FREE(cmdline);
99cbc7
+
99cbc7
+    return result;
99cbc7
+}
99cbc7
+
99cbc7
+
99cbc7
+static int
99cbc7
+mymain(void)
99cbc7
+{
99cbc7
+    int ret = 0;
99cbc7
+
99cbc7
+#define DO_TEST_FULL(shouldFail, pool) \
99cbc7
+    do { \
99cbc7
+        struct testInfo info = { shouldFail, pool }; \
99cbc7
+        if (virTestRun("Storage Pool XML-2-argv " pool, \
99cbc7
+                       testCompareXMLToArgvHelper, &info) < 0) \
99cbc7
+            ret = -1; \
99cbc7
+       } \
99cbc7
+    while (0);
99cbc7
+
99cbc7
+#define DO_TEST(pool, ...) \
99cbc7
+    DO_TEST_FULL(false, pool)
99cbc7
+
99cbc7
+#define DO_TEST_FAIL(pool, ...) \
99cbc7
+    DO_TEST_FULL(true, pool)
99cbc7
+
99cbc7
+    DO_TEST_FAIL("pool-dir");
99cbc7
+    DO_TEST_FAIL("pool-dir-naming");
99cbc7
+    DO_TEST("pool-fs");
99cbc7
+    DO_TEST_FAIL("pool-logical");
99cbc7
+    DO_TEST_FAIL("pool-logical-nopath");
99cbc7
+    DO_TEST_FAIL("pool-logical-create");
99cbc7
+    DO_TEST_FAIL("pool-logical-noname");
99cbc7
+    DO_TEST_FAIL("pool-disk");
99cbc7
+    DO_TEST_FAIL("pool-disk-device-nopartsep");
99cbc7
+    DO_TEST_FAIL("pool-iscsi");
99cbc7
+    DO_TEST_FAIL("pool-iscsi-auth");
99cbc7
+    DO_TEST("pool-netfs");
99cbc7
+    DO_TEST("pool-netfs-gluster");
99cbc7
+    DO_TEST("pool-netfs-cifs");
99cbc7
+    DO_TEST_FAIL("pool-scsi");
99cbc7
+    DO_TEST_FAIL("pool-scsi-type-scsi-host");
99cbc7
+    DO_TEST_FAIL("pool-scsi-type-fc-host");
99cbc7
+    DO_TEST_FAIL("pool-scsi-type-fc-host-managed");
99cbc7
+    DO_TEST_FAIL("pool-mpath");
99cbc7
+    DO_TEST_FAIL("pool-iscsi-multiiqn");
99cbc7
+    DO_TEST_FAIL("pool-iscsi-vendor-product");
99cbc7
+    DO_TEST_FAIL("pool-sheepdog");
99cbc7
+    DO_TEST_FAIL("pool-gluster");
99cbc7
+    DO_TEST_FAIL("pool-gluster-sub");
99cbc7
+    DO_TEST_FAIL("pool-scsi-type-scsi-host-stable");
99cbc7
+    DO_TEST_FAIL("pool-zfs");
99cbc7
+    DO_TEST_FAIL("pool-zfs-sourcedev");
99cbc7
+    DO_TEST_FAIL("pool-rbd");
99cbc7
+    DO_TEST_FAIL("pool-vstorage");
99cbc7
+    DO_TEST_FAIL("pool-iscsi-direct-auth");
99cbc7
+    DO_TEST_FAIL("pool-iscsi-direct");
99cbc7
+
99cbc7
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
99cbc7
+}
99cbc7
+
99cbc7
+VIR_TEST_MAIN(mymain)
99cbc7
-- 
99cbc7
2.21.0
99cbc7