tests/qtest: enhance migration channels
Change the migrate_qmp and migrate_qmp_fail channels argument to a QObject type so the caller can manipulate the object before passing it to the helper. Define migrate_str_to_channel to aid such manipulation. Add a channels argument to migrate_incoming_qmp. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/r/1736967650-129648-22-git-send-email-steven.sistare@oracle.com Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
parent
f5bac78cd8
commit
43ca9d1866
@ -18,6 +18,8 @@
|
|||||||
#include "migration/migration-qmp.h"
|
#include "migration/migration-qmp.h"
|
||||||
#include "migration/migration-util.h"
|
#include "migration/migration-util.h"
|
||||||
#include "ppc-util.h"
|
#include "ppc-util.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qapi/qmp/qjson.h"
|
||||||
#include "qapi/qmp/qlist.h"
|
#include "qapi/qmp/qlist.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "qemu/option.h"
|
#include "qemu/option.h"
|
||||||
@ -705,6 +707,7 @@ void test_precopy_common(MigrateCommon *args)
|
|||||||
{
|
{
|
||||||
QTestState *from, *to;
|
QTestState *from, *to;
|
||||||
void *data_hook = NULL;
|
void *data_hook = NULL;
|
||||||
|
QObject *out_channels = NULL;
|
||||||
|
|
||||||
if (migrate_start(&from, &to, args->listen_uri, &args->start)) {
|
if (migrate_start(&from, &to, args->listen_uri, &args->start)) {
|
||||||
return;
|
return;
|
||||||
@ -737,12 +740,16 @@ void test_precopy_common(MigrateCommon *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->connect_channels) {
|
||||||
|
out_channels = qobject_from_json(args->connect_channels, &error_abort);
|
||||||
|
}
|
||||||
|
|
||||||
if (args->result == MIG_TEST_QMP_ERROR) {
|
if (args->result == MIG_TEST_QMP_ERROR) {
|
||||||
migrate_qmp_fail(from, args->connect_uri, args->connect_channels, "{}");
|
migrate_qmp_fail(from, args->connect_uri, out_channels, "{}");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
migrate_qmp(from, to, args->connect_uri, args->connect_channels, "{}");
|
migrate_qmp(from, to, args->connect_uri, out_channels, "{}");
|
||||||
|
|
||||||
if (args->start.defer_target_connect) {
|
if (args->start.defer_target_connect) {
|
||||||
qtest_connect(to);
|
qtest_connect(to);
|
||||||
@ -892,7 +899,7 @@ void test_file_common(MigrateCommon *args, bool stop_src)
|
|||||||
* We need to wait for the source to finish before starting the
|
* We need to wait for the source to finish before starting the
|
||||||
* destination.
|
* destination.
|
||||||
*/
|
*/
|
||||||
migrate_incoming_qmp(to, args->connect_uri, "{}");
|
migrate_incoming_qmp(to, args->connect_uri, NULL, "{}");
|
||||||
wait_for_migration_complete(to);
|
wait_for_migration_complete(to);
|
||||||
|
|
||||||
if (stop_src) {
|
if (stop_src) {
|
||||||
@ -928,7 +935,7 @@ void *migrate_hook_start_precopy_tcp_multifd_common(QTestState *from,
|
|||||||
migrate_set_capability(to, "multifd", true);
|
migrate_set_capability(to, "multifd", true);
|
||||||
|
|
||||||
/* Start incoming migration from the 1st socket */
|
/* Start incoming migration from the 1st socket */
|
||||||
migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}");
|
migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL, "{}");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,13 @@
|
|||||||
#include "migration-qmp.h"
|
#include "migration-qmp.h"
|
||||||
#include "migration-util.h"
|
#include "migration-util.h"
|
||||||
#include "qapi/error.h"
|
#include "qapi/error.h"
|
||||||
|
#include "qapi/qapi-types-migration.h"
|
||||||
|
#include "qapi/qapi-visit-migration.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "qapi/qmp/qjson.h"
|
#include "qapi/qmp/qjson.h"
|
||||||
#include "qapi/qmp/qlist.h"
|
#include "qapi/qmp/qlist.h"
|
||||||
|
#include "qapi/qobject-input-visitor.h"
|
||||||
|
#include "qapi/qobject-output-visitor.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Number of seconds we wait when looking for migration
|
* Number of seconds we wait when looking for migration
|
||||||
@ -47,8 +51,33 @@ void migration_event_wait(QTestState *s, const char *target)
|
|||||||
} while (!found);
|
} while (!found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string representing a single channel to an object.
|
||||||
|
* @str may be in JSON or dotted keys format.
|
||||||
|
*/
|
||||||
|
QObject *migrate_str_to_channel(const char *str)
|
||||||
|
{
|
||||||
|
Visitor *v;
|
||||||
|
MigrationChannel *channel;
|
||||||
|
QObject *obj;
|
||||||
|
|
||||||
|
/* Create the channel */
|
||||||
|
v = qobject_input_visitor_new_str(str, "channel-type", &error_abort);
|
||||||
|
visit_type_MigrationChannel(v, NULL, &channel, &error_abort);
|
||||||
|
visit_free(v);
|
||||||
|
|
||||||
|
/* Create the object */
|
||||||
|
v = qobject_output_visitor_new(&obj);
|
||||||
|
visit_type_MigrationChannel(v, NULL, &channel, &error_abort);
|
||||||
|
visit_complete(v, &obj);
|
||||||
|
visit_free(v);
|
||||||
|
|
||||||
|
qapi_free_MigrationChannel(channel);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
void migrate_qmp_fail(QTestState *who, const char *uri,
|
void migrate_qmp_fail(QTestState *who, const char *uri,
|
||||||
const char *channels, const char *fmt, ...)
|
QObject *channels, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
QDict *args, *err;
|
QDict *args, *err;
|
||||||
@ -64,8 +93,7 @@ void migrate_qmp_fail(QTestState *who, const char *uri,
|
|||||||
|
|
||||||
g_assert(!qdict_haskey(args, "channels"));
|
g_assert(!qdict_haskey(args, "channels"));
|
||||||
if (channels) {
|
if (channels) {
|
||||||
QObject *channels_obj = qobject_from_json(channels, &error_abort);
|
qdict_put_obj(args, "channels", channels);
|
||||||
qdict_put_obj(args, "channels", channels_obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = qtest_qmp_assert_failure_ref(
|
err = qtest_qmp_assert_failure_ref(
|
||||||
@ -82,7 +110,7 @@ void migrate_qmp_fail(QTestState *who, const char *uri,
|
|||||||
* qobject_from_jsonf_nofail()) with "uri": @uri spliced in.
|
* qobject_from_jsonf_nofail()) with "uri": @uri spliced in.
|
||||||
*/
|
*/
|
||||||
void migrate_qmp(QTestState *who, QTestState *to, const char *uri,
|
void migrate_qmp(QTestState *who, QTestState *to, const char *uri,
|
||||||
const char *channels, const char *fmt, ...)
|
QObject *channels, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
QDict *args;
|
QDict *args;
|
||||||
@ -102,10 +130,9 @@ void migrate_qmp(QTestState *who, QTestState *to, const char *uri,
|
|||||||
|
|
||||||
g_assert(!qdict_haskey(args, "channels"));
|
g_assert(!qdict_haskey(args, "channels"));
|
||||||
if (channels) {
|
if (channels) {
|
||||||
QObject *channels_obj = qobject_from_json(channels, &error_abort);
|
QList *channel_list = qobject_to(QList, channels);
|
||||||
QList *channel_list = qobject_to(QList, channels_obj);
|
|
||||||
migrate_set_ports(to, channel_list);
|
migrate_set_ports(to, channel_list);
|
||||||
qdict_put_obj(args, "channels", channels_obj);
|
qdict_put_obj(args, "channels", channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
qtest_qmp_assert_success(who,
|
qtest_qmp_assert_success(who,
|
||||||
@ -123,7 +150,8 @@ void migrate_set_capability(QTestState *who, const char *capability,
|
|||||||
capability, value);
|
capability, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
|
void migrate_incoming_qmp(QTestState *to, const char *uri, QObject *channels,
|
||||||
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
QDict *args, *rsp;
|
QDict *args, *rsp;
|
||||||
@ -133,7 +161,14 @@ void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
g_assert(!qdict_haskey(args, "uri"));
|
g_assert(!qdict_haskey(args, "uri"));
|
||||||
qdict_put_str(args, "uri", uri);
|
if (uri) {
|
||||||
|
qdict_put_str(args, "uri", uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert(!qdict_haskey(args, "channels"));
|
||||||
|
if (channels) {
|
||||||
|
qdict_put_obj(args, "channels", channels);
|
||||||
|
}
|
||||||
|
|
||||||
/* This function relies on the event to work, make sure it's enabled */
|
/* This function relies on the event to work, make sure it's enabled */
|
||||||
migrate_set_capability(to, "events", true);
|
migrate_set_capability(to, "events", true);
|
||||||
|
@ -4,17 +4,19 @@
|
|||||||
|
|
||||||
#include "migration-util.h"
|
#include "migration-util.h"
|
||||||
|
|
||||||
|
QObject *migrate_str_to_channel(const char *str);
|
||||||
|
|
||||||
G_GNUC_PRINTF(4, 5)
|
G_GNUC_PRINTF(4, 5)
|
||||||
void migrate_qmp_fail(QTestState *who, const char *uri,
|
void migrate_qmp_fail(QTestState *who, const char *uri,
|
||||||
const char *channels, const char *fmt, ...);
|
QObject *channels, const char *fmt, ...);
|
||||||
|
|
||||||
G_GNUC_PRINTF(5, 6)
|
G_GNUC_PRINTF(5, 6)
|
||||||
void migrate_qmp(QTestState *who, QTestState *to, const char *uri,
|
void migrate_qmp(QTestState *who, QTestState *to, const char *uri,
|
||||||
const char *channels, const char *fmt, ...);
|
QObject *channels, const char *fmt, ...);
|
||||||
|
|
||||||
G_GNUC_PRINTF(3, 4)
|
G_GNUC_PRINTF(4, 5)
|
||||||
void migrate_incoming_qmp(QTestState *who, const char *uri,
|
void migrate_incoming_qmp(QTestState *who, const char *uri,
|
||||||
const char *fmt, ...);
|
QObject *channels, const char *fmt, ...);
|
||||||
|
|
||||||
void migration_event_wait(QTestState *s, const char *target);
|
void migration_event_wait(QTestState *s, const char *target);
|
||||||
void migrate_set_capability(QTestState *who, const char *capability,
|
void migrate_set_capability(QTestState *who, const char *capability,
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qapi/qmp/qjson.h"
|
||||||
#include "libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "migration/framework.h"
|
#include "migration/framework.h"
|
||||||
#include "migration/migration-qmp.h"
|
#include "migration/migration-qmp.h"
|
||||||
@ -205,6 +207,7 @@ static void test_validate_uuid_dst_not_set(void)
|
|||||||
static void do_test_validate_uri_channel(MigrateCommon *args)
|
static void do_test_validate_uri_channel(MigrateCommon *args)
|
||||||
{
|
{
|
||||||
QTestState *from, *to;
|
QTestState *from, *to;
|
||||||
|
QObject *channels;
|
||||||
|
|
||||||
if (migrate_start(&from, &to, args->listen_uri, &args->start)) {
|
if (migrate_start(&from, &to, args->listen_uri, &args->start)) {
|
||||||
return;
|
return;
|
||||||
@ -217,7 +220,11 @@ static void do_test_validate_uri_channel(MigrateCommon *args)
|
|||||||
* 'uri' and 'channels' validation is checked even before the migration
|
* 'uri' and 'channels' validation is checked even before the migration
|
||||||
* starts.
|
* starts.
|
||||||
*/
|
*/
|
||||||
migrate_qmp_fail(from, args->connect_uri, args->connect_channels, "{}");
|
channels = args->connect_channels ?
|
||||||
|
qobject_from_json(args->connect_channels, &error_abort) :
|
||||||
|
NULL;
|
||||||
|
migrate_qmp_fail(from, args->connect_uri, channels, "{}");
|
||||||
|
|
||||||
migrate_end(from, to, false);
|
migrate_end(from, to, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ static void *migrate_hook_start_fd(QTestState *from,
|
|||||||
close(pair[0]);
|
close(pair[0]);
|
||||||
|
|
||||||
/* Start incoming migration from the 1st socket */
|
/* Start incoming migration from the 1st socket */
|
||||||
migrate_incoming_qmp(to, "fd:fd-mig", "{}");
|
migrate_incoming_qmp(to, "fd:fd-mig", NULL, "{}");
|
||||||
|
|
||||||
/* Send the 2nd socket to the target */
|
/* Send the 2nd socket to the target */
|
||||||
qtest_qmp_fds_assert_success(from, &pair[1], 1,
|
qtest_qmp_fds_assert_success(from, &pair[1], 1,
|
||||||
@ -479,7 +479,7 @@ static void test_multifd_tcp_cancel(void)
|
|||||||
migrate_set_capability(to, "multifd", true);
|
migrate_set_capability(to, "multifd", true);
|
||||||
|
|
||||||
/* Start incoming migration from the 1st socket */
|
/* Start incoming migration from the 1st socket */
|
||||||
migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}");
|
migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL, "{}");
|
||||||
|
|
||||||
/* Wait for the first serial output from the source */
|
/* Wait for the first serial output from the source */
|
||||||
wait_for_serial("src_serial");
|
wait_for_serial("src_serial");
|
||||||
@ -518,7 +518,7 @@ static void test_multifd_tcp_cancel(void)
|
|||||||
migrate_set_capability(to2, "multifd", true);
|
migrate_set_capability(to2, "multifd", true);
|
||||||
|
|
||||||
/* Start incoming migration from the 1st socket */
|
/* Start incoming migration from the 1st socket */
|
||||||
migrate_incoming_qmp(to2, "tcp:127.0.0.1:0", "{}");
|
migrate_incoming_qmp(to2, "tcp:127.0.0.1:0", NULL, "{}");
|
||||||
|
|
||||||
migrate_ensure_non_converge(from);
|
migrate_ensure_non_converge(from);
|
||||||
|
|
||||||
|
@ -773,7 +773,7 @@ static void test_migrate_in(gconstpointer opaque)
|
|||||||
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
||||||
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
|
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
|
||||||
|
|
||||||
migrate_incoming_qmp(qts, uri, "{}");
|
migrate_incoming_qmp(qts, uri, NULL, "{}");
|
||||||
|
|
||||||
resp = get_failover_negociated_event(qts);
|
resp = get_failover_negociated_event(qts);
|
||||||
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");
|
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");
|
||||||
@ -895,7 +895,7 @@ static void test_off_migrate_in(gconstpointer opaque)
|
|||||||
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
||||||
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
|
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
|
||||||
|
|
||||||
migrate_incoming_qmp(qts, uri, "{}");
|
migrate_incoming_qmp(qts, uri, NULL, "{}");
|
||||||
|
|
||||||
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
||||||
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
|
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
|
||||||
@ -1022,7 +1022,7 @@ static void test_guest_off_migrate_in(gconstpointer opaque)
|
|||||||
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
||||||
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
|
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
|
||||||
|
|
||||||
migrate_incoming_qmp(qts, uri, "{}");
|
migrate_incoming_qmp(qts, uri, NULL, "{}");
|
||||||
|
|
||||||
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
check_one_card(qts, true, "standby0", MAC_STANDBY0);
|
||||||
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
|
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
|
||||||
@ -1747,7 +1747,7 @@ static void test_multi_in(gconstpointer opaque)
|
|||||||
check_one_card(qts, true, "standby1", MAC_STANDBY1);
|
check_one_card(qts, true, "standby1", MAC_STANDBY1);
|
||||||
check_one_card(qts, false, "primary1", MAC_PRIMARY1);
|
check_one_card(qts, false, "primary1", MAC_PRIMARY1);
|
||||||
|
|
||||||
migrate_incoming_qmp(qts, uri, "{}");
|
migrate_incoming_qmp(qts, uri, NULL, "{}");
|
||||||
|
|
||||||
resp = get_failover_negociated_event(qts);
|
resp = get_failover_negociated_event(qts);
|
||||||
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");
|
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user