On 02/16/2018 06:37 AM, Igor Mammedov wrote:
In the subject line: s/pereconfig/preconfig/
Add permission checks for commands in 'preconfig' state.
It should work for all targets, but won't work with
machine 'none' as it's limited to -smp 1 only.
So use PC machine for testing preconfig and 'runstate'
parameter.
Signed-off-by: Igor Mammedov <imamm...@redhat.com>
---
tests/qmp-test.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
+static bool is_err(QDict *rsp)
+{
+ const char *desc = NULL;
+ QDict *error = qdict_get_qdict(rsp, "error");
+ if (error) {
+ desc = qdict_get_try_str(error, "desc");
+ }
+ QDECREF(rsp);
+ return !!desc;
Wait, so this returns false if this was an error but without a valid desc?
+}
+
+static void test_qmp_preconfig(void)
+{
+ QDict *rsp, *ret;
+ QTestState *qs = qtest_startf("-nodefaults -preconfig -smp 2");
+
+ /* preconfig state */
+ /* enabled commands, no error expected */
+ g_assert(!is_err(qtest_qmp(qs, "{ 'execute': 'query-commands' }")));
+
+ /* forbidden commands, expected error */
+ g_assert(is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
Does introspection show which commands are valid in preconfig state?
That may be useful information for a client to know.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org