[PATCH 29/30] qemublocktest: Add JSON->JSON test cases for block device backends

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add testing of the interpretation of the JSON pseudo-protocol backing
store into JSON structs for blockdev. This will be used to test JSON
pseudo-URIs used by libguestfs while actually also validating the output
against the QMP schema. Since libguestfs uses obsolete/undocumented
values the outputs will differ and a benefit is that modern output is
used now.

The example test case covers the fields and values used by libguestfs
when using the https driver.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/qemublocktest.c                         | 65 +++++++++++++++++++
 .../jsontojson/curl-libguestfs-in.json        |  1 +
 .../jsontojson/curl-libguestfs-out.json       |  9 +++
 3 files changed, 75 insertions(+)
 create mode 100644 tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json
 create mode 100644 tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 77484cc8e7..ec32d28188 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -128,6 +128,57 @@ testBackingXMLjsonXML(const void *args)
     return 0;
 }

+static const char *testJSONtoJSONPath = abs_srcdir "/qemublocktestdata/jsontojson/";
+
+struct testJSONtoJSONData {
+    const char *name;
+    virHashTablePtr schema;
+    virJSONValuePtr schemaroot;
+};
+
+static int
+testJSONtoJSON(const void *args)
+{
+    const struct testJSONtoJSONData *data = args;
+    g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
+    g_autoptr(virJSONValue) jsonsrcout = NULL;
+    g_autoptr(virStorageSource) src = NULL;
+    g_autofree char *actual = NULL;
+    g_autofree char *in = NULL;
+    g_autofree char *infile = g_strdup_printf("%s%s-in.json", testJSONtoJSONPath,
+                                              data->name);
+    g_autofree char *outfile = g_strdup_printf("%s%s-out.json", testJSONtoJSONPath,
+                                              data->name);
+
+    if (virTestLoadFile(infile, &in) < 0)
+        return -1;
+
+    if (virStorageSourceNewFromBackingAbsolute(in, &src) < 0) {
+        fprintf(stderr, "failed to parse disk json\n");
+        return -1;
+    }
+
+    if (!(jsonsrcout = qemuBlockStorageSourceGetBackendProps(src, false, false, true))) {
+        fprintf(stderr, "failed to format disk source json\n");
+        return -1;
+    }
+
+    if (!(actual = virJSONValueToString(jsonsrcout, true)))
+        return -1;
+
+    if (testQEMUSchemaValidate(jsonsrcout, data->schemaroot,
+                               data->schema, &debug) < 0) {
+        g_autofree char *debugmsg = virBufferContentAndReset(&debug);
+
+        VIR_TEST_VERBOSE("json does not conform to QAPI schema");
+        VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
+                       actual, NULLSTR(debugmsg));
+        return -1;
+    }
+
+    return virTestCompareToFile(actual, outfile);
+}
+

 struct testQemuDiskXMLToJSONData {
     virQEMUDriverPtr driver;
@@ -879,6 +930,7 @@ mymain(void)
     virQEMUDriver driver;
     struct testBackingXMLjsonXMLdata xmljsonxmldata;
     struct testQemuDiskXMLToJSONData diskxmljsondata;
+    struct testJSONtoJSONData jsontojsondata;
     struct testQemuImageCreateData imagecreatedata;
     struct testQemuBackupIncrementalBitmapCalculateData backupbitmapcalcdata;
     struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
@@ -1072,6 +1124,19 @@ mymain(void)
     TEST_DISK_TO_JSON("block-raw-noopts");
     TEST_DISK_TO_JSON("block-raw-reservations");

+#define TEST_JSON_TO_JSON(nme) \
+    do { \
+        jsontojsondata.name = nme; \
+        if (virTestRun("JSON to JSON " nme, testJSONtoJSON, \
+                       &jsontojsondata) < 0) \
+            ret = -1; \
+    } while (0)
+
+    jsontojsondata.schema = qmp_schema_x86_64;
+    jsontojsondata.schemaroot = qmp_schemaroot_x86_64_blockdev_add;
+
+    TEST_JSON_TO_JSON("curl-libguestfs");
+
 #define TEST_IMAGE_CREATE(testname, testbacking) \
     do { \
         imagecreatedata.name = testname; \
diff --git a/tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json b/tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json
new file mode 100644
index 0000000000..0b92dabc6d
--- /dev/null
+++ b/tests/qemublocktestdata/jsontojson/curl-libguestfs-in.json
@@ -0,0 +1 @@
+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\""}
diff --git a/tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json b/tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json
new file mode 100644
index 0000000000..e130c7bd3c
--- /dev/null
+++ b/tests/qemublocktestdata/jsontojson/curl-libguestfs-out.json
@@ -0,0 +1,9 @@
+{
+  "driver": "https",
+  "url": "https://test.host:443/whatever.img";,
+  "sslverify": false,
+  "timeout": 2000,
+  "readahead": 65536,
+  "auto-read-only": true,
+  "discard": "unmap"
+}
-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux