Skip to contentSkip to conversation

tests/functional: Fix ppc64 issue with make -j

PATCH In review Fabiano Rosas 3 participants 7 messages Mar 3 PowerPC

lore
Share & tools
lore
#0 lore raw

v4 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/2361425606

v3:
https://lore.kernel.org/r/[email protected]
v2:
https://lore.kernel.org/r/[email protected]
v1:
https://lore.kernel.org/r/[email protected]

Fabiano Rosas (4):
tests/functional/migration: Use socket_dir tests/functional/migration: Add migrate_vms tests/functional/migration: Use the migrate_vms helper tests/functional/ppc64/pseries: Remove custom migration routine

 tests/functional/migration.py            | 46 ++++++++++++++----------
 tests/functional/ppc64/test_migration.py | 11 ------
 tests/functional/ppc64/test_pseries.py   | 10 +++---
 3 files changed, 33 insertions(+), 34 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v4 1/4 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
#2 lore raw

PATCH v4 2/4 tests/functional/migration: Add migrate_vms

In reply to Fabiano Rosas

Add a migration helper to MigrationTest that uses the migrate-incoming QMP commmand and takes the already instantiated VMs. The -incoming 'defer' command line option is preferred way instead of the -incoming URI syntax that's currently used.

---
 tests/functional/migration.py | 5 +++++
 1 file changed, 5 insertions(+)
tests/functional/migration.py +5 -0
index 0aa873edba..3362e5c743 100644
@@ -40,6 +40,11 @@ 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 migrate_vms(self, dst_uri, src_uri, dst_vm, src_vm):
+        dst_vm.qmp('migrate-incoming', uri=dst_uri)
+        src_vm.qmp('migrate', uri=src_uri)
+        self.assert_migration(src_vm, dst_vm)
+
     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')
Signature · 1 line
2.51.0
#3 lore raw

PATCH v4 3/4 tests/functional/migration: Use the migrate_vms helper

In reply to Fabiano Rosas

Change do_migrate() to call the migrate_vms() helper and provide it with the two VMs already created. Rename do_migrate -> migrate and adjust the callers.

While here, standardize on the "src" and "dst" names.

---
 tests/functional/migration.py | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
tests/functional/migration.py +18 -16
index 3362e5c743..49347a30bb 100644
@@ -45,17 +45,19 @@ def migrate_vms(self, dst_uri, src_uri, dst_vm, src_vm):
         src_vm.qmp('migrate', uri=src_uri)
         self.assert_migration(src_vm, dst_vm)
 
-    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 migrate(self, dst_uri, src_uri=None):
+        dst_vm = self.get_vm('-incoming', 'defer', name="dst-qemu")
+        dst_vm.add_args('-nodefaults')
+        dst_vm.launch()
+
+        src_vm = self.get_vm(name="src-qemu")
+        src_vm.add_args('-nodefaults')
+        src_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)
+            src_uri = dst_uri
+
+        self.migrate_vms(dst_uri, src_uri, dst_vm, src_vm)
 
     def _get_free_port(self, ports):
         port = ports.find_free_port()
@@ -65,18 +67,18 @@ def _get_free_port(self, ports):
 
     def migration_with_tcp_localhost(self):
         with Ports() as ports:
-            dest_uri = 'tcp:localhost:%u' % self._get_free_port(ports)
-            self.do_migrate(dest_uri)
+            dst_uri = 'tcp:localhost:%u' % self._get_free_port(ports)
+            self.migrate(dst_uri)
 
     def migration_with_unix(self):
-        dest_uri = 'unix:%s/migration.sock' % self.socket_dir().name
-        self.do_migrate(dest_uri)
+        dst_uri = 'unix:%s/migration.sock' % self.socket_dir().name
+        self.migrate(dst_uri)
 
     def migration_with_exec(self):
         if not which('ncat'):
             self.skipTest('ncat is not available')
         with Ports() as ports:
             free_port = self._get_free_port(ports)
