render / rpms / libvirt

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