testQEMUSchemaValidate(Command): Allow skipping validation of deprecated fields

Some test cases are used to validate interactions with old qemu. We need
to skip validation of deprecation with those once it will be added.

In case of commands which were already replaced by code based on
capabilities we can skip the full validation once the command is
removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-04-29 17:52:43 +02:00
parent 2c44ea900e
commit 4fcea23e6c
5 changed files with 31 additions and 11 deletions

View File

@ -86,7 +86,7 @@ testBackingXMLjsonXML(const void *args)
if (!data->legacy) { if (!data->legacy) {
if (testQEMUSchemaValidate(backendprops, data->schemaroot, if (testQEMUSchemaValidate(backendprops, data->schemaroot,
data->schema, &debug) < 0) { data->schema, false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
g_autofree char *debugprops = virJSONValueToString(backendprops, true); g_autofree char *debugprops = virJSONValueToString(backendprops, true);
@ -168,7 +168,7 @@ testJSONtoJSON(const void *args)
return -1; return -1;
if (testQEMUSchemaValidate(jsonsrcout, data->schemaroot, if (testQEMUSchemaValidate(jsonsrcout, data->schemaroot,
data->schema, &debug) < 0) { data->schema, false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
VIR_TEST_VERBOSE("json does not conform to QAPI schema"); VIR_TEST_VERBOSE("json does not conform to QAPI schema");
@ -341,7 +341,7 @@ testQemuDiskXMLToPropsValidateSchema(const void *opaque)
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
if (testQEMUSchemaValidate(data->images[i].formatprops, data->schemaroot, if (testQEMUSchemaValidate(data->images[i].formatprops, data->schemaroot,
data->schema, &debug) < 0) { data->schema, false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
g_autofree char *propsstr = virJSONValueToString(data->images[i].formatprops, true); g_autofree char *propsstr = virJSONValueToString(data->images[i].formatprops, true);
VIR_TEST_VERBOSE("json does not conform to QAPI schema"); VIR_TEST_VERBOSE("json does not conform to QAPI schema");
@ -353,7 +353,7 @@ testQemuDiskXMLToPropsValidateSchema(const void *opaque)
virBufferFreeAndReset(&debug); virBufferFreeAndReset(&debug);
if (testQEMUSchemaValidate(data->images[i].storageprops, data->schemaroot, if (testQEMUSchemaValidate(data->images[i].storageprops, data->schemaroot,
data->schema, &debug) < 0) { data->schema, false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
g_autofree char *propsstr = virJSONValueToString(data->images[i].storageprops, true); g_autofree char *propsstr = virJSONValueToString(data->images[i].storageprops, true);
VIR_TEST_VERBOSE("json does not conform to QAPI schema"); VIR_TEST_VERBOSE("json does not conform to QAPI schema");
@ -365,7 +365,7 @@ testQemuDiskXMLToPropsValidateSchema(const void *opaque)
virBufferFreeAndReset(&debug); virBufferFreeAndReset(&debug);
if (testQEMUSchemaValidate(data->images[i].storagepropssrc, data->schemaroot, if (testQEMUSchemaValidate(data->images[i].storagepropssrc, data->schemaroot,
data->schema, &debug) < 0) { data->schema, false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
g_autofree char *propsstr = virJSONValueToString(data->images[i].storagepropssrc, true); g_autofree char *propsstr = virJSONValueToString(data->images[i].storagepropssrc, true);
VIR_TEST_VERBOSE("json does not conform to QAPI schema"); VIR_TEST_VERBOSE("json does not conform to QAPI schema");
@ -543,7 +543,7 @@ testQemuImageCreate(const void *opaque)
return -1; return -1;
if (testQEMUSchemaValidate(formatprops, data->schemaroot, data->schema, if (testQEMUSchemaValidate(formatprops, data->schemaroot, data->schema,
&debug) < 0) { false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
VIR_TEST_VERBOSE("blockdev-create format json does not conform to QAPI schema"); VIR_TEST_VERBOSE("blockdev-create format json does not conform to QAPI schema");
VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s", VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
@ -558,7 +558,7 @@ testQemuImageCreate(const void *opaque)
return -1; return -1;
if (testQEMUSchemaValidate(protocolprops, data->schemaroot, data->schema, if (testQEMUSchemaValidate(protocolprops, data->schemaroot, data->schema,
&debug) < 0) { false, &debug) < 0) {
g_autofree char *debugmsg = virBufferContentAndReset(&debug); g_autofree char *debugmsg = virBufferContentAndReset(&debug);
VIR_TEST_VERBOSE("blockdev-create protocol json does not conform to QAPI schema"); VIR_TEST_VERBOSE("blockdev-create protocol json does not conform to QAPI schema");
VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s", VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",

View File

@ -2842,7 +2842,8 @@ testQAPISchemaValidate(const void *opaque)
if (!(json = virJSONValueFromString(data->json))) if (!(json = virJSONValueFromString(data->json)))
goto cleanup; goto cleanup;
if ((testQEMUSchemaValidate(json, schemaroot, data->schema, &debug) == 0) != data->success) { if ((testQEMUSchemaValidate(json, schemaroot, data->schema, false,
&debug) == 0) != data->success) {
if (!data->success) if (!data->success)
VIR_TEST_VERBOSE("\nschema validation should have failed"); VIR_TEST_VERBOSE("\nschema validation should have failed");
} else { } else {

View File

@ -554,7 +554,10 @@ qemuMonitorTestProcessCommandDefaultValidate(qemuMonitorTestPtr test,
if (STREQ(cmdname, "device_add")) if (STREQ(cmdname, "device_add"))
return 0; return 0;
if (testQEMUSchemaValidateCommand(cmdname, args, test->qapischema, &debug) < 0) { if (testQEMUSchemaValidateCommand(cmdname, args, test->qapischema,
test->skipValidationDeprecated,
test->skipValidationRemoved,
&debug) < 0) {
if (virTestGetDebug() == 2) { if (virTestGetDebug() == 2) {
g_autofree char *argstr = NULL; g_autofree char *argstr = NULL;

View File

@ -24,6 +24,7 @@
struct testQEMUSchemaValidateCtxt { struct testQEMUSchemaValidateCtxt {
virHashTablePtr schema; virHashTablePtr schema;
virBufferPtr debug; virBufferPtr debug;
bool allowDeprecated;
}; };
@ -488,10 +489,13 @@ int
testQEMUSchemaValidate(virJSONValuePtr obj, testQEMUSchemaValidate(virJSONValuePtr obj,
virJSONValuePtr root, virJSONValuePtr root,
virHashTablePtr schema, virHashTablePtr schema,
bool allowDeprecated,
virBufferPtr debug) virBufferPtr debug)
{ {
struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema, struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema,
.debug = debug }; .debug = debug,
.allowDeprecated = allowDeprecated };
return testQEMUSchemaValidateRecurse(obj, root, &ctxt); return testQEMUSchemaValidateRecurse(obj, root, &ctxt);
} }
@ -501,6 +505,9 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
* @command: command to validate * @command: command to validate
* @arguments: arguments of @command to validate * @arguments: arguments of @command to validate
* @schema: hash table containing schema entries * @schema: hash table containing schema entries
* @allowDeprecated: don't fails schema validation if @command or one of @arguments
* is deprecated
* @allowRemoved: skip validation fully if @command was not found
* @debug: a virBuffer which will be filled with debug information if provided * @debug: a virBuffer which will be filled with debug information if provided
* *
* Validates whether @command and its @arguments conform to the QAPI schema * Validates whether @command and its @arguments conform to the QAPI schema
@ -508,16 +515,22 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
* -1 if it does not and -2 if there is a problem with the schema or with * -1 if it does not and -2 if there is a problem with the schema or with
* internals. * internals.
* *
* @allowRemoved should generally be used only if it's certain that there's a
* replacement of @command in place.
*
* @debug is filled with information regarding the validation process * @debug is filled with information regarding the validation process
*/ */
int int
testQEMUSchemaValidateCommand(const char *command, testQEMUSchemaValidateCommand(const char *command,
virJSONValuePtr arguments, virJSONValuePtr arguments,
virHashTablePtr schema, virHashTablePtr schema,
bool allowDeprecated,
bool allowRemoved G_GNUC_UNUSED,
virBufferPtr debug) virBufferPtr debug)
{ {
struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema, struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema,
.debug = debug }; .debug = debug,
.allowDeprecated = allowDeprecated };
g_autofree char *schemapatharguments = g_strdup_printf("%s/arg-type", command); g_autofree char *schemapatharguments = g_strdup_printf("%s/arg-type", command);
g_autoptr(virJSONValue) emptyargs = NULL; g_autoptr(virJSONValue) emptyargs = NULL;
virJSONValuePtr schemarootcommand; virJSONValuePtr schemarootcommand;

View File

@ -26,12 +26,15 @@ int
testQEMUSchemaValidate(virJSONValuePtr obj, testQEMUSchemaValidate(virJSONValuePtr obj,
virJSONValuePtr root, virJSONValuePtr root,
virHashTablePtr schema, virHashTablePtr schema,
bool allowDeprecated,
virBufferPtr debug); virBufferPtr debug);
int int
testQEMUSchemaValidateCommand(const char *command, testQEMUSchemaValidateCommand(const char *command,
virJSONValuePtr arguments, virJSONValuePtr arguments,
virHashTablePtr schema, virHashTablePtr schema,
bool allowDeprecated,
bool allowRemoved,
virBufferPtr debug); virBufferPtr debug);
virJSONValuePtr virJSONValuePtr