Blame SOURCES/libvirt-qemublocktest-XMLjsonXML-Test-formatting-parsing-of-modern-JSON.patch

fbe740
From 6b38c75d24769798a6152ebf69ec71a24a4a2e50 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <6b38c75d24769798a6152ebf69ec71a24a4a2e50@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:12:11 +0100
fbe740
Subject: [PATCH] qemublocktest: XMLjsonXML: Test formatting/parsing of modern
fbe740
 JSON
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
The test was invoking the JSON formatter with the 'legacy' flag thus
fbe740
formatting bunch of obsolete JSON blockdev definitions. We also should
fbe740
test the modern ones. Add a boolean and re-run all the tests in both
fbe740
cases.
fbe740
fbe740
Additionally for any modern invocation we should also validate that the
fbe740
output conforms to the QAPI schema.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 7f8d0ca56a8335b29f3973e5490815c7cfbeac13)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
fbe740
Message-Id: <df8b109c41f11362999ffb84b9d1cf477a89c8f4.1584391727.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 tests/qemublocktest.c | 28 +++++++++++++++++++++++++++-
fbe740
 1 file changed, 27 insertions(+), 1 deletion(-)
fbe740
fbe740
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
fbe740
index 94f20eeb47..d2ba85c5e5 100644
fbe740
--- a/tests/qemublocktest.c
fbe740
+++ b/tests/qemublocktest.c
fbe740
@@ -41,6 +41,9 @@ VIR_LOG_INIT("tests.storagetest");
fbe740
 struct testBackingXMLjsonXMLdata {
fbe740
     int type;
fbe740
     const char *xml;
fbe740
+    bool legacy;
fbe740
+    virHashTablePtr schema;
fbe740
+    virJSONValuePtr schemaroot;
fbe740
 };
fbe740
 
fbe740
 static int
fbe740
@@ -57,6 +60,7 @@ testBackingXMLjsonXML(const void *args)
fbe740
     g_autofree char *actualxml = NULL;
fbe740
     g_autoptr(virStorageSource) xmlsrc = NULL;
fbe740
     g_autoptr(virStorageSource) jsonsrc = NULL;
fbe740
+    g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
fbe740
 
fbe740
     if (!(xmlsrc = virStorageSourceNew()))
fbe740
         return -1;
fbe740
@@ -71,12 +75,27 @@ testBackingXMLjsonXML(const void *args)
fbe740
         return -1;
fbe740
     }
fbe740
 
fbe740
-    if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc, true, false,
fbe740
+    if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc,
fbe740
+                                                               data->legacy,
fbe740
+                                                               false,
fbe740
                                                                false))) {
fbe740
         fprintf(stderr, "failed to format disk source json\n");
fbe740
         return -1;
fbe740
     }
fbe740
 
fbe740
+    if (!data->legacy) {
fbe740
+        if (testQEMUSchemaValidate(backendprops, data->schemaroot,
fbe740
+                                   data->schema, &debug) < 0) {
fbe740
+            g_autofree char *debugmsg = virBufferContentAndReset(&debug);
fbe740
+            g_autofree char *debugprops = virJSONValueToString(backendprops, true);
fbe740
+
fbe740
+            VIR_TEST_VERBOSE("json does not conform to QAPI schema");
fbe740
+            VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
fbe740
+                           debugprops, NULLSTR(debugmsg));
fbe740
+            return -1;
fbe740
+        }
fbe740
+    }
fbe740
+
fbe740
     if (virJSONValueObjectCreate(&wrapper, "a:file", &backendprops, NULL) < 0)
fbe740
         return -1;
fbe740
 
fbe740
@@ -907,6 +926,10 @@ mymain(void)
fbe740
     do { \
fbe740
         xmljsonxmldata.type = tpe; \
fbe740
         xmljsonxmldata.xml = xmlstr; \
fbe740
+        xmljsonxmldata.legacy = true; \
fbe740
+        if (virTestRun(virTestCounterNext(), testBackingXMLjsonXML, \
fbe740
+                       &xmljsonxmldata) < 0) \
fbe740
+        xmljsonxmldata.legacy = false; \
fbe740
         if (virTestRun(virTestCounterNext(), testBackingXMLjsonXML, \
fbe740
                        &xmljsonxmldata) < 0) \
fbe740
             ret = -1; \
fbe740
@@ -915,6 +938,9 @@ mymain(void)
fbe740
 #define TEST_JSON_FORMAT_NET(xmlstr) \
fbe740
     TEST_JSON_FORMAT(VIR_STORAGE_TYPE_NETWORK, xmlstr)
fbe740
 
fbe740
+    xmljsonxmldata.schema = qmp_schema_x86_64;
fbe740
+    xmljsonxmldata.schemaroot = qmp_schemaroot_x86_64_blockdev_add;
fbe740
+
fbe740
     TEST_JSON_FORMAT(VIR_STORAGE_TYPE_FILE, "<source file='/path/to/file'/>\n");
fbe740
 
fbe740
     /* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to 'file' */
fbe740
-- 
fbe740
2.25.1
fbe740