Improve error message for AggregateAlreadyHasHost exception

If a lease fails to end properly and some reserved hosts are not removed
from its aggregate, Blazar will get a Conflict exception from novaclient
while starting a new lease on the same hosts, with an error message
describing why a host cannot be added to the new aggregate, such as:

  Cannot add host to aggregate <new_aggregate_id>. Reason: One or more
  hosts already in availability zone(s) [u'blazar_<old_aggregate_uuid>']

However, Blazar is catching this exception and raising its own
AggregateAlreadyHasHost exception with a confusing error message:

  Aggregate <new_aggregate_id> already has host(s) <hostname>

This patch changes the error message of the AggregateAlreadyHasHost
exception to correctly describe the problem and include the error
message from novaclient containing information about the old aggregate.

Change-Id: Iea865b23e185957631fccef4e0624b140f2b835e
This commit is contained in:
Pierre Riteau 2018-10-17 15:26:57 +01:00
parent a8a3bd9d61
commit c491da2ab6
2 changed files with 5 additions and 4 deletions

View File

@ -48,7 +48,8 @@ class AggregateHaveHost(exceptions.BlazarException):
class AggregateAlreadyHasHost(exceptions.BlazarException):
code = 409
msg_fmt = _("Aggregate %(pool)s already has host(s) %(host)s ")
msg_fmt = _("Conflict while adding host %(host)s to aggregate %(pool)s: "
"%(nova_exception)s")
class AggregateNotFound(exceptions.NotFound):

View File

@ -365,9 +365,9 @@ class ReservationPool(NovaClientWrapper):
return self.nova.aggregates.add_host(agg.id, host)
except nova_exception.NotFound:
raise manager_exceptions.HostNotFound(host=host)
except nova_exception.Conflict:
raise manager_exceptions.AggregateAlreadyHasHost(pool=pool,
host=host)
except nova_exception.Conflict as e:
raise manager_exceptions.AggregateAlreadyHasHost(
pool=pool, host=host, nova_exception=str(e))
def remove_all_computehosts(self, pool):
"""Remove all compute hosts attached to an aggregate."""