summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvijaya-erukala <vijaya_erukala@persistent.co.in>2012-09-25 16:07:57 +0530
committervijaya-erukala <vijaya_erukala@persistent.co.in>2012-09-26 14:28:05 +0530
commitbe4f059aa225fde6170f75a1abd338cadc351ef2 (patch)
tree1f6470863cb1a3dda45840e2feaf17e8364ddbc1
parentc367fa5e4a5e4712bde9fc319ae6c2f4f2add606 (diff)
downloadnova-be4f059aa225fde6170f75a1abd338cadc351ef2.tar.gz
nova-be4f059aa225fde6170f75a1abd338cadc351ef2.tar.xz
nova-be4f059aa225fde6170f75a1abd338cadc351ef2.zip
Modified 404 error response to show specific message
User-friendly messages are returned for invalid floating-ip and volume inputs Fixes bug 1056038 Change-Id: I659323b81ac435793152f9b49335b350c0801d81
-rw-r--r--nova/api/openstack/compute/contrib/floating_ips.py9
-rw-r--r--nova/api/openstack/volume/volumes.py7
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py22
3 files changed, 33 insertions, 5 deletions
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py
index be952eb8a..7b9ff8988 100644
--- a/nova/api/openstack/compute/contrib/floating_ips.py
+++ b/nova/api/openstack/compute/contrib/floating_ips.py
@@ -140,7 +140,8 @@ class FloatingIPController(object):
try:
floating_ip = self.network_api.get_floating_ip(context, id)
except exception.NotFound:
- raise webob.exc.HTTPNotFound()
+ msg = _("Floating ip not found for id %s") % id
+ raise webob.exc.HTTPNotFound(explanation=msg)
self._set_metadata(context, floating_ip)
@@ -184,7 +185,11 @@ class FloatingIPController(object):
authorize(context)
# get the floating ip object
- floating_ip = self.network_api.get_floating_ip(context, id)
+ try:
+ floating_ip = self.network_api.get_floating_ip(context, id)
+ except exception.NotFound:
+ msg = _("Floating ip not found for id %s") % id
+ raise webob.exc.HTTPNotFound(explanation=msg)
address = floating_ip['address']
# get the associated instance object (if any)
diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py
index 6cc4af899..e13f04036 100644
--- a/nova/api/openstack/volume/volumes.py
+++ b/nova/api/openstack/volume/volumes.py
@@ -274,7 +274,8 @@ class VolumeController(wsgi.Controller):
def create(self, req, body):
"""Creates a new volume."""
if not self.is_valid_body(body, 'volume'):
- raise exc.HTTPUnprocessableEntity()
+ msg = _("Invalid request body. 'volume' not found")
+ raise exc.HTTPUnprocessableEntity(explanation=msg)
context = req.environ['nova.context']
volume = body['volume']
@@ -302,6 +303,10 @@ class VolumeController(wsgi.Controller):
if size is None and kwargs['snapshot'] is not None:
size = kwargs['snapshot']['volume_size']
+ if size is None:
+ msg = _("Invalid request body. 'size' not found")
+ raise exc.HTTPUnprocessableEntity(explanation=msg)
+
LOG.audit(_("Create volume of %s GB"), size, context=context)
image_href = None
diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
index f7788101c..7f5583492 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -197,6 +197,21 @@ class FloatingIpTest(test.TestCase):
'id': 2}]}
self.assertEqual(res_dict, response)
+ def test_floating_ip_release_nonexisting(self):
+ def fake_get_floating_ip(*args, **kwargs):
+ raise exception.FloatingIpNotFound(id=id)
+
+ self.stubs.Set(network.api.API, "get_floating_ip",
+ fake_get_floating_ip)
+
+ req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/9876')
+ req.method = 'DELETE'
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 404)
+ expected_msg = ('{"itemNotFound": {"message": "Floating ip not found '
+ 'for id 9876", "code": 404}}')
+ self.assertEqual(res.body, expected_msg)
+
def test_floating_ip_show(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/1')
res_dict = self.controller.show(req, 1)
@@ -214,8 +229,11 @@ class FloatingIpTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/9876')
- self.assertRaises(webob.exc.HTTPNotFound,
- self.controller.show, req, 9876)
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 404)
+ expected_msg = ('{"itemNotFound": {"message": "Floating ip not found '
+ 'for id 9876", "code": 404}}')
+ self.assertEqual(res.body, expected_msg)
def test_show_associated_floating_ip(self):
def get_floating_ip(self, context, id):