mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 13:47:13 +03:00
testutilsqemuschema: Allow loading non-latest schema
Add testQEMUSchemaLoad and refactor internals so that we can load the QMP schema from an arbitrary caps replies file. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
18e9806c64
commit
b6246d9320
@ -607,37 +607,23 @@ testQEMUSchemaValidateCommand(const char *command,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testQEMUSchemaGetLatest:
|
||||
*
|
||||
* Returns the schema data as the qemu monitor would reply from the latest
|
||||
* replies file used for qemucapabilitiestest for the x86_64 architecture.
|
||||
*/
|
||||
virJSONValuePtr
|
||||
testQEMUSchemaGetLatest(const char* arch)
|
||||
static virJSONValuePtr
|
||||
testQEMUSchemaLoadReplies(const char *filename)
|
||||
{
|
||||
g_autofree char *capsLatestFile = NULL;
|
||||
g_autofree char *capsLatest = NULL;
|
||||
g_autofree char *caps = NULL;
|
||||
char *schemaReply;
|
||||
char *end;
|
||||
g_autoptr(virJSONValue) reply = NULL;
|
||||
virJSONValuePtr schema = NULL;
|
||||
|
||||
if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) {
|
||||
VIR_TEST_VERBOSE("failed to find latest caps replies");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
|
||||
|
||||
if (virTestLoadFile(capsLatestFile, &capsLatest) < 0)
|
||||
if (virTestLoadFile(filename, &caps) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(schemaReply = strstr(capsLatest, "\"execute\": \"query-qmp-schema\"")) ||
|
||||
if (!(schemaReply = strstr(caps, "\"execute\": \"query-qmp-schema\"")) ||
|
||||
!(schemaReply = strstr(schemaReply, "\n\n")) ||
|
||||
!(end = strstr(schemaReply + 2, "\n\n"))) {
|
||||
VIR_TEST_VERBOSE("failed to find reply to 'query-qmp-schema' in '%s'",
|
||||
capsLatestFile);
|
||||
filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -646,13 +632,13 @@ testQEMUSchemaGetLatest(const char* arch)
|
||||
|
||||
if (!(reply = virJSONValueFromString(schemaReply))) {
|
||||
VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%s'",
|
||||
capsLatestFile);
|
||||
filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(schema = virJSONValueObjectStealArray(reply, "return"))) {
|
||||
VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'",
|
||||
capsLatestFile);
|
||||
filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -660,6 +646,28 @@ testQEMUSchemaGetLatest(const char* arch)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testQEMUSchemaGetLatest:
|
||||
*
|
||||
* Returns the schema data as the qemu monitor would reply from the latest
|
||||
* replies file used for qemucapabilitiestest for the x86_64 architecture.
|
||||
*/
|
||||
virJSONValuePtr
|
||||
testQEMUSchemaGetLatest(const char *arch)
|
||||
{
|
||||
g_autofree char *capsLatestFile = NULL;
|
||||
|
||||
if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) {
|
||||
VIR_TEST_VERBOSE("failed to find latest caps replies");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
|
||||
|
||||
return testQEMUSchemaLoadReplies(capsLatestFile);
|
||||
}
|
||||
|
||||
|
||||
virHashTablePtr
|
||||
testQEMUSchemaLoadLatest(const char *arch)
|
||||
{
|
||||
@ -670,3 +678,15 @@ testQEMUSchemaLoadLatest(const char *arch)
|
||||
|
||||
return virQEMUQAPISchemaConvert(schema);
|
||||
}
|
||||
|
||||
|
||||
virHashTablePtr
|
||||
testQEMUSchemaLoad(const char *filename)
|
||||
{
|
||||
virJSONValuePtr schema;
|
||||
|
||||
if (!(schema = testQEMUSchemaLoadReplies(filename)))
|
||||
return NULL;
|
||||
|
||||
return virQEMUQAPISchemaConvert(schema);
|
||||
}
|
||||
|
@ -42,3 +42,6 @@ testQEMUSchemaGetLatest(const char* arch);
|
||||
|
||||
virHashTablePtr
|
||||
testQEMUSchemaLoadLatest(const char *arch);
|
||||
|
||||
virHashTablePtr
|
||||
testQEMUSchemaLoad(const char *filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user