mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
test: Introduce testing of virStorageUtilGlusterExtractPoolSources
Add a test program called virstorageutiltest and test the gluster pool detection code.
This commit is contained in:
parent
e238bfa6d4
commit
69cc498676
@ -160,7 +160,9 @@ EXTRA_DIST = \
|
||||
xlconfigdata \
|
||||
xmconfigdata \
|
||||
xml2sexprdata \
|
||||
xml2vmxdata
|
||||
xml2vmxdata \
|
||||
virstorageutildata \
|
||||
$(NULL)
|
||||
|
||||
test_helpers = commandhelper ssh
|
||||
test_programs = virshtest sockettest \
|
||||
@ -353,6 +355,7 @@ endif WITH_NWFILTER
|
||||
|
||||
if WITH_STORAGE
|
||||
test_programs += storagevolxml2argvtest
|
||||
test_programs += virstorageutiltest
|
||||
endif WITH_STORAGE
|
||||
|
||||
if WITH_STORAGE_FS
|
||||
@ -859,6 +862,16 @@ genericxml2xmltest_LDADD = $(LDADDS)
|
||||
|
||||
|
||||
if WITH_STORAGE
|
||||
virstorageutiltest_SOURCES = \
|
||||
virstorageutiltest.c \
|
||||
testutils.c \
|
||||
testutils.h \
|
||||
$(NULL)
|
||||
virstorageutiltest_LDADD = \
|
||||
../src/libvirt_driver_storage_impl.la \
|
||||
$(LDADDS) \
|
||||
$(NULL)
|
||||
|
||||
storagevolxml2argvtest_SOURCES = \
|
||||
storagevolxml2argvtest.c \
|
||||
testutils.c testutils.h
|
||||
@ -868,6 +881,7 @@ storagevolxml2argvtest_LDADD = \
|
||||
|
||||
else ! WITH_STORAGE
|
||||
EXTRA_DIST += storagevolxml2argvtest.c
|
||||
EXTRA_DIST += virstorageutiltest.c
|
||||
endif ! WITH_STORAGE
|
||||
|
||||
storagevolxml2xmltest_SOURCES = \
|
||||
|
6
tests/virstorageutildata/gluster-parse-basic-native.xml
Normal file
6
tests/virstorageutildata/gluster-parse-basic-native.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<sources>
|
||||
<source>
|
||||
<host name='testhost'/>
|
||||
<dir path='vol0'/>
|
||||
</source>
|
||||
</sources>
|
7
tests/virstorageutildata/gluster-parse-basic-netfs.xml
Normal file
7
tests/virstorageutildata/gluster-parse-basic-netfs.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<sources>
|
||||
<source>
|
||||
<host name='testhost'/>
|
||||
<dir path='vol0'/>
|
||||
<format type='glusterfs'/>
|
||||
</source>
|
||||
</sources>
|
47
tests/virstorageutildata/gluster-parse-basic-src.xml
Normal file
47
tests/virstorageutildata/gluster-parse-basic-src.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<cliOutput>
|
||||
<opRet>0</opRet>
|
||||
<opErrno>0</opErrno>
|
||||
<opErrstr/>
|
||||
<volInfo>
|
||||
<volumes>
|
||||
<volume>
|
||||
<name>vol0</name>
|
||||
<id>ac14dfa5-0b98-4593-a2aa-9fe2bb9b9ce3</id>
|
||||
<status>1</status>
|
||||
<statusStr>Started</statusStr>
|
||||
<snapshotCount>0</snapshotCount>
|
||||
<brickCount>2</brickCount>
|
||||
<distCount>2</distCount>
|
||||
<stripeCount>1</stripeCount>
|
||||
<replicaCount>2</replicaCount>
|
||||
<arbiterCount>0</arbiterCount>
|
||||
<disperseCount>0</disperseCount>
|
||||
<redundancyCount>0</redundancyCount>
|
||||
<type>2</type>
|
||||
<typeStr>Replicate</typeStr>
|
||||
<transport>0</transport>
|
||||
<bricks>
|
||||
<brick uuid="a6f5ddea-bc6a-44db-ae1d-5aa1db743490">virt-gluster-node1:/bricks/brick1/brick<name>virt-gluster-node1:/bricks/brick1/brick</name><hostUuid>a6f5ddea-bc6a-44db-ae1d-5aa1db743490</hostUuid><isArbiter>0</isArbiter></brick>
|
||||
<brick uuid="f4ab9fb1-44ec-443b-8783-e5f70ed78da3">virt-gluster-node2:/bricks/brick1/brick<name>virt-gluster-node2:/bricks/brick1/brick</name><hostUuid>f4ab9fb1-44ec-443b-8783-e5f70ed78da3</hostUuid><isArbiter>0</isArbiter></brick>
|
||||
</bricks>
|
||||
<optCount>3</optCount>
|
||||
<options>
|
||||
<option>
|
||||
<name>nfs.disable</name>
|
||||
<value>on</value>
|
||||
</option>
|
||||
<option>
|
||||
<name>performance.readdir-ahead</name>
|
||||
<value>on</value>
|
||||
</option>
|
||||
<option>
|
||||
<name>transport.address-family</name>
|
||||
<value>inet</value>
|
||||
</option>
|
||||
</options>
|
||||
</volume>
|
||||
<count>1</count>
|
||||
</volumes>
|
||||
</volInfo>
|
||||
</cliOutput>
|
112
tests/virstorageutiltest.c
Normal file
112
tests/virstorageutiltest.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "testutils.h"
|
||||
#include "virerror.h"
|
||||
#include "virfile.h"
|
||||
#include "virlog.h"
|
||||
#include "virstring.h"
|
||||
|
||||
#include "storage/storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
VIR_LOG_INIT("tests.storageutiltest");
|
||||
|
||||
|
||||
struct testGlusterExtractPoolSourcesData {
|
||||
const char *srcxml;
|
||||
const char *dstxml;
|
||||
virStoragePoolType type;
|
||||
};
|
||||
|
||||
static int
|
||||
testGlusterExtractPoolSources(const void *opaque)
|
||||
{
|
||||
const struct testGlusterExtractPoolSourcesData *data = opaque;
|
||||
virStoragePoolSourceList list = { .type = data->type,
|
||||
.nsources = 0,
|
||||
.sources = NULL
|
||||
};
|
||||
size_t i;
|
||||
char *srcxmldata = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virTestLoadFile(data->srcxml, &srcxmldata) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virStorageUtilGlusterExtractPoolSources("testhost", srcxmldata,
|
||||
&list, data->type) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(actual = virStoragePoolSourceListFormat(&list)))
|
||||
goto cleanup;
|
||||
|
||||
ret = virTestCompareToFile(actual, data->dstxml);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(srcxmldata);
|
||||
VIR_FREE(actual);
|
||||
|
||||
for (i = 0; i < list.nsources; i++)
|
||||
virStoragePoolSourceClear(&list.sources[i]);
|
||||
VIR_FREE(list.sources);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#define DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL(testname, sffx, pooltype) \
|
||||
do { \
|
||||
struct testGlusterExtractPoolSourcesData data; \
|
||||
data.srcxml = abs_srcdir "/virstorageutildata/" \
|
||||
"gluster-parse-" testname "-src.xml"; \
|
||||
data.dstxml = abs_srcdir "/virstorageutildata/" \
|
||||
"gluster-parse-" testname "-" sffx ".xml"; \
|
||||
data.type = pooltype; \
|
||||
if (virTestRun("gluster-parse-" testname "-" sffx, \
|
||||
testGlusterExtractPoolSources, &data) < 0) \
|
||||
ret = -1; \
|
||||
} while (0)
|
||||
|
||||
#define DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE(testname) \
|
||||
DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL(testname, "native", \
|
||||
VIR_STORAGE_POOL_GLUSTER)
|
||||
#define DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS(testname) \
|
||||
DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL(testname, "netfs", \
|
||||
VIR_STORAGE_POOL_NETFS)
|
||||
|
||||
DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE("basic");
|
||||
DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS("basic");
|
||||
|
||||
#undef DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE
|
||||
#undef DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS
|
||||
#undef DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN(mymain)
|
Loading…
Reference in New Issue
Block a user