Use hvparams in instance migration
authorHelga Velroyen <helgav@google.com>
Wed, 5 Jun 2013 09:08:07 +0000 (11:08 +0200)
committerHelga Velroyen <helgav@google.com>
Wed, 12 Jun 2013 07:17:42 +0000 (09:17 +0200)
This patch makes use of hvparams on instance migration to
determine the list of instance before the migration. This way, in
xen, the xl/xm choice is respected.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/hypervisor/hv_xen.py
test/py/ganeti.hypervisor.hv_xen_unittest.py

index eefce00..63ab47c 100644 (file)
@@ -721,19 +721,22 @@ class XenHypervisor(hv_base.BaseHypervisor):
     cluster_name = ssconf.SimpleStore().GetClusterName()
 
     return self._MigrateInstance(cluster_name, instance.name, target, port,
-                                 live)
+                                 live, instance.hvparams)
 
   def _MigrateInstance(self, cluster_name, instance_name, target, port, live,
-                       _ping_fn=netutils.TcpPing):
+                       hvparams, _ping_fn=netutils.TcpPing):
     """Migrate an instance to a target node.
 
     @see: L{MigrateInstance} for details
 
     """
-    if self.GetInstanceInfo(instance_name) is None:
+    if hvparams is None:
+      raise errors.HypervisorError("No hvparams provided.")
+
+    if self.GetInstanceInfo(instance_name, hvparams=hvparams) is None:
       raise errors.HypervisorError("Instance not running, cannot migrate")
 
-    cmd = self._GetCommand()
+    cmd = self._GetCommand(hvparams=hvparams)
 
     if (cmd == constants.XEN_CMD_XM and
         not _ping_fn(target, port, live_port_needed=True)):
index 3b692da..e0b0213 100755 (executable)
@@ -524,6 +524,7 @@ class _TestXenHypervisor(object):
   TARGET = NotImplemented
   CMD = NotImplemented
   HVNAME = NotImplemented
+  VALID_HVPARAMS = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
 
   def setUp(self):
     super(_TestXenHypervisor, self).setUp()
@@ -791,7 +792,7 @@ class _TestXenHypervisor(object):
     for live in [False, True]:
       try:
         hv._MigrateInstance(NotImplemented, name, target, port, live,
-                            _ping_fn=NotImplemented)
+                            self.VALID_HVPARAMS, _ping_fn=NotImplemented)
       except errors.HypervisorError, err:
         self.assertEqual(str(err), "Instance not running, cannot migrate")
       else:
@@ -811,6 +812,7 @@ class _TestXenHypervisor(object):
     port = 28349
 
     hv = self._GetHv(run_cmd=self._MigrateInstTargetUnreachCmd)
+    hvparams = {constants.HV_XEN_CMD: self.CMD}
 
     for live in [False, True]:
       if self.CMD == constants.XEN_CMD_XL:
@@ -819,6 +821,7 @@ class _TestXenHypervisor(object):
       else:
         try:
           hv._MigrateInstance(NotImplemented, name, target, port, live,
+                              hvparams,
                               _ping_fn=compat.partial(self._FakeTcpPing,
                                                       (target, port), False))
         except errors.HypervisorError, err:
@@ -865,6 +868,8 @@ class _TestXenHypervisor(object):
     target = constants.IP4_ADDRESS_LOCALHOST
     port = 22364
 
+    hvparams = {constants.HV_XEN_CMD: self.CMD}
+
     for live in [False, True]:
       for fail in [False, True]:
         ping_fn = \
@@ -881,14 +886,14 @@ class _TestXenHypervisor(object):
         if fail:
           try:
             hv._MigrateInstance(clustername, instname, target, port, live,
-                                _ping_fn=ping_fn)
+                                hvparams, _ping_fn=ping_fn)
           except errors.HypervisorError, err:
             self.assertTrue(str(err).startswith("Failed to migrate instance"))
           else:
             self.fail("Exception was not raised")
         else:
           hv._MigrateInstance(clustername, instname, target, port, live,
-                              _ping_fn=ping_fn)
+                              hvparams, _ping_fn=ping_fn)
 
         if self.CMD == constants.XEN_CMD_XM:
           expected_pings = 1