tests: extend qmp test with preconfig checks

Add permission checks for commands at 'preconfig' stage.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Message-Id: <1526556524-267991-1-git-send-email-imammedo@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
Igor Mammedov 2018-05-17 13:28:44 +02:00 committed by Eduardo Habkost
parent 047f7038f5
commit fb1e58f72b

View File

@ -392,6 +392,52 @@ static void add_query_tests(QmpSchema *schema)
}
}
static bool qmp_rsp_is_err(QDict *rsp)
{
QDict *error = qdict_get_qdict(rsp, "error");
qobject_unref(rsp);
return !!error;
}
static void test_qmp_preconfig(void)
{
QDict *rsp, *ret;
QTestState *qs = qtest_startf("%s --preconfig", common_args);
/* preconfig state */
/* enabled commands, no error expected */
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-commands' }")));
/* forbidden commands, expected error */
g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
/* check that query-status returns preconfig state */
rsp = qtest_qmp(qs, "{ 'execute': 'query-status' }");
ret = qdict_get_qdict(rsp, "return");
g_assert(ret);
g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig");
qobject_unref(rsp);
/* exit preconfig state */
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'exit-preconfig' }")));
qtest_qmp_eventwait(qs, "RESUME");
/* check that query-status returns running state */
rsp = qtest_qmp(qs, "{ 'execute': 'query-status' }");
ret = qdict_get_qdict(rsp, "return");
g_assert(ret);
g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "running");
qobject_unref(rsp);
/* check that exit-preconfig returns error after exiting preconfig */
g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'exit-preconfig' }")));
/* enabled commands, no error expected */
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
qtest_quit(qs);
}
int main(int argc, char *argv[])
{
QmpSchema schema;
@ -403,6 +449,7 @@ int main(int argc, char *argv[])
qtest_add_func("qmp/oob", test_qmp_oob);
qmp_schema_init(&schema);
add_query_tests(&schema);
qtest_add_func("qmp/preconfig", test_qmp_preconfig);
ret = g_test_run();