Snapshots are refused whenever a CPR migration mode is set. Add a test which sets each of the CPR modes in turn and checks that 'savevm' and 'loadvm' fail with the corresponding error, then switches back to 'normal' mode and checks that the error is gone.
Reviewed-by: Peter Xu <[email protected]> Signed-off-by: Andrey Drobyshev <[email protected]> --- tests/qtest/migration/cpr-tests.c | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/qtest/migration/cpr-tests.c b/tests/qtest/migration/cpr-tests.c index 0bec753b4ab..05c2ac1336d 100644 --- a/tests/qtest/migration/cpr-tests.c +++ b/tests/qtest/migration/cpr-tests.c @@ -290,6 +290,44 @@ static void test_mode_exec(char *name, MigrateCommon *args) test_cpr_exec(args); } +/* Snapshots must be refused while a CPR migration mode is set */ +static void test_mode_no_snapshot(char *name, MigrateCommon *args) +{ + static const char *const modes[] = { + "cpr-reboot", "cpr-transfer", "cpr-exec", + }; + QTestState *vm = qtest_init("-nodefaults -machine none"); + char *out; + int i; + + for (i = 0; i < ARRAY_SIZE(modes); i++) { + g_autofree char *expected = g_strdup_printf( + "Snapshots are not compatible with migration mode %s", modes[i]); + + migrate_set_parameter_str(vm, "mode", modes[i]); + + out = qtest_hmp(vm, "savevm snap"); + g_assert_nonnull(strstr(out, expected)); + g_free(out); + + out = qtest_hmp(vm, "loadvm snap"); + g_assert_nonnull(strstr(out, expected)); + g_free(out); + } + + /* + * The check should no longer fire in normal mode. savevm still fails + * (there's no block device for storing the snapshot). We just check + * that it's not the mode error any more. + */ + migrate_set_parameter_str(vm, "mode", "normal"); + out = qtest_hmp(vm, "savevm snap"); + g_assert_null(strstr(out, "not compatible with migration mode")); + g_free(out); + + qtest_quit(vm); +} + void migration_test_add_cpr(MigrationTestEnv *env) { tmpfs = env->tmpfs; @@ -300,6 +338,8 @@ void migration_test_add_cpr(MigrationTestEnv *env) return; } + migration_test_add("/migration/mode/no-snapshot", test_mode_no_snapshot); + /* * Our CI system has problems with shared memory. * Don't run this test until we find a workaround. -- 2.47.1
