提交 d0892341 编写于 作者: P Peter Krempa

qemublocktest: Add JSON->JSON test cases for block device backends

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 7f8d0ca5
......@@ -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; \
......
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\""}
{
"driver": "https",
"url": "https://test.host:443/whatever.img",
"sslverify": false,
"timeout": 2000,
"readahead": 65536,
"auto-read-only": true,
"discard": "unmap"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册