summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorChris Yeoh <cyeoh@au1.ibm.com>2013-05-08 15:36:28 +0930
committerChris Yeoh <cyeoh@au1.ibm.com>2013-05-08 15:36:28 +0930
commit46ce2e345bce18c2e2f645bb90aea11ca53ba825 (patch)
tree34a761be8dbc1e0c3cc5511e9bb9f5420f183a5e /nova
parent4ce8f2a6a9d4644153b4ba532ca1b78665507d6a (diff)
Catch volume create exception
Catch InvalidInput exception from cinder when the parameters are invalid such as an invalid size. Currently the exception is not caught which results in a 400 Bad Request correctly being returned, but also leaving a traceback in the logs. Correctly catching the exception and explicitly raising an HTTPBadRequest removes the production of the traceback Fixes bug #1098048 Change-Id: Ia66e67f302cf20e96417f4ff3c1430b755a4a861
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/compute/contrib/volumes.py22
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_volumes.py18
2 files changed, 31 insertions, 9 deletions
diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py
index 640ac0c76..5b2097365 100644
--- a/nova/api/openstack/compute/contrib/volumes.py
+++ b/nova/api/openstack/compute/contrib/volumes.py
@@ -244,15 +244,19 @@ class VolumeController(wsgi.Controller):
availability_zone = vol.get('availability_zone', None)
- new_volume = self.volume_api.create(context,
- size,
- vol.get('display_name'),
- vol.get('display_description'),
- snapshot=snapshot,
- volume_type=vol_type,
- metadata=metadata,
- availability_zone=availability_zone
- )
+ try:
+ new_volume = self.volume_api.create(
+ context,
+ size,
+ vol.get('display_name'),
+ vol.get('display_description'),
+ snapshot=snapshot,
+ volume_type=vol_type,
+ metadata=metadata,
+ availability_zone=availability_zone
+ )
+ except exception.InvalidInput as err:
+ raise exc.HTTPBadRequest(explanation=str(err))
# TODO(vish): Instance should be None at db layer instead of
# trying to lazy load, but for now we turn it into
diff --git a/nova/tests/api/openstack/compute/contrib/test_volumes.py b/nova/tests/api/openstack/compute/contrib/test_volumes.py
index 83372b251..256fb58fc 100644
--- a/nova/tests/api/openstack/compute/contrib/test_volumes.py
+++ b/nova/tests/api/openstack/compute/contrib/test_volumes.py
@@ -24,6 +24,7 @@ from nova.api.openstack.compute.contrib import volumes
from nova.compute import api as compute_api
from nova.compute import instance_types
from nova import context
+from nova import exception
from nova.openstack.common import jsonutils
from nova.openstack.common import timeutils
from nova import test
@@ -183,6 +184,23 @@ class VolumeApiTest(test.TestCase):
self.assertEqual(resp_dict['volume']['availabilityZone'],
vol['availability_zone'])
+ def test_volume_create_bad(self):
+ def fake_volume_create(self, context, size, name, description,
+ snapshot, **param):
+ raise exception.InvalidInput(reason="bad request data")
+
+ self.stubs.Set(cinder.API, "create", fake_volume_create)
+
+ vol = {"size": '#$?',
+ "display_name": "Volume Test Name",
+ "display_description": "Volume Test Desc",
+ "availability_zone": "zone1:host1"}
+ body = {"volume": vol}
+
+ req = fakes.HTTPRequest.blank('/v2/fake/os-volumes')
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ volumes.VolumeController().create, req, body)
+
def test_volume_index(self):
req = webob.Request.blank('/v2/fake/os-volumes')
resp = req.get_response(self.app)