From: "Michael S. Tsirkin" <mst@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Thomas Huth <thuth@redhat.com>,
Jens Freimann <jfreimann@redhat.com>,
qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>
Subject: Re: [PATCH v6 5/6] test/libqtest: add some virtio-net failover migration cancelling tests
Date: Wed, 8 Dec 2021 02:44:17 -0500 [thread overview]
Message-ID: <20211208024325-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20211206222040.3872253-6-lvivier@redhat.com>
On Mon, Dec 06, 2021 at 11:20:39PM +0100, Laurent Vivier wrote:
> Add some tests to check the state of the machine if the migration
> is cancelled while we are using virtio-net failover.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
So this one I think is needed for the release. Thomas, are you
merging it there or should I?
> ---
> tests/qtest/virtio-net-failover.c | 291 ++++++++++++++++++++++++++++++
> 1 file changed, 291 insertions(+)
>
> diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
> index c88f8ddec39a..57abb99e7f6e 100644
> --- a/tests/qtest/virtio-net-failover.c
> +++ b/tests/qtest/virtio-net-failover.c
> @@ -682,6 +682,289 @@ static void test_migrate_in(gconstpointer opaque)
> machine_stop(qts);
> }
>
> +static void test_migrate_abort_wait_unplug(gconstpointer opaque)
> +{
> + QTestState *qts;
> + QDict *resp, *args, *data, *ret;
> + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque);
> + const gchar *status;
> +
> + qts = machine_start(BASE_MACHINE
> + "-netdev user,id=hs0 "
> + "-netdev user,id=hs1 ",
> + 2);
> +
> + check_one_card(qts, false, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + qtest_qmp_device_add(qts, "virtio-net", "standby0",
> + "{'bus': 'root0',"
> + "'failover': 'on',"
> + "'netdev': 'hs0',"
> + "'mac': '"MAC_STANDBY0"'}");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + start_virtio_net(qts, 1, 0, "standby0");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + qtest_qmp_device_add(qts, "virtio-net", "primary0",
> + "{'bus': 'root1',"
> + "'failover_pair_id': 'standby0',"
> + "'netdev': 'hs1',"
> + "'rombar': 0,"
> + "'romfile': '',"
> + "'mac': '"MAC_PRIMARY0"'}");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, true, "primary0", MAC_PRIMARY0);
> +
> + args = qdict_from_jsonf_nofail("{}");
> + g_assert_nonnull(args);
> + qdict_put_str(args, "uri", uri);
> +
> + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args);
> + g_assert(qdict_haskey(resp, "return"));
> + qobject_unref(resp);
> +
> + /* the event is sent whan QEMU asks the OS to unplug the card */
> + resp = qtest_qmp_eventwait_ref(qts, "UNPLUG_PRIMARY");
> + g_assert(qdict_haskey(resp, "data"));
> +
> + data = qdict_get_qdict(resp, "data");
> + g_assert(qdict_haskey(data, "device-id"));
> + g_assert_cmpstr(qdict_get_str(data, "device-id"), ==, "primary0");
> +
> + qobject_unref(resp);
> +
> + resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }");
> + g_assert(qdict_haskey(resp, "return"));
> + qobject_unref(resp);
> +
> + /* migration has been cancelled while the unplug was in progress */
> +
> + /* while the card is not ejected, we must be in "cancelling" state */
> + ret = migrate_status(qts);
> +
> + status = qdict_get_str(ret, "status");
> + g_assert_cmpstr(status, ==, "cancelling");
> + qobject_unref(ret);
> +
> + /* OS unplugs the cards, QEMU can move from wait-unplug state */
> + qtest_outl(qts, ACPI_PCIHP_ADDR_ICH9 + PCI_EJ_BASE, 1);
> +
> + while (true) {
> + ret = migrate_status(qts);
> +
> + status = qdict_get_str(ret, "status");
> + if (strcmp(status, "cancelled") == 0) {
> + break;
> + }
> + g_assert_cmpstr(status, !=, "failed");
> + g_assert_cmpstr(status, !=, "active");
> + qobject_unref(ret);
> + }
> + qobject_unref(ret);
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, true, "primary0", MAC_PRIMARY0);
> +
> + machine_stop(qts);
> +}
> +
> +static void test_migrate_abort_active(gconstpointer opaque)
> +{
> + QTestState *qts;
> + QDict *resp, *args, *data, *ret;
> + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque);
> + const gchar *status;
> +
> + qts = machine_start(BASE_MACHINE
> + "-netdev user,id=hs0 "
> + "-netdev user,id=hs1 ",
> + 2);
> +
> + check_one_card(qts, false, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + qtest_qmp_device_add(qts, "virtio-net", "standby0",
> + "{'bus': 'root0',"
> + "'failover': 'on',"
> + "'netdev': 'hs0',"
> + "'mac': '"MAC_STANDBY0"'}");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + start_virtio_net(qts, 1, 0, "standby0");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + qtest_qmp_device_add(qts, "virtio-net", "primary0",
> + "{'bus': 'root1',"
> + "'failover_pair_id': 'standby0',"
> + "'netdev': 'hs1',"
> + "'rombar': 0,"
> + "'romfile': '',"
> + "'mac': '"MAC_PRIMARY0"'}");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, true, "primary0", MAC_PRIMARY0);
> +
> + args = qdict_from_jsonf_nofail("{}");
> + g_assert_nonnull(args);
> + qdict_put_str(args, "uri", uri);
> +
> + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args);
> + g_assert(qdict_haskey(resp, "return"));
> + qobject_unref(resp);
> +
> + /* the event is sent whan QEMU asks the OS to unplug the card */
> + resp = qtest_qmp_eventwait_ref(qts, "UNPLUG_PRIMARY");
> + g_assert(qdict_haskey(resp, "data"));
> +
> + data = qdict_get_qdict(resp, "data");
> + g_assert(qdict_haskey(data, "device-id"));
> + g_assert_cmpstr(qdict_get_str(data, "device-id"), ==, "primary0");
> +
> + qobject_unref(resp);
> +
> + /* OS unplugs the cards, QEMU can move from wait-unplug state */
> + qtest_outl(qts, ACPI_PCIHP_ADDR_ICH9 + PCI_EJ_BASE, 1);
> +
> + while (true) {
> + ret = migrate_status(qts);
> +
> + status = qdict_get_str(ret, "status");
> + if (strcmp(status, "wait-unplug") != 0) {
> + break;
> + }
> + g_assert_cmpstr(status, !=, "failed");
> + qobject_unref(ret);
> + }
> + qobject_unref(resp);
> +
> + resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }");
> + g_assert(qdict_haskey(resp, "return"));
> + qobject_unref(resp);
> +
> + while (true) {
> + ret = migrate_status(qts);
> +
> + status = qdict_get_str(ret, "status");
> + if (strcmp(status, "cancelled") == 0) {
> + break;
> + }
> + g_assert_cmpstr(status, !=, "failed");
> + g_assert_cmpstr(status, !=, "active");
> + qobject_unref(ret);
> + }
> + qobject_unref(ret);
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, true, "primary0", MAC_PRIMARY0);
> +
> + machine_stop(qts);
> +}
> +
> +static void test_migrate_abort_timeout(gconstpointer opaque)
> +{
> + QTestState *qts;
> + QDict *resp, *args, *data, *ret;
> + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque);
> + const gchar *status;
> + int total;
> +
> + qts = machine_start(BASE_MACHINE
> + "-netdev user,id=hs0 "
> + "-netdev user,id=hs1 ",
> + 2);
> +
> + check_one_card(qts, false, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + qtest_qmp_device_add(qts, "virtio-net", "standby0",
> + "{'bus': 'root0',"
> + "'failover': 'on',"
> + "'netdev': 'hs0',"
> + "'mac': '"MAC_STANDBY0"'}");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + start_virtio_net(qts, 1, 0, "standby0");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, false, "primary0", MAC_PRIMARY0);
> +
> + qtest_qmp_device_add(qts, "virtio-net", "primary0",
> + "{'bus': 'root1',"
> + "'failover_pair_id': 'standby0',"
> + "'netdev': 'hs1',"
> + "'rombar': 0,"
> + "'romfile': '',"
> + "'mac': '"MAC_PRIMARY0"'}");
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, true, "primary0", MAC_PRIMARY0);
> +
> + args = qdict_from_jsonf_nofail("{}");
> + g_assert_nonnull(args);
> + qdict_put_str(args, "uri", uri);
> +
> + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args);
> + g_assert(qdict_haskey(resp, "return"));
> + qobject_unref(resp);
> +
> + /* the event is sent whan QEMU asks the OS to unplug the card */
> + resp = qtest_qmp_eventwait_ref(qts, "UNPLUG_PRIMARY");
> + g_assert(qdict_haskey(resp, "data"));
> +
> + data = qdict_get_qdict(resp, "data");
> + g_assert(qdict_haskey(data, "device-id"));
> + g_assert_cmpstr(qdict_get_str(data, "device-id"), ==, "primary0");
> +
> + qobject_unref(resp);
> +
> + resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }");
> + g_assert(qdict_haskey(resp, "return"));
> + qobject_unref(resp);
> +
> + /* migration has been cancelled while the unplug was in progress */
> +
> + /* while the card is not ejected, we must be in "cancelling" state */
> +
> + total = 0;
> + while (true) {
> + ret = migrate_status(qts);
> +
> + status = qdict_get_str(ret, "status");
> + if (strcmp(status, "cancelled") == 0) {
> + break;
> + }
> + g_assert_cmpstr(status, ==, "cancelling");
> + g_assert(qdict_haskey(ret, "total-time"));
> + total = qdict_get_int(ret, "total-time");
> + qobject_unref(ret);
> + }
> + qobject_unref(ret);
> +
> + /*
> + * migration timeout in this case is 30 seconds
> + * check we exit on the timeout (ms)
> + */
> + g_assert_cmpint(total, >, 30000);
> +
> + check_one_card(qts, true, "standby0", MAC_STANDBY0);
> + check_one_card(qts, true, "primary0", MAC_PRIMARY0);
> +
> + machine_stop(qts);
> +}
> +
> int main(int argc, char **argv)
> {
> gchar *tmpfile = g_strdup_printf("/tmp/failover_test_migrate-%u-%u",
> @@ -714,6 +997,14 @@ int main(int argc, char **argv)
> test_migrate_out);
> qtest_add_data_func("failover-virtio-net/migrate/in", tmpfile,
> test_migrate_in);
> + qtest_add_data_func("failover-virtio-net/migrate/abort/wait-unplug",
> + tmpfile, test_migrate_abort_wait_unplug);
> + qtest_add_data_func("failover-virtio-net/migrate/abort/active", tmpfile,
> + test_migrate_abort_active);
> + if (g_test_slow()) {
> + qtest_add_data_func("failover-virtio-net/migrate/abort/timeout",
> + tmpfile, test_migrate_abort_timeout);
> + }
>
> ret = g_test_run();
>
> --
> 2.33.1
>
>
>
next prev parent reply other threads:[~2021-12-08 7:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-06 22:20 [PATCH v6 0/6] tests/qtest: add some tests for virtio-net failover Laurent Vivier
2021-12-06 22:20 ` [PATCH v6 1/6] qtest/libqos: add a function to initialize secondary PCI buses Laurent Vivier
2021-12-07 8:09 ` Thomas Huth
2021-12-06 22:20 ` [PATCH v6 2/6] tests/qtest: add some tests for virtio-net failover Laurent Vivier
2021-12-07 8:29 ` Thomas Huth
2021-12-06 22:20 ` [PATCH v6 3/6] failover: fix unplug pending detection Laurent Vivier
2021-12-07 4:13 ` Ani Sinha
2021-12-07 7:31 ` Laurent Vivier
2021-12-06 22:20 ` [PATCH v6 4/6] tests/libqtest: update virtio-net failover test Laurent Vivier
2021-12-07 8:33 ` Thomas Huth
2021-12-06 22:20 ` [PATCH v6 5/6] test/libqtest: add some virtio-net failover migration cancelling tests Laurent Vivier
2021-12-07 8:35 ` Thomas Huth
2021-12-08 7:44 ` Michael S. Tsirkin [this message]
2021-12-08 7:48 ` Thomas Huth
2021-12-08 7:53 ` Thomas Huth
2021-12-06 22:20 ` [PATCH v6 6/6] tests/libqtest: add a migration test with two couples of failover devices Laurent Vivier
2021-12-07 8:39 ` Thomas Huth
2021-12-08 7:44 ` [PATCH v6 0/6] tests/qtest: add some tests for virtio-net failover Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211208024325-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=jfreimann@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).