tests: qemublock: Add testing of pure disk source specification JSON generator

Add testing of the host specification part so that we can be sure that
no image/host specific data will be present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2018-12-17 16:29:05 +01:00
parent 423b4f6625
commit 13f59e6f40
33 changed files with 495 additions and 1 deletions

View File

@ -115,6 +115,9 @@ struct testQemuDiskXMLToJSONData {
virJSONValuePtr *props;
size_t nprops;
virJSONValuePtr *propssrc;
size_t npropssrc;
virQEMUCapsPtr qemuCaps;
};
@ -127,8 +130,13 @@ testQemuDiskXMLToPropsClear(struct testQemuDiskXMLToJSONData *data)
for (i = 0; i < data->nprops; i++)
virJSONValueFree(data->props[i]);
for (i = 0; i < data->npropssrc; i++)
virJSONValueFree(data->propssrc[i]);
data->nprops = 0;
VIR_FREE(data->props);
data->npropssrc = 0;
VIR_FREE(data->propssrc);
}
@ -180,6 +188,7 @@ testQemuDiskXMLToProps(const void *opaque)
virStorageSourcePtr n;
virJSONValuePtr formatProps = NULL;
virJSONValuePtr storageProps = NULL;
VIR_AUTOPTR(virJSONValue) storageSrcOnlyProps = NULL;
char *xmlpath = NULL;
char *xmlstr = NULL;
int ret = -1;
@ -213,6 +222,7 @@ testQemuDiskXMLToProps(const void *opaque)
goto cleanup;
if (!(formatProps = qemuBlockStorageSourceGetBlockdevProps(n)) ||
!(storageSrcOnlyProps = qemuBlockStorageSourceGetBackendProps(n, false, true)) ||
!(storageProps = qemuBlockStorageSourceGetBackendProps(n, false, false))) {
if (!data->fail) {
VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n");
@ -224,7 +234,8 @@ testQemuDiskXMLToProps(const void *opaque)
}
if (VIR_APPEND_ELEMENT(data->props, data->nprops, formatProps) < 0 ||
VIR_APPEND_ELEMENT(data->props, data->nprops, storageProps) < 0)
VIR_APPEND_ELEMENT(data->props, data->nprops, storageProps) < 0 ||
VIR_APPEND_ELEMENT(data->propssrc, data->npropssrc, storageSrcOnlyProps) < 0)
goto cleanup;
}
@ -268,6 +279,23 @@ testQemuDiskXMLToPropsValidateSchema(const void *opaque)
virBufferFreeAndReset(&debug);
}
for (i = 0; i < data->npropssrc; i++) {
if (testQEMUSchemaValidate(data->propssrc[i], data->schemaroot,
data->schema, &debug) < 0) {
debugmsg = virBufferContentAndReset(&debug);
propsstr = virJSONValueToString(data->propssrc[i], true);
VIR_TEST_VERBOSE("json does not conform to QAPI schema");
VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
propsstr, NULLSTR(debugmsg));
VIR_FREE(debugmsg);
VIR_FREE(propsstr);
ret = -1;
}
virBufferFreeAndReset(&debug);
}
return ret;
}
@ -313,6 +341,40 @@ testQemuDiskXMLToPropsValidateFile(const void *opaque)
}
static int
testQemuDiskXMLToPropsValidateFileSrcOnly(const void *opaque)
{
struct testQemuDiskXMLToJSONData *data = (void *) opaque;
VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
VIR_AUTOFREE(char *) jsonpath = NULL;
VIR_AUTOFREE(char *) actual = NULL;
size_t i;
if (data->fail)
return EXIT_AM_SKIP;
if (virAsprintf(&jsonpath, "%s%s-srconly.json",
testQemuDiskXMLToJSONPath, data->name) < 0)
return -1;
for (i = 0; i < data->npropssrc; i++) {
VIR_AUTOFREE(char *) jsonstr = NULL;
if (!(jsonstr = virJSONValueToString(data->propssrc[i], true)))
return -1;
virBufferAdd(&buf, jsonstr, -1);
}
if (virBufferCheckError(&buf) < 0)
return -1;
actual = virBufferContentAndReset(&buf);
return virTestCompareToFile(actual, jsonpath);
}
static int
mymain(void)
{
@ -411,6 +473,8 @@ mymain(void)
diskxmljsondata.name = nme; \
diskxmljsondata.props = NULL; \
diskxmljsondata.nprops = 0; \
diskxmljsondata.propssrc = NULL; \
diskxmljsondata.npropssrc = 0; \
diskxmljsondata.fail = fl; \
if (virTestRun("disk xml to props " nme, testQemuDiskXMLToProps, \
&diskxmljsondata) < 0) \
@ -421,6 +485,9 @@ mymain(void)
if (virTestRun("disk xml to props validate file " nme, \
testQemuDiskXMLToPropsValidateFile, &diskxmljsondata) < 0) \
ret = -1; \
if (virTestRun("disk xml to props source only validate file " nme, \
testQemuDiskXMLToPropsValidateFileSrcOnly, &diskxmljsondata) < 0) \
ret = -1; \
testQemuDiskXMLToPropsClear(&diskxmljsondata); \
} while (0)

View File

@ -0,0 +1,4 @@
{
"driver": "host_device",
"filename": "/dev/blah"
}

View File

@ -0,0 +1,4 @@
{
"driver": "host_device",
"filename": "/dev/blah"
}

View File

@ -0,0 +1,5 @@
{
"driver": "vvfat",
"dir": "/var/somefiles",
"floppy": false
}

View File

@ -0,0 +1,5 @@
{
"driver": "vvfat",
"dir": "/var/somefiles",
"floppy": true
}

View File

@ -0,0 +1,5 @@
{
"driver": "vvfat",
"dir": "/var/somefiles",
"floppy": false
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,16 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/c"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,24 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}
{
"driver": "gluster",
"volume": "images",
"path": "c",
"server": [
{
"type": "inet",
"host": "test.org",
"port": "24007"
}
]
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/d"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,8 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/a"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/b"
}

View File

@ -0,0 +1,40 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1507297895"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1484071872"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483615252"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483605924"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483605920"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483546244"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483545901"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483545313"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1483536402"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.qcow2"
}

View File

@ -0,0 +1,8 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1507297895"
}
{
"driver": "file",
"filename": "/var/lib/libvirt/images/rhel7.3.1484071872"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/luks.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/var/lib/libvirt/images/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,4 @@
{
"driver": "file",
"filename": "/path/to/i.img"
}

View File

@ -0,0 +1,8 @@
{
"driver": "nbd",
"server": {
"type": "inet",
"host": "host1.example.com",
"port": "10809"
}
}

View File

@ -0,0 +1,22 @@
{
"driver": "rbd",
"pool": "rbdpool",
"image": "rbdimg",
"server": [
{
"host": "host1.example.com",
"port": "0"
},
{
"host": "host2.example.com",
"port": "0"
}
]
}
{
"driver": "iscsi",
"portal": "example.org:3260",
"target": "iscsitarget",
"lun": 1,
"transport": "tcp"
}

View File

@ -0,0 +1,22 @@
{
"driver": "rbd",
"pool": "rbdpool",
"image": "rbdimg",
"server": [
{
"host": "host1.example.com",
"port": "0"
},
{
"host": "host2.example.com",
"port": "0"
}
]
}
{
"driver": "iscsi",
"portal": "example.org:3260",
"target": "iqn.2016-09.com.example:iscsitarget",
"lun": 1,
"transport": "tcp"
}