diff --git a/ccserver/election.py b/ccserver/election.py index 3431746abc5d56d9cbd0034b58a36dd7cd0601c7..0acbed1a528939ab61aeebd08270b2ca48fa9372 100644 --- a/ccserver/election.py +++ b/ccserver/election.py @@ -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: