diff mbox series

[for-3.0,8/9] tests: add postcopy recovery test

Message ID 20180705031755.3254-9-peterx@redhat.com
State New
Headers show
Series migration: postcopy recovery unit test, bug fixes | expand

Commit Message

Peter Xu July 5, 2018, 3:17 a.m. UTC
Test the postcopy recovery procedure by emulating a network failure
using migrate-pause command.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tests/migration-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

Comments

Dr. David Alan Gilbert July 5, 2018, 10:30 a.m. UTC | #1
* Peter Xu (peterx@redhat.com) wrote:
> Test the postcopy recovery procedure by emulating a network failure
> using migrate-pause command.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>

OK, that's nice.


Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  tests/migration-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 71 insertions(+)
> 
> diff --git a/tests/migration-test.c b/tests/migration-test.c
> index 761bf62ffe..182fc88e93 100644
> --- a/tests/migration-test.c
> +++ b/tests/migration-test.c
> @@ -352,6 +352,29 @@ static void migrate_set_parameter(QTestState *who, const char *parameter,
>      migrate_check_parameter(who, parameter, value);
>  }
>  
> +static void migrate_pause(QTestState *who)
> +{
> +    QDict *rsp;
> +
> +    rsp = wait_command(who, "{ 'execute': 'migrate-pause' }");
> +    g_assert(qdict_haskey(rsp, "return"));
> +    qobject_unref(rsp);
> +}
> +
> +static void migrate_recover(QTestState *who, const char *uri)
> +{
> +    QDict *rsp;
> +    gchar *cmd = g_strdup_printf(
> +        "{ 'execute': 'migrate-recover', "
> +        "  'id': 'recover-cmd', "
> +        "  'arguments': { 'uri': '%s' } }", uri);
> +
> +    rsp = wait_command(who, cmd);
> +    g_assert(qdict_haskey(rsp, "return"));
> +    g_free(cmd);
> +    qobject_unref(rsp);
> +}
> +
>  static void migrate_set_capability(QTestState *who, const char *capability,
>                                     const char *value)
>  {
> @@ -597,6 +620,53 @@ static void test_postcopy(void)
>      migrate_postcopy_complete(from, to);
>  }
>  
> +static void test_postcopy_recovery(void)
> +{
> +    QTestState *from, *to;
> +    char *uri;
> +
> +    migrate_postcopy_prepare(&from, &to);
> +
> +    /* Turn postcopy speed down, 4K/s is slow enough on any machines */
> +    migrate_set_parameter(from, "max-postcopy-bandwidth", "4096");
> +
> +    /* Now we start the postcopy */
> +    migrate_postcopy_start(from, to);
> +
> +    /*
> +     * Wait until postcopy is really started; we can only run the
> +     * migrate-pause command during a postcopy
> +     */
> +    wait_for_migration_status(from, "postcopy-active");
> +
> +    /*
> +     * Manually stop the postcopy migration. This emulates a network
> +     * failure with the migration socket
> +     */
> +    migrate_pause(from);
> +
> +    /*
> +     * Create a new socket to emulate a new channel that is different
> +     * from the broken migration channel; tell the destination to
> +     * listen to the new port
> +     */
> +    uri = g_strdup_printf("unix:%s/migsocket-recover", tmpfs);
> +    migrate_recover(to, uri);
> +
> +    /*
> +     * Try to rebuild the migration channel using the resume flag and
> +     * the newly created channel
> +     */
> +    wait_for_migration_status(from, "postcopy-paused");
> +    migrate(from, uri, ", 'resume': true");
> +    g_free(uri);
> +
> +    /* Restore the postcopy bandwidth to unlimited */
> +    migrate_set_parameter(from, "max-postcopy-bandwidth", "0");
> +
> +    migrate_postcopy_complete(from, to);
> +}
> +
>  static void test_baddest(void)
>  {
>      QTestState *from, *to;
> @@ -683,6 +753,7 @@ int main(int argc, char **argv)
>      module_call_init(MODULE_INIT_QOM);
>  
>      qtest_add_func("/migration/postcopy/unix", test_postcopy);
> +    qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery);
>      qtest_add_func("/migration/deprecated", test_deprecated);
>      qtest_add_func("/migration/bad_dest", test_baddest);
>      qtest_add_func("/migration/precopy/unix", test_precopy_unix);
> -- 
> 2.17.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Juan Quintela July 5, 2018, 1:08 p.m. UTC | #2
Peter Xu <peterx@redhat.com> wrote:
> Test the postcopy recovery procedure by emulating a network failure
> using migrate-pause command.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
diff mbox series

Patch

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 761bf62ffe..182fc88e93 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -352,6 +352,29 @@  static void migrate_set_parameter(QTestState *who, const char *parameter,
     migrate_check_parameter(who, parameter, value);
 }
 
+static void migrate_pause(QTestState *who)
+{
+    QDict *rsp;
+
+    rsp = wait_command(who, "{ 'execute': 'migrate-pause' }");
+    g_assert(qdict_haskey(rsp, "return"));
+    qobject_unref(rsp);
+}
+
+static void migrate_recover(QTestState *who, const char *uri)
+{
+    QDict *rsp;
+    gchar *cmd = g_strdup_printf(
+        "{ 'execute': 'migrate-recover', "
+        "  'id': 'recover-cmd', "
+        "  'arguments': { 'uri': '%s' } }", uri);
+
+    rsp = wait_command(who, cmd);
+    g_assert(qdict_haskey(rsp, "return"));
+    g_free(cmd);
+    qobject_unref(rsp);
+}
+
 static void migrate_set_capability(QTestState *who, const char *capability,
                                    const char *value)
 {
@@ -597,6 +620,53 @@  static void test_postcopy(void)
     migrate_postcopy_complete(from, to);
 }
 
+static void test_postcopy_recovery(void)
+{
+    QTestState *from, *to;
+    char *uri;
+
+    migrate_postcopy_prepare(&from, &to);
+
+    /* Turn postcopy speed down, 4K/s is slow enough on any machines */
+    migrate_set_parameter(from, "max-postcopy-bandwidth", "4096");
+
+    /* Now we start the postcopy */
+    migrate_postcopy_start(from, to);
+
+    /*
+     * Wait until postcopy is really started; we can only run the
+     * migrate-pause command during a postcopy
+     */
+    wait_for_migration_status(from, "postcopy-active");
+
+    /*
+     * Manually stop the postcopy migration. This emulates a network
+     * failure with the migration socket
+     */
+    migrate_pause(from);
+
+    /*
+     * Create a new socket to emulate a new channel that is different
+     * from the broken migration channel; tell the destination to
+     * listen to the new port
+     */
+    uri = g_strdup_printf("unix:%s/migsocket-recover", tmpfs);
+    migrate_recover(to, uri);
+
+    /*
+     * Try to rebuild the migration channel using the resume flag and
+     * the newly created channel
+     */
+    wait_for_migration_status(from, "postcopy-paused");
+    migrate(from, uri, ", 'resume': true");
+    g_free(uri);
+
+    /* Restore the postcopy bandwidth to unlimited */
+    migrate_set_parameter(from, "max-postcopy-bandwidth", "0");
+
+    migrate_postcopy_complete(from, to);
+}
+
 static void test_baddest(void)
 {
     QTestState *from, *to;
@@ -683,6 +753,7 @@  int main(int argc, char **argv)
     module_call_init(MODULE_INIT_QOM);
 
     qtest_add_func("/migration/postcopy/unix", test_postcopy);
+    qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery);
     qtest_add_func("/migration/deprecated", test_deprecated);
     qtest_add_func("/migration/bad_dest", test_baddest);
     qtest_add_func("/migration/precopy/unix", test_precopy_unix);