testQEMUSchemaValidate*: Reject usage of fields with 'deprecated' set

Make our QMP schema validator reject any use of schema entries which
were deprecated by QEMU except for those whitelisted.

This will allow us to catch this before qemu actually removed what we'd
still use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-03-04 09:02:54 +01:00
parent add3607ea8
commit de8216af13

View File

@ -445,6 +445,47 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj,
} }
static int
testQEMUSchemaValidateDeprecated(virJSONValuePtr root,
const char *name,
struct testQEMUSchemaValidateCtxt *ctxt)
{
virJSONValuePtr features = virJSONValueObjectGetArray(root, "features");
size_t nfeatures;
size_t i;
if (!features)
return 0;
nfeatures = virJSONValueArraySize(features);
for (i = 0; i < nfeatures; i++) {
virJSONValuePtr cur = virJSONValueArrayGet(features, i);
const char *curstr;
if (!cur ||
!(curstr = virJSONValueGetString(cur))) {
virBufferAsprintf(ctxt->debug, "ERROR: features of '%s' are malformed", name);
return -2;
}
if (STREQ(curstr, "deprecated")) {
if (ctxt->allowDeprecated) {
virBufferAsprintf(ctxt->debug, "WARNING: '%s' is deprecated", name);
if (virTestGetVerbose())
g_fprintf(stderr, "\nWARNING: '%s' is deprecated\n", name);
return 0;
} else {
virBufferAsprintf(ctxt->debug, "ERROR: '%s' is deprecated", name);
return -1;
}
}
}
return 0;
}
static int static int
testQEMUSchemaValidateRecurse(virJSONValuePtr obj, testQEMUSchemaValidateRecurse(virJSONValuePtr obj,
virJSONValuePtr root, virJSONValuePtr root,
@ -452,6 +493,10 @@ testQEMUSchemaValidateRecurse(virJSONValuePtr obj,
{ {
const char *n = virJSONValueObjectGetString(root, "name"); const char *n = virJSONValueObjectGetString(root, "name");
const char *t = virJSONValueObjectGetString(root, "meta-type"); const char *t = virJSONValueObjectGetString(root, "meta-type");
int rc;
if ((rc = testQEMUSchemaValidateDeprecated(root, n, ctxt)) < 0)
return rc;
if (STREQ_NULLABLE(t, "builtin")) { if (STREQ_NULLABLE(t, "builtin")) {
return testQEMUSchemaValidateBuiltin(obj, root, ctxt); return testQEMUSchemaValidateBuiltin(obj, root, ctxt);
@ -525,7 +570,7 @@ testQEMUSchemaValidateCommand(const char *command,
virJSONValuePtr arguments, virJSONValuePtr arguments,
virHashTablePtr schema, virHashTablePtr schema,
bool allowDeprecated, bool allowDeprecated,
bool allowRemoved G_GNUC_UNUSED, bool allowRemoved,
virBufferPtr debug) virBufferPtr debug)
{ {
struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema, struct testQEMUSchemaValidateCtxt ctxt = { .schema = schema,
@ -535,13 +580,20 @@ testQEMUSchemaValidateCommand(const char *command,
g_autoptr(virJSONValue) emptyargs = NULL; g_autoptr(virJSONValue) emptyargs = NULL;
virJSONValuePtr schemarootcommand; virJSONValuePtr schemarootcommand;
virJSONValuePtr schemarootarguments; virJSONValuePtr schemarootarguments;
int rc;
if (virQEMUQAPISchemaPathGet(command, schema, &schemarootcommand) < 0 || if (virQEMUQAPISchemaPathGet(command, schema, &schemarootcommand) < 0 ||
!schemarootcommand) { !schemarootcommand) {
if (allowRemoved)
return 0;
virBufferAsprintf(debug, "ERROR: command '%s' not found in the schema", command); virBufferAsprintf(debug, "ERROR: command '%s' not found in the schema", command);
return -1; return -1;
} }
if ((rc = testQEMUSchemaValidateDeprecated(schemarootcommand, command, &ctxt)) < 0)
return rc;
if (!arguments) if (!arguments)
arguments = emptyargs = virJSONValueNewObject(); arguments = emptyargs = virJSONValueNewObject();