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
(cherry picked from commit 2afc4e4669)
This commit is contained in:
Ken'ichi Ohmichi 2016-10-05 14:14:30 -07:00
parent f680157175
commit 090bff767b
3 changed files with 13 additions and 1 deletions

View File

@ -112,6 +112,8 @@ class VolumeController(wsgi.Controller):
try:
self.volume_api.delete(context, id)
except exception.InvalidInput as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.NotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
return webob.Response(status_int=202)

View File

@ -100,7 +100,7 @@ class VolumeController(wsgi.Controller):
return {'volume': _translate_volume_detail_view(context, vol)}
@wsgi.response(202)
@extensions.expected_errors(404)
@extensions.expected_errors((400, 404))
def delete(self, req, id):
"""Delete a volume."""
context = req.environ['nova.context']
@ -108,6 +108,8 @@ class VolumeController(wsgi.Controller):
try:
self.volume_api.delete(context, id)
except exception.InvalidInput as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.VolumeNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())

View File

@ -757,6 +757,14 @@ class BadRequestVolumeTestCaseV21(CommonBadRequestTestCase,
controller_cls = volumes_v21.VolumeController
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 BadRequestVolumeTestCaseV2(BadRequestVolumeTestCaseV21):
controller_cls = volumes.VolumeController