diff --git a/nova/api/openstack/compute/contrib/aggregates.py b/nova/api/openstack/compute/contrib/aggregates.py index ea90a57d76f..583fe1b5137 100644 --- a/nova/api/openstack/compute/contrib/aggregates.py +++ b/nova/api/openstack/compute/contrib/aggregates.py @@ -72,7 +72,8 @@ def create(self, req, body): try: aggregate = self.api.create_aggregate(context, name, avail_zone) - except exception.AggregateNameExists: + except (exception.AggregateNameExists, + exception.InvalidAggregateAction): LOG.exception(_("Cannot create aggregate with name %(name)s and " "availability zone %(avail_zone)s") % locals()) raise exc.HTTPConflict diff --git a/nova/tests/api/openstack/compute/contrib/test_aggregates.py b/nova/tests/api/openstack/compute/contrib/test_aggregates.py index 6c8bc5a2f69..080cf84287e 100644 --- a/nova/tests/api/openstack/compute/contrib/test_aggregates.py +++ b/nova/tests/api/openstack/compute/contrib/test_aggregates.py @@ -87,6 +87,17 @@ def stub_create_aggregate(context, name, availability_zone): {"name": "test", "availability_zone": "nova1"}}) + def test_create_with_incorrect_availability_zone(self): + def stub_create_aggregate(context, name, availability_zone): + raise exception.InvalidAggregateAction + self.stubs.Set(self.controller.api, "create_aggregate", + stub_create_aggregate) + + self.assertRaises(exc.HTTPConflict, self.controller.create, + self.req, {"aggregate": + {"name": "test", + "availability_zone": "nova_bad"}}) + def test_create_with_no_aggregate(self): self.assertRaises(exc.HTTPBadRequest, self.controller.create, self.req, {"foo":