Skip to contentSkip to conversation

tests/functional: Fix ppc64 issue with make -j

PATCH Superseded Fabiano Rosas 4 participants 17 messages Feb 4 – Feb 26 PowerPC

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 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/2306044343

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: Remove custom migration routine

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

PATCH v2 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
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] tests/functional/migration: Use socket_dir

Quoted 24 lines · Fabiano Rosas

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 +0 -1
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)

tests/functional/migration.py def migration_with_tcp_localhost(self): · line 71

Quoted 10 lines
tests/functional/migration.py +2 -3
 
      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'):
#3 lore raw

PATCH v2 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
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] tests/functional/migration: Add migrate_vms

Quoted 7 lines · 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.

Signature · 1 line
Peter Xu
Reviewed-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] tests/functional/migration: Add migrate_vms

In reply to Fabiano Rosas
Quoted 16 lines · 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 +0 -0
index 0aa873edba..3362e5c743 100644

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

Quoted 7 lines
tests/functional/migration.py +4 -0
@@ -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)
#6 lore raw

PATCH v2 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
Reviewed-by on v2 3/4
#7 lore raw

Re: [PATCH v2 3/4] tests/functional/migration: Use the migrate_vms helper

Quoted 7 lines · 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.

Signature · 1 line
Peter Xu
Reviewed-by on v2 3/4
#8 lore raw

Re: [PATCH v2 3/4] tests/functional/migration: Use the migrate_vms helper

In reply to Fabiano Rosas
Quoted 10 lines · 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(-)
#9 lore raw

PATCH v2 4/4 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            |  5 +++++
 tests/functional/ppc64/test_migration.py | 11 -----------
 tests/functional/ppc64/test_pseries.py   |  6 ++++--
 3 files changed, 9 insertions(+), 13 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 +4 -2
index b45763c305..3996a4a878 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_vms(dest_vm, source_vm);
 
         # ensure the boot proceeds after migration
         wait_for_console_pattern(self, self.good_message, self.panic_message,
Signature · 1 line
2.51.0
Acked-by on v2 4/4
#10 lore raw

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

Quoted 71 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'

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   |  6 ++++--
 3 files changed, 9 insertions(+), 13 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 +0 -0
index b45763c305..3996a4a878 100755

tests/functional/ppc64/test_pseries.py line 14

Quoted 7 lines
tests/functional/ppc64/test_pseries.py +1 -1
@@ -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):

