Skip to contentSkip to conversation

tests/functional: Fix ppc64 issue with make -j

PATCH Superseded Fabiano Rosas 2 participants 11 messages Mar 3 PowerPC

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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]

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

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

Fabiano Rosas (5):
tests/functional/migration: Use socket_dir tests/functional/migration: Add migrate_vms tests/functional/migration: Use the migrate_vms helper tests/functional/ppc64/pseries: Inherit from MigrationTest 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   |  8 ++---
 3 files changed, 32 insertions(+), 33 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v3 1/5 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 v3 2/5 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 v3 2/5
#3 lore raw

Re: [PATCH v3 2/5] tests/functional/migration: Add migrate_vms

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)
#4 lore raw

PATCH v3 3/5 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 v3 3/5
#5 lore raw

Re: [PATCH v3 3/5] tests/functional/migration: Use the migrate_vms helper

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(-)
#6 lore raw

PATCH v3 4/5 tests/functional/ppc64/pseries: Inherit from MigrationTest

In reply to Fabiano Rosas

Make the PseriesMachine class inherit from MigrationTest so the next patch can access migration routines without needing to instantiate a MigrationTest object. This is just for cleanliness of the code.

Note that creating a separate class for migration wouldn't work quite well because the class attributes of PseriesMachine would then have to be exposed to that class somehow.

---
 tests/functional/ppc64/test_pseries.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/functional/ppc64/test_pseries.py +3 -3
index b45763c305..ce39e16a22 100755
@@ -11,7 +11,7 @@
 from qemu_test import wait_for_console_pattern
 from test_migration import PpcMigrationTest
 
-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.do_migrate_ppc64_linux(source_vm, dest_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
#7 lore raw

Re: [PATCH v3 4/5] tests/functional/ppc64/pseries: Inherit from MigrationTest

Quoted 19 lines · Fabiano Rosas

Make the PseriesMachine class inherit from MigrationTest so the next patch can access migration routines without needing to instantiate a MigrationTest object. This is just for cleanliness of the code.

Note that creating a separate class for migration wouldn't work quite well because the class attributes of PseriesMachine would then have to be exposed to that class somehow.

---
  tests/functional/ppc64/test_pseries.py | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/functional/ppc64/test_pseries.py +0 -0
index b45763c305..ce39e16a22 100755

tests/functional/ppc64/test_pseries.py line 14

Quoted 5 lines
tests/functional/ppc64/test_pseries.py +1 -1
@@ -11,7 +11,7 @@
  from qemu_test import wait_for_console_pattern
  from test_migration import PpcMigrationTest
 
-class PseriesMachine(QemuSystemTest):
+class PseriesMachine(MigrationTest):

This patch does not work (without the following one). You only import PpcMigrationTest, but not MigrationTest, so inheriting from MigrationTest is not possible here...

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

Quoted 8 lines
tests/functional/ppc64/test_pseries.py +1 -1
      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.do_migrate_ppc64_linux(source_vm, dest_vm);

... and do_migrate_ppc64_linux is also not a method of MigrationTest.

Easiest fix: Squash this patch with the next one. Otherwise you have to take the detour through inheriting from PpcMigrationTest here.

Thomas

Quoted 7 lines
tests/functional/ppc64/test_pseries.py +1 -1
          # 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()
#8 lore raw

Re: [PATCH v3 4/5] tests/functional/ppc64/pseries: Inherit from MigrationTest

Quoted 23 lines · Thomas Huth
Quoted 22 lines · Fabiano Rosas

Make the PseriesMachine class inherit from MigrationTest so the next patch can access migration routines without needing to instantiate a MigrationTest object. This is just for cleanliness of the code.

Note that creating a separate class for migration wouldn't work quite well because the class attributes of PseriesMachine would then have to be exposed to that class somehow.

---
  tests/functional/ppc64/test_pseries.py | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/functional/ppc64/test_pseries.py +0 -0
index b45763c305..ce39e16a22 100755
@@ -11,7 +11,7 @@
  from qemu_test import wait_for_console_pattern
  from test_migration import PpcMigrationTest
 
Quoted 7 lines

tests/functional/ppc64/test_pseries.py line 14

Quoted 2 lines
tests/functional/ppc64/test_pseries.py +1 -1
-class PseriesMachine(QemuSystemTest):
+class PseriesMachine(MigrationTest):

This patch does not work (without the following one). You only import PpcMigrationTest, but not MigrationTest, so inheriting from MigrationTest is not possible here...

Ouch, sorry. I'll repost.

#9 lore raw

PATCH v3 5/5 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'

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   |  4 ++--
 3 files changed, 7 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 +2 -2
index ce39e16a22..7373ca1647 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(MigrationTest):
 
@@ -116,7 +116,7 @@ def test_ppc64_linux_migration(self):
         wait_for_console_pattern(self, console_pattern, self.panic_message,
                                  vm=source_vm)
 
-        self.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,
Signature · 1 line
2.51.0
Reviewed-by on v3 5/5
#10 lore raw

Re: [PATCH v3 5/5] 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
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   |  4 ++--
  3 files changed, 7 insertions(+), 13 deletions(-)