From c491da2ab65dfa94ceb74ba0b5f33fb914388c51 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Wed, 17 Oct 2018 15:26:57 +0100 Subject: [PATCH] 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 . Reason: One or more hosts already in availability zone(s) [u'blazar_'] However, Blazar is catching this exception and raising its own AggregateAlreadyHasHost exception with a confusing error message: Aggregate already has host(s) 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 --- blazar/manager/exceptions.py | 3 ++- blazar/utils/openstack/nova.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/blazar/manager/exceptions.py b/blazar/manager/exceptions.py index 4907ffc1..3b2118b9 100644 --- a/blazar/manager/exceptions.py +++ b/blazar/manager/exceptions.py @@ -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): diff --git a/blazar/utils/openstack/nova.py b/blazar/utils/openstack/nova.py index 91fd6a00..54251a99 100644 --- a/blazar/utils/openstack/nova.py +++ b/blazar/utils/openstack/nova.py @@ -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."""