I wonder if PseriesMachine would be better to inherit directly from MigrationTest, to avoid the timeout setup and temp QemuSystemTest to be created on the fly (I'm not familiar with the test framework on side effects). But I don't see a major issue with it either so far.

Quoted 15 lines
tests/functional/ppc64/test_pseries.py +3 -1
@@ -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_vms(dest_vm, source_vm);
 
         # ensure the boot proceeds after migration
         wait_for_console_pattern(self, self.good_message, self.panic_message,
Signature · 1 line
2.51.0
Signature · 1 line
Peter Xu
#11 lore raw

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

Quoted 78 lines · Peter Xu
Quoted 77 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'

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   |  6 ++++--
  3 files changed, 9 insertions(+), 13 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 +1 -1
index b45763c305..3996a4a878 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
 
Quoted 6 lines

tests/functional/ppc64/test_pseries.py line 14

Quoted 1 line
tests/functional/ppc64/test_pseries.py +0 -0
  class PseriesMachine(QemuSystemTest):

I wonder if PseriesMachine would be better to inherit directly from MigrationTest, to avoid the timeout setup and temp QemuSystemTest to be created on the fly (I'm not familiar with the test framework on side effects). But I don't see a major issue with it either so far.

I think I'd also prefer to inherit directly from MigrationTest.
You could put the test_ppc64_linux_migration() method into a separate class that inherits from MigrationTest, while the other test_* methods stay in the old class, so that there is for sure no impact on the other tests. (Having multiple test classes in one file is fine, we have that in a couple of other places already).

Thomas

Quoted 16 lines
Quoted 15 lines
tests/functional/ppc64/test_pseries.py +3 -1
@@ -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_vms(dest_vm, source_vm);
 
          # ensure the boot proceeds after migration
          wait_for_console_pattern(self, self.good_message, self.panic_message,
Signature · 1 line
2.51.0
#12 lore raw

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

Quoted 86 lines · Thomas Huth
Quoted 78 lines · Peter Xu
Quoted 77 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'

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   |  6 ++++--
  3 files changed, 9 insertions(+), 13 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 +1 -1
index b45763c305..3996a4a878 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
 
Quoted 6 lines

tests/functional/ppc64/test_pseries.py line 14

Quoted 1 line
tests/functional/ppc64/test_pseries.py +0 -0
  class PseriesMachine(QemuSystemTest):

I wonder if PseriesMachine would be better to inherit directly from MigrationTest, to avoid the timeout setup and temp QemuSystemTest to be created on the fly (I'm not familiar with the test framework on side effects). But I don't see a major issue with it either so far.

Quoted 7 lines

I think I'd also prefer to inherit directly from MigrationTest. You could put the test_ppc64_linux_migration() method into a separate class that inherits from MigrationTest, while the other test_* methods stay in the old class, so that there is for sure no impact on the other tests. (Having multiple test classes in one file is fine, we have that in a couple of other places already).

A new class will make it cumbersome to access the class attributes from PseriesMachine:

KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 console=hvc0 ' panic_message = 'Kernel panic - not syncing' good_message = 'VFS: Cannot open root device' ASSET_KERNEL = Asset(...

The "best" way is to make the whole class inherit from MigrationTest. If you're ok with that I can send a v3.

Quoted 19 lines

Thomas

Quoted 16 lines
Quoted 15 lines
tests/functional/ppc64/test_pseries.py +3 -1
@@ -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_vms(dest_vm, source_vm);
 
          # ensure the boot proceeds after migration
          wait_for_console_pattern(self, self.good_message, self.panic_message,
Signature · 1 line
2.51.0
#13 lore raw

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

Quoted 99 lines · Fabiano Rosas
Quoted 86 lines · Thomas Huth
Quoted 78 lines · Peter Xu
Quoted 77 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'

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   |  6 ++++--
   3 files changed, 9 insertions(+), 13 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 +1 -1
index b45763c305..3996a4a878 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
 
Quoted 6 lines

tests/functional/ppc64/test_pseries.py line 14

Quoted 1 line
tests/functional/ppc64/test_pseries.py +0 -0
   class PseriesMachine(QemuSystemTest):

I wonder if PseriesMachine would be better to inherit directly from MigrationTest, to avoid the timeout setup and temp QemuSystemTest to be created on the fly (I'm not familiar with the test framework on side effects). But I don't see a major issue with it either so far.

Quoted 7 lines

I think I'd also prefer to inherit directly from MigrationTest. You could put the test_ppc64_linux_migration() method into a separate class that inherits from MigrationTest, while the other test_* methods stay in the old class, so that there is for sure no impact on the other tests. (Having multiple test classes in one file is fine, we have that in a couple of other places already).

A new class will make it cumbersome to access the class attributes from PseriesMachine:

Quoted 7 lines

KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 console=hvc0 ' panic_message = 'Kernel panic - not syncing' good_message = 'VFS: Cannot open root device' ASSET_KERNEL = Asset(...

The "best" way is to make the whole class inherit from MigrationTest. If you're ok with that I can send a v3.

Fine for me, too!

Thanks,
Thomas

Tested-by on v2 4/4
#14 lore raw

Re: [PATCH v2 4/4] tests/functional/ppc64: 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 3 lines
Fixes f4e34d0fd5 ("tests/functional: Add a OS level migration test for pseries")

Thank you for fixing the issue Fabiano. Now I don't see any issues running the tests in parallel.
- Aditya G

#15 lore raw

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

In reply to Fabiano Rosas

Hello all,

Just a ping, the issue still exists with functional tests for ppc64 failing when run in parallel.

Can we get this merged ?

Thanks,

- Aditya G

#16 lore raw

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

Quoted 5 lines · Aditya Gupta

Hello all,

Just a ping, the issue still exists with functional tests for ppc64 failing when run in parallel.

Can we get this merged ?

There were suggestions for improvements that were not addressed:

https://lore.kernel.org/qemu-devel/[email protected]/

I don't insist on that change, but I think we should at least have a common understanding on whether we want it or not. Fabiano, could you please comment on that?

Thomas