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