A spice client can be informed of a migration, so it
connects to the new vm automatically, keeping the
client connection alive during any number of migrations,
through a monitor command.

This patch implements calling the appropriate command
(there are 3 different valid commands for RHEL userspace,
older upstream and current upstream qemu), for both
human monitor and qmp. This way it'll be possible to
create a test for spice seamless migration test (issue #158).

Spice team, please take a look at this and provide feedback.

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 client/virt/kvm_vm.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/client/virt/kvm_vm.py b/client/virt/kvm_vm.py
index 90f26fd..c1e5e74 100644
--- a/client/virt/kvm_vm.py
+++ b/client/virt/kvm_vm.py
@@ -2329,6 +2329,49 @@ class VM(virt_vm.BaseVM):
             error.context()
 
         try:
+            if self.params["display"] == "spice":
+                dest_port = clone.spice_options['spice_port']
+                logging.debug("Informing migration to spice client")
+                commands = ["__com.redhat_spice_migrate_info",
+                            "spice_migrate_info",
+                            "client_migrate_info"]
+
+                if self.monitor.protocol == "human":
+                    out = self.monitor.cmd("help", debug=False)
+                    for command in commands:
+                        if "\n%s" % command in out:
+                            # spice_migrate_info requires dest_host, dest_port
+                            if command in commands[:2]:
+                                command = "%s %s %s" % (command, dest_host,
+                                                        dest_port)
+                            # client_migrate_info also requires protocol
+                            else:
+                                command = "%s %s %s %s" % (command,
+                                                         
self.params['display'],
+                                                         dest_host, dest_port)
+                            break
+                    self.monitor.cmd(command)
+
+                elif self.monitor.protocol == "qmp":
+                    out = self.monitor.cmd_obj({"execute": "query-commands"})
+                    for command in commands:
+                        if {'name': command} in out['return']:
+                            # spice_migrate_info requires dest_host, dest_port
+                            if command in commands[:2]:
+                                command_dict = {"execute": command,
+                                                "arguments":
+                                                 {"hostname": dest_host,
+                                                  "port": dest_port}}
+                            # client_migrate_info also requires protocol
+                            else:
+                                command_dict = {"execute": command,
+                                                "arguments":
+                                            {"protocol": 
self.params['display'],
+                                             "hostname": dest_host,
+                                             "port": dest_port}}
+                            break
+                    self.monitor.cmd_obj(command_dict)
+
             if protocol == "tcp":
                 if local:
                     uri = "tcp:0:%d" % clone.migration_port
-- 
1.7.11.2

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to