Skip to contentSkip to conversation

tests/functional: Fix ppc64 issue with make -j

PATCH Superseded Fabiano Rosas 2 participants 6 messages Jan 28 PowerPC

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover tests/functional: Fix ppc64 issue with make -j

As reported in [1], running the ppc64 functional tests in parallel is currently broken due to one test importing another and causing unittest.main to instantiate the imported test twice. Fix by removing the dependency between tests.

1- https://lore.kernel.org/r/[email protected]
CI run: https://gitlab.com/farosas/qemu/-/pipelines/2289828999

Fabiano Rosas (3):
tests/functional/migration: Use socket_dir tests/functional/migration: Accept vm objects in do_migrate tests/functional/ppc64: Remove custom migration routine

 tests/functional/migration.py            | 31 ++++++++++++++----------
 tests/functional/ppc64/test_migration.py | 11 ---------
 tests/functional/ppc64/test_pseries.py   |  6 +++--
 3 files changed, 22 insertions(+), 26 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/3 tests/functional/migration: Use socket_dir

Use QemuBaseTest.socket_dir instead of calling tempfile directly so all tests have consistent directory prefixes.

---
 tests/functional/migration.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tests/functional/migration.py +2 -4
index 2bfb1f7790..0aa873edba 100644
@@ -11,7 +11,6 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or
 # later.  See the COPYING file in the top-level directory.
 
-import tempfile
 import time
 
 from qemu_test import QemuSystemTest, which
@@ -65,9 +64,8 @@ def migration_with_tcp_localhost(self):
             self.do_migrate(dest_uri)
 
     def migration_with_unix(self):
-        with tempfile.TemporaryDirectory(prefix='socket_') as socket_path:
-            dest_uri = 'unix:%s/qemu-test.sock' % socket_path
-            self.do_migrate(dest_uri)
+        dest_uri = 'unix:%s/migration.sock' % self.socket_dir().name
+        self.do_migrate(dest_uri)
 
     def migration_with_exec(self):
         if not which('ncat'):
Signature · 1 line
2.51.0
#3 lore raw

PATCH 2/3 tests/functional/migration: Accept vm objects in do_migrate

In reply to Fabiano Rosas

Allow MigrationTest.do_migrate() to receive objects for virtual machines already created. This will allow MigrationTest to provide the migration functionality for tests that are defined in a separate module and require extra setup (e.g. arch-specific) to the virtual machines before migration.

The next patches will instantiate MigrationTest from another test class.

---
 tests/functional/migration.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
tests/functional/migration.py +14 -7
index 0aa873edba..ac6feeeefb 100644
@@ -40,15 +40,22 @@ def assert_migration(self, src_vm, dst_vm):
         self.assertEqual(dst_vm.cmd('query-status')['status'], 'running')
         self.assertEqual(src_vm.cmd('query-status')['status'],'postmigrate')
 
-    def do_migrate(self, dest_uri, src_uri=None):
-        dest_vm = self.get_vm('-incoming', dest_uri, name="dest-qemu")
-        dest_vm.add_args('-nodefaults')
-        dest_vm.launch()
+    def do_migrate(self, dest_uri, src_uri=None, source_vm=None, dest_vm=None):
+        if dest_vm:
+            dest_vm.qmp('migrate-incoming', uri=dest_uri)
+        else:
+            dest_vm = self.get_vm('-incoming', dest_uri, name="dest-qemu")
+            dest_vm.add_args('-nodefaults')
+            dest_vm.launch()
+
+        if not source_vm:
+            source_vm = self.get_vm(name="source-qemu")
+            source_vm.add_args('-nodefaults')
+            source_vm.launch()
+
         if src_uri is None:
             src_uri = dest_uri
-        source_vm = self.get_vm(name="source-qemu")
-        source_vm.add_args('-nodefaults')
-        source_vm.launch()
+
         source_vm.qmp('migrate', uri=src_uri)
         self.assert_migration(source_vm, dest_vm)
 
Signature · 1 line
2.51.0
#4 lore raw

Re: [PATCH 2/3] tests/functional/migration: Accept vm objects in do_migrate

Quoted 19 lines · Fabiano Rosas

Allow MigrationTest.do_migrate() to receive objects for virtual machines already created. This will allow MigrationTest to provide the migration functionality for tests that are defined in a separate module and require extra setup (e.g. arch-specific) to the virtual machines before migration.

The next patches will instantiate MigrationTest from another test class.

---
 tests/functional/migration.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
tests/functional/migration.py +0 -0
index 0aa873edba..ac6feeeefb 100644

tests/functional/migration.py def assert_migration(self, src_vm, dst_vm): · line 43

Quoted 8 lines
tests/functional/migration.py +1 -4
@@ -40,15 +40,22 @@ def assert_migration(self, src_vm, dst_vm):
         self.assertEqual(dst_vm.cmd('query-status')['status'], 'running')
         self.assertEqual(src_vm.cmd('query-status')['status'],'postmigrate')
 
-    def do_migrate(self, dest_uri, src_uri=None):
-        dest_vm = self.get_vm('-incoming', dest_uri, name="dest-qemu")
-        dest_vm.add_args('-nodefaults')
-        dest_vm.launch()
+    def do_migrate(self, dest_uri, src_uri=None, source_vm=None, dest_vm=None):