-            dest_uri = 'exec:ncat -l localhost %u' % free_port
+            dst_uri = 'exec:ncat -l localhost %u' % free_port
             src_uri = 'exec:ncat localhost %u' % free_port
-            self.do_migrate(dest_uri, src_uri)
+            self.migrate(dst_uri, src_uri)
Signature · 1 line
2.51.0
#4 lore raw

PATCH v4 4/4 tests/functional/ppc64/pseries: 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'

The PseriesMachine class is changed to inherit from MigrationTest so both the migration routines and the class attributes of PseriesMachine can be accessed without the need to instantiate another object.

Fixes f4e34d0fd5 ("tests/functional: Add a OS level migration test for pseries")
---
 tests/functional/migration.py            |  5 +++++
 tests/functional/ppc64/test_migration.py | 11 -----------
 tests/functional/ppc64/test_pseries.py   | 10 +++++-----
 3 files changed, 10 insertions(+), 16 deletions(-)
tests/functional/migration.py +5 -0
index 49347a30bb..e995328e83 100644
@@ -65,6 +65,11 @@ def _get_free_port(self, ports):
             self.skipTest('Failed to find a free port')
         return port
 
+    def migration_with_tcp_localhost_vms(self, dst_vm, src_vm):
+        with Ports() as ports:
+            uri = 'tcp:localhost:%u' % self._get_free_port(ports)
+            self.migrate_vms(uri, uri, dst_vm, src_vm)
+
     def migration_with_tcp_localhost(self):
         with Ports() as ports:
             dst_uri = 'tcp:localhost:%u' % self._get_free_port(ports)
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 +5 -5
index b45763c305..b28292233d 100755
@@ -7,11 +7,11 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or
 # later.  See the COPYING file in the top-level directory.
 
-from qemu_test import QemuSystemTest, Asset
+from qemu_test import Asset
 from qemu_test import wait_for_console_pattern
-from test_migration import PpcMigrationTest
+from migration import MigrationTest
 
-class PseriesMachine(QemuSystemTest):
+class PseriesMachine(MigrationTest):
 
     timeout = 90
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 console=hvc0 '
@@ -116,11 +116,11 @@ 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);
+        self.migration_with_tcp_localhost_vms(dest_vm, source_vm);
 
         # ensure the boot proceeds after migration
         wait_for_console_pattern(self, self.good_message, self.panic_message,
                                  vm=dest_vm)
 
 if __name__ == '__main__':
-    QemuSystemTest.main()
+    MigrationTest.main()
Signature · 1 line
2.51.0
Tested-by on v4 4/4
#5 lore raw

Re: [PATCH v4 4/4] tests/functional/ppc64/pseries: Remove custom migration routine

Quoted 19 lines · 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'

Quoted 8 lines

The PseriesMachine class is changed to inherit from MigrationTest so both the migration routines and the class attributes of PseriesMachine can be accessed without the need to instantiate another object.

Fixes f4e34d0fd5 ("tests/functional: Add a OS level migration test for pseries")

I don't see any issues with the tests now, and able to run them parallely, thanks for fixing it !

tests/functional/ppc64/test_pseries.py def test_ppc64_linux_migration(self): · line 119

Quoted 8 lines

timeout = 90
KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 console=hvc0 '

tests/functional/ppc64/test_pseries.py +1 -1
@@ -116,11 +116,11 @@ 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);
+        self.migration_with_tcp_localhost_vms(dest_vm, source_vm);

nit: the ';', can ignore though

Thanks,
- Aditya G

Reviewed-by on v4 4/4
#6 lore raw

Re: [PATCH v4 4/4] tests/functional/ppc64/pseries: Remove custom migration routine

In reply to Fabiano Rosas
Quoted 19 lines · 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'

Quoted 8 lines

The PseriesMachine class is changed to inherit from MigrationTest so both the migration routines and the class attributes of PseriesMachine can be accessed without the need to instantiate another object.

Fixes f4e34d0fd5 ("tests/functional: Add a OS level migration test for pseries")
Signature · 1 line
Peter Xu