mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
storage: add test for qemu-img command line generation
This commit is contained in:
parent
c6e87d1a4b
commit
56e1b4c30f
@ -74,6 +74,7 @@ EXTRA_DIST = \
|
||||
storagepoolschematest \
|
||||
storagepoolxml2xmlin \
|
||||
storagepoolxml2xmlout \
|
||||
storagevolxml2argvdata \
|
||||
storagevolschematest \
|
||||
storagevolxml2xmlin \
|
||||
storagevolxml2xmlout \
|
||||
@ -170,6 +171,8 @@ endif
|
||||
|
||||
test_programs += nwfilterxml2xmltest
|
||||
|
||||
test_programs += storagevolxml2argvtest
|
||||
|
||||
test_programs += storagevolxml2xmltest storagepoolxml2xmltest
|
||||
|
||||
test_programs += nodedevxml2xmltest
|
||||
@ -470,6 +473,12 @@ nwfilterxml2xmltest_SOURCES = \
|
||||
testutils.c testutils.h
|
||||
nwfilterxml2xmltest_LDADD = $(LDADDS)
|
||||
|
||||
storagevolxml2argvtest_SOURCES = \
|
||||
storagevolxml2argvtest.c \
|
||||
testutils.c testutils.h
|
||||
storagevolxml2argvtest_LDADD = \
|
||||
../src/libvirt_driver_storage_impl.la $(LDADDS)
|
||||
|
||||
storagevolxml2xmltest_SOURCES = \
|
||||
storagevolxml2xmltest.c \
|
||||
testutils.c testutils.h
|
||||
|
18
tests/storagevolxml2argvdata/pool-dir.xml
Normal file
18
tests/storagevolxml2argvdata/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>-1</owner>
|
||||
<group>-1</group>
|
||||
<label>some_label_t</label>
|
||||
</permissions>
|
||||
</target>
|
||||
</pool>
|
1
tests/storagevolxml2argvdata/qcow2-flag.argv
Normal file
1
tests/storagevolxml2argvdata/qcow2-flag.argv
Normal file
@ -0,0 +1 @@
|
||||
qemu-img create -f qcow2 -b /dev/null -F raw /var/lib/libvirt/images/OtherDemo.img 5242880K -e
|
@ -0,0 +1 @@
|
||||
qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img -e
|
@ -0,0 +1 @@
|
||||
qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img -e
|
@ -0,0 +1 @@
|
||||
qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img -o encryption=on,preallocation=metadata
|
1
tests/storagevolxml2argvdata/qcow2-nobacking-flag.argv
Normal file
1
tests/storagevolxml2argvdata/qcow2-nobacking-flag.argv
Normal file
@ -0,0 +1 @@
|
||||
qemu-img create -f qcow2 /var/lib/libvirt/images/OtherDemo.img 5242880K -e
|
1
tests/storagevolxml2argvdata/qcow2-nobacking-none.argv
Normal file
1
tests/storagevolxml2argvdata/qcow2-nobacking-none.argv
Normal file
@ -0,0 +1 @@
|
||||
qemu-img create -f qcow2 /var/lib/libvirt/images/OtherDemo.img 5242880K -e
|
@ -0,0 +1 @@
|
||||
qemu-img create -f qcow2 /var/lib/libvirt/images/OtherDemo.img 5242880K -o encryption=on,preallocation=metadata
|
1
tests/storagevolxml2argvdata/qcow2-none.argv
Normal file
1
tests/storagevolxml2argvdata/qcow2-none.argv
Normal file
@ -0,0 +1 @@
|
||||
qemu-img create -f qcow2 -b /dev/null /var/lib/libvirt/images/OtherDemo.img 5242880K -e
|
1
tests/storagevolxml2argvdata/qcow2.argv
Normal file
1
tests/storagevolxml2argvdata/qcow2.argv
Normal file
@ -0,0 +1 @@
|
||||
qemu-img create -f qcow2 -b /dev/null -o backing_fmt=raw,encryption=on /var/lib/libvirt/images/OtherDemo.img 5242880K
|
20
tests/storagevolxml2argvdata/vol-file.xml
Normal file
20
tests/storagevolxml2argvdata/vol-file.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<volume>
|
||||
<name>sparse.img</name>
|
||||
<source/>
|
||||
<capacity unit="TiB">1</capacity>
|
||||
<allocation unit="bytes">0</allocation>
|
||||
<target>
|
||||
<path>/var/lib/libvirt/images/sparse.img</path>
|
||||
<permissions>
|
||||
<mode>0</mode>
|
||||
<owner>0744</owner>
|
||||
<group>0</group>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
<timestamps>
|
||||
<atime>1341933637.273190990</atime>
|
||||
<mtime>1341930622.047245868</mtime>
|
||||
<ctime>1341930622.047245868</ctime>
|
||||
</timestamps>
|
||||
</target>
|
||||
</volume>
|
21
tests/storagevolxml2argvdata/vol-qcow2-nobacking.xml
Normal file
21
tests/storagevolxml2argvdata/vol-qcow2-nobacking.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<volume>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
</source>
|
||||
<capacity unit="G">5</capacity>
|
||||
<allocation>294912</allocation>
|
||||
<target>
|
||||
<path>/var/lib/libvirt/images/OtherDemo.img</path>
|
||||
<format type='qcow2'/>
|
||||
<permissions>
|
||||
<mode>0644</mode>
|
||||
<owner>0</owner>
|
||||
<group>0</group>
|
||||
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||
</permissions>
|
||||
<encryption format='qcow'>
|
||||
<secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
|
||||
</encryption>
|
||||
</target>
|
||||
</volume>
|
31
tests/storagevolxml2argvdata/vol-qcow2.xml
Normal file
31
tests/storagevolxml2argvdata/vol-qcow2.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<volume>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
</source>
|
||||
<capacity unit="G">5</capacity>
|
||||
<allocation>294912</allocation>
|
||||
<target>
|
||||
<path>/var/lib/libvirt/images/OtherDemo.img</path>
|
||||
<format type='qcow2'/>
|
||||
<permissions>
|
||||
<mode>0644</mode>
|
||||
<owner>0</owner>
|
||||
<group>0</group>
|
||||
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||
</permissions>
|
||||
<encryption format='qcow'>
|
||||
<secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
|
||||
</encryption>
|
||||
</target>
|
||||
<backingStore>
|
||||
<path>/dev/null</path>
|
||||
<format type='raw'/>
|
||||
<permissions>
|
||||
<mode>0644</mode>
|
||||
<owner>0</owner>
|
||||
<group>0</group>
|
||||
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||
</permissions>
|
||||
</backingStore>
|
||||
</volume>
|
189
tests/storagevolxml2argvtest.c
Normal file
189
tests/storagevolxml2argvtest.c
Normal file
@ -0,0 +1,189 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "testutils.h"
|
||||
#include "datatypes.h"
|
||||
#include "storage/storage_backend.h"
|
||||
#include "testutilsqemu.h"
|
||||
|
||||
const char create_tool[] = "qemu-img";
|
||||
|
||||
static int
|
||||
testCompareXMLToArgvFiles(bool shouldFail,
|
||||
const char *poolxml,
|
||||
const char *volxml,
|
||||
const char *inputvolxml,
|
||||
const char *cmdline,
|
||||
unsigned int flags,
|
||||
int imgformat)
|
||||
{
|
||||
char *volXmlData = NULL;
|
||||
char *poolXmlData = NULL;
|
||||
char *inputvolXmlData = NULL;
|
||||
char *expectedCmdline = NULL;
|
||||
char *actualCmdline = NULL;
|
||||
int ret = -1;
|
||||
|
||||
int len;
|
||||
|
||||
virCommandPtr cmd = NULL;
|
||||
virConnectPtr conn;
|
||||
|
||||
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
||||
virStoragePoolDefPtr pool = NULL;
|
||||
virStoragePoolObj poolobj = {.def = NULL };
|
||||
|
||||
|
||||
if (!(conn = virGetConnect()))
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
|
||||
goto cleanup;
|
||||
if (virtTestLoadFile(volxml, &volXmlData) < 0)
|
||||
goto cleanup;
|
||||
if (inputvolxml &&
|
||||
virtTestLoadFile(inputvolxml, &inputvolXmlData) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(pool = virStoragePoolDefParseString(poolXmlData)))
|
||||
goto cleanup;
|
||||
|
||||
poolobj.def = pool;
|
||||
|
||||
if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
|
||||
goto cleanup;
|
||||
|
||||
if (inputvolxml &&
|
||||
!(inputvol = virStorageVolDefParseString(pool, inputvolXmlData)))
|
||||
goto cleanup;
|
||||
|
||||
cmd = virStorageBackendCreateQemuImgCmd(conn, &poolobj, vol, inputvol,
|
||||
flags, create_tool, imgformat);
|
||||
|
||||
actualCmdline = virCommandToString(cmd);
|
||||
if (!actualCmdline) {
|
||||
if (shouldFail) {
|
||||
virResetLastError();
|
||||
ret = 0;
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectedCmdline);
|
||||
if (len < 0)
|
||||
goto cleanup;
|
||||
if (len && expectedCmdline[len-1] == '\n')
|
||||
expectedCmdline[len-1] = '\0';
|
||||
|
||||
if (STRNEQ_NULLABLE(expectedCmdline, actualCmdline)) {
|
||||
virtTestDifference(stderr, expectedCmdline, actualCmdline);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virStoragePoolDefFree(pool);
|
||||
virStorageVolDefFree(vol);
|
||||
virStorageVolDefFree(inputvol);
|
||||
virCommandFree(cmd);
|
||||
VIR_FREE(actualCmdline);
|
||||
VIR_FREE(expectedCmdline);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct testInfo {
|
||||
bool shouldFail;
|
||||
const char *pool;
|
||||
const char *vol;
|
||||
const char *inputvol;
|
||||
const char *cmdline;
|
||||
unsigned int flags;
|
||||
int imgformat;
|
||||
};
|
||||
|
||||
static int
|
||||
testCompareXMLToArgvHelper(const void *data)
|
||||
{
|
||||
int result = -1;
|
||||
const struct testInfo *info = data;
|
||||
char *poolxml = NULL;
|
||||
char *volxml = NULL;
|
||||
char *inputvolxml = NULL;
|
||||
char *cmdline = NULL;
|
||||
|
||||
if (info->inputvol &&
|
||||
virAsprintf(&inputvolxml, "%s/storagevolxml2argvdata/%s.xml",
|
||||
abs_srcdir, info->inputvol) < 0)
|
||||
goto cleanup;
|
||||
if (virAsprintf(&poolxml, "%s/storagevolxml2argvdata/%s.xml",
|
||||
abs_srcdir, info->pool) < 0 ||
|
||||
virAsprintf(&volxml, "%s/storagevolxml2argvdata/%s.xml",
|
||||
abs_srcdir, info->vol) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv",
|
||||
abs_srcdir, info->cmdline) < 0 && !info->shouldFail)
|
||||
goto cleanup;
|
||||
|
||||
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
|
||||
inputvolxml, cmdline, info->flags,
|
||||
info->imgformat);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(poolxml);
|
||||
VIR_FREE(volxml);
|
||||
VIR_FREE(inputvolxml);
|
||||
VIR_FREE(cmdline);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
enum {
|
||||
FMT_NONE = 0,
|
||||
FMT_FLAG,
|
||||
FMT_OPTIONS,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int flags = VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
|
||||
|
||||
#define DO_TEST(shouldFail, pool, vol, inputvol, cmdline, flags, imgformat) \
|
||||
do { \
|
||||
struct testInfo info = { shouldFail, pool, vol, inputvol, cmdline, \
|
||||
flags, imgformat }; \
|
||||
if (virtTestRun("Storage Vol XML-2-argv " cmdline, \
|
||||
1, testCompareXMLToArgvHelper, &info) < 0) \
|
||||
ret = -1; \
|
||||
} \
|
||||
while (0);
|
||||
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2", NULL, "qcow2", 0, FMT_OPTIONS);
|
||||
DO_TEST(true, "pool-dir", "vol-qcow2", NULL, "qcow2-prealloc", flags,
|
||||
FMT_OPTIONS);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", NULL,
|
||||
"qcow2-nobacking-prealloc", flags, FMT_OPTIONS);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file",
|
||||
"qcow2-nobacking-convert-prealloc", flags, FMT_OPTIONS);
|
||||
DO_TEST(true, "pool-dir", "vol-qcow2", "vol-file",
|
||||
"qcow2-convert-prealloc", flags, FMT_OPTIONS);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2", NULL, "qcow2-flag", 0, FMT_FLAG);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", NULL,
|
||||
"qcow2-nobacking-flag", 0, FMT_FLAG);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file",
|
||||
"qcow2-nobacking-convert-flag", 0, FMT_FLAG);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2", NULL, "qcow2-none", 0, FMT_NONE);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", NULL,
|
||||
"qcow2-nobacking-none", 0, FMT_NONE);
|
||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file",
|
||||
"qcow2-nobacking-convert-none", 0, FMT_NONE);
|
||||
|
||||
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN(mymain)
|
Loading…
Reference in New Issue
Block a user