--- tests/Makefile.am | 9 + tests/storagevolxml2argvdata/pool-dir.xml | 18 ++ tests/storagevolxml2argvdata/qcow2-flag.argv | 1 + .../qcow2-nobacking-convert-flag.argv | 1 + .../qcow2-nobacking-convert-none.argv | 1 + .../qcow2-nobacking-convert-prealloc.argv | 1 + .../qcow2-nobacking-flag.argv | 1 + .../qcow2-nobacking-none.argv | 1 + .../qcow2-nobacking-prealloc.argv | 1 + tests/storagevolxml2argvdata/qcow2-none.argv | 1 + tests/storagevolxml2argvdata/qcow2.argv | 1 + tests/storagevolxml2argvdata/vol-file.xml | 20 +++ .../storagevolxml2argvdata/vol-qcow2-nobacking.xml | 21 +++ tests/storagevolxml2argvdata/vol-qcow2.xml | 31 ++++ tests/storagevolxml2argvtest.c | 189 +++++++++++++++++++++ 15 files changed, 297 insertions(+) create mode 100644 tests/storagevolxml2argvdata/pool-dir.xml create mode 100644 tests/storagevolxml2argvdata/qcow2-flag.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-convert-flag.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-convert-none.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-flag.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-none.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-prealloc.argv create mode 100644 tests/storagevolxml2argvdata/qcow2-none.argv create mode 100644 tests/storagevolxml2argvdata/qcow2.argv create mode 100644 tests/storagevolxml2argvdata/vol-file.xml create mode 100644 tests/storagevolxml2argvdata/vol-qcow2-nobacking.xml create mode 100644 tests/storagevolxml2argvdata/vol-qcow2.xml create mode 100644 tests/storagevolxml2argvtest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index cafdae0..0304829 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -74,6 +74,7 @@ EXTRA_DIST = \ storagepoolschematest \ storagepoolxml2xmlin \ storagepoolxml2xmlout \ + storagevolxml2argvdata \ storagevolschematest \ storagevolxml2xmlin \ storagevolxml2xmlout \ @@ -170,6 +171,8 @@ endif test_programs += nwfilterxml2xmltest +test_programs += storagevolxml2argvtest + test_programs += storagevolxml2xmltest storagepoolxml2xmltest test_programs += nodedevxml2xmltest @@ -470,6 +473,12 @@ nwfilterxml2xmltest_SOURCES = \ testutils.c testutils.h nwfilterxml2xmltest_LDADD = $(LDADDS) +storagevolxml2argvtest_SOURCES = \ + storagevolxml2argvtest.c \ + testutils.c testutils.h +storagevolxml2argvtest_LDADD = \ + ../src/libvirt_driver_storage_impl.la $(LDADDS) + storagevolxml2xmltest_SOURCES = \ storagevolxml2xmltest.c \ testutils.c testutils.h diff --git a/tests/storagevolxml2argvdata/pool-dir.xml b/tests/storagevolxml2argvdata/pool-dir.xml new file mode 100644 index 0000000..e10ccb7 --- /dev/null +++ b/tests/storagevolxml2argvdata/pool-dir.xml @@ -0,0 +1,18 @@ +<pool type='dir'> + <name>virtimages</name> + <uuid>70a7eb15-6c34-ee9c-bf57-69e8e5ff3fb2</uuid> + <capacity>0</capacity> + <allocation>0</allocation> + <available>0</available> + <source> + </source> + <target> + <path>///var/////lib/libvirt/images//</path> + <permissions> + <mode>0700</mode> + <owner>-1</owner> + <group>-1</group> + <label>some_label_t</label> + </permissions> + </target> +</pool> diff --git a/tests/storagevolxml2argvdata/qcow2-flag.argv b/tests/storagevolxml2argvdata/qcow2-flag.argv new file mode 100644 index 0000000..3ac9010 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-flag.argv @@ -0,0 +1 @@ +qemu-img create -f qcow2 -b /dev/null -F raw /var/lib/libvirt/images/OtherDemo.img 5242880K -e diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-convert-flag.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-flag.argv new file mode 100644 index 0000000..2d37c50 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-flag.argv @@ -0,0 +1 @@ +qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img -e diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-convert-none.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-none.argv new file mode 100644 index 0000000..2d37c50 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-none.argv @@ -0,0 +1 @@ +qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img -e diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc.argv new file mode 100644 index 0000000..18e8f64 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc.argv @@ -0,0 +1 @@ +qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img -o encryption=on,preallocation=metadata diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-flag.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-flag.argv new file mode 100644 index 0000000..8980cc4 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nobacking-flag.argv @@ -0,0 +1 @@ +qemu-img create -f qcow2 /var/lib/libvirt/images/OtherDemo.img 5242880K -e diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-none.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-none.argv new file mode 100644 index 0000000..8980cc4 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nobacking-none.argv @@ -0,0 +1 @@ +qemu-img create -f qcow2 /var/lib/libvirt/images/OtherDemo.img 5242880K -e diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-prealloc.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-prealloc.argv new file mode 100644 index 0000000..828f5fc --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nobacking-prealloc.argv @@ -0,0 +1 @@ +qemu-img create -f qcow2 /var/lib/libvirt/images/OtherDemo.img 5242880K -o encryption=on,preallocation=metadata diff --git a/tests/storagevolxml2argvdata/qcow2-none.argv b/tests/storagevolxml2argvdata/qcow2-none.argv new file mode 100644 index 0000000..f2dfd15 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-none.argv @@ -0,0 +1 @@ +qemu-img create -f qcow2 -b /dev/null /var/lib/libvirt/images/OtherDemo.img 5242880K -e diff --git a/tests/storagevolxml2argvdata/qcow2.argv b/tests/storagevolxml2argvdata/qcow2.argv new file mode 100644 index 0000000..d6f4cb6 --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2.argv @@ -0,0 +1 @@ +qemu-img create -f qcow2 -b /dev/null -o backing_fmt=raw,encryption=on /var/lib/libvirt/images/OtherDemo.img 5242880K diff --git a/tests/storagevolxml2argvdata/vol-file.xml b/tests/storagevolxml2argvdata/vol-file.xml new file mode 100644 index 0000000..d3f65f6 --- /dev/null +++ b/tests/storagevolxml2argvdata/vol-file.xml @@ -0,0 +1,20 @@ +<volume> + <name>sparse.img</name> + <source/> + <capacity unit="TiB">1</capacity> + <allocation unit="bytes">0</allocation> + <target> + <path>/var/lib/libvirt/images/sparse.img</path> + <permissions> + <mode>0</mode> + <owner>0744</owner> + <group>0</group> + <label>virt_image_t</label> + </permissions> + <timestamps> + <atime>1341933637.273190990</atime> + <mtime>1341930622.047245868</mtime> + <ctime>1341930622.047245868</ctime> + </timestamps> + </target> +</volume> diff --git a/tests/storagevolxml2argvdata/vol-qcow2-nobacking.xml b/tests/storagevolxml2argvdata/vol-qcow2-nobacking.xml new file mode 100644 index 0000000..6a6bd5b --- /dev/null +++ b/tests/storagevolxml2argvdata/vol-qcow2-nobacking.xml @@ -0,0 +1,21 @@ +<volume> + <name>OtherDemo.img</name> + <key>/var/lib/libvirt/images/OtherDemo.img</key> + <source> + </source> + <capacity unit="G">5</capacity> + <allocation>294912</allocation> + <target> + <path>/var/lib/libvirt/images/OtherDemo.img</path> + <format type='qcow2'/> + <permissions> + <mode>0644</mode> + <owner>0</owner> + <group>0</group> + <label>unconfined_u:object_r:virt_image_t:s0</label> + </permissions> + <encryption format='qcow'> + <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/> + </encryption> + </target> +</volume> diff --git a/tests/storagevolxml2argvdata/vol-qcow2.xml b/tests/storagevolxml2argvdata/vol-qcow2.xml new file mode 100644 index 0000000..49a7de3 --- /dev/null +++ b/tests/storagevolxml2argvdata/vol-qcow2.xml @@ -0,0 +1,31 @@ +<volume> + <name>OtherDemo.img</name> + <key>/var/lib/libvirt/images/OtherDemo.img</key> + <source> + </source> + <capacity unit="G">5</capacity> + <allocation>294912</allocation> + <target> + <path>/var/lib/libvirt/images/OtherDemo.img</path> + <format type='qcow2'/> + <permissions> + <mode>0644</mode> + <owner>0</owner> + <group>0</group> + <label>unconfined_u:object_r:virt_image_t:s0</label> + </permissions> + <encryption format='qcow'> + <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/> + </encryption> + </target> + <backingStore> + <path>/dev/null</path> + <format type='raw'/> + <permissions> + <mode>0644</mode> + <owner>0</owner> + <group>0</group> + <label>unconfined_u:object_r:virt_image_t:s0</label> + </permissions> + </backingStore> +</volume> diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c new file mode 100644 index 0000000..416bb6f --- /dev/null +++ b/tests/storagevolxml2argvtest.c @@ -0,0 +1,189 @@ +#include <config.h> + +#include "internal.h" +#include "testutils.h" +#include "datatypes.h" +#include "storage/storage_backend.h" +#include "testutilsqemu.h" + +const char create_tool[] = "qemu-img"; + +static int +testCompareXMLToArgvFiles(bool shouldFail, + const char *poolxml, + const char *volxml, + const char *inputvolxml, + const char *cmdline, + unsigned int flags, + int imgformat) +{ + char *volXmlData = NULL; + char *poolXmlData = NULL; + char *inputvolXmlData = NULL; + char *expectedCmdline = NULL; + char *actualCmdline = NULL; + int ret = -1; + + int len; + + virCommandPtr cmd = NULL; + virConnectPtr conn; + + virStorageVolDefPtr vol = NULL, inputvol = NULL; + virStoragePoolDefPtr pool = NULL; + virStoragePoolObj poolobj = {.def = NULL }; + + + if (!(conn = virGetConnect())) + goto cleanup; + + if (virtTestLoadFile(poolxml, &poolXmlData) < 0) + goto cleanup; + if (virtTestLoadFile(volxml, &volXmlData) < 0) + goto cleanup; + if (inputvolxml && + virtTestLoadFile(inputvolxml, &inputvolXmlData) < 0) + goto cleanup; + + if (!(pool = virStoragePoolDefParseString(poolXmlData))) + goto cleanup; + + poolobj.def = pool; + + if (!(vol = virStorageVolDefParseString(pool, volXmlData))) + goto cleanup; + + if (inputvolxml && + !(inputvol = virStorageVolDefParseString(pool, inputvolXmlData))) + goto cleanup; + + cmd = virStorageBackendCreateQemuImgCmd(conn, &poolobj, vol, inputvol, + flags, create_tool, imgformat); + + actualCmdline = virCommandToString(cmd); + if (!actualCmdline) { + if (shouldFail) { + virResetLastError(); + ret = 0; + } + goto cleanup; + } + + len = virtTestLoadFile(cmdline, &expectedCmdline); + if (len < 0) + goto cleanup; + if (len && expectedCmdline[len-1] == '\n') + expectedCmdline[len-1] = '\0'; + + if (STRNEQ_NULLABLE(expectedCmdline, actualCmdline)) { + virtTestDifference(stderr, expectedCmdline, actualCmdline); + goto cleanup; + } + + ret = 0; + +cleanup: + virStoragePoolDefFree(pool); + virStorageVolDefFree(vol); + virStorageVolDefFree(inputvol); + virCommandFree(cmd); + VIR_FREE(actualCmdline); + VIR_FREE(expectedCmdline); + return ret; +} + +struct testInfo { + bool shouldFail; + const char *pool; + const char *vol; + const char *inputvol; + const char *cmdline; + unsigned int flags; + int imgformat; +}; + +static int +testCompareXMLToArgvHelper(const void *data) +{ + int result = -1; + const struct testInfo *info = data; + char *poolxml = NULL; + char *volxml = NULL; + char *inputvolxml = NULL; + char *cmdline = NULL; + + if (info->inputvol && + virAsprintf(&inputvolxml, "%s/storagevolxml2argvdata/%s.xml", + abs_srcdir, info->inputvol) < 0) + goto cleanup; + if (virAsprintf(&poolxml, "%s/storagevolxml2argvdata/%s.xml", + abs_srcdir, info->pool) < 0 || + virAsprintf(&volxml, "%s/storagevolxml2argvdata/%s.xml", + abs_srcdir, info->vol) < 0) { + goto cleanup; + } + if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv", + abs_srcdir, info->cmdline) < 0 && !info->shouldFail) + goto cleanup; + + result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml, + inputvolxml, cmdline, info->flags, + info->imgformat); + +cleanup: + VIR_FREE(poolxml); + VIR_FREE(volxml); + VIR_FREE(inputvolxml); + VIR_FREE(cmdline); + + return result; +} + +enum { + FMT_NONE = 0, + FMT_FLAG, + FMT_OPTIONS, +}; + + + +static int +mymain(void) +{ + int ret = 0; + unsigned int flags = VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + +#define DO_TEST(shouldFail, pool, vol, inputvol, cmdline, flags, imgformat) \ + do { \ + struct testInfo info = { shouldFail, pool, vol, inputvol, cmdline, \ + flags, imgformat }; \ + if (virtTestRun("Storage Vol XML-2-argv " cmdline, \ + 1, testCompareXMLToArgvHelper, &info) < 0) \ + ret = -1; \ + } \ + while (0); + + DO_TEST(false, "pool-dir", "vol-qcow2", NULL, "qcow2", 0, FMT_OPTIONS); + DO_TEST(true, "pool-dir", "vol-qcow2", NULL, "qcow2-prealloc", flags, + FMT_OPTIONS); + DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", NULL, + "qcow2-nobacking-prealloc", flags, FMT_OPTIONS); + DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file", + "qcow2-nobacking-convert-prealloc", flags, FMT_OPTIONS); + DO_TEST(true, "pool-dir", "vol-qcow2", "vol-file", + "qcow2-convert-prealloc", flags, FMT_OPTIONS); + DO_TEST(false, "pool-dir", "vol-qcow2", NULL, "qcow2-flag", 0, FMT_FLAG); + DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", NULL, + "qcow2-nobacking-flag", 0, FMT_FLAG); + DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file", + "qcow2-nobacking-convert-flag", 0, FMT_FLAG); + DO_TEST(false, "pool-dir", "vol-qcow2", NULL, "qcow2-none", 0, FMT_NONE); + DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", NULL, + "qcow2-nobacking-none", 0, FMT_NONE); + DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file", + "qcow2-nobacking-convert-none", 0, FMT_NONE); + + return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN(mymain) -- 1.7.12.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list