]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testQEMUSchemaValidateCommand: Add possibility for partial QMP validation
authorPeter Krempa <pkrempa@redhat.com>
Fri, 15 Oct 2021 10:06:14 +0000 (12:06 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 18 Oct 2021 12:00:58 +0000 (14:00 +0200)
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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/qemumigparamstest.c
tests/qemumigrationcookiexmltest.c
tests/qemumonitortestutils.c
tests/qemuxml2argvtest.c
tests/testutilsqemuschema.c
tests/testutilsqemuschema.h

index dd6b7d5d605265efdb3853c8eb4b43c972c9a237..f445c92ff8c195fd7b119abed0d01aadb31056a4 100644 (file)
@@ -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));
index 6ef5dc0ad60e80d83abfceac6ca175cf755f9baf..316bfedd158cebc4909c5f8d211afcebacffe4b9 100644 (file)
@@ -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));
index 71b26c326e4def18d89565c07ff4199dca858cca..f5eb77d190465ebb3c5ab9ba7471d7c668c21503 100644 (file)
@@ -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;
index a0ee5f9943b6f31209dd555ab92127a9fe039fe9..d6cc2a51c28434aec413e938b74824c9b151d6d3 100644 (file)
@@ -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;
index f6347231a8ba43e5f3c5dc56b52beda04e3f8d86..4f9db98e07b22fa21ffaf608413703c7e1ba63f6 100644 (file)
@@ -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;
index ba881a991aef84bc9935e3944d6215f0ad7ee59b..cb1e6da69eaa91298eb5df6416c5879bf408fe1a 100644 (file)
@@ -35,6 +35,7 @@ testQEMUSchemaValidateCommand(const char *command,
                               GHashTable *schema,
                               bool allowDeprecated,
                               bool allowRemoved,
+                              bool allowIncomplete,
                               virBuffer *debug);
 
 int