summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen'ichi Ohmichi <ken-oomichi@wx.jp.nec.com>2016-10-05 14:14:30 -0700
committerKen'ichi Ohmichi <ken-oomichi@wx.jp.nec.com>2016-10-11 09:44:15 -0700
commit6ea56f87d1516a7efe3b4dbd5f774fce819d39dc (patch)
tree572d88e3fd2541991ebf3e53ad6a56cbcca2c76c
parent63f3d99819137315b9cb8475614b86314733b1d7 (diff)
downloadnova-6ea56f87d1516a7efe3b4dbd5f774fce819d39dc.tar.gz
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 2afc4e466958b19a4cbb9147abb69f54a06bd507)
-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