summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorChris Yeoh <cyeoh@au1.ibm.com>2013-04-17 13:02:02 +0930
committerChris Yeoh <cyeoh@au1.ibm.com>2013-04-18 16:30:33 +0930
commitf9be01a42a513d7d579cc2424a439ae800ec6df6 (patch)
tree717397a267b61844e92f2650c7bee6c305f2d18a /nova
parent36b10384724fec9657784980cd2bd38e72b445bc (diff)
downloadnova-f9be01a42a513d7d579cc2424a439ae800ec6df6.tar.gz
nova-f9be01a42a513d7d579cc2424a439ae800ec6df6.tar.xz
nova-f9be01a42a513d7d579cc2424a439ae800ec6df6.zip
Translate NoMoreFloatingIps exception
When the pool of floating ips is exhausted the NoMoreFloatingIps exception is raised but not handled properly in the floating ips extension resulting in the exception propagating further up and causing a stack trace to be logged. This change translates the exception explicitly into a HTTPNotFound, preserving the current REST API behaviour. It fixes a bug where the pool name was not correctly inserted into the message returned if allocation from a specific pool was requested. Fixes bug 1169811 Part of blueprint no-stacktraces-in-logs Change-Id: I8f35d25d065bb1fa709cff6f59841ac8c86658bd
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/compute/contrib/floating_ips.py8
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py19
2 files changed, 20 insertions, 7 deletions
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py
index bf1246ccb..7be479e5a 100644
--- a/nova/api/openstack/compute/contrib/floating_ips.py
+++ b/nova/api/openstack/compute/contrib/floating_ips.py
@@ -160,12 +160,12 @@ class FloatingIPController(object):
try:
address = self.network_api.allocate_floating_ip(context, pool)
ip = self.network_api.get_floating_ip_by_address(context, address)
- except exception.NoMoreFloatingIps, nmfi:
+ except exception.NoMoreFloatingIps:
if pool:
- nmfi.message = _("No more floating ips in pool %s.") % pool
+ msg = _("No more floating ips in pool %s.") % pool
else:
- nmfi.message = _("No more floating ips available.")
- raise
+ msg = _("No more floating ips available.")
+ raise webob.exc.HTTPNotFound(explanation=msg)
return _translate_floating_ip_view(ip)
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 00759a7ef..385d56939 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -17,6 +17,7 @@
import uuid
from lxml import etree
+import testtools
import webob
from nova.api.openstack.compute.contrib import floating_ips
@@ -281,9 +282,21 @@ class FloatingIpTest(test.TestCase):
self.stubs.Set(network.api.API, "allocate_floating_ip", fake_allocate)
req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips')
- self.assertRaises(exception.NoMoreFloatingIps,
- self.controller.create,
- req)
+ with testtools.ExpectedException(webob.exc.HTTPNotFound,
+ 'No more floating ips'):
+ self.controller.create(req)
+
+ def test_floating_ip_allocate_no_free_ips_pool(self):
+ def fake_allocate(*args, **kwargs):
+ raise exception.NoMoreFloatingIps()
+
+ self.stubs.Set(network.api.API, "allocate_floating_ip", fake_allocate)
+
+ req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips')
+ with testtools.ExpectedException(
+ webob.exc.HTTPNotFound,
+ 'No more floating ips in pool non_existant_pool'):
+ self.controller.create(req, {'pool': 'non_existant_pool'})
def test_floating_ip_allocate(self):
def fake1(*args, **kwargs):