Add error handling for delete-volume API
Due to lack of an error handling, delete-volume API returns HTTP500 error when deleting an attached volume. This patch adds the error handling. The corresponding Tempest test is Idb6267be770bcf2541595babebf269cdc71c2b8d Closes-Bug: #1630783 Change-Id: Ia07556b2dc18678baa4c8fbd65820d8047362ef9
This commit is contained in:
parent
290c31beaa
commit
2afc4e4669
@ -118,7 +118,7 @@ class VolumeController(wsgi.Controller):
|
|||||||
|
|
||||||
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
|
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
|
||||||
@wsgi.response(202)
|
@wsgi.response(202)
|
||||||
@extensions.expected_errors(404)
|
@extensions.expected_errors((400, 404))
|
||||||
def delete(self, req, id):
|
def delete(self, req, id):
|
||||||
"""Delete a volume."""
|
"""Delete a volume."""
|
||||||
context = req.environ['nova.context']
|
context = req.environ['nova.context']
|
||||||
@ -126,6 +126,8 @@ class VolumeController(wsgi.Controller):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.volume_api.delete(context, id)
|
self.volume_api.delete(context, id)
|
||||||
|
except exception.InvalidInput as e:
|
||||||
|
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||||
except exception.VolumeNotFound as e:
|
except exception.VolumeNotFound as e:
|
||||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||||
|
|
||||||
|
@ -780,6 +780,14 @@ class BadRequestVolumeTestCaseV21(CommonBadRequestTestCase,
|
|||||||
controller_cls = volumes_v21.VolumeController
|
controller_cls = volumes_v21.VolumeController
|
||||||
bad_request = exception.ValidationError
|
bad_request = exception.ValidationError
|
||||||
|
|
||||||
|
@mock.patch.object(cinder.API, 'delete',
|
||||||
|
side_effect=exception.InvalidInput(reason='vol attach'))
|
||||||
|
def test_delete_invalid_status_volume(self, mock_delete):
|
||||||
|
req = fakes.HTTPRequest.blank('/v2.1/os-volumes')
|
||||||
|
req.method = 'DELETE'
|
||||||
|
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||||
|
self.controller.delete, req, FAKE_UUID)
|
||||||
|
|
||||||
|
|
||||||
class BadRequestSnapshotTestCaseV21(CommonBadRequestTestCase,
|
class BadRequestSnapshotTestCaseV21(CommonBadRequestTestCase,
|
||||||
test.NoDBTestCase):
|
test.NoDBTestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user