mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-08 16:54:49 +00:00
qemuxml2argvtest: Add QAPI/QMP schema validation for -blockdev and -netdev
Our hotplug test cases are weak in comparison to the qemuxml2argvtest. Use all the the input data to also validate the arguments for -netdev and -blockdev against the appropriate commands of the QMP schema. Note that currently it's done just for the _CAPS versions of tests but commenting out a line in the test file allows to validate even cases which don't use real capabilities. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
b6246d9320
commit
576746d412
@ -570,7 +570,7 @@ qemuxml2argvtest_SOURCES = \
|
|||||||
testutils.c testutils.h \
|
testutils.c testutils.h \
|
||||||
virfilewrapper.c virfilewrapper.h \
|
virfilewrapper.c virfilewrapper.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
qemuxml2argvtest_LDADD = libqemutestdriver.la \
|
qemuxml2argvtest_LDADD = libqemutestdriver.la libqemumonitortestutils.la \
|
||||||
$(LDADDS) $(LIBXML_LIBS)
|
$(LDADDS) $(LIBXML_LIBS)
|
||||||
|
|
||||||
libqemuxml2argvmock_la_SOURCES = \
|
libqemuxml2argvmock_la_SOURCES = \
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
# include "qemu/qemu_migration.h"
|
# include "qemu/qemu_migration.h"
|
||||||
# include "qemu/qemu_process.h"
|
# include "qemu/qemu_process.h"
|
||||||
# include "qemu/qemu_slirp.h"
|
# include "qemu/qemu_slirp.h"
|
||||||
|
# include "qemu/qemu_qapi.h"
|
||||||
# include "datatypes.h"
|
# include "datatypes.h"
|
||||||
# include "conf/storage_conf.h"
|
# include "conf/storage_conf.h"
|
||||||
# include "cpu/cpu_map.h"
|
# include "cpu/cpu_map.h"
|
||||||
@ -26,6 +27,8 @@
|
|||||||
# include "virmock.h"
|
# include "virmock.h"
|
||||||
# include "virfilewrapper.h"
|
# include "virfilewrapper.h"
|
||||||
# include "configmake.h"
|
# include "configmake.h"
|
||||||
|
# include "testutilsqemuschema.h"
|
||||||
|
# include "qemu/qemu_monitor_json.h"
|
||||||
|
|
||||||
# define LIBVIRT_QEMU_CAPSPRIV_H_ALLOW
|
# define LIBVIRT_QEMU_CAPSPRIV_H_ALLOW
|
||||||
# include "qemu/qemu_capspriv.h"
|
# include "qemu/qemu_capspriv.h"
|
||||||
@ -477,6 +480,76 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
const char *migrateURI,
|
||||||
|
struct testQemuInfo *info,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
VIR_AUTOSTRINGLIST args = NULL;
|
||||||
|
size_t nargs = 0;
|
||||||
|
size_t i;
|
||||||
|
g_autoptr(virHashTable) schema = NULL;
|
||||||
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
|
|
||||||
|
if (info->schemafile)
|
||||||
|
schema = testQEMUSchemaLoad(info->schemafile);
|
||||||
|
|
||||||
|
/* comment out with line comment to enable schema checking for non _CAPS tests
|
||||||
|
if (!schema)
|
||||||
|
schema = testQEMUSchemaLoadLatest(virArchToString(info->arch));
|
||||||
|
// */
|
||||||
|
|
||||||
|
if (!schema)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!(cmd = testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info, flags,
|
||||||
|
true)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virCommandGetArgList(cmd, &args, &nargs) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < nargs; i++) {
|
||||||
|
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
|
||||||
|
g_autoptr(virJSONValue) jsonargs = NULL;
|
||||||
|
|
||||||
|
if (STREQ(args[i], "-blockdev")) {
|
||||||
|
if (!(jsonargs = virJSONValueFromString(args[i + 1])))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (testQEMUSchemaValidateCommand("blockdev-add", jsonargs,
|
||||||
|
schema, false, false, &debug) < 0) {
|
||||||
|
VIR_TEST_VERBOSE("failed to validate -blockdev '%s' against QAPI schema: %s",
|
||||||
|
args[i + 1], virBufferCurrentContent(&debug));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
} else if (STREQ(args[i], "-netdev")) {
|
||||||
|
if (!(jsonargs = virJSONValueFromString(args[i + 1])))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* skip the validation for pre-QAPIfication cases */
|
||||||
|
if (virQEMUQAPISchemaPathExists("netdev_add/arg-type/type/!string", schema))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (testQEMUSchemaValidateCommand("netdev_add", jsonargs,
|
||||||
|
schema, false, false, &debug) < 0) {
|
||||||
|
VIR_TEST_VERBOSE("failed to validate -netdev '%s' against QAPI schema: %s",
|
||||||
|
args[i + 1], virBufferCurrentContent(&debug));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testCompareXMLToArgv(const void *data)
|
testCompareXMLToArgv(const void *data)
|
||||||
{
|
{
|
||||||
@ -578,6 +651,9 @@ testCompareXMLToArgv(const void *data)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (testCompareXMLToArgvValidateSchema(&driver, vm, migrateURI, info, flags) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!(actualargv = virCommandToString(cmd, false)))
|
if (!(actualargv = virCommandToString(cmd, false)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -770,6 +770,10 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
|
|||||||
if (stripmachinealiases)
|
if (stripmachinealiases)
|
||||||
virQEMUCapsStripMachineAliases(qemuCaps);
|
virQEMUCapsStripMachineAliases(qemuCaps);
|
||||||
info->flags |= FLAG_REAL_CAPS;
|
info->flags |= FLAG_REAL_CAPS;
|
||||||
|
|
||||||
|
/* provide path to the replies file for schema testing */
|
||||||
|
capsfile[strlen(capsfile) - 3] = '\0';
|
||||||
|
info->schemafile = g_strdup_printf("%sreplies", capsfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!qemuCaps) {
|
if (!qemuCaps) {
|
||||||
@ -796,5 +800,6 @@ testQemuInfoClear(struct testQemuInfo *info)
|
|||||||
{
|
{
|
||||||
VIR_FREE(info->infile);
|
VIR_FREE(info->infile);
|
||||||
VIR_FREE(info->outfile);
|
VIR_FREE(info->outfile);
|
||||||
|
VIR_FREE(info->schemafile);
|
||||||
virObjectUnref(info->qemuCaps);
|
virObjectUnref(info->qemuCaps);
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ struct testQemuInfo {
|
|||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
unsigned int parseFlags;
|
unsigned int parseFlags;
|
||||||
virArch arch;
|
virArch arch;
|
||||||
|
char *schemafile;
|
||||||
};
|
};
|
||||||
|
|
||||||
virCapsPtr testQemuCapsInit(void);
|
virCapsPtr testQemuCapsInit(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user