testQEMUSchemaValidateEnum: Refactor logic to simplify switching to new QMP schema format

QEMU-6.2 is reporting enum values in the new 'members' array which we'll
be switching to. Rewrite the logic so that adding the new checker is
more straightforward.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-09-17 16:21:43 +02:00
parent 626b53ba9b
commit 91453650f3

View File

@ -324,7 +324,6 @@ testQEMUSchemaValidateEnum(virJSONValue *obj,
{ {
const char *objstr; const char *objstr;
virJSONValue *values = NULL; virJSONValue *values = NULL;
virJSONValue *value;
size_t i; size_t i;
if (virJSONValueGetType(obj) != VIR_JSON_TYPE_STRING) { if (virJSONValueGetType(obj) != VIR_JSON_TYPE_STRING) {
@ -334,24 +333,24 @@ testQEMUSchemaValidateEnum(virJSONValue *obj,
objstr = virJSONValueGetString(obj); objstr = virJSONValueGetString(obj);
if (!(values = virJSONValueObjectGetArray(root, "values"))) { if ((values = virJSONValueObjectGetArray(root, "values"))) {
virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'", for (i = 0; i < virJSONValueArraySize(values); i++) {
NULLSTR(virJSONValueObjectGetString(root, "name"))); virJSONValue *value = virJSONValueArrayGet(values, i);
return -2;
}
for (i = 0; i < virJSONValueArraySize(values); i++) { if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
value = virJSONValueArrayGet(values, i); virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
return 0;
if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) { }
virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
return 0;
} }
virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
NULLSTR(objstr));
return -1;
} }
virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema", virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
NULLSTR(objstr)); NULLSTR(virJSONValueObjectGetString(root, "name")));
return -1; return -2;
} }