render / rpms / libvirt

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