tests: Introduce storage pool capabilites test

Add a new test for the storage pool capabilities. There will be
one test mocked with every backend available (full) and one where
only the file system pool is available.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
John Ferlan 2019-02-07 12:07:16 -05:00
parent 3b1988f3e3
commit 73426c55b7
3 changed files with 398 additions and 0 deletions

View File

@ -369,6 +369,7 @@ test_programs += storagevolxml2argvtest
test_programs += storagepoolxml2argvtest
test_programs += virstorageutiltest
test_programs += storagepoolxml2xmltest
test_programs += storagepoolcapstest
endif WITH_STORAGE
if WITH_STORAGE_FS
@ -936,11 +937,16 @@ storagepoolxml2xmltest_LDADD = $(LDADDS) \
../src/libvirt_driver_storage_impl.la \
$(GNULIB_LIBS)
storagepoolcapstest_SOURCES = \
storagepoolcapstest.c testutils.h testutils.c
storagepoolcapstest_LDADD = $(LDADDS)
else ! WITH_STORAGE
EXTRA_DIST += storagevolxml2argvtest.c
EXTRA_DIST += virstorageutiltest.c
EXTRA_DIST += storagepoolxml2argvtest.c
EXTRA_DIST += storagepoolxml2xmltest.c
EXTRA_DIST += storagepoolcapstest.c
endif ! WITH_STORAGE
storagevolxml2xmltest_SOURCES = \

View File

@ -0,0 +1,268 @@
<storagepoolCapabilities>
<pool type='dir' supported='no'>
<volOptions>
<defaultFormat type='raw'/>
<enum name='targetFormatType'>
<value>none</value>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
<value>cloop</value>
<value>dmg</value>
<value>iso</value>
<value>vpc</value>
<value>vdi</value>
<value>fat</value>
<value>vhd</value>
<value>ploop</value>
<value>cow</value>
<value>qcow</value>
<value>qcow2</value>
<value>qed</value>
<value>vmdk</value>
</enum>
</volOptions>
</pool>
<pool type='fs' supported='yes'>
<poolOptions>
<defaultFormat type='auto'/>
<enum name='sourceFormatType'>
<value>auto</value>
<value>ext2</value>
<value>ext3</value>
<value>ext4</value>
<value>ufs</value>
<value>iso9660</value>
<value>udf</value>
<value>gfs</value>
<value>gfs2</value>
<value>vfat</value>
<value>hfs+</value>
<value>xfs</value>
<value>ocfs2</value>
</enum>
<enum name='requiredSourceElements'>
<value>device</value>
</enum>
</poolOptions>
<volOptions>
<defaultFormat type='raw'/>
<enum name='targetFormatType'>
<value>none</value>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
<value>cloop</value>
<value>dmg</value>
<value>iso</value>
<value>vpc</value>
<value>vdi</value>
<value>fat</value>
<value>vhd</value>
<value>ploop</value>
<value>cow</value>
<value>qcow</value>
<value>qcow2</value>
<value>qed</value>
<value>vmdk</value>
</enum>
</volOptions>
</pool>
<pool type='netfs' supported='no'>
<poolOptions>
<defaultFormat type='auto'/>
<enum name='sourceFormatType'>
<value>auto</value>
<value>nfs</value>
<value>glusterfs</value>
<value>cifs</value>
</enum>
<enum name='requiredSourceElements'>
<value>host</value>
<value>dir</value>
</enum>
</poolOptions>
<volOptions>
<defaultFormat type='raw'/>
<enum name='targetFormatType'>
<value>none</value>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
<value>cloop</value>
<value>dmg</value>
<value>iso</value>
<value>vpc</value>
<value>vdi</value>
<value>fat</value>
<value>vhd</value>
<value>ploop</value>
<value>cow</value>
<value>qcow</value>
<value>qcow2</value>
<value>qed</value>
<value>vmdk</value>
</enum>
</volOptions>
</pool>
<pool type='logical' supported='no'>
<poolOptions>
<defaultFormat type='lvm2'/>
<enum name='sourceFormatType'>
<value>unknown</value>
<value>lvm2</value>
</enum>
<enum name='requiredSourceElements'>
<value>device</value>
<value>name</value>
</enum>
</poolOptions>
</pool>
<pool type='disk' supported='no'>
<poolOptions>
<defaultFormat type='unknown'/>
<enum name='sourceFormatType'>
<value>unknown</value>
<value>dos</value>
<value>dvh</value>
<value>gpt</value>
<value>mac</value>
<value>bsd</value>
<value>pc98</value>
<value>sun</value>
<value>lvm2</value>
</enum>
<enum name='requiredSourceElements'>
<value>device</value>
</enum>
</poolOptions>
<volOptions>
<defaultFormat type='none'/>
<enum name='targetFormatType'>
<value>none</value>
<value>linux</value>
<value>fat16</value>
<value>fat32</value>
<value>linux-swap</value>
<value>linux-lvm</value>
<value>linux-raid</value>
<value>extended</value>
</enum>
</volOptions>
</pool>
<pool type='iscsi' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>host</value>
<value>device</value>
<value>initiator</value>
</enum>
</poolOptions>
</pool>
<pool type='iscsi-direct' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>host</value>
<value>device</value>
<value>initiator</value>
<value>network</value>
</enum>
</poolOptions>
</pool>
<pool type='scsi' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>adapter</value>
</enum>
</poolOptions>
</pool>
<pool type='mpath' supported='no'>
</pool>
<pool type='rbd' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>host</value>
<value>name</value>
<value>network</value>
</enum>
</poolOptions>
</pool>
<pool type='sheepdog' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>host</value>
<value>name</value>
<value>network</value>
</enum>
</poolOptions>
</pool>
<pool type='gluster' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>host</value>
<value>dir</value>
<value>name</value>
<value>network</value>
</enum>
</poolOptions>
<volOptions>
<defaultFormat type='raw'/>
<enum name='targetFormatType'>
<value>none</value>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
<value>cloop</value>
<value>dmg</value>
<value>iso</value>
<value>vpc</value>
<value>vdi</value>
<value>fat</value>
<value>vhd</value>
<value>ploop</value>
<value>cow</value>
<value>qcow</value>
<value>qcow2</value>
<value>qed</value>
<value>vmdk</value>
</enum>
</volOptions>
</pool>
<pool type='zfs' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>device</value>
<value>name</value>
</enum>
</poolOptions>
</pool>
<pool type='vstorage' supported='no'>
<poolOptions>
<enum name='requiredSourceElements'>
<value>name</value>
</enum>
</poolOptions>
<volOptions>
<defaultFormat type='raw'/>
<enum name='targetFormatType'>
<value>none</value>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
<value>cloop</value>
<value>dmg</value>
<value>iso</value>
<value>vpc</value>
<value>vdi</value>
<value>fat</value>
<value>vhd</value>
<value>ploop</value>
<value>cow</value>
<value>qcow</value>
<value>qcow2</value>
<value>qed</value>
<value>vmdk</value>
</enum>
</volOptions>
</pool>
</storagepoolCapabilities>

