Commit 72ad3cec authored by Antoine Millet's avatar Antoine Millet

Better error reporting in Elector class.

parent 5ab5e88b
......@@ -86,7 +86,16 @@ class Elector(object):
distribute = getattr(self, func)
# Get the destination hypervisor candidates:
candidates = self._get_candidates(self.FILTERS[mtype])
candidates, errors = self._get_candidates(self.FILTERS[mtype])
# Check if VM migration election raised an error:
if errors:
# If errors are found, we report only the first of them, because we
# have currently no way to report problem for each vm:
vm, desc = errors[0]
raise ElectionError('No destination found for %r, last destination'
' filtered by %s' % (vm['id'], desc))
# Distributes VMs to each candidate:
migration_plan = distribute(mtype, candidates)
......@@ -110,6 +119,7 @@ class Elector(object):
hvs = self._server.list(self._query_dest, show=hv_tags)
candidates = []
errors = []
# Filters the candidates:
for vm in vms:
......@@ -121,9 +131,14 @@ class Elector(object):
vm_dest = copy(hvs)
for func, desc in filterfuncs:
vm_dest = func(vm, vm_dest)
candidates.append((vm, vm_dest))
# VM is added to errors if none destination HV is found for it:
if not vm_dest:
errors.append((vm, desc))
break
else:
candidates.append((vm, vm_dest))
return candidates
return candidates, errors
#####
##### Distribution algorithm methods:
......
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