summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-10-14 20:03:37 +0000
committerGerrit Code Review <review@openstack.org>2016-10-14 20:03:37 +0000
commitfad76268ac84eb736acc5fd7f5afc20d5f94d208 (patch)
tree249ec4144b0df2842f4960bdc8c18795ec6f7f1f
parentb3772b788d4a10705120b7f73defc6e338d0dd2d (diff)
parent6ea56f87d1516a7efe3b4dbd5f774fce819d39dc (diff)
downloadnova-fad76268ac84eb736acc5fd7f5afc20d5f94d208.tar.gz
Merge "Add error handling for delete-volume API" into stable/mitaka
-rw-r--r--nova/api/openstack/compute/legacy_v2/contrib/volumes.py2
-rw-r--r--nova/api/openstack/compute/volumes.py4
-rw-r--r--nova/tests/unit/api/openstack/compute/test_volumes.py8
3 files changed, 13 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py
index 6b0e9966e2..54a1847542 100644
--- a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py
+++ b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py
@@ -124,6 +124,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)
diff --git a/nova/api/openstack/compute/volumes.py b/nova/api/openstack/compute/volumes.py
index 7dc2caaebe..2c07c59094 100644
--- a/nova/api/openstack/compute/volumes.py
+++ b/nova/api/openstack/compute/volumes.py
@@ -114,7 +114,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']
@@ -122,6 +122,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())
diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py
index 42745aa100..857da39071 100644
--- a/nova/tests/unit/api/openstack/compute/test_volumes.py
+++ b/nova/tests/unit/api/openstack/compute/test_volumes.py
@@ -828,6 +828,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