]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Add XML 2 XML tests for storage pools.
authorCole Robinson <crobinso@redhat.com>
Thu, 8 Oct 2009 21:26:30 +0000 (17:26 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 16 Oct 2009 14:21:47 +0000 (10:21 -0400)
Move existing schema data to an input directory. Add extra files for more
thorough XML testing.

24 files changed:
tests/.gitignore
tests/Makefile.am
tests/storagepoolschematest
tests/storagepoolxml2xmlin/pool-dir.xml [moved from tests/storagepoolschemadata/pool-dir.xml with 91% similarity]
tests/storagepoolxml2xmlin/pool-disk.xml [moved from tests/storagepoolschemadata/pool-disk.xml with 100% similarity]
tests/storagepoolxml2xmlin/pool-fs.xml [moved from tests/storagepoolschemadata/pool-fs.xml with 100% similarity]
tests/storagepoolxml2xmlin/pool-iscsi-auth.xml [new file with mode: 0644]
tests/storagepoolxml2xmlin/pool-iscsi.xml [moved from tests/storagepoolschemadata/pool-iscsi.xml with 56% similarity]
tests/storagepoolxml2xmlin/pool-logical-create.xml [new file with mode: 0644]
tests/storagepoolxml2xmlin/pool-logical.xml [moved from tests/storagepoolschemadata/pool-logical.xml with 100% similarity]
tests/storagepoolxml2xmlin/pool-mpath.xml [new file with mode: 0644]
tests/storagepoolxml2xmlin/pool-netfs.xml [moved from tests/storagepoolschemadata/pool-netfs.xml with 100% similarity]
tests/storagepoolxml2xmlin/pool-scsi.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-dir.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-disk.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-fs.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-iscsi-auth.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-iscsi.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-logical-create.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-logical.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-mpath.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-netfs.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-scsi.xml [new file with mode: 0644]
tests/storagepoolxml2xmltest.c [new file with mode: 0644]

index 6d67c2adab7d480004013f86b587a9b08cb4b31f..41f84543f4b99e17357afa89ef2ad54d11110547 100644 (file)
@@ -15,6 +15,7 @@ qemuargv2xmltest
 qemuhelptest
 nodedevxml2xmltest
 interfacexml2xmltest
+storagepoolxml2xmltest
 nodeinfotest
 statstest
 qparamtest
index b67df5dc325d383d9aa93b91749a47727650b58a..a62c01bb420e7e6bb4691c7572f46bc785116de9 100644 (file)
@@ -61,7 +61,8 @@ EXTRA_DIST =          \
        domainschemadata \
        interfaceschemadata \
        storagepoolschematest \
-       storagepoolschemadata \
+       storagepoolxml2xmlout \
+       storagepoolxml2xmlin \
        storagevolschematest \
        storagevolschemadata \
        nodedevschematest \
@@ -95,6 +96,8 @@ if WITH_CIL
 noinst_PROGRAMS += object-locking
 endif
 
+noinst_PROGRAMS += storagepoolxml2xmltest
+
 noinst_PROGRAMS += nodedevxml2xmltest
 
 noinst_PROGRAMS += interfacexml2xmltest
@@ -168,6 +171,8 @@ noinst_PROGRAMS += eventtest
 TESTS += eventtest
 endif
 
+TESTS += storagepoolxml2xmltest
+
 TESTS += nodedevxml2xmltest
 
 TESTS += interfacexml2xmltest
@@ -264,6 +269,11 @@ else
 EXTRA_DIST += esxutilstest.c vmx2xmltest.c xml2vmxtest.c
 endif
 
+storagepoolxml2xmltest_SOURCES = \
+       storagepoolxml2xmltest.c \
+       testutils.c testutils.h
+storagepoolxml2xmltest_LDADD = $(LDADDS)
+
 nodedevxml2xmltest_SOURCES = \
        nodedevxml2xmltest.c \
        testutils.c testutils.h
index d04b83b96dfdb593361a16bd9eba272e5c9564c9..be4767d5e670f3f71a12fd1e5c92eb091d3aeeb7 100755 (executable)
@@ -2,7 +2,7 @@
 
 source ./schematestutils.sh
 
-DIRS="storagepoolschemadata"
+DIRS="storagepoolxml2xmlin storagepoolxml2xmlout"
 SCHEMA="storagepool.rng"
 
 check_schema "$DIRS" "$SCHEMA"
similarity index 91%
rename from tests/storagepoolschemadata/pool-dir.xml
rename to tests/storagepoolxml2xmlin/pool-dir.xml
index 2b8735c215904d061fd0107bed19bae017417caa..361e3831038188bf03a727d64928369deac390f6 100644 (file)
@@ -12,6 +12,7 @@
       <mode>0700</mode>
       <owner>0</owner>
       <group>0</group>
+      <label>some_label_t</label>
     </permissions>
   </target>
 </pool>
diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
new file mode 100644 (file)
index 0000000..f7d4d52
--- /dev/null
@@ -0,0 +1,17 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <source>
+    <host name="iscsi.example.com"/>
+    <device path="demo-target"/>
+    <auth type='chap' login='foobar' passwd='frobbar'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
similarity index 56%
rename from tests/storagepoolschemadata/pool-iscsi.xml
rename to tests/storagepoolxml2xmlin/pool-iscsi.xml
index 8d60f38b88e2a88338ad700594ffe0e0523fa08d..37a16f734b260d13e0958ebd0aeee60a5a98cda8 100644 (file)
@@ -1,10 +1,16 @@
 <pool type='iscsi'>
   <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
   <source>
     <host name="iscsi.example.com"/>
     <device path="demo-target"/>
   </source>
   <target>
     <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
   </target>
 </pool>
diff --git a/tests/storagepoolxml2xmlin/pool-logical-create.xml b/tests/storagepoolxml2xmlin/pool-logical-create.xml
new file mode 100644 (file)
index 0000000..4c67089
--- /dev/null
@@ -0,0 +1,20 @@
+<pool type='logical'>
+  <name>HostVG</name>
+  <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
+  <capacity>99891544064</capacity>
+  <allocation>99220455424</allocation>
+  <available>671088640</available>
+  <source>
+    <device path="/dev/sdb1"/>
+    <device path="/dev/sdb2"/>
+    <device path="/dev/sdb3"/>
+  </source>
+  <target>
+    <path>/dev/HostVG</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlin/pool-mpath.xml b/tests/storagepoolxml2xmlin/pool-mpath.xml
new file mode 100644 (file)
index 0000000..a5fbbcb
--- /dev/null
@@ -0,0 +1,12 @@
+<pool type="mpath">
+  <name>mpath</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <target>
+    <path>/dev/mapper</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlin/pool-scsi.xml b/tests/storagepoolxml2xmlin/pool-scsi.xml
new file mode 100644 (file)
index 0000000..3650e43
--- /dev/null
@@ -0,0 +1,15 @@
+<pool type="scsi">
+  <name>hba0</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <source>
+    <adapter name="host0"/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-dir.xml b/tests/storagepoolxml2xmlout/pool-dir.xml
new file mode 100644 (file)
index 0000000..361e383
--- /dev/null
@@ -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>0</owner>
+      <group>0</group>
+      <label>some_label_t</label>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-disk.xml b/tests/storagepoolxml2xmlout/pool-disk.xml
new file mode 100644 (file)
index 0000000..d6c595f
--- /dev/null
@@ -0,0 +1,19 @@
+<pool type='disk'>
+  <name>sda</name>
+  <uuid>e3509a62-1b4c-e20b-94bd-9168963f9b97</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <device path='/dev/sda'/>
+    <format type='dos'/>
+  </source>
+  <target>
+    <path>/dev</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-fs.xml b/tests/storagepoolxml2xmlout/pool-fs.xml
new file mode 100644 (file)
index 0000000..ee2bb55
--- /dev/null
@@ -0,0 +1,19 @@
+<pool type='fs'>
+  <name>images</name>
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <device path='/dev/sda6'/>
+    <format type='ext3'/>
+  </source>
+  <target>
+    <path>/mnt</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
new file mode 100644 (file)
index 0000000..557295d
--- /dev/null
@@ -0,0 +1,20 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <host name='iscsi.example.com'/>
+    <device path='demo-target'/>
+    <auth type='chap' login='foobar' passwd='frobbar'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-iscsi.xml b/tests/storagepoolxml2xmlout/pool-iscsi.xml
new file mode 100644 (file)
index 0000000..774bdd3
--- /dev/null
@@ -0,0 +1,19 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <host name='iscsi.example.com'/>
+    <device path='demo-target'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-logical-create.xml b/tests/storagepoolxml2xmlout/pool-logical-create.xml
new file mode 100644 (file)
index 0000000..c30359b
--- /dev/null
@@ -0,0 +1,22 @@
+<pool type='logical'>
+  <name>HostVG</name>
+  <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <device path='/dev/sdb1'/>
+    <device path='/dev/sdb2'/>
+    <device path='/dev/sdb3'/>
+    <name>HostVG</name>
+    <format type='lvm2'/>
+  </source>
+  <target>
+    <path>/dev/HostVG</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-logical.xml b/tests/storagepoolxml2xmlout/pool-logical.xml
new file mode 100644 (file)
index 0000000..6ce41e1
--- /dev/null
@@ -0,0 +1,19 @@
+<pool type='logical'>
+  <name>HostVG</name>
+  <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <name>HostVG</name>
+    <format type='lvm2'/>
+  </source>
+  <target>
+    <path>/dev/HostVG</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-mpath.xml b/tests/storagepoolxml2xmlout/pool-mpath.xml
new file mode 100644 (file)
index 0000000..8f5d2c7
--- /dev/null
@@ -0,0 +1,17 @@
+<pool type='mpath'>
+  <name>mpath</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+  </source>
+  <target>
+    <path>/dev/mapper</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-netfs.xml b/tests/storagepoolxml2xmlout/pool-netfs.xml
new file mode 100644 (file)
index 0000000..4bd18c5
--- /dev/null
@@ -0,0 +1,20 @@
+<pool type='netfs'>
+  <name>nfsimages</name>
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <host name='localhost'/>
+    <dir path='/var/lib/libvirt/images'/>
+    <format type='nfs'/>
+  </source>
+  <target>
+    <path>/mnt</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-scsi.xml b/tests/storagepoolxml2xmlout/pool-scsi.xml
new file mode 100644 (file)
index 0000000..b24a9f2
--- /dev/null
@@ -0,0 +1,18 @@
+<pool type='scsi'>
+  <name>hba0</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <adapter name='host0'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
new file mode 100644 (file)
index 0000000..a7370c7
--- /dev/null
@@ -0,0 +1,102 @@
+#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 *inxml, const char *outxml) {
+    char inXmlData[MAX_FILE];
+    char *inXmlPtr = &(inXmlData[0]);
+    char outXmlData[MAX_FILE];
+    char *outXmlPtr = &(outXmlData[0]);
+    char *actual = NULL;
+    int ret = -1;
+    virStoragePoolDefPtr dev = NULL;
+
+    if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+        goto fail;
+    if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+        goto fail;
+
+    if (!(dev = virStoragePoolDefParseString(NULL, inXmlData)))
+        goto fail;
+
+    if (!(actual = virStoragePoolDefFormat(NULL, dev)))
+        goto fail;
+
+    if (STRNEQ(outXmlData, actual)) {
+        virtTestDifference(stderr, outXmlData, actual);
+        goto fail;
+    }
+
+    ret = 0;
+
+ fail:
+    free(actual);
+    virStoragePoolDefFree(dev);
+    return ret;
+}
+
+static int testCompareXMLToXMLHelper(const void *data) {
+    char inxml[PATH_MAX];
+    char outxml[PATH_MAX];
+    snprintf(inxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml",
+             abs_srcdir, (const char*)data);
+    snprintf(outxml, PATH_MAX, "%s/storagepoolxml2xmlout/%s.xml",
+             abs_srcdir, (const char*)data);
+    return testCompareXMLToXMLFiles(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(name) \
+    if (virtTestRun("Storage Pool XML-2-XML " name, \
+                    1, testCompareXMLToXMLHelper, (name)) < 0) \
+        ret = -1
+
+    DO_TEST("pool-dir");
+    DO_TEST("pool-fs");
+    DO_TEST("pool-logical");
+    DO_TEST("pool-logical-create");
+    DO_TEST("pool-disk");
+    DO_TEST("pool-iscsi");
+    DO_TEST("pool-iscsi-auth");
+    DO_TEST("pool-netfs");
+    DO_TEST("pool-scsi");
+    DO_TEST("pool-mpath");
+
+    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+VIRT_TEST_MAIN(mymain)