124
tests/storagepoolcapstest.c Normal file
View File

@ -0,0 +1,124 @@
/*
* Copyright (C) Red Hat, Inc. 2019
*
* 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 "testutils.h"
#include "storage_conf.h"
#include "storage_capabilities.h"
#define VIR_FROM_THIS VIR_FROM_NONE
struct test_virStoragePoolCapsFormatData {
const char *filename;
virCapsPtr driverCaps;
};
static void
test_virCapabilitiesAddFullStoragePool(virCapsPtr caps)
{
size_t i;
for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
virCapabilitiesAddStoragePool(caps, i);
}
static void
test_virCapabilitiesAddFSStoragePool(virCapsPtr caps)
{
virCapabilitiesAddStoragePool(caps, VIR_STORAGE_POOL_FS);
}
static int
test_virStoragePoolCapsFormat(const void *opaque)
{
struct test_virStoragePoolCapsFormatData *data =
(struct test_virStoragePoolCapsFormatData *) opaque;
virCapsPtr driverCaps = data->driverCaps;
virStoragePoolCapsPtr poolCaps = NULL;
int ret = -1;
VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) poolCapsFromFile = NULL;
VIR_AUTOFREE(char *) poolCapsXML = NULL;
if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
goto cleanup;
if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml",
abs_srcdir, data->filename) < 0)
goto cleanup;
if (virFileReadAll(path, 8192, &poolCapsFromFile) < 0)
goto cleanup;
if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
goto cleanup;
if (STRNEQ(poolCapsFromFile, poolCapsXML)) {
virTestDifference(stderr, poolCapsFromFile, poolCapsXML);
goto cleanup;
}
ret = 0;
cleanup:
virObjectUnref(poolCaps);
return ret;
}
static int
mymain(void)
{
int ret = -1;
virCapsPtr fullCaps = NULL;
virCapsPtr fsCaps = NULL;
#define DO_TEST(Filename, DriverCaps) \
do { \
struct test_virStoragePoolCapsFormatData data = \
{.filename = Filename, .driverCaps = DriverCaps }; \
if (virTestRun(Filename, test_virStoragePoolCapsFormat, &data) < 0) \
goto cleanup; \
} while (0)
if (!(fullCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)) ||
!(fsCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)))
goto cleanup;
test_virCapabilitiesAddFullStoragePool(fullCaps);
test_virCapabilitiesAddFSStoragePool(fsCaps);
DO_TEST("full", fullCaps);
DO_TEST("fs", fsCaps);
ret = 0;
cleanup:
virObjectUnref(fullCaps);
virObjectUnref(fsCaps);
return ret;
}
VIR_TEST_MAIN(mymain)