summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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):