From 0e57a4cd184688363b9857b8bb35136855064f0f Mon Sep 17 00:00:00 2001 From: jichenjc Date: Sun, 2 Mar 2014 11:51:06 +0800 Subject: [PATCH] Correct exception handling when create aggregate when create an aggregate, InvalidAggregateAction might be raised, this patch translates the InvalidAggregateAction to HTTPBadRequest. Also, 2 unnecessary logs was removed becuase log is not output in most BadRequest. Change-Id: I3dac808d8edab6118e347eb5d78b96f96b9d40ca --- nova/api/openstack/compute/contrib/aggregates.py | 6 ++---- nova/tests/api/openstack/compute/contrib/test_aggregates.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/nova/api/openstack/compute/contrib/aggregates.py b/nova/api/openstack/compute/contrib/aggregates.py index 78075afc4bd..7c6d31d0d90 100644 --- a/nova/api/openstack/compute/contrib/aggregates.py +++ b/nova/api/openstack/compute/contrib/aggregates.py @@ -81,11 +81,9 @@ def create(self, req, body): try: aggregate = self.api.create_aggregate(context, name, avail_zone) except exception.AggregateNameExists as e: - LOG.info(e) - raise exc.HTTPConflict() + raise exc.HTTPConflict(explanation=e.format_message()) except exception.InvalidAggregateAction as e: - LOG.info(e) - raise + raise exc.HTTPBadRequest(explanation=e.format_message()) return self._marshall_aggregate(aggregate) def show(self, req, id): diff --git a/nova/tests/api/openstack/compute/contrib/test_aggregates.py b/nova/tests/api/openstack/compute/contrib/test_aggregates.py index a971d33e62d..33259070d86 100644 --- a/nova/tests/api/openstack/compute/contrib/test_aggregates.py +++ b/nova/tests/api/openstack/compute/contrib/test_aggregates.py @@ -108,7 +108,7 @@ def stub_create_aggregate(context, name, availability_zone): self.stubs.Set(self.controller.api, "create_aggregate", stub_create_aggregate) - self.assertRaises(exception.InvalidAggregateAction, + self.assertRaises(exc.HTTPBadRequest, self.controller.create, self.req, {"aggregate": {"name": "test",