Commit 43a8f36a authored by Bernardo Dal Seno's avatar Bernardo Dal Seno
Browse files

Explicitly ask for the default iallocator in commands



Now "gnt-instance recreate-disks" uses the default iallocator when "." is
specified as the iallocator. For uniformity, the same behavior applies to
these commands:
  gnt-node evacuate
  gnt-instance migrate
  gnt-instance add
"." is used instead of "default" becuse the latter could be a valid name for
an iallocator.
Signed-off-by: default avatarBernardo Dal Seno <bdalseno@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent fbdac0d9
......@@ -1610,8 +1610,9 @@ def _CheckIAllocatorOrNode(lu, iallocator_slot, node_slot):
cluster-wide iallocator if appropriate.
 
Check that at most one of (iallocator, node) is specified. If none is
specified, then the LU's opcode's iallocator slot is filled with the
cluster-wide default iallocator.
specified, or the iallocator is L{constants.DEFAULT_IALLOCATOR_SHORTCUT},
then the LU's opcode's iallocator slot is filled with the cluster-wide
default iallocator.
 
@type iallocator_slot: string
@param iallocator_slot: the name of the opcode iallocator slot
......@@ -1621,11 +1622,14 @@ def _CheckIAllocatorOrNode(lu, iallocator_slot, node_slot):
"""
node = getattr(lu.op, node_slot, None)
ialloc = getattr(lu.op, iallocator_slot, None)
if node == []:
node = None
 
if node is not None and ialloc is not None:
raise errors.OpPrereqError("Do not specify both, iallocator and node",
errors.ECODE_INVAL)
elif node is None and ialloc is None:
elif ((node is None and ialloc is None) or
ialloc == constants.DEFAULT_IALLOCATOR_SHORTCUT):
default_iallocator = lu.cfg.GetDefaultIAllocator()
if default_iallocator:
setattr(lu.op, iallocator_slot, default_iallocator)
......@@ -7137,9 +7141,10 @@ class LUInstanceRecreateDisks(LogicalUnit):
" once: %s" % utils.CommaJoin(duplicates),
errors.ECODE_INVAL)
 
if self.op.iallocator and self.op.nodes:
raise errors.OpPrereqError("Give either the iallocator or the new"
" nodes, not both", errors.ECODE_INVAL)
# We don't want _CheckIAllocatorOrNode selecting the default iallocator
# when neither iallocator nor nodes are specified
if self.op.iallocator or self.op.nodes:
_CheckIAllocatorOrNode(self, "iallocator", "nodes")
 
for (idx, params) in self.op.disks:
utils.ForceDictType(params, constants.IDISK_PARAMS_TYPES)
......
......@@ -1455,6 +1455,7 @@ VALID_IALLOCATOR_MODES = frozenset([
IALLOCATOR_MODE_MULTI_ALLOC,
])
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
DEFAULT_IALLOCATOR_SHORTCUT = "."
IALLOCATOR_NEVAC_PRI = "primary-only"
IALLOCATOR_NEVAC_SEC = "secondary-only"
......
......@@ -108,23 +108,26 @@ class TestIAllocatorChecks(testutils.GanetiTestCase):
c_i = lambda: cmdlib._CheckIAllocatorOrNode(lu, "iallocator", "node")
# Neither node nor iallocator given
op.iallocator = None
op.node = None
c_i()
self.assertEqual(lu.op.iallocator, default_iallocator)
self.assertEqual(lu.op.node, None)
for n in (None, []):
op.iallocator = None
op.node = n
c_i()
self.assertEqual(lu.op.iallocator, default_iallocator)
self.assertEqual(lu.op.node, n)
# Both, iallocator and node given
op.iallocator = "test"
op.node = "test"
self.assertRaises(errors.OpPrereqError, c_i)
for a in ("test", constants.DEFAULT_IALLOCATOR_SHORTCUT):
op.iallocator = a
op.node = "test"
self.assertRaises(errors.OpPrereqError, c_i)
# Only iallocator given
op.iallocator = other_iallocator
op.node = None
c_i()
self.assertEqual(lu.op.iallocator, other_iallocator)
self.assertEqual(lu.op.node, None)
for n in (None, []):
op.iallocator = other_iallocator
op.node = n
c_i()
self.assertEqual(lu.op.iallocator, other_iallocator)
self.assertEqual(lu.op.node, n)
# Only node given
op.iallocator = None
......@@ -133,6 +136,13 @@ class TestIAllocatorChecks(testutils.GanetiTestCase):
self.assertEqual(lu.op.iallocator, None)
self.assertEqual(lu.op.node, "node")
# Asked for default iallocator, no node given
op.iallocator = constants.DEFAULT_IALLOCATOR_SHORTCUT
op.node = None
c_i()
self.assertEqual(lu.op.iallocator, default_iallocator)
self.assertEqual(lu.op.node, None)
# No node, iallocator or default iallocator
op.iallocator = None
op.node = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment