mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-03 15:43:51 +00:00
tests: qemumonitorjson: simplify path handling in testBlockNodeNameDetect
Extract the test prefix path into a variable and reuse virTestLoadFileJSON to load the sample json files rather than doing it manually. Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
e5d03a2c1a
commit
e3b0eb5b1c
@ -2736,8 +2736,7 @@ static int
|
||||
testBlockNodeNameDetect(const void *opaque)
|
||||
{
|
||||
const struct testBlockNodeNameDetectData *data = opaque;
|
||||
char *namedNodesFile = NULL;
|
||||
char *namedNodesStr = NULL;
|
||||
const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-";
|
||||
char *resultFile = NULL;
|
||||
char *actual = NULL;
|
||||
char **nodenames = NULL;
|
||||
@ -2747,21 +2746,15 @@ testBlockNodeNameDetect(const void *opaque)
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&namedNodesFile,
|
||||
"%s/qemumonitorjsondata/qemumonitorjson-nodename-%s-named-nodes.json",
|
||||
abs_srcdir, data->name) < 0 ||
|
||||
virAsprintf(&resultFile,
|
||||
"%s/qemumonitorjsondata/qemumonitorjson-nodename-%s.result",
|
||||
abs_srcdir, data->name) < 0)
|
||||
if (virAsprintf(&resultFile, "%s/%s%s.result",
|
||||
abs_srcdir, pathprefix, data->name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(nodenames = virStringSplit(data->nodenames, ",", 0)))
|
||||
goto cleanup;
|
||||
|
||||
if (virTestLoadFile(namedNodesFile, &namedNodesStr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(namedNodesJson = virJSONValueFromString(namedNodesStr)))
|
||||
if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, data->name,
|
||||
"-named-nodes.json", NULL)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(nodedata = qemuBlockNodeNameGetBackingChain(namedNodesJson)))
|
||||
@ -2783,9 +2776,7 @@ testBlockNodeNameDetect(const void *opaque)
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(namedNodesFile);
|
||||
VIR_FREE(resultFile);
|
||||
VIR_FREE(namedNodesStr);
|
||||
VIR_FREE(actual);
|
||||
virHashFree(nodedata);
|
||||
virStringListFree(nodenames);
|
||||
|
Loading…
x
Reference in New Issue
Block a user