Catch InvalidAggregateAction when deleting an aggregate
When an aggregate with 'host' attribute not empty is deleted, InvalidAggregateAction exception will be raised, but this exception is not handled. Closes-Bug: #1303591 Change-Id: I4ef0c4a6008acea7e9769e93de79451cfbc0a0fa
This commit is contained in:
parent
977d469e4b
commit
86d1007c20
|
@ -147,6 +147,8 @@ class AggregateController(object):
|
|||
self.api.delete_aggregate(context, id)
|
||||
except exception.AggregateNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.InvalidAggregateAction as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
def action(self, req, id, body):
|
||||
_actions = {
|
||||
|
|
|
@ -103,7 +103,7 @@ class AggregateController(wsgi.Controller):
|
|||
|
||||
return self._marshall_aggregate(aggregate)
|
||||
|
||||
@extensions.expected_errors(404)
|
||||
@extensions.expected_errors((400, 404))
|
||||
@wsgi.response(204)
|
||||
def delete(self, req, id):
|
||||
"""Removes an aggregate by id."""
|
||||
|
@ -113,6 +113,8 @@ class AggregateController(wsgi.Controller):
|
|||
self.api.delete_aggregate(context, id)
|
||||
except exception.AggregateNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.InvalidAggregateAction as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
@extensions.expected_errors((400, 404, 409))
|
||||
@wsgi.action('add_host')
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
"""Tests for the aggregates admin api."""
|
||||
|
||||
import mock
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.contrib import aggregates
|
||||
|
@ -560,3 +561,12 @@ class AggregateTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertRaises(exc.HTTPNotFound, self.controller.delete,
|
||||
self.req, "bogus_aggregate")
|
||||
|
||||
def test_delete_aggregate_with_host(self):
|
||||
with mock.patch.object(self.controller.api, "delete_aggregate",
|
||||
side_effect=exception.InvalidAggregateAction(
|
||||
action="delete", aggregate_id="agg1",
|
||||
reason="not empty")):
|
||||
self.assertRaises(exc.HTTPBadRequest,
|
||||
self.controller.delete,
|
||||
self.req, "agg1")
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
"""Tests for the aggregates admin api."""
|
||||
|
||||
import mock
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import aggregates
|
||||
|
@ -545,3 +546,12 @@ class AggregateTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertRaises(exc.HTTPNotFound, self.controller.delete,
|
||||
self.req, "bogus_aggregate")
|
||||
|
||||
def test_delete_aggregate_with_host(self):
|
||||
with mock.patch.object(self.controller.api, "delete_aggregate",
|
||||
side_effect=exception.InvalidAggregateAction(
|
||||
action="delete", aggregate_id="agg1",
|
||||
reason="not empty")):
|
||||
self.assertRaises(exc.HTTPBadRequest,
|
||||
self.controller.delete,
|
||||
self.req, "agg1")
|
||||
|
|
Loading…
Reference in New Issue