1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemumigparamstest: Validate output parameters against QMP schema

Ensure that the migration parameters are formatted properly according to
the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-08-07 16:02:03 +02:00
parent c501663a71
commit 8098462bfb

View File

@ -22,8 +22,10 @@
#include "virjson.h"
#include "virbuffer.h"
#include "virxml.h"
#include "virhash.h"
#include "testutils.h"
#include "testutilsqemu.h"
#include "tests/testutilsqemuschema.h"
#include "qemumonitortestutils.h"
#include "qemu/qemu_migration_params.h"
#define LIBVIRT_QEMU_MIGRATION_PARAMSPRIV_H_ALLOW
@ -36,6 +38,7 @@ typedef struct _qemuMigParamsData qemuMigParamsData;
struct _qemuMigParamsData {
virDomainXMLOptionPtr xmlopt;
const char *name;
virHashTablePtr qmpschema;
};
@ -141,6 +144,7 @@ qemuMigParamsTestJSON(const void *opaque)
g_autoptr(virJSONValue) paramsOut = NULL;
g_autoptr(qemuMigrationParams) migParams = NULL;
g_autofree char *actualJSON = NULL;
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
int ret = -1;
replyFile = g_strdup_printf("%s/qemumigparamsdata/%s.reply",
@ -162,6 +166,17 @@ qemuMigParamsTestJSON(const void *opaque)
!(actualJSON = virJSONValueToString(paramsOut, true)))
goto cleanup;
if (testQEMUSchemaValidateCommand("migrate-set-parameters",
paramsOut,
data->qmpschema,
false,
false,
&debug) < 0) {
VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
actualJSON, virBufferCurrentContent(&debug));
goto cleanup;
}
if (virTestCompareToFile(actualJSON, jsonFile) < 0)
goto cleanup;
@ -176,6 +191,7 @@ qemuMigParamsTestJSON(const void *opaque)
static int
mymain(void)
{
g_autoptr(virHashTable) qmpschema = NULL;
virQEMUDriver driver;
int ret = 0;
@ -184,10 +200,15 @@ mymain(void)
virEventRegisterDefaultImpl();
if (!(qmpschema = testQEMUSchemaLoadLatest("x86_64"))) {
VIR_TEST_VERBOSE("failed to load QMP schema");
return EXIT_FAILURE;
}
#define DO_TEST(name) \
do { \
qemuMigParamsData data = { \
driver.xmlopt, name \
driver.xmlopt, name, qmpschema \
}; \
if (virTestRun(name " (xml)", qemuMigParamsTestXML, &data) < 0) \
ret = -1; \