mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
testQEMUSchemaValidateCommand: Add possibility for partial QMP validation
The QMP schema for 'device_add' is not complete yet. Allow validation of incomplete schema so that we can enable at least some validation. Once there's more schema in the future all present members are still validated. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
387c900de9
commit
b17fd211e2
@ -171,6 +171,7 @@ qemuMigParamsTestJSON(const void *opaque)
|
|||||||
data->qmpschema,
|
data->qmpschema,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&debug) < 0) {
|
&debug) < 0) {
|
||||||
VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
|
VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
|
||||||
actualJSON, virBufferCurrentContent(&debug));
|
actualJSON, virBufferCurrentContent(&debug));
|
||||||
|
@ -342,6 +342,7 @@ testQemuMigrationCookieBlockDirtyBitmaps(const void *opaque)
|
|||||||
qmpschema,
|
qmpschema,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&debug) < 0) {
|
&debug) < 0) {
|
||||||
VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
|
VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
|
||||||
actualJSON, virBufferCurrentContent(&debug));
|
actualJSON, virBufferCurrentContent(&debug));
|
||||||
|
@ -542,6 +542,7 @@ qemuMonitorTestProcessCommandDefaultValidate(qemuMonitorTest *test,
|
|||||||
if (testQEMUSchemaValidateCommand(cmdname, args, test->qapischema,
|
if (testQEMUSchemaValidateCommand(cmdname, args, test->qapischema,
|
||||||
test->skipValidationDeprecated,
|
test->skipValidationDeprecated,
|
||||||
test->skipValidationRemoved,
|
test->skipValidationRemoved,
|
||||||
|
false,
|
||||||
&debug) < 0) {
|
&debug) < 0) {
|
||||||
if (virTestGetDebug() == 2) {
|
if (virTestGetDebug() == 2) {
|
||||||
g_autofree char *argstr = NULL;
|
g_autofree char *argstr = NULL;
|
||||||
|
@ -535,7 +535,7 @@ testCompareXMLToArgvValidateSchemaCommand(GStrv args,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (testQEMUSchemaValidateCommand(command->schema, jsonargs,
|
if (testQEMUSchemaValidateCommand(command->schema, jsonargs,
|
||||||
schema, false, false, &debug) < 0) {
|
schema, false, false, false, &debug) < 0) {
|
||||||
VIR_TEST_VERBOSE("failed to validate '%s %s' against QAPI schema: %s",
|
VIR_TEST_VERBOSE("failed to validate '%s %s' against QAPI schema: %s",
|
||||||
command->name, curargs, virBufferCurrentContent(&debug));
|
command->name, curargs, virBufferCurrentContent(&debug));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -25,6 +25,7 @@ struct testQEMUSchemaValidateCtxt {
|
|||||||
GHashTable *schema;
|
GHashTable *schema;
|
||||||
virBuffer *debug;
|
virBuffer *debug;
|
||||||
bool allowDeprecated;
|
bool allowDeprecated;
|
||||||
|
bool allowIncomplete; /* allow members not (yet) covered by the schema */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -137,6 +138,10 @@ testQEMUSchemaValidateObjectMember(const char *key,
|
|||||||
|
|
||||||
/* lookup 'member' entry for key */
|
/* lookup 'member' entry for key */
|
||||||
if (!(keymember = testQEMUSchemaStealObjectMemberByName(key, data->rootmembers))) {
|
if (!(keymember = testQEMUSchemaStealObjectMemberByName(key, data->rootmembers))) {
|
||||||
|
if (data->ctxt->allowIncomplete) {
|
||||||
|
virBufferAddLit(data->ctxt->debug, " schema missing - OK(waived)\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
virBufferAddLit(data->ctxt->debug, "ERROR: attribute not in schema\n");
|
virBufferAddLit(data->ctxt->debug, "ERROR: attribute not in schema\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -553,6 +558,8 @@ testQEMUSchemaValidate(virJSONValue *obj,
|
|||||||
* @allowDeprecated: don't fails schema validation if @command or one of @arguments
|
* @allowDeprecated: don't fails schema validation if @command or one of @arguments
|
||||||
* is deprecated
|
* is deprecated
|
||||||
* @allowRemoved: skip validation fully if @command was not found
|
* @allowRemoved: skip validation fully if @command was not found
|
||||||
|
* @allowIncomplete: don't fail validation if members not covered by schema are present
|
||||||
|
* (for waiving commands with incomplete schema)
|
||||||
* @debug: a virBuffer which will be filled with debug information if provided
|
* @debug: a virBuffer which will be filled with debug information if provided
|
||||||
*
|
*
|
||||||
* Validates whether @command and its @arguments conform to the QAPI schema
|
* Validates whether @command and its @arguments conform to the QAPI schema
|
||||||
@ -571,11 +578,13 @@ testQEMUSchemaValidateCommand(const char *command,
|
|||||||
GHashTable *schema,
|
GHashTable *schema,
|
||||||
bool allowDeprecated,
|
bool allowDeprecated,
|
||||||
bool allowRemoved,
|
bool allowRemoved,
|
||||||
|
bool allowIncomplete,
|
||||||
virBuffer *debug)
|
virBuffer *debug)
|
||||||
{
|
{
|
||||||
struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema,
|
struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema,
|
||||||
.debug = debug,
|
.debug = debug,
|
||||||
.allowDeprecated = allowDeprecated };
|
.allowDeprecated = allowDeprecated,
|
||||||
|
.allowIncomplete = allowIncomplete };
|
||||||
g_autofree char *schemapatharguments = g_strdup_printf("%s/arg-type", command);
|
g_autofree char *schemapatharguments = g_strdup_printf("%s/arg-type", command);
|
||||||
g_autoptr(virJSONValue) emptyargs = NULL;
|
g_autoptr(virJSONValue) emptyargs = NULL;
|
||||||
virJSONValue *schemarootcommand;
|
virJSONValue *schemarootcommand;
|
||||||
|
@ -35,6 +35,7 @@ testQEMUSchemaValidateCommand(const char *command,
|
|||||||
GHashTable *schema,
|
GHashTable *schema,
|
||||||
bool allowDeprecated,
|
bool allowDeprecated,
|
||||||
bool allowRemoved,
|
bool allowRemoved,
|
||||||
|
bool allowIncomplete,
|
||||||
virBuffer *debug);
|
virBuffer *debug);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user