]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemumonitorjsontest: Add a last-resort warning if object-add/device_add are QAPIfied
authorPeter Krempa <pkrempa@redhat.com>
Thu, 6 Aug 2020 17:45:24 +0000 (19:45 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 24 Aug 2020 11:02:35 +0000 (13:02 +0200)
When netdev-add was qapified it took us by surprise and we had to
scramble to fix the internals to format conformant monitor arguments.

Add a last-resort early warning system if this happens to object-add or
device_add. Hopefully qemu developers notify us sooner than this.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
tests/qemumonitorjsontest.c

index 77e70c1dc4cf69d31eb716d1c1233351a4492341..bc25958e70f01f0001716fa0f72b1d0770493ab6 100644 (file)
@@ -2888,6 +2888,55 @@ testQAPISchemaValidate(const void *opaque)
 }
 
 
+/**
+ * testQAPISchemaObjectDeviceAdd:
+ *
+ * Purpose of this test is to add a last-resort notification that 'object-add'
+ * and 'device_add' are not covered by the QMP schema by surprise. Ideally QEMU
+ * developers will notify us before they switch so we have time to adapt our
+ * generators first. This didn't work out when netdev-add was converted.
+ *
+ * We validate that the QMP schema describes only the expected types and nothing
+ * else assuming that no new field will be added until final conversion.
+ */
+static int
+testQAPISchemaObjectDeviceAdd(const void *opaque)
+{
+    virHashTablePtr schema = (virHashTablePtr) opaque;
+    virJSONValuePtr entry;
+
+    if (virQEMUQAPISchemaPathGet("device_add/arg-type", schema, &entry) < 0) {
+        fprintf(stderr, "schema for 'device_add' not found\n");
+        return -1;
+    }
+
+    if (testQEMUSchemaEntryMatchTemplate(entry,
+                                         "str:driver",
+                                         "str:bus",
+                                         "str:id",
+                                         NULL) < 0) {
+        VIR_TEST_VERBOSE("device_add has unexpected members in schema");
+        return -1;
+    }
+
+    if (virQEMUQAPISchemaPathGet("object-add/arg-type", schema, &entry) < 0) {
+        fprintf(stderr, "schema for 'objectadd' not found\n");
+        return -1;
+    }
+
+    if (testQEMUSchemaEntryMatchTemplate(entry,
+                                         "str:qom-type",
+                                         "str:id",
+                                         "any:props",
+                                         NULL) < 0) {
+        VIR_TEST_VERBOSE("object-add has unexpected members in schema");
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static void
 testQueryJobsPrintJob(virBufferPtr buf,
                       qemuMonitorJobInfoPtr job)
@@ -3380,6 +3429,10 @@ mymain(void)
 
 #undef DO_TEST_QAPI_VALIDATE
 
+    if (virTestRun("validate that object-add and device_add don't have schema",
+                   testQAPISchemaObjectDeviceAdd, qapiData.schema) < 0)
+        ret = -1;
+
 #define DO_TEST_QUERY_JOBS(name) \
     do { \
         struct testQueryJobsData data = { name, driver.xmlopt}; \