This allows testing the command line for cloning file-based
volumes into logical volumes and vice versa.
---
.../storagevolxml2argvdata/logical-from-qcow2.argv | 2 +
.../storagevolxml2argvdata/qcow2-from-logical.argv | 2 +
tests/storagevolxml2argvtest.c | 90 +++++++++++++++++-----
3 files changed, 74 insertions(+), 20 deletions(-)
create mode 100644 tests/storagevolxml2argvdata/logical-from-qcow2.argv
create mode 100644 tests/storagevolxml2argvdata/qcow2-from-logical.argv
diff --git a/tests/storagevolxml2argvdata/logical-from-qcow2.argv
b/tests/storagevolxml2argvdata/logical-from-qcow2.argv
new file mode 100644
index 0000000..7beded8
--- /dev/null
+++ b/tests/storagevolxml2argvdata/logical-from-qcow2.argv
@@ -0,0 +1,2 @@
+qemu-img convert -f qcow2 -O raw /var/lib/libvirt/images/OtherDemo.img \
+/dev/HostVG/Swap
diff --git a/tests/storagevolxml2argvdata/qcow2-from-logical.argv
b/tests/storagevolxml2argvdata/qcow2-from-logical.argv
new file mode 100644
index 0000000..6a75815
--- /dev/null
+++ b/tests/storagevolxml2argvdata/qcow2-from-logical.argv
@@ -0,0 +1,2 @@
+qemu-img convert -f raw -O qcow2 -o encryption=on /dev/HostVG/Swap \
+/var/lib/libvirt/images/OtherDemo.img
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index b220994..3c338ce 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -11,10 +11,32 @@
const char create_tool[] = "qemu-img";
+/* createVol sets this on volume creation */
+static void
+testSetVolumeType(virStorageVolDefPtr vol,
+ virStoragePoolDefPtr pool)
+{
+ if (!vol)
+ return;
+
+ switch (pool->type) {
+ case VIR_STORAGE_POOL_DIR:
+ case VIR_STORAGE_POOL_FS:
+ case VIR_STORAGE_POOL_NETFS:
+ vol->type = VIR_STORAGE_VOL_FILE;
+ return;
+
+ case VIR_STORAGE_POOL_LOGICAL:
+ vol->type = VIR_STORAGE_VOL_BLOCK;
+ return;
+ }
+}
+
static int
testCompareXMLToArgvFiles(bool shouldFail,
const char *poolxml,
const char *volxml,
+ const char *inputpoolxml,
const char *inputvolxml,
const char *cmdline,
unsigned int flags,
@@ -22,6 +44,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
{
char *volXmlData = NULL;
char *poolXmlData = NULL;
+ char *inputpoolXmlData = NULL;
char *inputvolXmlData = NULL;
char *expectedCmdline = NULL;
char *actualCmdline = NULL;
@@ -34,6 +57,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
virStorageVolDefPtr vol = NULL, inputvol = NULL;
virStoragePoolDefPtr pool = NULL;
+ virStoragePoolDefPtr inputpool = NULL;
virStoragePoolObj poolobj = {.def = NULL };
@@ -53,13 +77,23 @@ testCompareXMLToArgvFiles(bool shouldFail,
poolobj.def = pool;
+ if (inputpoolxml) {
+ if (virtTestLoadFile(inputpoolxml, &inputpoolXmlData) < 0)
+ goto cleanup;
+ if (!(inputpool = virStoragePoolDefParseString(inputpoolXmlData)))
+ goto cleanup;
+ }
+
if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
goto cleanup;
if (inputvolxml &&
- !(inputvol = virStorageVolDefParseString(pool, inputvolXmlData)))
+ !(inputvol = virStorageVolDefParseString(inputpool, inputvolXmlData)))
goto cleanup;
+ testSetVolumeType(vol, pool);
+ testSetVolumeType(inputvol, inputpool);
+
cmd = virStorageBackendCreateQemuImgCmd(conn, &poolobj, vol, inputvol,
flags, create_tool, imgformat);
if (!cmd) {
@@ -88,11 +122,13 @@ testCompareXMLToArgvFiles(bool shouldFail,
cleanup:
virStoragePoolDefFree(pool);
+ virStoragePoolDefFree(inputpool);
virStorageVolDefFree(vol);
virStorageVolDefFree(inputvol);
virCommandFree(cmd);
VIR_FREE(actualCmdline);
VIR_FREE(expectedCmdline);
+ VIR_FREE(inputpoolXmlData);
VIR_FREE(poolXmlData);
VIR_FREE(volXmlData);
VIR_FREE(inputvolXmlData);
@@ -104,6 +140,7 @@ struct testInfo {
bool shouldFail;
const char *pool;
const char *vol;
+ const char *inputpool;
const char *inputvol;
const char *cmdline;
unsigned int flags;
@@ -116,6 +153,7 @@ testCompareXMLToArgvHelper(const void *data)
int result = -1;
const struct testInfo *info = data;
char *poolxml = NULL;
+ char *inputpoolxml = NULL;
char *volxml = NULL;
char *inputvolxml = NULL;
char *cmdline = NULL;
@@ -124,6 +162,10 @@ testCompareXMLToArgvHelper(const void *data)
virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->inputvol) < 0)
goto cleanup;
+ if (info->inputpool &&
+ virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml",
+ abs_srcdir, info->inputpool) < 0)
+ goto cleanup;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0 ||
virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml",
@@ -135,13 +177,15 @@ testCompareXMLToArgvHelper(const void *data)
goto cleanup;
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
- inputvolxml, cmdline, info->flags,
+ inputpoolxml, inputvolxml,
+ cmdline, info->flags,
info->imgformat);
cleanup:
VIR_FREE(poolxml);
VIR_FREE(volxml);
VIR_FREE(inputvolxml);
+ VIR_FREE(inputpoolxml);
VIR_FREE(cmdline);
return result;
@@ -161,11 +205,11 @@ mymain(void)
int ret = 0;
unsigned int flags = VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
-#define DO_TEST_FULL(shouldFail, pool, vol, inputvol, cmdline, flags, \
- imgformat) \
+#define DO_TEST_FULL(shouldFail, pool, vol, inputpool, inputvol, cmdline, \
+ flags, imgformat) \
do { \
- struct testInfo info = { shouldFail, pool, vol, inputvol, cmdline, \
- flags, imgformat }; \
+ struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
+ cmdline, flags, imgformat }; \
if (virtTestRun("Storage Vol XML-2-argv " cmdline, \
1, testCompareXMLToArgvHelper, &info) < 0) \
ret = -1; \
@@ -179,47 +223,53 @@ mymain(void)
DO_TEST_FULL(true, pool, __VA_ARGS__)
DO_TEST("pool-dir", "vol-qcow2",
- NULL,
+ NULL, NULL,
"qcow2", 0, FMT_OPTIONS);
DO_TEST_FAIL("pool-dir", "vol-qcow2",
- NULL,
+ NULL, NULL,
"qcow2-prealloc", flags, FMT_OPTIONS);
DO_TEST("pool-dir", "vol-qcow2-nobacking",
- NULL,
+ NULL, NULL,
"qcow2-nobacking-prealloc", flags, FMT_OPTIONS);
DO_TEST("pool-dir", "vol-qcow2-nobacking",
- "vol-file",
+ "pool-dir", "vol-file",
"qcow2-nobacking-convert-prealloc", flags, FMT_OPTIONS);
DO_TEST_FAIL("pool-dir", "vol-qcow2",
- "vol-file",
+ "pool-dir", "vol-file",
"qcow2-convert-prealloc", flags, FMT_OPTIONS);
DO_TEST("pool-dir", "vol-qcow2",
- NULL,
+ NULL, NULL,
"qcow2-flag", 0, FMT_FLAG);
DO_TEST("pool-dir", "vol-qcow2-nobacking",
- NULL,
+ NULL, NULL,
"qcow2-nobacking-flag", 0, FMT_FLAG);
DO_TEST("pool-dir", "vol-qcow2-nobacking",
- "vol-file",
+ "pool-dir", "vol-file",
"qcow2-nobacking-convert-flag", 0, FMT_FLAG);
DO_TEST("pool-dir", "vol-qcow2",
- NULL,
+ NULL, NULL,
"qcow2-none", 0, FMT_NONE);
DO_TEST("pool-dir", "vol-qcow2-nobacking",
- NULL,
+ NULL, NULL,
"qcow2-nobacking-none", 0, FMT_NONE);
DO_TEST("pool-dir", "vol-qcow2-nobacking",
- "vol-file",
+ "pool-dir", "vol-file",
"qcow2-nobacking-convert-none", 0, FMT_NONE);
DO_TEST("pool-dir", "vol-qcow2-lazy",
- NULL,
+ NULL, NULL,
"qcow2-lazy", 0, FMT_OPTIONS);
DO_TEST("pool-dir", "vol-qcow2-1.1",
- NULL,
+ NULL, NULL,
"qcow2-1.1", 0, FMT_OPTIONS);
DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
- NULL,
+ NULL, NULL,
"qcow2-0.10-lazy", 0, FMT_OPTIONS);
+ DO_TEST("pool-dir", "vol-qcow2-nobacking",
+ "pool-logical", "vol-logical",
+ "qcow2-from-logical", 0, FMT_OPTIONS);
+ DO_TEST("pool-logical", "vol-logical",
+ "pool-dir", "vol-qcow2-nobacking",
+ "logical-from-qcow2", 0, FMT_OPTIONS);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
1.8.1.5