mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
tests: Add XML 2 XML tests for storage pools.
Move existing schema data to an input directory. Add extra files for more thorough XML testing.
This commit is contained in:
parent
39a7be470c
commit
e1ea1b2af7
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@ -15,6 +15,7 @@ qemuargv2xmltest
|
||||
qemuhelptest
|
||||
nodedevxml2xmltest
|
||||
interfacexml2xmltest
|
||||
storagepoolxml2xmltest
|
||||
nodeinfotest
|
||||
statstest
|
||||
qparamtest
|
||||
|
@ -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
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
source ./schematestutils.sh
|
||||
|
||||
DIRS="storagepoolschemadata"
|
||||
DIRS="storagepoolxml2xmlin storagepoolxml2xmlout"
|
||||
SCHEMA="storagepool.rng"
|
||||
|
||||
check_schema "$DIRS" "$SCHEMA"
|
||||
|
@ -12,6 +12,7 @@
|
||||
<mode>0700</mode>
|
||||
<owner>0</owner>
|
||||
<group>0</group>
|
||||
<label>some_label_t</label>
|
||||
</permissions>
|
||||
</target>
|
||||
</pool>
|
17
tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
Normal file
17
tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
Normal file
@ -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>
|
@ -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>
|
20
tests/storagepoolxml2xmlin/pool-logical-create.xml
Normal file
20
tests/storagepoolxml2xmlin/pool-logical-create.xml
Normal file
@ -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>
|
12
tests/storagepoolxml2xmlin/pool-mpath.xml
Normal file
12
tests/storagepoolxml2xmlin/pool-mpath.xml
Normal file
@ -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>
|
15
tests/storagepoolxml2xmlin/pool-scsi.xml
Normal file
15
tests/storagepoolxml2xmlin/pool-scsi.xml
Normal file
@ -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>
|
18
tests/storagepoolxml2xmlout/pool-dir.xml
Normal file
18
tests/storagepoolxml2xmlout/pool-dir.xml
Normal file
@ -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>
|
19
tests/storagepoolxml2xmlout/pool-disk.xml
Normal file
19
tests/storagepoolxml2xmlout/pool-disk.xml
Normal file
@ -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>
|
19
tests/storagepoolxml2xmlout/pool-fs.xml
Normal file
19
tests/storagepoolxml2xmlout/pool-fs.xml
Normal file
@ -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>
|
20
tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
Normal file
20
tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
Normal file
@ -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>
|
19
tests/storagepoolxml2xmlout/pool-iscsi.xml
Normal file
19
tests/storagepoolxml2xmlout/pool-iscsi.xml
Normal file
@ -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>
|
22
tests/storagepoolxml2xmlout/pool-logical-create.xml
Normal file
22
tests/storagepoolxml2xmlout/pool-logical-create.xml
Normal file
@ -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>
|
19
tests/storagepoolxml2xmlout/pool-logical.xml
Normal file
19
tests/storagepoolxml2xmlout/pool-logical.xml
Normal file
@ -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>
|
17
tests/storagepoolxml2xmlout/pool-mpath.xml
Normal file
17
tests/storagepoolxml2xmlout/pool-mpath.xml
Normal file
@ -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>
|
20
tests/storagepoolxml2xmlout/pool-netfs.xml
Normal file
20
tests/storagepoolxml2xmlout/pool-netfs.xml
Normal file
@ -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>
|
18
tests/storagepoolxml2xmlout/pool-scsi.xml
Normal file
18
tests/storagepoolxml2xmlout/pool-scsi.xml
Normal file
@ -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>
|
102
tests/storagepoolxml2xmltest.c
Normal file
102
tests/storagepoolxml2xmltest.c
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user