ddf19c
From d6df1426ae65b3a0d50bdbb1f8a7246386dd6ebf Mon Sep 17 00:00:00 2001
ddf19c
From: Kevin Wolf <kwolf@redhat.com>
ddf19c
Date: Fri, 7 Feb 2020 11:24:04 +0000
ddf19c
Subject: [PATCH 07/18] iotests.py: Let wait_migration wait even more
ddf19c
ddf19c
RH-Author: Kevin Wolf <kwolf@redhat.com>
ddf19c
Message-id: <20200207112404.25198-7-kwolf@redhat.com>
ddf19c
Patchwork-id: 93751
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 6/6] iotests.py: Let wait_migration wait even more
ddf19c
Bugzilla: 1781637
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
From: Max Reitz <mreitz@redhat.com>
ddf19c
ddf19c
The "migration completed" event may be sent (on the source, to be
ddf19c
specific) before the migration is actually completed, so the VM runstate
ddf19c
will still be "finish-migrate" instead of "postmigrate".  So ask the
ddf19c
users of VM.wait_migration() to specify the final runstate they desire
ddf19c
and then poll the VM until it has reached that state.  (This should be
ddf19c
over very quickly, so busy polling is fine.)
ddf19c
ddf19c
Without this patch, I see intermittent failures in the new iotest 280
ddf19c
under high system load.  I have not yet seen such failures with other
ddf19c
iotests that use VM.wait_migration() and query-status afterwards, but
ddf19c
maybe they just occur even more rarely, or it is because they also wait
ddf19c
on the destination VM to be running.
ddf19c
ddf19c
Signed-off-by: Max Reitz <mreitz@redhat.com>
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit 8da7969bd7014f6de037d8ae132b40721944b186)
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 tests/qemu-iotests/234        | 8 ++++----
ddf19c
 tests/qemu-iotests/262        | 4 ++--
ddf19c
 tests/qemu-iotests/280        | 2 +-
ddf19c
 tests/qemu-iotests/iotests.py | 6 +++++-
ddf19c
 4 files changed, 12 insertions(+), 8 deletions(-)
ddf19c
ddf19c
diff --git a/tests/qemu-iotests/234 b/tests/qemu-iotests/234
ddf19c
index 34c818c..59a7f94 100755
ddf19c
--- a/tests/qemu-iotests/234
ddf19c
+++ b/tests/qemu-iotests/234
ddf19c
@@ -69,9 +69,9 @@ with iotests.FilePath('img') as img_path, \
ddf19c
     iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo_a)))
ddf19c
     with iotests.Timeout(3, 'Migration does not complete'):
ddf19c
         # Wait for the source first (which includes setup=setup)
ddf19c
-        vm_a.wait_migration()
ddf19c
+        vm_a.wait_migration('postmigrate')
ddf19c
         # Wait for the destination second (which does not)
ddf19c
-        vm_b.wait_migration()
ddf19c
+        vm_b.wait_migration('running')
ddf19c
 
ddf19c
     iotests.log(vm_a.qmp('query-migrate')['return']['status'])
ddf19c
     iotests.log(vm_b.qmp('query-migrate')['return']['status'])
ddf19c
@@ -98,9 +98,9 @@ with iotests.FilePath('img') as img_path, \
ddf19c
     iotests.log(vm_b.qmp('migrate', uri='exec:cat >%s' % (fifo_b)))
ddf19c
     with iotests.Timeout(3, 'Migration does not complete'):
ddf19c
         # Wait for the source first (which includes setup=setup)
ddf19c
-        vm_b.wait_migration()
ddf19c
+        vm_b.wait_migration('postmigrate')
ddf19c
         # Wait for the destination second (which does not)
ddf19c
-        vm_a.wait_migration()
ddf19c
+        vm_a.wait_migration('running')
ddf19c
 
ddf19c
     iotests.log(vm_a.qmp('query-migrate')['return']['status'])
ddf19c
     iotests.log(vm_b.qmp('query-migrate')['return']['status'])
ddf19c
diff --git a/tests/qemu-iotests/262 b/tests/qemu-iotests/262
ddf19c
index 0963daa..bbcb526 100755
ddf19c
--- a/tests/qemu-iotests/262
ddf19c
+++ b/tests/qemu-iotests/262
ddf19c
@@ -71,9 +71,9 @@ with iotests.FilePath('img') as img_path, \
ddf19c
     iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo)))
ddf19c
     with iotests.Timeout(3, 'Migration does not complete'):
ddf19c
         # Wait for the source first (which includes setup=setup)
ddf19c
-        vm_a.wait_migration()
ddf19c
+        vm_a.wait_migration('postmigrate')
ddf19c
         # Wait for the destination second (which does not)
ddf19c
-        vm_b.wait_migration()
ddf19c
+        vm_b.wait_migration('running')
ddf19c
 
ddf19c
     iotests.log(vm_a.qmp('query-migrate')['return']['status'])
ddf19c
     iotests.log(vm_b.qmp('query-migrate')['return']['status'])
ddf19c
diff --git a/tests/qemu-iotests/280 b/tests/qemu-iotests/280
ddf19c
index 0b1fa8e..85e9114 100755
ddf19c
--- a/tests/qemu-iotests/280
ddf19c
+++ b/tests/qemu-iotests/280
ddf19c
@@ -45,7 +45,7 @@ with iotests.FilePath('base') as base_path , \
ddf19c
     vm.qmp_log('migrate', uri='exec:cat > /dev/null')
ddf19c
 
ddf19c
     with iotests.Timeout(3, 'Migration does not complete'):
ddf19c
-        vm.wait_migration()
ddf19c
+        vm.wait_migration('postmigrate')
ddf19c
 
ddf19c
     iotests.log('\nVM is now stopped:')
ddf19c
     iotests.log(vm.qmp('query-migrate')['return']['status'])
ddf19c
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
ddf19c
index 5741efb..0c55f7b 100644
ddf19c
--- a/tests/qemu-iotests/iotests.py
ddf19c
+++ b/tests/qemu-iotests/iotests.py
ddf19c
@@ -663,12 +663,16 @@ class VM(qtest.QEMUQtestMachine):
ddf19c
             }
ddf19c
         ]))
ddf19c
 
ddf19c
-    def wait_migration(self):
ddf19c
+    def wait_migration(self, expect_runstate):
ddf19c
         while True:
ddf19c
             event = self.event_wait('MIGRATION')
ddf19c
             log(event, filters=[filter_qmp_event])
ddf19c
             if event['data']['status'] == 'completed':
ddf19c
                 break
ddf19c
+        # The event may occur in finish-migrate, so wait for the expected
ddf19c
+        # post-migration runstate
ddf19c
+        while self.qmp('query-status')['return']['status'] != expect_runstate:
ddf19c
+            pass
ddf19c
 
ddf19c
     def node_info(self, node_name):
ddf19c
         nodes = self.qmp('query-named-block-nodes')
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c