diff mbox series

[3/6] tests/qtest: migration: Add migrate_incoming_qmp helper

Message ID 20230628165542.17214-4-farosas@suse.de
State New
Headers show
Series migration: Test the new "file:" migration | expand

Commit Message

Fabiano Rosas June 28, 2023, 4:55 p.m. UTC
file-based migration requires the target to initiate its migration after
the source has finished writing out the data in the file. Currently
there's no easy way to initiate 'migrate-incoming', allow this by
introducing migrate_incoming_qmp helper, similarly to migrate_qmp.

Also make sure migration events are enabled and wait for the incoming
migration to start before returning. This avoid a race when querying
the migration status too soon after issuing the command.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 tests/qtest/migration-helpers.c | 28 ++++++++++++++++++++++++++++
 tests/qtest/migration-helpers.h |  4 ++++
 2 files changed, 32 insertions(+)

Comments

Peter Xu June 29, 2023, 9:16 p.m. UTC | #1
On Wed, Jun 28, 2023 at 01:55:39PM -0300, Fabiano Rosas wrote:
> file-based migration requires the target to initiate its migration after
> the source has finished writing out the data in the file. Currently
> there's no easy way to initiate 'migrate-incoming', allow this by
> introducing migrate_incoming_qmp helper, similarly to migrate_qmp.
> 
> Also make sure migration events are enabled and wait for the incoming
> migration to start before returning. This avoid a race when querying
> the migration status too soon after issuing the command.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>  tests/qtest/migration-helpers.c | 28 ++++++++++++++++++++++++++++
>  tests/qtest/migration-helpers.h |  4 ++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
> index 2df198c99e..bc54b29184 100644
> --- a/tests/qtest/migration-helpers.c
> +++ b/tests/qtest/migration-helpers.c
> @@ -81,6 +81,34 @@ void migrate_set_capability(QTestState *who, const char *capability,
>                               capability, value);
>  }
>  
> +void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
> +{
> +    va_list ap;
> +    QDict *args, *rsp, *data;
> +
> +    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);
> +
> +    migrate_set_capability(to, "events", true);
> +
> +    rsp = qtest_qmp(to, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
> +                    args);
> +    g_assert(qdict_haskey(rsp, "return"));

rsp leaked?

> +
> +    rsp = qtest_qmp_eventwait_ref(to, "MIGRATION");
> +    g_assert(qdict_haskey(rsp, "data"));
> +
> +    data = qdict_get_qdict(rsp, "data");
> +    g_assert(qdict_haskey(data, "status"));
> +    g_assert_cmpstr(qdict_get_str(data, "status"), ==, "setup");
> +
> +    qobject_unref(rsp);
> +}
> +
>  /*
>   * Note: caller is responsible to free the returned object via
>   * qobject_unref() after use
> diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
> index 484d7c960f..57d295a4fe 100644
> --- a/tests/qtest/migration-helpers.h
> +++ b/tests/qtest/migration-helpers.h
> @@ -23,6 +23,10 @@ bool migrate_watch_for_resume(QTestState *who, const char *name,
>  G_GNUC_PRINTF(3, 4)
>  void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...);
>  
> +G_GNUC_PRINTF(3, 4)
> +void migrate_incoming_qmp(QTestState *who, const char *uri,
> +                          const char *fmt, ...);
> +
>  void migrate_set_capability(QTestState *who, const char *capability,
>                              bool value);
>  
> -- 
> 2.35.3
>
Fabiano Rosas June 30, 2023, 2:57 p.m. UTC | #2
Peter Xu <peterx@redhat.com> writes:

> On Wed, Jun 28, 2023 at 01:55:39PM -0300, Fabiano Rosas wrote:
>> file-based migration requires the target to initiate its migration after
>> the source has finished writing out the data in the file. Currently
>> there's no easy way to initiate 'migrate-incoming', allow this by
>> introducing migrate_incoming_qmp helper, similarly to migrate_qmp.
>> 
>> Also make sure migration events are enabled and wait for the incoming
>> migration to start before returning. This avoid a race when querying
>> the migration status too soon after issuing the command.
>> 
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>>  tests/qtest/migration-helpers.c | 28 ++++++++++++++++++++++++++++
>>  tests/qtest/migration-helpers.h |  4 ++++
>>  2 files changed, 32 insertions(+)
>> 
>> diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
>> index 2df198c99e..bc54b29184 100644
>> --- a/tests/qtest/migration-helpers.c
>> +++ b/tests/qtest/migration-helpers.c
>> @@ -81,6 +81,34 @@ void migrate_set_capability(QTestState *who, const char *capability,
>>                               capability, value);
>>  }
>>  
>> +void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
>> +{
>> +    va_list ap;
>> +    QDict *args, *rsp, *data;
>> +
>> +    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);
>> +
>> +    migrate_set_capability(to, "events", true);
>> +
>> +    rsp = qtest_qmp(to, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
>> +                    args);
>> +    g_assert(qdict_haskey(rsp, "return"));
>
> rsp leaked?
>

Good catch. I'll fix it.
diff mbox series

Patch

diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index 2df198c99e..bc54b29184 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -81,6 +81,34 @@  void migrate_set_capability(QTestState *who, const char *capability,
                              capability, value);
 }
 
+void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
+{
+    va_list ap;
+    QDict *args, *rsp, *data;
+
+    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);
+
+    migrate_set_capability(to, "events", true);
+
+    rsp = qtest_qmp(to, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
+                    args);
+    g_assert(qdict_haskey(rsp, "return"));
+
+    rsp = qtest_qmp_eventwait_ref(to, "MIGRATION");
+    g_assert(qdict_haskey(rsp, "data"));
+
+    data = qdict_get_qdict(rsp, "data");
+    g_assert(qdict_haskey(data, "status"));
+    g_assert_cmpstr(qdict_get_str(data, "status"), ==, "setup");
+
+    qobject_unref(rsp);
+}
+
 /*
  * Note: caller is responsible to free the returned object via
  * qobject_unref() after use
diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 484d7c960f..57d295a4fe 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -23,6 +23,10 @@  bool migrate_watch_for_resume(QTestState *who, const char *name,
 G_GNUC_PRINTF(3, 4)
 void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...);
 
+G_GNUC_PRINTF(3, 4)
+void migrate_incoming_qmp(QTestState *who, const char *uri,
+                          const char *fmt, ...);
+
 void migrate_set_capability(QTestState *who, const char *capability,
                             bool value);