Revision 342f9172
b/lib/cmdlib.py | ||
---|---|---|
11891 | 11891 |
if not isinstance(rdict["result"], list): |
11892 | 11892 |
raise errors.OpExecError("Can't parse iallocator results: 'result' key" |
11893 | 11893 |
" is not a list") |
11894 |
|
|
11895 |
if self.mode == constants.IALLOCATOR_MODE_RELOC: |
|
11896 |
assert self.relocate_from is not None |
|
11897 |
assert self.required_nodes == 1 |
|
11898 |
|
|
11899 |
node2group = dict((name, ndata["group"]) |
|
11900 |
for (name, ndata) in self.in_data["nodes"].items()) |
|
11901 |
|
|
11902 |
fn = compat.partial(self._NodesToGroups, node2group, |
|
11903 |
self.in_data["nodegroups"]) |
|
11904 |
|
|
11905 |
request_groups = fn(self.relocate_from) |
|
11906 |
result_groups = fn(rdict["result"]) |
|
11907 |
|
|
11908 |
if result_groups != request_groups: |
|
11909 |
raise errors.OpExecError("Groups of nodes returned by iallocator (%s)" |
|
11910 |
" differ from original groups (%s)" % |
|
11911 |
(utils.CommaJoin(result_groups), |
|
11912 |
utils.CommaJoin(request_groups))) |
|
11913 |
|
|
11894 | 11914 |
self.out_data = rdict |
11895 | 11915 |
|
11916 |
@staticmethod |
|
11917 |
def _NodesToGroups(node2group, groups, nodes): |
|
11918 |
"""Returns a list of unique group names for a list of nodes. |
|
11919 |
|
|
11920 |
@type node2group: dict |
|
11921 |
@param node2group: Map from node name to group UUID |
|
11922 |
@type groups: dict |
|
11923 |
@param groups: Group information |
|
11924 |
@type nodes: list |
|
11925 |
@param nodes: Node names |
|
11926 |
|
|
11927 |
""" |
|
11928 |
result = set() |
|
11929 |
|
|
11930 |
for node in nodes: |
|
11931 |
try: |
|
11932 |
group_uuid = node2group[node] |
|
11933 |
except KeyError: |
|
11934 |
# Ignore unknown node |
|
11935 |
pass |
|
11936 |
else: |
|
11937 |
try: |
|
11938 |
group = groups[group_uuid] |
|
11939 |
except KeyError: |
|
11940 |
# Can't find group, let's use UUID |
|
11941 |
group_name = group_uuid |
|
11942 |
else: |
|
11943 |
group_name = group["name"] |
|
11944 |
|
|
11945 |
result.add(group_name) |
|
11946 |
|
|
11947 |
return sorted(result) |
|
11948 |
|
|
11896 | 11949 |
|
11897 | 11950 |
class LUTestAllocator(NoHooksLU): |
11898 | 11951 |
"""Run allocator tests. |
Also available in: Unified diff