Migration: add check for listening target
authorIustin Pop <iustin@google.com>
Wed, 4 Nov 2009 13:21:55 +0000 (14:21 +0100)
committerIustin Pop <iustin@google.com>
Wed, 4 Nov 2009 15:35:44 +0000 (16:35 +0100)
This patch adds a check for listening on the remote port in Xen and KVM
migrations. This will be generating a single “load of migration failed”
message for KVM, but otherwise not prevent the migration. For Xen (which
has a dedicated, always listening daemon) this should not create any
problems.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/hypervisor/hv_kvm.py
lib/hypervisor/hv_xen.py

index eee6fe1..11d25bd 100644 (file)
@@ -624,14 +624,18 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     """
     instance_name = instance.name
+    port = instance.hvparams[constants.HV_MIGRATION_PORT]
     pidfile, pid, alive = self._InstancePidAlive(instance_name)
     if not alive:
       raise errors.HypervisorError("Instance not running, cannot migrate")
 
+    if not utils.TcpPing(target, port, live_port_needed=True):
+      raise errors.HypervisorError("Remote host %s not listening on port"
+                                   " %s, cannot migrate" % (target, port))
+
     if not live:
       self._CallMonitorCommand(instance_name, 'stop')
 
-    port = instance.hvparams[constants.HV_MIGRATION_PORT]
     migrate_command = 'migrate -d tcp:%s:%s' % (target, port)
     self._CallMonitorCommand(instance_name, migrate_command)
 
index e29d4ca..1addef7 100644 (file)
@@ -402,7 +402,13 @@ class XenHypervisor(hv_base.BaseHypervisor):
     """
     if self.GetInstanceInfo(instance.name) is None:
       raise errors.HypervisorError("Instance not running, cannot migrate")
+
     port = instance.hvparams[constants.HV_MIGRATION_PORT]
+
+    if not utils.TcpPing(target, port, live_port_needed=True):
+      raise errors.HypervisorError("Remote host %s not listening on port"
+                                   " %s, cannot migrate" % (target, port))
+
     args = ["xm", "migrate", "-p", "%d" % port]
     if live:
       args.append("-l")