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