Hello again.
Please, drop the commit message for this patch.
Use the following one:
Added XML 2 XML tests for fspool and item.
________________________________
From: Olga Krishtal
Sent: Thursday, September 15, 2016 10:39:01 AM
To: openstack-devel
Cc: Maxim Nestratov; Nikolay Shirokovskiy
Subject: Re: [PATCH 8/8] fspools: docs and tests for fspool directory backend
On 26/08/16 17:17, Olga Krishtal wrote:
Pleas, drop the commit message, test is present for both: item and fspool.
At the moment only pool test is implemented.
You need to inplement item test.
Signed-off-by: Olga Krishtal <okrishtal(a)virtuozzo.com>
---
docs/schemas/fsitem.rng | 69 ++++++++++++++
docs/schemas/fspool.rng | 83 ++++++++++++++++
tests/fsitemxml2xmltest.c | 105 +++++++++++++++++++++
.../dir-missing-target-path-invalid.xml | 12 +++
tests/fspoolxml2xmlin/fspool-dir.xml | 17 ++++
tests/fspoolxml2xmlout/fspool-dir.xml | 17 ++++
tests/fspoolxml2xmltest.c | 82 ++++++++++++++++
7 files changed, 385 insertions(+)
create mode 100644 docs/schemas/fsitem.rng
create mode 100644 docs/schemas/fspool.rng
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..a41659c
--- /dev/null
+++ b/docs/schemas/fsitem.rng
@@ -0,0 +1,69 @@
+<?xml version="1.0"?>
+<!-- A Relax NG schema for the libvirt storage volume 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='vol'/>
+ </start>
+
+ <include href='storagecommon.rng'/>
+
+
+ <define name='item'>
+ <element name='fsitem'>
+ <optional>
+ <attribute name='type'>
+ <value>dir</value>
+ </attribute>
+ </optional>
+ <interleave>
+ <element name='name'>
+ <ref name='volName'/>
+ </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..132b65c
--- /dev/null
+++ b/docs/schemas/fspool.rng
@@ -0,0 +1,83 @@
+<?xml version="1.0"?>
+<!-- A Relax NG schema for the libvirt storage pool XML format -->
+<grammar
xmlns="http://relaxng.org/ns/structure/1.0"
+
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <include href='basictypes.rng'/>
+ <include href='storagecommon.rng'/>
+ <start>
+ <ref name='pool'/>
+ </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/fsitemxml2xmltest.c b/tests/fsitemxml2xmltest.c
new file mode 100644
index 0000000..87a24e3
--- /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 "storage_conf.h"
+#include "testutilsqemu.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static int
+testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
+ const char *outxml, unsigned int flags)
+{
+ char *actual = NULL;
+ int ret = -1;
+ virFSPoolDefPtr pool = NULL;
+ virFSItemDefPtr dev = NULL;
+
+ if (!(pool = virFSPoolDefParseFile(poolxml)))
+ goto fail;
+
+ if (!(dev = virFSItemDefParseFile(pool, inxml, flags)))
+ goto fail;
+
+ if (!(actual = virFSItemDefFormat(pool, dev)))
+ goto fail;
+
+ if (virTestCompareToFile(actual, outxml) < 0)
+ goto fail;
+
+ ret = 0;
+
+ fail:
+ VIR_FREE(actual);
+ virFSPoolDefFree(pool);
+ virFSItemDefFree(dev);
+ return ret;
+}
+
+struct testInfo {
+ const char *pool;
+ const char *name;
+ unsigned int flags;
+};
+
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ const struct testInfo *info = data;
+ char *poolxml = NULL;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
+ abs_srcdir, info->pool) < 0 ||
+ virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
+ abs_srcdir, info->name) < 0) {
+ goto cleanup;
+ }
+
+ result = testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags);
+
+ cleanup:
+ VIR_FREE(poolxml);
+ VIR_FREE(inxml);
+ VIR_FREE(outxml);
+
+ return result;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = 0;
+
+#define DO_TEST_FULL(pool, name, flags) \
+ do { \
+ struct testInfo info = { pool, name, flags }; \
+ if (virTestRun("FS Item XML-2-XML " name, \
+ testCompareXMLToXMLHelper, &info) < 0) \
+ ret = -1; \
+ } \
+ while (0);
+
+#define DO_TEST(pool, name) DO_TEST_FULL(pool, name, 0)
+
+ DO_TEST("pool-dir", "vol-file");
+
+ 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..a3a1639
--- /dev/null
+++ b/tests/fspoolxml2xmlin/fspool-dir.xml
@@ -0,0 +1,17 @@
+<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>
+ <owner>-1</owner>
+ <group>-1</group>
+ </permissions>
+ </target>
+</fspool>
diff --git a/tests/fspoolxml2xmlout/fspool-dir.xml
b/tests/fspoolxml2xmlout/fspool-dir.xml
new file mode 100644
index 0000000..30aca89
--- /dev/null
+++ b/tests/fspoolxml2xmlout/fspool-dir.xml
@@ -0,0 +1,17 @@
+<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>
+ <owner>-1</owner>
+ <group>-1</group>
+ </permissions>
+ </target>
+</fspool>
diff --git a/tests/fspoolxml2xmltest.c b/tests/fspoolxml2xmltest.c
new file mode 100644
index 0000000..b66e959
--- /dev/null
+++ b/tests/fspoolxml2xmltest.c
@@ -0,0 +1,82 @@
+#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("pool-dir");
+#endif
+
+ return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)