Patch db366d9a added support for EXT_MIRROR instances, but
inadvertently introduced a bug: for INT_MIRROR cases, we don't need
(actually we can't support) neither an iallocator nor a target node.

To fix this, we move the iallocator/node checks in CheckPrereq, where
we have access to the instance configuration, and additionally we
check for and prevent passing either of these two for INT_MIRROR
instances.
---
 lib/cmdlib.py |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 051e5fe..6ada424 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -5716,7 +5716,6 @@ class LUInstanceFailover(LogicalUnit):
     """
     self.iallocator = getattr(self.op, "iallocator", None)
     self.target_node = getattr(self.op, "target_node", None)
-    _CheckIAllocatorOrNode(self, "iallocator", "target_node")
 
   def ExpandNames(self):
     self._ExpandAndLockInstance()
@@ -5784,6 +5783,7 @@ class LUInstanceFailover(LogicalUnit):
                                  errors.ECODE_STATE)
 
     if instance.disk_template in constants.DTS_EXT_MIRROR:
+      _CheckIAllocatorOrNode(self, "iallocator", "target_node")
       if self.op.iallocator:
         self._RunAllocator()
         # Release all unnecessary node locks
@@ -5805,6 +5805,13 @@ class LUInstanceFailover(LogicalUnit):
                                         instance.disk_template)
       target_node = secondary_nodes[0]
 
+      if self.op.iallocator or (self.op.target_node and
+                                self.op.target_node != target_node):
+        raise errors.OpPrereqError("Instances with disk template %s cannot"
+                                   " be failed over to arbitrary nodes"
+                                   " (neither an iallocator nor a target"
+                                   " node can be passed)" %
+                                   instance.disk_template, errors.ECODE_INVAL)
     _CheckNodeOnline(self, target_node)
     _CheckNodeNotDrained(self, target_node)
 
-- 
1.7.3.1

Reply via email to