Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx> --- tests/.gitignore | 1 + tests/Makefile.am | 12 ++- tests/storagevolschemadata/vol-logical.xml | 20 --- tests/storagevolschemadata/vol-partition.xml | 21 ---- tests/storagevolschemadata/vol-qcow2.xml | 31 ----- tests/storagevolschematest | 3 +- tests/storagevolxml2xmlin/vol-file-backing.xml | 24 ++++ tests/storagevolxml2xmlin/vol-file.xml | 15 +++ tests/storagevolxml2xmlin/vol-logical-backing.xml | 29 +++++ tests/storagevolxml2xmlin/vol-logical.xml | 20 +++ tests/storagevolxml2xmlin/vol-partition.xml | 21 ++++ tests/storagevolxml2xmlin/vol-qcow2.xml | 31 +++++ tests/storagevolxml2xmlout/vol-file-backing.xml | 27 +++++ tests/storagevolxml2xmlout/vol-file.xml | 18 +++ tests/storagevolxml2xmlout/vol-logical-backing.xml | 26 ++++ tests/storagevolxml2xmlout/vol-logical.xml | 17 +++ tests/storagevolxml2xmlout/vol-partition.xml | 18 +++ tests/storagevolxml2xmlout/vol-qcow2.xml | 31 +++++ tests/storagevolxml2xmltest.c | 123 ++++++++++++++++++++ 19 files changed, 411 insertions(+), 77 deletions(-) delete mode 100644 tests/storagevolschemadata/vol-logical.xml delete mode 100644 tests/storagevolschemadata/vol-partition.xml delete mode 100644 tests/storagevolschemadata/vol-qcow2.xml create mode 100644 tests/storagevolxml2xmlin/vol-file-backing.xml create mode 100644 tests/storagevolxml2xmlin/vol-file.xml create mode 100644 tests/storagevolxml2xmlin/vol-logical-backing.xml create mode 100644 tests/storagevolxml2xmlin/vol-logical.xml create mode 100644 tests/storagevolxml2xmlin/vol-partition.xml create mode 100644 tests/storagevolxml2xmlin/vol-qcow2.xml create mode 100644 tests/storagevolxml2xmlout/vol-file-backing.xml create mode 100644 tests/storagevolxml2xmlout/vol-file.xml create mode 100644 tests/storagevolxml2xmlout/vol-logical-backing.xml create mode 100644 tests/storagevolxml2xmlout/vol-logical.xml create mode 100644 tests/storagevolxml2xmlout/vol-partition.xml create mode 100644 tests/storagevolxml2xmlout/vol-qcow2.xml create mode 100644 tests/storagevolxml2xmltest.c diff --git a/tests/.gitignore b/tests/.gitignore index c202141..399baee 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -16,6 +16,7 @@ qemuhelptest networkxml2xmltest nodedevxml2xmltest interfacexml2xmltest +storagevolxml2xmltest storagepoolxml2xmltest nodeinfotest statstest diff --git a/tests/Makefile.am b/tests/Makefile.am index b6acfa4..44f16ad 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,7 +65,8 @@ EXTRA_DIST = \ storagepoolxml2xmlout \ storagepoolxml2xmlin \ storagevolschematest \ - storagevolschemadata \ + storagevolxml2xmlout \ + storagevolxml2xmlin \ nodedevschematest \ nodedevschemadata \ $(patsubst %,qemuhelpdata/%,$(qemuhelpdata)) @@ -99,7 +100,7 @@ endif noinst_PROGRAMS += networkxml2xmltest -noinst_PROGRAMS += storagepoolxml2xmltest +noinst_PROGRAMS += storagevolxml2xmltest storagepoolxml2xmltest noinst_PROGRAMS += nodedevxml2xmltest @@ -176,7 +177,7 @@ endif TESTS += networkxml2xmltest -TESTS += storagepoolxml2xmltest +TESTS += storagevolxml2xmltest storagepoolxml2xmltest TESTS += nodedevxml2xmltest @@ -279,6 +280,11 @@ networkxml2xmltest_SOURCES = \ testutils.c testutils.h networkxml2xmltest_LDADD = $(LDADDS) +storagevolxml2xmltest_SOURCES = \ + storagevolxml2xmltest.c \ + testutils.c testutils.h +storagevolxml2xmltest_LDADD = $(LDADDS) + storagepoolxml2xmltest_SOURCES = \ storagepoolxml2xmltest.c \ testutils.c testutils.h diff --git a/tests/storagevolschemadata/vol-logical.xml b/tests/storagevolschemadata/vol-logical.xml deleted file mode 100644 index 1c1e29c..0000000 --- a/tests/storagevolschemadata/vol-logical.xml +++ /dev/null @@ -1,20 +0,0 @@ -<volume> - <name>Swap</name> - <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key> - <source> - <device path='/dev/sda2'> - <extent start='31440502784' end='33520877568'/> - </device> - </source> - <capacity>2080374784</capacity> - <allocation>2080374784</allocation> - <target> - <path>/dev/HostVG/Swap</path> - <permissions> - <mode>060660</mode> - <owner>0</owner> - <group>6</group> - <label>system_u:object_r:fixed_disk_device_t:s0</label> - </permissions> - </target> -</volume> diff --git a/tests/storagevolschemadata/vol-partition.xml b/tests/storagevolschemadata/vol-partition.xml deleted file mode 100644 index 2db7e92..0000000 --- a/tests/storagevolschemadata/vol-partition.xml +++ /dev/null @@ -1,21 +0,0 @@ -<volume> - <name>sda1</name> - <key>/dev/sda1</key> - <source> - <device path='/dev/sda'> - <extent start='32256' end='106928640'/> - </device> - </source> - <capacity>106896384</capacity> - <allocation>106896384</allocation> - <target> - <path>/dev/sda1</path> - <format type='none'/> - <permissions> - <mode>060660</mode> - <owner>0</owner> - <group>6</group> - <label>system_u:object_r:fixed_disk_device_t:s0</label> - </permissions> - </target> -</volume> diff --git a/tests/storagevolschemadata/vol-qcow2.xml b/tests/storagevolschemadata/vol-qcow2.xml deleted file mode 100644 index 2a13cd1..0000000 --- a/tests/storagevolschemadata/vol-qcow2.xml +++ /dev/null @@ -1,31 +0,0 @@ -<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>0100644</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>/var/lib/libvirt/images/BaseDemo.img</path> - <format type='raw'/> - <permissions> - <mode>0100644</mode> - <owner>0</owner> - <group>0</group> - <label>unconfined_u:object_r:virt_image_t:s0</label> - </permissions> - </backingStore> -</volume> diff --git a/tests/storagevolschematest b/tests/storagevolschematest index 8b5559a..ffc5c8a 100755 --- a/tests/storagevolschematest +++ b/tests/storagevolschematest @@ -2,8 +2,7 @@ source ./schematestutils.sh -DIRS="storagevolschemadata" +DIRS="storagevolxml2xmlin storagevolxml2xmlout" SCHEMA="storagevol.rng" check_schema "$DIRS" "$SCHEMA" - diff --git a/tests/storagevolxml2xmlin/vol-file-backing.xml b/tests/storagevolxml2xmlin/vol-file-backing.xml new file mode 100644 index 0000000..c1a5837 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-file-backing.xml @@ -0,0 +1,24 @@ +<volume> + <name>sparse.img</name> + <source/> + <capacity>10000000000</capacity> + <allocation>0</allocation> + <target> + <path>/var/lib/libvirt/images/sparse.img</path> + <permissions> + <mode>0</mode> + <owner>0744</owner> + <group>0</group> + </permissions> + </target> + <backingStore> + <path>/var/lib/virt/images/master.img</path> + <format type='vmdk'/> + <permissions> + <mode>0744</mode> + <owner>1</owner> + <group>1</group> + <label>virt_image_t</label> + </permissions> + </backingStore> +</volume> diff --git a/tests/storagevolxml2xmlin/vol-file.xml b/tests/storagevolxml2xmlin/vol-file.xml new file mode 100644 index 0000000..d7de0aa --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-file.xml @@ -0,0 +1,15 @@ +<volume> + <name>sparse.img</name> + <source/> + <capacity unit="T">1</capacity> + <allocation>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> + </target> +</volume> diff --git a/tests/storagevolxml2xmlin/vol-logical-backing.xml b/tests/storagevolxml2xmlin/vol-logical-backing.xml new file mode 100644 index 0000000..b4141a5 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-logical-backing.xml @@ -0,0 +1,29 @@ +<volume> + <name>Swap</name> + <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key> + <source> + <device path='/dev/sda2'> + <extent start='31440502784' end='33520877568'/> + </device> + </source> + <capacity>2080374784</capacity> + <allocation>2080374784</allocation> + <target> + <path>/dev/HostVG/Swap</path> + <permissions> + <mode>0660</mode> + <owner>0</owner> + <group>6</group> + <label>system_u:object_r:fixed_disk_device_t:s0</label> + </permissions> + </target> + <backingStore> + <path>/dev/HostVG/snapshot</path> + <permissions> + <mode>0744</mode> + <owner>1</owner> + <group>1</group> + <label>virt_image_t</label> + </permissions> + </backingStore> +</volume> diff --git a/tests/storagevolxml2xmlin/vol-logical.xml b/tests/storagevolxml2xmlin/vol-logical.xml new file mode 100644 index 0000000..cd4d3f7 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-logical.xml @@ -0,0 +1,20 @@ +<volume> + <name>Swap</name> + <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key> + <source> + <device path='/dev/sda2'> + <extent start='31440502784' end='33520877568'/> + </device> + </source> + <capacity>2080374784</capacity> + <allocation>2080374784</allocation> + <target> + <path>/dev/HostVG/Swap</path> + <permissions> + <mode>0660</mode> + <owner>0</owner> + <group>6</group> + <label>system_u:object_r:fixed_disk_device_t:s0</label> + </permissions> + </target> +</volume> diff --git a/tests/storagevolxml2xmlin/vol-partition.xml b/tests/storagevolxml2xmlin/vol-partition.xml new file mode 100644 index 0000000..6990bb5 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-partition.xml @@ -0,0 +1,21 @@ +<volume> + <name>sda1</name> + <key>/dev/sda1</key> + <source> + <device path='/dev/sda'> + <extent start='32256' end='106928640'/> + </device> + </source> + <capacity>106896384</capacity> + <allocation>106896384</allocation> + <target> + <path>/dev/sda1</path> + <format type='none'/> + <permissions> + <mode>0660</mode> + <owner>0</owner> + <group>6</group> + <label>system_u:object_r:fixed_disk_device_t:s0</label> + </permissions> + </target> +</volume> diff --git a/tests/storagevolxml2xmlin/vol-qcow2.xml b/tests/storagevolxml2xmlin/vol-qcow2.xml new file mode 100644 index 0000000..b4924de --- /dev/null +++ b/tests/storagevolxml2xmlin/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>/var/lib/libvirt/images/BaseDemo.img</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/storagevolxml2xmlout/vol-file-backing.xml b/tests/storagevolxml2xmlout/vol-file-backing.xml new file mode 100644 index 0000000..2d7b9d0 --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-file-backing.xml @@ -0,0 +1,27 @@ +<volume> + <name>sparse.img</name> + <key>(null)</key> + <source> + </source> + <capacity>10000000000</capacity> + <allocation>0</allocation> + <target> + <path>/var/lib/libvirt/images/sparse.img</path> + <format type='raw'/> + <permissions> + <mode>00</mode> + <owner>744</owner> + <group>0</group> + </permissions> + </target> + <backingStore> + <path>/var/lib/virt/images/master.img</path> + <format type='vmdk'/> + <permissions> + <mode>0744</mode> + <owner>1</owner> + <group>1</group> + <label>virt_image_t</label> + </permissions> + </backingStore> +</volume> diff --git a/tests/storagevolxml2xmlout/vol-file.xml b/tests/storagevolxml2xmlout/vol-file.xml new file mode 100644 index 0000000..c4cc91e --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-file.xml @@ -0,0 +1,18 @@ +<volume> + <name>sparse.img</name> + <key>(null)</key> + <source> + </source> + <capacity>1099511627776</capacity> + <allocation>0</allocation> + <target> + <path>/var/lib/libvirt/images/sparse.img</path> + <format type='raw'/> + <permissions> + <mode>00</mode> + <owner>744</owner> + <group>0</group> + <label>virt_image_t</label> + </permissions> + </target> +</volume> diff --git a/tests/storagevolxml2xmlout/vol-logical-backing.xml b/tests/storagevolxml2xmlout/vol-logical-backing.xml new file mode 100644 index 0000000..45b8f3a --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-logical-backing.xml @@ -0,0 +1,26 @@ +<volume> + <name>Swap</name> + <key>(null)</key> + <source> + </source> + <capacity>2080374784</capacity> + <allocation>2080374784</allocation> + <target> + <path>/dev/HostVG/Swap</path> + <permissions> + <mode>0660</mode> + <owner>0</owner> + <group>6</group> + <label>system_u:object_r:fixed_disk_device_t:s0</label> + </permissions> + </target> + <backingStore> + <path>/dev/HostVG/snapshot</path> + <permissions> + <mode>0744</mode> + <owner>1</owner> + <group>1</group> + <label>virt_image_t</label> + </permissions> + </backingStore> +</volume> diff --git a/tests/storagevolxml2xmlout/vol-logical.xml b/tests/storagevolxml2xmlout/vol-logical.xml new file mode 100644 index 0000000..570956e --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-logical.xml @@ -0,0 +1,17 @@ +<volume> + <name>Swap</name> + <key>(null)</key> + <source> + </source> + <capacity>2080374784</capacity> + <allocation>2080374784</allocation> + <target> + <path>/dev/HostVG/Swap</path> + <permissions> + <mode>0660</mode> + <owner>0</owner> + <group>6</group> + <label>system_u:object_r:fixed_disk_device_t:s0</label> + </permissions> + </target> +</volume> diff --git a/tests/storagevolxml2xmlout/vol-partition.xml b/tests/storagevolxml2xmlout/vol-partition.xml new file mode 100644 index 0000000..c3d861e --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-partition.xml @@ -0,0 +1,18 @@ +<volume> + <name>sda1</name> + <key>(null)</key> + <source> + </source> + <capacity>106896384</capacity> + <allocation>106896384</allocation> + <target> + <path>/dev/sda1</path> + <format type='none'/> + <permissions> + <mode>0660</mode> + <owner>0</owner> + <group>6</group> + <label>system_u:object_r:fixed_disk_device_t:s0</label> + </permissions> + </target> +</volume> diff --git a/tests/storagevolxml2xmlout/vol-qcow2.xml b/tests/storagevolxml2xmlout/vol-qcow2.xml new file mode 100644 index 0000000..30fea1e --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-qcow2.xml @@ -0,0 +1,31 @@ +<volume> + <name>OtherDemo.img</name> + <key>(null)</key> + <source> + </source> + <capacity>5368709120</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>/var/lib/libvirt/images/BaseDemo.img</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/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c new file mode 100644 index 0000000..17bf009 --- /dev/null +++ b/tests/storagevolxml2xmltest.c @@ -0,0 +1,123 @@ +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include <sys/types.h> +#include <fcntl.h> + +#include "internal.h" +#include "testutils.h" +#include "storage_conf.h" +#include "testutilsqemu.h" + +static char *progname; +static char *abs_srcdir; + +#define MAX_FILE 4096 + + +static int testCompareXMLToXMLFiles(const char *poolxml, + const char *inxml, + const char *outxml) { + char poolXmlData[MAX_FILE]; + char *poolXmlPtr = &(poolXmlData[0]); + char inXmlData[MAX_FILE]; + char *inXmlPtr = &(inXmlData[0]); + char outXmlData[MAX_FILE]; + char *outXmlPtr = &(outXmlData[0]); + char *actual = NULL; + int ret = -1; + virStoragePoolDefPtr pool = NULL; + virStorageVolDefPtr dev = NULL; + + if (virtTestLoadFile(poolxml, &poolXmlPtr, MAX_FILE) < 0) + goto fail; + if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) + goto fail; + if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) + goto fail; + + if (!(pool = virStoragePoolDefParseString(NULL, poolXmlData))) + goto fail; + + if (!(dev = virStorageVolDefParseString(NULL, pool, inXmlData))) + goto fail; + + if (!(actual = virStorageVolDefFormat(NULL, pool, dev))) + goto fail; + + if (STRNEQ(outXmlData, actual)) { + virtTestDifference(stderr, outXmlData, actual); + goto fail; + } + + ret = 0; + + fail: + free(actual); + virStoragePoolDefFree(pool); + virStorageVolDefFree(dev); + return ret; +} + +struct testInfo { + const char *pool; + const char *name; +}; + +static int testCompareXMLToXMLHelper(const void *data) { + char poolxml[PATH_MAX]; + char inxml[PATH_MAX]; + char outxml[PATH_MAX]; + const struct testInfo *info = data; + + snprintf(poolxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml", + abs_srcdir, (const char*)info->pool); + snprintf(inxml, PATH_MAX, "%s/storagevolxml2xmlin/%s.xml", + abs_srcdir, (const char*)info->name); + snprintf(outxml, PATH_MAX, "%s/storagevolxml2xmlout/%s.xml", + abs_srcdir, (const char*)info->name); + return testCompareXMLToXMLFiles(poolxml, inxml, outxml); +} + + +static int +mymain(int argc, char **argv) +{ + int ret = 0; + char cwd[PATH_MAX]; + + progname = argv[0]; + + if (argc > 1) { + fprintf(stderr, "Usage: %s\n", progname); + return (EXIT_FAILURE); + } + + abs_srcdir = getenv("abs_srcdir"); + if (!abs_srcdir) + abs_srcdir = getcwd(cwd, sizeof(cwd)); + +#define DO_TEST(pool, name) \ + do { \ + struct testInfo info = { pool, name }; \ + if (virtTestRun("Storage Vol XML-2-XML " name, \ + 1, testCompareXMLToXMLHelper, &info) < 0) \ + ret = -1; \ + } \ + while(0); + + DO_TEST("pool-dir", "vol-file"); + DO_TEST("pool-dir", "vol-file-backing"); + DO_TEST("pool-dir", "vol-qcow2"); + DO_TEST("pool-disk", "vol-partition"); + DO_TEST("pool-logical", "vol-logical"); + DO_TEST("pool-logical", "vol-logical-backing"); + + return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); +} + +VIRT_TEST_MAIN(mymain) -- 1.6.5.rc2 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list