qtest: migration: Add tests for introducing 'channels' argument in migrate QAPIs
v6 cover qtest: migration: Add tests for introducing 'channels' argument in migrate QAPIs
With recent migrate QAPI changes, enabling the direct use of the 'channels' argument to avoid redundant URI string parsing is achieved.
To ensure backward compatibility, both 'uri' and 'channels' are kept as optional parameters in migration QMP commands. However, they are mutually exhaustive, requiring at least one for a successful migration connection. This patchset adds qtests to validate 'uri' and 'channels' arguments' mututally exhaustive behaviour.
Additionally, all migration qtests fail to employ 'channel' as the primary method for validating migration QAPIs. This patchset also adds test to enforce only use of 'channel' argument as the initial entry point for migration QAPIs.
Patch Summary:
-------------
Patch 1-2:
---------
Introduce 'to' object inside migrate_qmp() so and move the calls to migrate_get_socket_address() inside migrate_qmp. Also, replace connect_uri with args->connect_uri everywhere.
Patch 3-6:
---------
Add channels argument to allow both migration QAPI arguments independently into migrate_qmp and migrate_qmp_fail. migrate_qmp requires the port value to be changed from 0 to port value coming from migrate_get_socket_address. Add migrate_set_ports to address this change of port value.
Patch 7-8:
---------
Add 2 negative tests to validate mutually exhaustive behaviour of migration QAPIs. Add a positive multifd_tcp_plain qtest with only channels as the initial entry point for migration QAPIs.
v5->v6 Changelog:
----------------
1. Pass args->connect_channels variable instead of NULL while calling migrate_qmp for .../multifd/channels/plain/none test. Passing NULL beats the whole purpose of the test.
v4->v5 Changelog:
----------------
1. Remove redundant imports from migration-test.c after moving helper functions to migration-helpers.c
2. call migrate_get_socket_address(to) and internally let qdict_get() call “socket-address” parameter to make more sense to the reader.
3. qdict needs to be freed, other small fixups.
v3->v4 Changelog:
----------------
1. introduced migrate_get_connect_uri and migrate_get_connect_qdict to both used migrate_get_socket_address to get dest uri in socket- address, and then use SokcketAddress_to_qdict to convert it into qdict.
2. Misc code changes.
v2->v3 Changelog:
-----------------
1. 'channels' introduction is not required now for migrate_qmp_incoming
2. Refactor the code into 7 different patches
3. 'channels' introduction is not required now for migrate_qmp_incoming
4. Remove custom function for converting string to MigrationChannelList
5. move calls for migrate_get_socket_address inside migrate_qmp so that migrate_set_ports can replace the QAPI's port with correct value.
Het Gala (8):
Add 'to' object into migrate_qmp()
Replace connect_uri and move migrate_get_socket_address inside
migrate_qmp
Replace migrate_get_connect_uri inplace of migrate_get_socket_address Add channels parameter in migrate_qmp_fail
Add migrate_set_ports into migrate_qmp to update migration port value Add channels parameter in migrate_qmp
Add multifd_tcp_plain test using list of channels instead of uri Add negative tests to validate migration QAPIs
tests/qtest/migration-helpers.c | 158 +++++++++++++++++++++++++++- tests/qtest/migration-helpers.h | 10 +- tests/qtest/migration-test.c | 180 +++++++++++++++++--------------- 3 files changed, 257 insertions(+), 91 deletions(-)
Signature · 1 line
2.22.3
PATCH v6 1/8 Add 'to' object into migrate_qmp()
Add the 'to' object into migrate_qmp(), so we can use migrate_get_socket_address() inside migrate_qmp() to get the port value. This is not applied to other migrate_qmp* because they don't need the port.
--- tests/qtest/migration-helpers.c | 3 ++- tests/qtest/migration-helpers.h | 5 +++-- tests/qtest/migration-test.c | 28 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-)
tests/qtest/migration-helpers.c +2 -1
@@ -68,7 +68,8 @@ void migrate_qmp_fail(QTestState *who, const char *uri, const char *fmt, ...)* Arguments are built from @fmt... (formatted like * qobject_from_jsonf_nofail()) with "uri": @uri spliced in. */ -void migrate_qmp (QTestState *who,const char *uri,const char *fmt, ...) +void migrate_qmp (QTestState *who,QTestState *to,const char *uri, +const char *fmt, ...) {va_list ap;QDict *args;
tests/qtest/migration-helpers.h +3 -2
@@ -25,8 +25,9 @@ typedef struct QTestMigrationState {bool migrate_watch_for_events (QTestState *who,const char *name,QDict *event,void *opaque); -G_GNUC_PRINTF(3, 4) -void migrate_qmp (QTestState *who,const char *uri,const char *fmt, ...); +G_GNUC_PRINTF(4, 5) +void migrate_qmp (QTestState *who,QTestState *to,const char *uri, +const char *fmt, ...); G_GNUC_PRINTF(3, 4) void migrate_incoming_qmp(QTestState *who, const char *uri,
tests/qtest/migration-test.c +14 -14
@@ -1350,7 +1350,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr,wait_for_suspend (from, &src_state); g_autofree char *uri = migrate_get_socket_address(to, "socket-address"); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );migrate_wait_for_dirty_mem (from, to);
@@ -1500,7 +1500,7 @@ static void postcopy_recover_fail(QTestState *from, QTestState *to) g_assert_cmpint(ret, ==, 1);migrate_recover (to,"fd:fd-mig" ); -migrate_qmp (from,"fd:fd-mig" ,"{'resume': true}" ); +migrate_qmp (from, to,"fd:fd-mig" ,"{'resume': true}" );/* * Make sure both QEMU instances will go into RECOVER stage, then test
@@ -1588,7 +1588,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)* Try to rebuild the migration channel using the resume flag and * the newly created channel */ -migrate_qmp (from, uri,"{'resume': true}" ); +migrate_qmp (from, to, uri,"{'resume': true}" );/* Restore the postcopy bandwidth to unlimited */ migrate_set_parameter_int (from,"max-postcopy-bandwidth" ,0 );
@@ -1669,7 +1669,7 @@ static void test_baddest(void)if (test_migrate_start (&from, &to,"tcp:127.0.0.1:0" , &args)) {return ; } -migrate_qmp (from,"tcp:127.0.0.1:0" ,"{}" ); +migrate_qmp (from, to,"tcp:127.0.0.1:0" ,"{}" );wait_for_migration_fail (from, false);test_migrate_end (from, to, false); }
@@ -1708,7 +1708,7 @@ static void test_analyze_script(void) uri =g_strdup_printf ("exec:cat > %s" , file);migrate_ensure_converge (from); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );wait_for_migration_complete (from); pid =fork ();
@@ -1777,7 +1777,7 @@ static void test_precopy_common(MigrateCommon *args) goto finish; } -migrate_qmp (from, connect_uri,"{}" ); +migrate_qmp (from, to, connect_uri,"{}" );if (args->result !=MIG_TEST_SUCCEED ) {bool allow_active = args->result ==MIG_TEST_FAIL ;
@@ -1873,7 +1873,7 @@ static void test_file_common(MigrateCommon *args, bool stop_src) goto finish; } -migrate_qmp (from, connect_uri,"{}" ); +migrate_qmp (from, to, connect_uri,"{}" );wait_for_migration_complete (from);/*
@@ -2029,7 +2029,7 @@ static void test_ignore_shared(void)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );migrate_wait_for_dirty_mem (from, to);
@@ -2605,7 +2605,7 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );if (should_fail) {qtest_set_expected_status (to,EXIT_FAILURE );
@@ -2708,7 +2708,7 @@ static void test_migrate_auto_converge(void)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );/* Wait for throttling begins */ percentage =0 ;
@@ -3029,7 +3029,7 @@ static void test_multifd_tcp_cancel(void) uri =migrate_get_socket_address (to,"socket-address" ); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );migrate_wait_for_dirty_mem (from, to);
@@ -3061,7 +3061,7 @@ static void test_multifd_tcp_cancel(void)migrate_ensure_non_converge (from); -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to2, uri,"{}" );migrate_wait_for_dirty_mem (from, to2);
@@ -3394,7 +3394,7 @@ static void test_migrate_dirty_limit(void)migrate_dirty_limit_wait_showup (from, dirtylimit_period, dirtylimit_value);/* Start migrate */ -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );/* Wait for dirty limit throttle begin */ throttle_us_per_full =0 ;
@@ -3435,7 +3435,7 @@ static void test_migrate_dirty_limit(void) }/* Start migrate */ -migrate_qmp (from, uri,"{}" ); +migrate_qmp (from, to, uri,"{}" );/* Wait for dirty limit throttle begin */ throttle_us_per_full =0 ;
Signature · 1 line
2.22.3
PATCH v6 2/8 Replace connect_uri and move migrate_get_socket_address inside migrate_qmp
In reply to Het GalaMove the calls to migrate_get_socket_address() into migrate_qmp(). Get rid of connect_uri and replace it with args->connect_uri only because 'to' object will help to generate connect_uri with the correct port number.
--- tests/qtest/migration-helpers.c | 54 ++++++++++++++++++++- tests/qtest/migration-test.c | 83 ++++----------------------------- 2 files changed, 63 insertions(+), 74 deletions(-)
tests/qtest/migration-helpers.c +53 -1
@@ -13,6 +13,9 @@#include "qemu/osdep.h" #include "qemu/ctype.h" #include "qapi/qmp/qjson.h" +#include "qapi/qapi-visit-sockets.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/error.h" #include "migration-helpers.h"
@@ -24,6 +27,51 @@*/ #define MIGRATION_STATUS_WAIT_TIMEOUT 120 +static char *SocketAddress_to_str (SocketAddress *addr) +{ +switch (addr->type) { +case SOCKET_ADDRESS_TYPE_INET : +return g_strdup_printf ("tcp:%s:%s" , + addr->u.inet.host, + addr->u.inet.port); +case SOCKET_ADDRESS_TYPE_UNIX : +return g_strdup_printf ("unix:%s" , + addr->u.q_unix.path); +case SOCKET_ADDRESS_TYPE_FD : +return g_strdup_printf ("fd:%s" , addr->u.fd.str); +case SOCKET_ADDRESS_TYPE_VSOCK : +return g_strdup_printf ("tcp:%s:%s" , + addr->u.vsock.cid, + addr->u.vsock.port); +default : +return g_strdup ("unknown address type" ); + } +} + +static char * +migrate_get_socket_address (QTestState *who,const char *parameter) +{ +QDict *rsp; +char *result; +SocketAddressList *addrs; +Visitor *iv =NULL ; +QObject *object; + + rsp =migrate_query (who); + object =qdict_get (rsp, parameter); + + iv =qobject_input_visitor_new (object); +visit_type_SocketAddressList (iv,NULL , &addrs, &error_abort); +visit_free (iv); + +/* we are only using a single address */ + result =SocketAddress_to_str (addrs->value); + +qapi_free_SocketAddressList (addrs); +qobject_unref (rsp); +return result; +} +bool migrate_watch_for_events (QTestState *who,const char *name,QDict *event,void *opaque) {
@@ -73,13 +121,17 @@ void migrate_qmp(QTestState *who, QTestState *to, const char *uri, {va_list ap;QDict *args; + g_autofree char *connect_uri = NULL;va_start (ap, fmt); args =qdict_from_vjsonf_nofail (fmt, ap);va_end (ap);g_assert (!qdict_haskey (args,"uri" )); -qdict_put_str (args,"uri" , uri); +if (!uri) { + connect_uri =migrate_get_socket_address (to,"socket-address" ); + } +qdict_put_str (args,"uri" , uri ? uri : connect_uri);qtest_qmp_assert_success (who,"{ 'execute': 'migrate', 'arguments': %p}" , args);
tests/qtest/migration-test.c +10 -73
178 lines not on this page · raw message
Signature · 1 line
2.22.3
Re: [PATCH v6 2/8] Replace connect_uri and move migrate_get_socket_address inside migrate_qmp
Quoted 7 lines · Het Gala
Move the calls to
migrate_get_socket_address()intomigrate_qmp(). Get rid ofconnect_uriand replace it withargs->connect_urionly because 'to' object will help to generateconnect_uriwith the correct port number.Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
PATCH v6 3/8 Replace migrate_get_connect_uri inplace of migrate_get_socket_address
In reply to Het GalaRefactor migrate_get_socket_address to internally utilize 'socket-address' parameter, reducing redundancy in the function definition.
migrate_get_socket_address implicitly converts SocketAddress into str. Move migrate_get_socket_address inside migrate_get_connect_uri which should return the uri string instead.
--- tests/qtest/migration-helpers.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
tests/qtest/migration-helpers.c +19 -10
@@ -48,28 +48,37 @@ static char *SocketAddress_to_str(SocketAddress *addr) } } -static char * -migrate_get_socket_address (QTestState *who,const char *parameter) +static SocketAddress *migrate_get_socket_address (QTestState *who) {QDict *rsp; -char *result;SocketAddressList *addrs; +SocketAddress *addr;Visitor *iv =NULL ;QObject *object; rsp =migrate_query (who); - object =qdict_get (rsp, parameter); + object =qdict_get (rsp,"socket-address" ); iv =qobject_input_visitor_new (object);visit_type_SocketAddressList (iv,NULL , &addrs, &error_abort); + addr = addrs->value;visit_free (iv); -/* we are only using a single address */ - result =SocketAddress_to_str (addrs->value); - -qapi_free_SocketAddressList (addrs);qobject_unref (rsp); -return result; +return addr; +} + +static char * +migrate_get_connect_uri (QTestState *who) +{ +SocketAddress *addrs; +char *connect_uri; + + addrs =migrate_get_socket_address (who); + connect_uri =SocketAddress_to_str (addrs); + +qapi_free_SocketAddress (addrs); +return connect_uri; } bool migrate_watch_for_events(QTestState *who, const char *name,
@@ -129,7 +138,7 @@ void migrate_qmp(QTestState *who, QTestState *to, const char *uri,g_assert (!qdict_haskey (args,"uri" ));if (!uri) { - connect_uri =migrate_get_socket_address (to,"socket-address" ); + connect_uri =migrate_get_connect_uri (to); }qdict_put_str (args,"uri" , uri ? uri : connect_uri);
Signature · 1 line
2.22.3
Re: [PATCH v6 3/8] Replace migrate_get_connect_uri inplace of migrate_get_socket_address
Quoted 9 lines · Het Gala
Refactor
migrate_get_socket_addressto internally utilize 'socket-address' parameter, reducing redundancy in the function definition.
migrate_get_socket_addressimplicitly converts SocketAddress into str. Movemigrate_get_socket_addressinsidemigrate_get_connect_uriwhich should return the uri string instead.Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
PATCH v6 4/8 Add channels parameter in migrate_qmp_fail
In reply to Het GalaAlter migrate_qmp_fail() to allow both uri and channels independently. For channels, convert string to a Dict. No dealing with migrate_get_socket_address() here because we will fail before starting the migration anyway.
--- tests/qtest/migration-helpers.c | 13 +++++++++++-- tests/qtest/migration-helpers.h | 5 +++-- tests/qtest/migration-test.c | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-)
tests/qtest/migration-helpers.c +11 -2
@@ -100,7 +100,8 @@ bool migrate_watch_for_events(QTestState *who, const char *name,return false; } -void migrate_qmp_fail (QTestState *who,const char *uri,const char *fmt, ...) +void migrate_qmp_fail (QTestState *who,const char *uri, +const char *channels,const char *fmt, ...) {va_list ap;QDict *args, *err;
@@ -110,7 +111,15 @@ void migrate_qmp_fail(QTestState *who, const char *uri, const char *fmt, ...)va_end (ap);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) { +QObject *channels_obj =qobject_from_json (channels, &error_abort); +qdict_put_obj (args,"channels" , channels_obj); + } err =qtest_qmp_assert_failure_ref ( who,"{ 'execute': 'migrate', 'arguments': %p}" , args);
tests/qtest/migration-helpers.h +3 -2
@@ -33,8 +33,9 @@ G_GNUC_PRINTF(3, 4)void migrate_incoming_qmp (QTestState *who,const char *uri,const char *fmt, ...); -G_GNUC_PRINTF(3, 4) -void migrate_qmp_fail (QTestState *who,const char *uri,const char *fmt, ...); +G_GNUC_PRINTF(4, 5) +void migrate_qmp_fail (QTestState *who,const char *uri, +const char *channels,const char *fmt, ...);void migrate_set_capability (QTestState *who,const char *capability,bool value);
tests/qtest/migration-test.c +2 -2
@@ -1717,7 +1717,7 @@ static void test_precopy_common(MigrateCommon *args) }if (args->result ==MIG_TEST_QMP_ERROR ) { -migrate_qmp_fail (from, args->connect_uri,"{}" ); +migrate_qmp_fail (from, args->connect_uri,NULL ,"{}" ); goto finish; }
@@ -1812,7 +1812,7 @@ static void test_file_common(MigrateCommon *args, bool stop_src) }if (args->result ==MIG_TEST_QMP_ERROR ) { -migrate_qmp_fail (from, args->connect_uri,"{}" ); +migrate_qmp_fail (from, args->connect_uri,NULL ,"{}" ); goto finish; }
Signature · 1 line
2.22.3
Re: [PATCH v6 4/8] Add channels parameter in migrate_qmp_fail
Quoted 7 lines · Het Gala
Alter
migrate_qmp_fail()to allow both uri and channels independently. For channels, convert string to a Dict. No dealing withmigrate_get_socket_address()here because we will fail before starting the migration anyway.Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
PATCH v6 5/8 Add migrate_set_ports into migrate_qmp to update migration port value
In reply to Het Galamigrate_get_connect_qdict gets qdict with the dst QEMU parameters.
migrate_set_ports() from list of channels reads each QDict for port, and fills the port with correct value in case it was 0 in the test.
--- tests/qtest/migration-helpers.c | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
tests/qtest/migration-helpers.c +75 -0
@@ -16,6 +16,8 @@#include "qapi/qapi-visit-sockets.h" #include "qapi/qobject-input-visitor.h" #include "qapi/error.h" +#include "qapi/qmp/qlist.h" +#include "qemu/cutils.h" #include "migration-helpers.h"
@@ -48,6 +50,37 @@ static char *SocketAddress_to_str(SocketAddress *addr) } } +static QDict *SocketAddress_to_qdict (SocketAddress *addr) +{ +QDict *dict =qdict_new (); + +switch (addr->type) { +case SOCKET_ADDRESS_TYPE_INET : +qdict_put_str (dict,"type" ,"inet" ); +qdict_put_str (dict,"host" , addr->u.inet.host); +qdict_put_str (dict,"port" , addr->u.inet.port); +break ; +case SOCKET_ADDRESS_TYPE_UNIX : +qdict_put_str (dict,"type" ,"unix" ); +qdict_put_str (dict,"path" , addr->u.q_unix.path); +break ; +case SOCKET_ADDRESS_TYPE_FD : +qdict_put_str (dict,"type" ,"fd" ); +qdict_put_str (dict,"str" , addr->u.fd.str); +break ; +case SOCKET_ADDRESS_TYPE_VSOCK : +qdict_put_str (dict,"type" ,"vsock" ); +qdict_put_str (dict,"cid" , addr->u.vsock.cid); +qdict_put_str (dict,"port" , addr->u.vsock.port); +break ; +default : +g_assert_not_reached (); +break ; + } + +return dict; +} +static SocketAddress *migrate_get_socket_address (QTestState *who) {QDict *rsp;
@@ -81,6 +114,46 @@ migrate_get_connect_uri(QTestState *who)return connect_uri; } +static QDict * +migrate_get_connect_qdict (QTestState *who) +{ +SocketAddress *addrs; +QDict *connect_qdict; + + addrs =migrate_get_socket_address (who); + connect_qdict =SocketAddress_to_qdict (addrs); + +qapi_free_SocketAddress (addrs); +return connect_qdict; +} + +static void migrate_set_ports (QTestState *to,QList *channel_list) +{ +QDict *addr; +QListEntry *entry; + g_autofree const char *addr_port = NULL; + +if (channel_list ==NULL ) { +return ; + } + + addr =migrate_get_connect_qdict (to); + + QLIST_FOREACH_ENTRY(channel_list, entry) { +QDict *channel =qobject_to (QDict,qlist_entry_obj (entry)); +QDict *addrdict =qdict_get_qdict (channel,"addr" ); + +if (qdict_haskey (addrdict,"port" ) && +qdict_haskey (addr,"port" ) && + (strcmp (qdict_get_str (addrdict,"port" ),"0" ) ==0 )) { + addr_port =qdict_get_str (addr,"port" ); +qdict_put_str (addrdict,"port" , addr_port); + } + } + +qobject_unref (addr); +} +bool migrate_watch_for_events (QTestState *who,const char *name,QDict *event,void *opaque) {
@@ -139,6 +212,7 @@ void migrate_qmp(QTestState *who, QTestState *to, const char *uri, {va_list ap;QDict *args; +QList *channel_list =NULL ; g_autofree char *connect_uri = NULL;va_start (ap, fmt);
@@ -149,6 +223,7 @@ void migrate_qmp(QTestState *who, QTestState *to, const char *uri,if (!uri) { connect_uri =migrate_get_connect_uri (to); } +migrate_set_ports (to, channel_list);qdict_put_str (args,"uri" , uri ? uri : connect_uri); qtest_qmp_assert_success(who,
Signature · 1 line
2.22.3
Re: [PATCH v6 5/8] Add migrate_set_ports into migrate_qmp to update migration port value
Quoted 7 lines · Het Gala
migrate_get_connect_qdictgets qdict with the dst QEMU parameters.
migrate_set_ports()from list of channels reads each QDict for port, and fills the port with correct value in case it was 0 in the test.Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
PATCH v6 6/8 Add channels parameter in migrate_qmp
In reply to Het GalaAlter migrate_qmp() to allow use of channels parameter, but only fill the uri with correct port number if there are no channels. Here we don't want to allow the wrong cases of having both or none (ex: migrate_qmp_fail).
--- tests/qtest/migration-helpers.c | 22 +++++++++++++--------- tests/qtest/migration-helpers.h | 4 ++-- tests/qtest/migration-test.c | 28 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 25 deletions(-)
tests/qtest/migration-helpers.c +13 -9
@@ -133,10 +133,6 @@ static void migrate_set_ports(QTestState *to, QList *channel_list)QListEntry *entry; g_autofree const char *addr_port = NULL; -if (channel_list ==NULL ) { -return ; - } - addr =migrate_get_connect_qdict (to); QLIST_FOREACH_ENTRY(channel_list, entry) {
@@ -208,11 +204,10 @@ void migrate_qmp_fail(QTestState *who, const char *uri,* qobject_from_jsonf_nofail()) with "uri": @uri spliced in. */ void migrate_qmp (QTestState *who,QTestState *to,const char *uri, -const char *fmt, ...) +const char *channels,const char *fmt, ...) {va_list ap;QDict *args; -QList *channel_list =NULL ; g_autofree char *connect_uri = NULL;va_start (ap, fmt);
@@ -220,11 +215,20 @@ void migrate_qmp(QTestState *who, QTestState *to, const char *uri,va_end (ap);g_assert (!qdict_haskey (args,"uri" )); -if (!uri) { +if (uri) { +qdict_put_str (args,"uri" , uri); + }else if (!channels) { connect_uri =migrate_get_connect_uri (to); +qdict_put_str (args,"uri" , connect_uri); + } + +g_assert (!qdict_haskey (args,"channels" )); +if (channels) { +QObject *channels_obj =qobject_from_json (channels, &error_abort); +QList *channel_list =qobject_to (QList, channels_obj); +migrate_set_ports (to, channel_list); +qdict_put_obj (args,"channels" , channels_obj); } -migrate_set_ports (to, channel_list); -qdict_put_str (args,"uri" , uri ? uri : connect_uri);qtest_qmp_assert_success (who,"{ 'execute': 'migrate', 'arguments': %p}" , args);
tests/qtest/migration-helpers.h +2 -2
@@ -25,9 +25,9 @@ typedef struct QTestMigrationState {bool migrate_watch_for_events (QTestState *who,const char *name,QDict *event,void *opaque); -G_GNUC_PRINTF(4, 5) +G_GNUC_PRINTF(5, 6)void migrate_qmp (QTestState *who,QTestState *to,const char *uri, -const char *fmt, ...); +const char *channels,const char *fmt, ...); G_GNUC_PRINTF(3, 4) void migrate_incoming_qmp(QTestState *who, const char *uri,
tests/qtest/migration-test.c +14 -14
@@ -1301,7 +1301,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr,wait_for_serial ("src_serial" );wait_for_suspend (from, &src_state); -migrate_qmp (from, to,NULL ,"{}" ); +migrate_qmp (from, to,NULL ,NULL ,"{}" );migrate_wait_for_dirty_mem (from, to);
@@ -1451,7 +1451,7 @@ static void postcopy_recover_fail(QTestState *from, QTestState *to) g_assert_cmpint(ret, ==, 1);migrate_recover (to,"fd:fd-mig" ); -migrate_qmp (from, to,"fd:fd-mig" ,"{'resume': true}" ); +migrate_qmp (from, to,"fd:fd-mig" ,NULL ,"{'resume': true}" );/* * Make sure both QEMU instances will go into RECOVER stage, then test
@@ -1539,7 +1539,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)* Try to rebuild the migration channel using the resume flag and * the newly created channel */ -migrate_qmp (from, to, uri,"{'resume': true}" ); +migrate_qmp (from, to, uri,NULL ,"{'resume': true}" );/* Restore the postcopy bandwidth to unlimited */ migrate_set_parameter_int (from,"max-postcopy-bandwidth" ,0 );
@@ -1620,7 +1620,7 @@ static void test_baddest(void)if (test_migrate_start (&from, &to,"tcp:127.0.0.1:0" , &args)) {return ; } -migrate_qmp (from, to,"tcp:127.0.0.1:0" ,"{}" ); +migrate_qmp (from, to,"tcp:127.0.0.1:0" ,NULL ,"{}" );wait_for_migration_fail (from, false);test_migrate_end (from, to, false); }
@@ -1659,7 +1659,7 @@ static void test_analyze_script(void) uri =g_strdup_printf ("exec:cat > %s" , file);migrate_ensure_converge (from); -migrate_qmp (from, to, uri,"{}" ); +migrate_qmp (from, to, uri,NULL ,"{}" );wait_for_migration_complete (from); pid =fork ();
@@ -1721,7 +1721,7 @@ static void test_precopy_common(MigrateCommon *args) goto finish; } -migrate_qmp (from, to, args->connect_uri,"{}" ); +migrate_qmp (from, to, args->connect_uri,NULL ,"{}" );if (args->result !=MIG_TEST_SUCCEED ) {bool allow_active = args->result ==MIG_TEST_FAIL ;
@@ -1816,7 +1816,7 @@ static void test_file_common(MigrateCommon *args, bool stop_src) goto finish; } -migrate_qmp (from, to, args->connect_uri,"{}" ); +migrate_qmp (from, to, args->connect_uri,NULL ,"{}" );wait_for_migration_complete (from);/*
@@ -1972,7 +1972,7 @@ static void test_ignore_shared(void)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, to, uri,"{}" ); +migrate_qmp (from, to, uri,NULL ,"{}" );migrate_wait_for_dirty_mem (from, to);
@@ -2548,7 +2548,7 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, to, uri,"{}" ); +migrate_qmp (from, to, uri,NULL ,"{}" );if (should_fail) {qtest_set_expected_status (to,EXIT_FAILURE );
@@ -2651,7 +2651,7 @@ static void test_migrate_auto_converge(void)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, to, uri,"{}" ); +migrate_qmp (from, to, uri,NULL ,"{}" );/* Wait for throttling begins */ percentage =0 ;
@@ -2969,7 +2969,7 @@ static void test_multifd_tcp_cancel(void)/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); -migrate_qmp (from, to,NULL ,"{}" ); +migrate_qmp (from, to,NULL ,NULL ,"{}" );migrate_wait_for_dirty_mem (from, to);
@@ -2998,7 +2998,7 @@ static void test_multifd_tcp_cancel(void)migrate_ensure_non_converge (from); -migrate_qmp (from, to2,NULL ,"{}" ); +migrate_qmp (from, to2,NULL ,NULL ,"{}" );migrate_wait_for_dirty_mem (from, to2);
@@ -3331,7 +3331,7 @@ static void test_migrate_dirty_limit(void)migrate_dirty_limit_wait_showup (from, dirtylimit_period, dirtylimit_value);/* Start migrate */ -migrate_qmp (from, to, args.connect_uri,"{}" ); +migrate_qmp (from, to, args.connect_uri,NULL ,"{}" );/* Wait for dirty limit throttle begin */ throttle_us_per_full =0 ;
@@ -3372,7 +3372,7 @@ static void test_migrate_dirty_limit(void) }/* Start migrate */ -migrate_qmp (from, to, args.connect_uri,"{}" ); +migrate_qmp (from, to, args.connect_uri,NULL ,"{}" );/* Wait for dirty limit throttle begin */ throttle_us_per_full =0 ;
Signature · 1 line
2.22.3
Re: [PATCH v6 6/8] Add channels parameter in migrate_qmp
Quoted 7 lines · Het Gala
Alter
migrate_qmp()to allow use of channels parameter, but only fill the uri with correct port number if there are no channels. Here we don't want to allow the wrong cases of having both or none (ex:migrate_qmp_fail).Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
PATCH v6 7/8 Add multifd_tcp_plain test using list of channels instead of uri
In reply to Het GalaAdd a positive test to check multifd live migration but this time using list of channels (restricted to 1) as the starting point instead of simple uri string.
--- tests/qtest/migration-test.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
tests/qtest/migration-test.c +27 -3
@@ -655,6 +655,13 @@ typedef struct {*/ const char *connect_uri; +/* +* Optional: JSON-formatted list of src QEMU URIs. If a port is +* defined as '0' in any QDict key a value of '0' will be +* automatically converted to the correct destination port. +*/ +const char *connect_channels; +/* Optional: callback to run at start to set migration parameters */ TestMigrateStartHook start_hook;/* Optional: callback to run at finish to cleanup */
@@ -2740,7 +2747,7 @@ test_migrate_precopy_tcp_multifd_zstd_start(QTestState *from, }#endif /* CONFIG_ZSTD */ -static void test_multifd_tcp_none (void ) +static void test_multifd_tcp_uri_none (void ) {MigrateCommon args = { .listen_uri ="defer" ,
@@ -2755,6 +2762,21 @@ static void test_multifd_tcp_none(void)test_precopy_common (&args); } +static void test_multifd_tcp_channels_none (void ) +{ +MigrateCommon args = { + .listen_uri ="defer" , + .start_hook = test_migrate_precopy_tcp_multifd_start, + .live = true, + .connect_channels ="[ { 'channel-type': 'main'," +" 'addr': { 'transport': 'socket'," +" 'type': 'inet'," +" 'host': '127.0.0.1'," +" 'port': '0' } } ]" , + }; +test_precopy_common (&args); +} +static void test_multifd_tcp_zlib (void ) {MigrateCommon args = {
@@ -3664,8 +3686,10 @@ int main(int argc, char **argv) test_migrate_dirty_limit); } } -migration_test_add ("/migration/multifd/tcp/plain/none" , - test_multifd_tcp_none); +migration_test_add ("/migration/multifd/tcp/uri/plain/none" , + test_multifd_tcp_uri_none); +migration_test_add ("/migration/multifd/tcp/channels/plain/none" , + test_multifd_tcp_channels_none);migration_test_add ("/migration/multifd/tcp/plain/cancel" , test_multifd_tcp_cancel); migration_test_add("/migration/multifd/tcp/plain/zlib",
Signature · 1 line
2.22.3
Re: [PATCH v6 7/8] Add multifd_tcp_plain test using list of channels instead of uri
Quoted 6 lines · Het Gala
Add a positive test to check multifd live migration but this time using list of channels (restricted to 1) as the starting point instead of simple uri string.
Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
PATCH v6 8/8 Add negative tests to validate migration QAPIs
In reply to Het GalaMigration QAPI arguments - uri and channels are mutually exhaustive. Add negative validation tests, one with both arguments present and one with none present.
--- tests/qtest/migration-test.c | 55 +++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
tests/qtest/migration-test.c +54 -1
@@ -1724,7 +1724,7 @@ static void test_precopy_common(MigrateCommon *args) }if (args->result ==MIG_TEST_QMP_ERROR ) { -migrate_qmp_fail (from, args->connect_uri,NULL ,"{}" ); +migrate_qmp_fail (from, args->connect_uri, args->connect_uri,"{}" ); goto finish; }
@@ -2608,6 +2608,55 @@ static void test_validate_uuid_dst_not_set(void)do_test_validate_uuid (&args, false); } +static void do_test_validate_uri_channel (MigrateCommon *args) +{ +QTestState *from, *to; + +if (test_migrate_start (&from, &to, args->listen_uri, &args->start)) { +return ; + } + +/* Wait for the first serial output from the source */ +wait_for_serial ("src_serial" ); + +/* +* 'uri' and 'channels' validation is checked even before the migration +* starts. +*/ +migrate_qmp_fail (from, args->connect_uri, args->connect_channels,"{}" ); +test_migrate_end (from, to, false); +} + +static void test_validate_uri_channels_both_set (void ) +{ +MigrateCommon args = { + .start = { + .hide_stderr = true, + }, + .listen_uri ="defer" , + .connect_uri ="tcp:127.0.0.1:0" , + .connect_channels ="[ { 'channel-type': 'main'," +" 'addr': { 'transport': 'socket'," +" 'type': 'inet'," +" 'host': '127.0.0.1'," +" 'port': '0' } } ]" , + }; + +do_test_validate_uri_channel (&args); +} + +static void test_validate_uri_channels_none_set (void ) +{ +MigrateCommon args = { + .start = { + .hide_stderr = true, + }, + .listen_uri ="defer" , + }; + +do_test_validate_uri_channel (&args); +} +/* * The way auto_converge works, we need to do too many passes to * run this test. Auto_converge logic is only run once every
@@ -3674,6 +3723,10 @@ int main(int argc, char **argv) test_validate_uuid_src_not_set);migration_test_add ("/migration/validate_uuid_dst_not_set" , test_validate_uuid_dst_not_set); +migration_test_add ("/migration/validate_uri/channels/both_set" , + test_validate_uri_channels_both_set); +migration_test_add ("/migration/validate_uri/channels/none_set" , + test_validate_uri_channels_none_set);/* * See explanation why this test is slow on function definition */
Signature · 1 line
2.22.3
Re: [PATCH v6 8/8] Add negative tests to validate migration QAPIs
Quoted 6 lines · Het Gala
Migration QAPI arguments - uri and channels are mutually exhaustive. Add negative validation tests, one with both arguments present and one with none present.
Signed-off-by Het Gala <[email protected]>Suggested-by Fabiano Rosas <[email protected]>
Het,
Could you rebase this to latest master?
Meanwhile, please provide a prefix in each of the subjects, it can be any of "tests/migration-test:", "tests/qtest/migration", "tests/migration", etc. I don't think we have a rule yet.. but any such prefix is still helpful.
Thanks,
Signature · 1 line
Peter Xu
Quoted 10 lines · Peter Xu
Het,
Could you rebase this to latest master?
Meanwhile, please provide a prefix in each of the subjects, it can be any of "tests/migration-test:", "tests/qtest/migration", "tests/migration", etc. I don't think we have a rule yet.. but any such prefix is still helpful.
Thanks,
Yes, sure Peter. Let me rebase it to latest master and also share the latest passed build link. Will add "tests/qtest/migration" prefix to all the commit message headers.
Regards,
Het Gala