Blame SOURCES/libvirt-qemublocktest-Add-JSON-JSON-test-cases-for-block-device-backends.patch

a41c76
From b385c22388eb9810f654936decc970bc882d6c8b Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <b385c22388eb9810f654936decc970bc882d6c8b@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 16 Mar 2020 22:12:12 +0100
a41c76
Subject: [PATCH] qemublocktest: Add JSON->JSON test cases for block device
a41c76
 backends
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Add testing of the interpretation of the JSON pseudo-protocol backing
a41c76
store into JSON structs for blockdev. This will be used to test JSON
a41c76
pseudo-URIs used by libguestfs while actually also validating the output
a41c76
against the QMP schema. Since libguestfs uses obsolete/undocumented
a41c76
values the outputs will differ and a benefit is that modern output is
a41c76
used now.
a41c76
a41c76
The example test case covers the fields and values used by libguestfs
a41c76
when using the https driver.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit d089234110282069e9a6dfe879ca257d114bb5bd)
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
a41c76
Message-Id: <f63c18cbdf69b27bd91fe44250737cf89b3cb090.1584391727.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 tests/qemublocktest.c                         | 65 +++++++++++++++++++
a41c76
 .../jsontojson/curl-libguestfs-in.json        |  1 +
a41c76
 .../jsontojson/curl-libguestfs-out.json       |  9 +++
a41c76
 3 files changed, 75 insertions(+)
a41c76
 create mode 100644 tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json
a41c76
 create mode 100644 tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json
a41c76
a41c76
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
a41c76
index d2ba85c5e5..d8bd811b4d 100644
a41c76
--- a/tests/qemublocktest.c
a41c76
+++ b/tests/qemublocktest.c
a41c76
@@ -128,6 +128,57 @@ testBackingXMLjsonXML(const void *args)
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
+static const char *testJSONtoJSONPath = abs_srcdir "/qemublocktestdata/jsontojson/";
a41c76
+
a41c76
+struct testJSONtoJSONData {
a41c76
+    const char *name;
a41c76
+    virHashTablePtr schema;
a41c76
+    virJSONValuePtr schemaroot;
a41c76
+};
a41c76
+
a41c76
+static int
a41c76
+testJSONtoJSON(const void *args)
a41c76
+{
a41c76
+    const struct testJSONtoJSONData *data = args;
a41c76
+    g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
a41c76
+    g_autoptr(virJSONValue) jsonsrcout = NULL;
a41c76
+    g_autoptr(virStorageSource) src = NULL;
a41c76
+    g_autofree char *actual = NULL;
a41c76
+    g_autofree char *in = NULL;
a41c76
+    g_autofree char *infile = g_strdup_printf("%s%s-in.json", testJSONtoJSONPath,
a41c76
+                                              data->name);
a41c76
+    g_autofree char *outfile = g_strdup_printf("%s%s-out.json", testJSONtoJSONPath,
a41c76
+                                              data->name);
a41c76
+
a41c76
+    if (virTestLoadFile(infile, &in) < 0)
a41c76
+        return -1;
a41c76
+
a41c76
+    if (virStorageSourceNewFromBackingAbsolute(in, &src) < 0) {
a41c76
+        fprintf(stderr, "failed to parse disk json\n");
a41c76
+        return -1;
a41c76
+    }
a41c76
+
a41c76
+    if (!(jsonsrcout = qemuBlockStorageSourceGetBackendProps(src, false, false, true))) {
a41c76
+        fprintf(stderr, "failed to format disk source json\n");
a41c76
+        return -1;
a41c76
+    }
a41c76
+
a41c76
+    if (!(actual = virJSONValueToString(jsonsrcout, true)))
a41c76
+        return -1;
a41c76
+
a41c76
+    if (testQEMUSchemaValidate(jsonsrcout, data->schemaroot,
a41c76
+                               data->schema, &debug) < 0) {
a41c76
+        g_autofree char *debugmsg = virBufferContentAndReset(&debug);
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
+                       actual, NULLSTR(debugmsg));
a41c76
+        return -1;
a41c76
+    }
a41c76
+
a41c76
+    return virTestCompareToFile(actual, outfile);
a41c76
+}
a41c76
+
a41c76
 
a41c76
 struct testQemuDiskXMLToJSONData {
a41c76
     virQEMUDriverPtr driver;
a41c76
@@ -875,6 +926,7 @@ mymain(void)
a41c76
     virQEMUDriver driver;
a41c76
     struct testBackingXMLjsonXMLdata xmljsonxmldata;
a41c76
     struct testQemuDiskXMLToJSONData diskxmljsondata;
a41c76
+    struct testJSONtoJSONData jsontojsondata;
a41c76
     struct testQemuImageCreateData imagecreatedata;
a41c76
     struct testQemuBackupIncrementalBitmapCalculateData backupbitmapcalcdata;
a41c76
     struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
a41c76
@@ -1068,6 +1120,19 @@ mymain(void)
a41c76
     TEST_DISK_TO_JSON("block-raw-noopts");
a41c76
     TEST_DISK_TO_JSON("block-raw-reservations");
a41c76
 
a41c76
+#define TEST_JSON_TO_JSON(nme) \
a41c76
+    do { \
a41c76
+        jsontojsondata.name = nme; \
a41c76
+        if (virTestRun("JSON to JSON " nme, testJSONtoJSON, \
a41c76
+                       &jsontojsondata) < 0) \
a41c76
+            ret = -1; \
a41c76
+    } while (0)
a41c76
+
a41c76
+    jsontojsondata.schema = qmp_schema_x86_64;
a41c76
+    jsontojsondata.schemaroot = qmp_schemaroot_x86_64_blockdev_add;
a41c76
+
a41c76
+    TEST_JSON_TO_JSON("curl-libguestfs");
a41c76
+
a41c76
 #define TEST_IMAGE_CREATE(testname, testbacking) \
a41c76
     do { \
a41c76
         imagecreatedata.name = testname; \
a41c76
diff --git a/tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json b/tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json
a41c76
new file mode 100644
a41c76
index 0000000000..0b92dabc6d
a41c76
--- /dev/null
a41c76
+++ b/tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json
a41c76
@@ -0,0 +1 @@
a41c76
+json:{"file.driver":"https","file.url":"https://test.host/whatever.img","file.timeout":2000,"file.readahead":65536,"file.sslverify":"off","file.cookie":"some_cookie=\"some_value_or_whatever\""}
a41c76
diff --git a/tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json b/tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json
a41c76
new file mode 100644
a41c76
index 0000000000..e130c7bd3c
a41c76
--- /dev/null
a41c76
+++ b/tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json
a41c76
@@ -0,0 +1,9 @@
a41c76
+{
a41c76
+  "driver": "https",
a41c76
+  "url": "https://test.host:443/whatever.img",
a41c76
+  "sslverify": false,
a41c76
+  "timeout": 2000,
a41c76
+  "readahead": 65536,
a41c76
+  "auto-read-only": true,
a41c76
+  "discard": "unmap"
a41c76
+}
a41c76
-- 
a41c76
2.25.1
a41c76