Merge "Add error handling for delete-volume API" into stable/newton

This commit is contained in:
Jenkins 2016-10-11 22:52:14 +00:00 committed by Gerrit Code Review
commit ac641eb526
2 changed files with 11 additions and 1 deletions

View File

@ -118,7 +118,7 @@ class VolumeController(wsgi.Controller):
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@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']
@ -126,6 +126,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

@ -780,6 +780,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 BadRequestSnapshotTestCaseV21(CommonBadRequestTestCase,
test.NoDBTestCase):