At the moment only pool test is implemented. Signed-off-by: Olga Krishtal <okrishtal@virtuozzo.com> --- docs/schemas/fsitem.rng | 66 +++++++++++++ docs/schemas/fspool.rng | 82 ++++++++++++++++ tests/Makefile.am | 12 +++ tests/fsitemxml2xmlin/item.xml | 13 +++ tests/fsitemxml2xmlout/item.xml | 13 +++ tests/fsitemxml2xmltest.c | 105 +++++++++++++++++++++ .../dir-missing-target-path-invalid.xml | 12 +++ tests/fspoolxml2xmlin/fspool-dir.xml | 16 ++++ tests/fspoolxml2xmlout/fspool-dir.xml | 16 ++++ tests/fspoolxml2xmltest.c | 81 ++++++++++++++++ 10 files changed, 416 insertions(+) create mode 100644 docs/schemas/fsitem.rng create mode 100644 docs/schemas/fspool.rng create mode 100644 tests/fsitemxml2xmlin/item.xml create mode 100644 tests/fsitemxml2xmlout/item.xml create mode 100644 tests/fsitemxml2xmltest.c create mode 100644 tests/fspoolschemadata/dir-missing-target-path-invalid.xml create mode 100644 tests/fspoolxml2xmlin/fspool-dir.xml create mode 100644 tests/fspoolxml2xmlout/fspool-dir.xml create mode 100644 tests/fspoolxml2xmltest.c diff --git a/docs/schemas/fsitem.rng b/docs/schemas/fsitem.rng new file mode 100644 index 0000000..d828978 --- /dev/null +++ b/docs/schemas/fsitem.rng @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<!-- A Relax NG schema for the libvirt fspool item XML format --> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <include href='basictypes.rng'/> + <start> + <ref name='item'/> + </start> + + <define name='item'> + <element name='fsitem'> + <optional> + <attribute name='type'> + <value>dir</value> + </attribute> + </optional> + <interleave> + <element name='name'> + <ref name='itemName'/> + </element> + <optional> + <element name='key'> + <text/> + </element> + </optional> + <ref name='sizing'/> + <ref name='target'/> + </interleave> + </element> + </define> + + <define name='sizing'> + <interleave> + <optional> + <element name='capacity'> + <ref name='scaledInteger'/> + </element> + </optional> + <optional> + <element name='allocation'> + <ref name='scaledInteger'/> + </element> + </optional> + </interleave> + </define> + + <define name='target'> + <element name='target'> + <interleave> + <optional> + <element name='path'> + <choice> + <data type='anyURI'/> + <ref name='absFilePath'/> + </choice> + </element> + </optional> + <ref name='permissions'/> + <optional> + <ref name='fileFormatFeatures'/> + </optional> + </interleave> + </element> + </define> + +</grammar> diff --git a/docs/schemas/fspool.rng b/docs/schemas/fspool.rng new file mode 100644 index 0000000..33ea0a2 --- /dev/null +++ b/docs/schemas/fspool.rng @@ -0,0 +1,82 @@ +<?xml version="1.0"?> +<!-- A Relax NG schema for the libvirt fspool XML format --> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <include href='basictypes.rng'/> + <start> + <ref name='fspool'/> + </start> + + + <define name='fspool'> + <element name='fspool'> + <choice> + <ref name='fspooldir'/> + </choice> + </element> + </define> + + <define name='fspooldir'> + <attribute name='type'> + <value>dir</value> + </attribute> + <interleave> + <ref name='commonmetadata'/> + <ref name='sizing'/> + <ref name='sourcedir'/> + <ref name='target'/> + </interleave> + </define> + + <define name='commonmetadata'> + <interleave> + <element name='name'> + <ref name='genericName'/> + </element> + <optional> + <element name='uuid'> + <ref name='UUID'/> + </element> + </optional> + </interleave> + </define> + + <define name='sizing'> + <interleave> + <optional> + <element name='capacity'> + <ref name='scaledInteger'/> + </element> + </optional> + <optional> + <element name='allocation'> + <ref name='scaledInteger'/> + </element> + </optional> + <optional> + <element name='available'> + <ref name='scaledInteger'/> + </element> + </optional> + </interleave> + </define> + + <define name='target'> + <element name='target'> + <interleave> + <element name='path'> + <ref name='absFilePath'/> + </element> + <ref name='permissions'/> + </interleave> + </element> + </define> + + <define name='sourcedir'> + <optional> + <element name='source'> + </element> + </optional> + </define> + +</grammar> diff --git a/tests/Makefile.am b/tests/Makefile.am index 0cd8391..526366e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -339,6 +339,8 @@ endif WITH_NSS test_programs += storagevolxml2xmltest storagepoolxml2xmltest +test_programs += fsitemxml2xmltest fspoolxml2xmltest + test_programs += nodedevxml2xmltest test_programs += interfacexml2xmltest @@ -862,6 +864,16 @@ storagepoolxml2xmltest_SOURCES = \ testutils.c testutils.h storagepoolxml2xmltest_LDADD = $(LDADDS) +fsitemxml2xmltest_SOURCES = \ + fsitemxml2xmltest.c \ + testutils.c testutils.h +fsitemxml2xmltest_LDADD = $(LDADDS) + +fspoolxml2xmltest_SOURCES = \ + fspoolxml2xmltest.c \ + testutils.c testutils.h +fspoolxml2xmltest_LDADD = $(LDADDS) + nodedevxml2xmltest_SOURCES = \ nodedevxml2xmltest.c \ testutils.c testutils.h diff --git a/tests/fsitemxml2xmlin/item.xml b/tests/fsitemxml2xmlin/item.xml new file mode 100644 index 0000000..ae1be59 --- /dev/null +++ b/tests/fsitemxml2xmlin/item.xml @@ -0,0 +1,13 @@ +<item> + <name>item1</name> + <key>/var/lib/libvirt/images/fs/item1</key> + <capacity unit='bytes'>0</capacity> + <allocation unit='bytes'>4096</allocation> + <target> + <permissions> + <mode>0600</mode> + <owner>0</owner> + <group>0</group> + </permissions> + </target> +</item> diff --git a/tests/fsitemxml2xmlout/item.xml b/tests/fsitemxml2xmlout/item.xml new file mode 100644 index 0000000..ae1be59 --- /dev/null +++ b/tests/fsitemxml2xmlout/item.xml @@ -0,0 +1,13 @@ +<item> + <name>item1</name> + <key>/var/lib/libvirt/images/fs/item1</key> + <capacity unit='bytes'>0</capacity> + <allocation unit='bytes'>4096</allocation> + <target> + <permissions> + <mode>0600</mode> + <owner>0</owner> + <group>0</group> + </permissions> + </target> +</item> diff --git a/tests/fsitemxml2xmltest.c b/tests/fsitemxml2xmltest.c new file mode 100644 index 0000000..dbfcf13 --- /dev/null +++ b/tests/fsitemxml2xmltest.c @@ -0,0 +1,105 @@ +#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 "fs_conf.h" +#include "testutilsqemu.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +static int +testCompareXMLToXMLFiles(const char *fspoolxml, const char *inxml, + const char *outxml, unsigned int flags) +{ + char *actual = NULL; + int ret = -1; + virFSPoolDefPtr fspool = NULL; + virFSItemDefPtr dev = NULL; + + if (!(fspool = virFSPoolDefParseFile(fspoolxml))) + goto fail; + + if (!(dev = virFSItemDefParseFile(fspool, inxml, flags))) + goto fail; + + if (!(actual = virFSItemDefFormat(fspool, dev))) + goto fail; + + if (virTestCompareToFile(actual, outxml) < 0) + goto fail; + + ret = 0; + + fail: + VIR_FREE(actual); + virFSPoolDefFree(fspool); + virFSItemDefFree(dev); + return ret; +} + +struct testInfo { + const char *fspool; + const char *name; + unsigned int flags; +}; + +static int +testCompareXMLToXMLHelper(const void *data) +{ + int result = -1; + const struct testInfo *info = data; + char *fspoolxml = NULL; + char *inxml = NULL; + char *outxml = NULL; + + if (virAsprintf(&fspoolxml, "%s/fspoolxml2xmlin/%s.xml", + abs_srcdir, info->fspool) < 0 || + virAsprintf(&inxml, "%s/fsitemxml2xmlin/%s.xml", + abs_srcdir, info->name) < 0 || + virAsprintf(&outxml, "%s/fsitemxml2xmlout/%s.xml", + abs_srcdir, info->name) < 0) { + goto cleanup; + } + + result = testCompareXMLToXMLFiles(fspoolxml, inxml, outxml, info->flags); + + cleanup: + VIR_FREE(fspoolxml); + VIR_FREE(inxml); + VIR_FREE(outxml); + + return result; +} + + +static int +mymain(void) +{ + int ret = 0; + +#define DO_TEST_FULL(fspool, name, flags) \ + do { \ + struct testInfo info = { fspool, name, flags }; \ + if (virTestRun("FS Item XML-2-XML " name, \ + testCompareXMLToXMLHelper, &info) < 0) \ + ret = -1; \ + } \ + while (0); + +#define DO_TEST(fspool, name) DO_TEST_FULL(fspool, name, 0) + + DO_TEST("fspool-dir", "item"); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN(mymain) diff --git a/tests/fspoolschemadata/dir-missing-target-path-invalid.xml b/tests/fspoolschemadata/dir-missing-target-path-invalid.xml new file mode 100644 index 0000000..a52bf49 --- /dev/null +++ b/tests/fspoolschemadata/dir-missing-target-path-invalid.xml @@ -0,0 +1,12 @@ +<fspool type='dir'> + <name>test</name> + <source> + </source> + <target> + <permissions> + <mode>0700</mode> + <owner>-1</owner> + <group>-1</group> + </permissions> + </target> +</fspool> diff --git a/tests/fspoolxml2xmlin/fspool-dir.xml b/tests/fspoolxml2xmlin/fspool-dir.xml new file mode 100644 index 0000000..d1a3f28 --- /dev/null +++ b/tests/fspoolxml2xmlin/fspool-dir.xml @@ -0,0 +1,16 @@ +<fspool type='dir'> + <name>virtfs</name> + <uuid>5584ee21-db40-4e98-980e-44802c47b62f</uuid> + <capacity unit='bytes'>0</capacity> + <allocation unit='bytes'>0</allocation> + <available unit='bytes'>0</available> + <source> + </source> + <target> + <path>///var/////lib/libvirt/fs//</path> + <permissions> + <mode>0700</mode> + <label>some_lable_t</label> + </permissions> + </target> +</fspool> diff --git a/tests/fspoolxml2xmlout/fspool-dir.xml b/tests/fspoolxml2xmlout/fspool-dir.xml new file mode 100644 index 0000000..dbca470 --- /dev/null +++ b/tests/fspoolxml2xmlout/fspool-dir.xml @@ -0,0 +1,16 @@ +<fspool type='dir'> + <name>virtfs</name> + <uuid>5584ee21-db40-4e98-980e-44802c47b62f</uuid> + <capacity unit='bytes'>0</capacity> + <allocation unit='bytes'>0</allocation> + <available unit='bytes'>0</available> + <source> + </source> + <target> + <path>/var/lib/libvirt/fs</path> + <permissions> + <mode>0700</mode> + <label>some_lable_t</label> + </permissions> + </target> +</fspool> diff --git a/tests/fspoolxml2xmltest.c b/tests/fspoolxml2xmltest.c new file mode 100644 index 0000000..726a3ec --- /dev/null +++ b/tests/fspoolxml2xmltest.c @@ -0,0 +1,81 @@ +#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 "fs_conf.h" +#include "testutilsqemu.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +static int +testCompareXMLToXMLFiles(const char *inxml, const char *outxml) +{ + char *actual = NULL; + int ret = -1; + virFSPoolDefPtr dev = NULL; + + if (!(dev = virFSPoolDefParseFile(inxml))) + goto fail; + + if (!(actual = virFSPoolDefFormat(dev))) + goto fail; + + if (virTestCompareToFile(actual, outxml) < 0) + goto fail; + + ret = 0; + + fail: + VIR_FREE(actual); + virFSPoolDefFree(dev); + return ret; +} + +static int +testCompareXMLToXMLHelper(const void *data) +{ + int result = -1; + char *inxml = NULL; + char *outxml = NULL; + + if (virAsprintf(&inxml, "%s/fspoolxml2xmlin/%s.xml", + abs_srcdir, (const char*)data) < 0 || + virAsprintf(&outxml, "%s/fspoolxml2xmlout/%s.xml", + abs_srcdir, (const char*)data) < 0) { + goto cleanup; + } + + result = testCompareXMLToXMLFiles(inxml, outxml); + + cleanup: + VIR_FREE(inxml); + VIR_FREE(outxml); + + return result; +} + +static int +mymain(void) +{ + int ret = 0; + +#define DO_TEST(name) \ + if (virTestRun("FS Pool XML-2-XML " name, \ + testCompareXMLToXMLHelper, (name)) < 0) \ + ret = -1 + + DO_TEST("fspool-dir"); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN(mymain)