From b17fd211e25991edffa2401e01f54daed1927699 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 15 Oct 2021 12:06:14 +0200 Subject: [PATCH] testQEMUSchemaValidateCommand: Add possibility for partial QMP validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QMP schema for 'device_add' is not complete yet. Allow validation of incomplete schema so that we can enable at least some validation. Once there's more schema in the future all present members are still validated. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tests/qemumigparamstest.c | 1 + tests/qemumigrationcookiexmltest.c | 1 + tests/qemumonitortestutils.c | 1 + tests/qemuxml2argvtest.c | 2 +- tests/testutilsqemuschema.c | 11 ++++++++++- tests/testutilsqemuschema.h | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c index dd6b7d5d60..f445c92ff8 100644 --- a/tests/qemumigparamstest.c +++ b/tests/qemumigparamstest.c @@ -171,6 +171,7 @@ qemuMigParamsTestJSON(const void *opaque) data->qmpschema, false, false, + false, &debug) < 0) { VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s", actualJSON, virBufferCurrentContent(&debug)); diff --git a/tests/qemumigrationcookiexmltest.c b/tests/qemumigrationcookiexmltest.c index 6ef5dc0ad6..316bfedd15 100644 --- a/tests/qemumigrationcookiexmltest.c +++ b/tests/qemumigrationcookiexmltest.c @@ -342,6 +342,7 @@ testQemuMigrationCookieBlockDirtyBitmaps(const void *opaque) qmpschema, false, false, + false, &debug) < 0) { VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s", actualJSON, virBufferCurrentContent(&debug)); diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 71b26c326e..f5eb77d190 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -542,6 +542,7 @@ qemuMonitorTestProcessCommandDefaultValidate(qemuMonitorTest *test, if (testQEMUSchemaValidateCommand(cmdname, args, test->qapischema, test->skipValidationDeprecated, test->skipValidationRemoved, + false, &debug) < 0) { if (virTestGetDebug() == 2) { g_autofree char *argstr = NULL; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a0ee5f9943..d6cc2a51c2 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -535,7 +535,7 @@ testCompareXMLToArgvValidateSchemaCommand(GStrv args, return -1; if (testQEMUSchemaValidateCommand(command->schema, jsonargs, - schema, false, false, &debug) < 0) { + schema, false, false, false, &debug) < 0) { VIR_TEST_VERBOSE("failed to validate '%s %s' against QAPI schema: %s", command->name, curargs, virBufferCurrentContent(&debug)); return -1; diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index f6347231a8..4f9db98e07 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -25,6 +25,7 @@ struct testQEMUSchemaValidateCtxt { GHashTable *schema; virBuffer *debug; bool allowDeprecated; + bool allowIncomplete; /* allow members not (yet) covered by the schema */ }; @@ -137,6 +138,10 @@ testQEMUSchemaValidateObjectMember(const char *key, /* lookup 'member' entry for key */ if (!(keymember = testQEMUSchemaStealObjectMemberByName(key, data->rootmembers))) { + if (data->ctxt->allowIncomplete) { + virBufferAddLit(data->ctxt->debug, " schema missing - OK(waived)\n"); + return 0; + } virBufferAddLit(data->ctxt->debug, "ERROR: attribute not in schema\n"); return -1; } @@ -553,6 +558,8 @@ testQEMUSchemaValidate(virJSONValue *obj, * @allowDeprecated: don't fails schema validation if @command or one of @arguments * is deprecated * @allowRemoved: skip validation fully if @command was not found + * @allowIncomplete: don't fail validation if members not covered by schema are present + * (for waiving commands with incomplete schema) * @debug: a virBuffer which will be filled with debug information if provided * * Validates whether @command and its @arguments conform to the QAPI schema @@ -571,11 +578,13 @@ testQEMUSchemaValidateCommand(const char *command, GHashTable *schema, bool allowDeprecated, bool allowRemoved, + bool allowIncomplete, virBuffer *debug) { struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema, .debug = debug, - .allowDeprecated = allowDeprecated }; + .allowDeprecated = allowDeprecated, + .allowIncomplete = allowIncomplete }; g_autofree char *schemapatharguments = g_strdup_printf("%s/arg-type", command); g_autoptr(virJSONValue) emptyargs = NULL; virJSONValue *schemarootcommand; diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index ba881a991a..cb1e6da69e 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -35,6 +35,7 @@ testQEMUSchemaValidateCommand(const char *command, GHashTable *schema, bool allowDeprecated, bool allowRemoved, + bool allowIncomplete, virBuffer *debug); int