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

Fabiano Rosas posted 3 patches 1 week, 4 days ago
Maintainers: Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>
There is a newer version of this series
[PATCH 2/3] tests/functional/migration: Accept vm objects in do_migrate
Posted by Fabiano Rosas 1 week, 4 days ago
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.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 tests/functional/migration.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tests/functional/migration.py b/tests/functional/migration.py
index 0aa873edba..ac6feeeefb 100644
--- a/tests/functional/migration.py
+++ b/tests/functional/migration.py
@@ -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)
 
-- 
2.51.0
Re: [PATCH 2/3] tests/functional/migration: Accept vm objects in do_migrate
Posted by Peter Xu 1 week, 4 days ago
On Wed, Jan 28, 2026 at 11:28:28AM -0300, Fabiano Rosas wrote:
> 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.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>  tests/functional/migration.py | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/functional/migration.py b/tests/functional/migration.py
> index 0aa873edba..ac6feeeefb 100644
> --- a/tests/functional/migration.py
> +++ b/tests/functional/migration.py
> @@ -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.

> +        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.

> +
> +        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)
>  
> -- 
> 2.51.0
> 

-- 
Peter Xu