Commit 342f9172 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

iallocator: Relocation nodes must be in same group

Quoting from iallocator.rst: “[…] ``relocate`` request is used when an
existing instance needs to be moved within its node group […]”.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 55f67cc9
......@@ -11891,8 +11891,61 @@ class IAllocator(object):
if not isinstance(rdict["result"], list):
raise errors.OpExecError("Can't parse iallocator results: 'result' key"
" is not a list")
if self.mode == constants.IALLOCATOR_MODE_RELOC:
assert self.relocate_from is not None
assert self.required_nodes == 1
node2group = dict((name, ndata["group"])
for (name, ndata) in self.in_data["nodes"].items())
fn = compat.partial(self._NodesToGroups, node2group,
request_groups = fn(self.relocate_from)
result_groups = fn(rdict["result"])
if result_groups != request_groups:
raise errors.OpExecError("Groups of nodes returned by iallocator (%s)"
" differ from original groups (%s)" %
self.out_data = rdict
def _NodesToGroups(node2group, groups, nodes):
"""Returns a list of unique group names for a list of nodes.
@type node2group: dict
@param node2group: Map from node name to group UUID
@type groups: dict
@param groups: Group information
@type nodes: list
@param nodes: Node names
result = set()
for node in nodes:
group_uuid = node2group[node]
except KeyError:
# Ignore unknown node
group = groups[group_uuid]
except KeyError:
# Can't find group, let's use UUID
group_name = group_uuid
group_name = group["name"]
return sorted(result)
class LUTestAllocator(NoHooksLU):
"""Run allocator tests.
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