Nit: maybe good to always have dst, then src, or vice versa.

tests/functional/migration.py def assert_migration(self, src_vm, dst_vm): · line 49

Quoted 6 lines
tests/functional/migration.py +6 -0
+        if dest_vm:
+            dest_vm.qmp('migrate-incoming', uri=dest_uri)
+        else:
+            dest_vm = self.get_vm('-incoming', dest_uri, name="dest-qemu")
+            dest_vm.add_args('-nodefaults')
+            dest_vm.launch()

Maybe this is a chance to switch to -incoming defer and always use "migrate-incoming" QMP?

Then we can have _do_migrate() (or some better name..) do the real migration commands, always taking VMs + URIs, making do_migrate() only create two VMs and pass it over.

Quoted 18 lines
tests/functional/migration.py +7 -3
+
+        if not source_vm:
+            source_vm = self.get_vm(name="source-qemu")
+            source_vm.add_args('-nodefaults')
+            source_vm.launch()
+
         if src_uri is None:
             src_uri = dest_uri
-        source_vm = self.get_vm(name="source-qemu")
-        source_vm.add_args('-nodefaults')
-        source_vm.launch()
+
         source_vm.qmp('migrate', uri=src_uri)
         self.assert_migration(source_vm, dest_vm)
 
Signature · 1 line
2.51.0
Signature · 1 line
Peter Xu
#5 lore raw

PATCH 3/3 tests/functional/ppc64: Remove custom migration routine

In reply to Fabiano Rosas

Don't implement a custom migration routine at PpcMigrationTest and instead reuse the generic one from MigrationTest.

This removes the dependency of PpcMigrationTest from PseriesMachine. Having one test import another causes unittest code to instantiate the imported test, resulting in the setup and teardown methods being invoked for the imported test class, even if no test from that class will be executed.

If run in parallel, the extra setup/teardown methods that result from importing can race with the ones from the actual test being executed and cause the following error:

File "<SRC_DIR>/tests/functional/qemu_test/testcase.py", line 238, in tearDown shutil.rmtree(self.workdir)
...
FileNotFoundError: [Errno 2] No such file or directory:
'<SRC_DIR>/build/tests/functional/ppc64/.../test_migration_with_exec/scratch'

Fixes f4e34d0fd5 ("tests/functional: Add a OS level migration test for pseries")
---
 tests/functional/migration.py            |  4 ++--
 tests/functional/ppc64/test_migration.py | 11 -----------
 tests/functional/ppc64/test_pseries.py   |  6 ++++--
 3 files changed, 6 insertions(+), 15 deletions(-)
tests/functional/migration.py +2 -2
index ac6feeeefb..008be67d3f 100644
@@ -65,10 +65,10 @@ def _get_free_port(self, ports):
             self.skipTest('Failed to find a free port')
         return port
 
-    def migration_with_tcp_localhost(self):
+    def migration_with_tcp_localhost(self, src_vm=None, dst_vm=None):
         with Ports() as ports:
             dest_uri = 'tcp:localhost:%u' % self._get_free_port(ports)
-            self.do_migrate(dest_uri)
+            self.do_migrate(dest_uri, source_vm=src_vm, dest_vm=dst_vm)
 
     def migration_with_unix(self):
         dest_uri = 'unix:%s/migration.sock' % self.socket_dir().name
tests/functional/ppc64/test_migration.py +0 -11
index a3b819680b..7d49ee175b 100755
@@ -22,17 +22,6 @@ def test_migration_with_exec(self):
         self.set_machine('mac99')
         self.migration_with_exec()
 
-    def do_migrate_ppc64_linux(self, source_vm, dest_vm):
-        with Ports() as ports:
-            port = ports.find_free_port()
-            if port is None:
-                self.skipTest('Failed to find a free port')
-            uri = 'tcp:localhost:%u' % port
-
-            dest_vm.qmp('migrate-incoming', uri=uri)
-            source_vm.qmp('migrate', uri=uri)
-            self.assert_migration(source_vm, dest_vm)
-
 
 if __name__ == '__main__':
     MigrationTest.main()
tests/functional/ppc64/test_pseries.py +4 -2
index b45763c305..368c85762e 100755
@@ -9,7 +9,7 @@
 
 from qemu_test import QemuSystemTest, Asset
 from qemu_test import wait_for_console_pattern
-from test_migration import PpcMigrationTest
+from migration import MigrationTest
 
 class PseriesMachine(QemuSystemTest):
 
@@ -116,7 +116,9 @@ def test_ppc64_linux_migration(self):
         wait_for_console_pattern(self, console_pattern, self.panic_message,
                                  vm=source_vm)
 
-        PpcMigrationTest().do_migrate_ppc64_linux(source_vm, dest_vm);
+        mt = MigrationTest()
+        mt.timeout = self.timeout
+        mt.migration_with_tcp_localhost(source_vm, dest_vm);
 
         # ensure the boot proceeds after migration
         wait_for_console_pattern(self, self.good_message, self.panic_message,
Signature · 1 line
2.51.0