summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-10-01 21:54:35 +0000
committerGerrit Code Review <review@openstack.org>2012-10-01 21:54:35 +0000
commit14cfc19381b7f923b9c0e174038810a1a1aec5dc (patch)
treebb71eda1c772ab494415edb08a5d79cdcd5cbb77
parent8a332ea285f824ed3b19e05543ce53e44c329860 (diff)
parent9a303f2cc231f5d43257ebced5b1167c08d32648 (diff)
downloadnova-14cfc19381b7f923b9c0e174038810a1a1aec5dc.tar.gz
nova-14cfc19381b7f923b9c0e174038810a1a1aec5dc.tar.xz
nova-14cfc19381b7f923b9c0e174038810a1a1aec5dc.zip
Merge "Catch NotFound exception in FloatingIP add/remove"
-rw-r--r--nova/api/openstack/compute/contrib/floating_ips.py12
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py33
2 files changed, 43 insertions, 2 deletions
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py
index 7b9ff8988..1c17591a4 100644
--- a/nova/api/openstack/compute/contrib/floating_ips.py
+++ b/nova/api/openstack/compute/contrib/floating_ips.py
@@ -259,6 +259,9 @@ class FloatingIPActionController(wsgi.Controller):
except exception.NoFloatingIpInterface:
msg = _('l3driver call to add floating ip failed')
raise webob.exc.HTTPBadRequest(explanation=msg)
+ except exception.FloatingIpNotFoundForAddress:
+ msg = _('floating ip not found')
+ raise webob.exc.HTTPNotFound(explanation=msg)
except Exception:
msg = _('Error. Unable to associate floating ip')
LOG.exception(msg)
@@ -282,8 +285,13 @@ class FloatingIPActionController(wsgi.Controller):
raise webob.exc.HTTPBadRequest(explanation=msg)
# get the floating ip object
- floating_ip = self.network_api.get_floating_ip_by_address(context,
- address)
+ try:
+ floating_ip = self.network_api.get_floating_ip_by_address(context,
+ address)
+ except exception.FloatingIpNotFoundForAddress:
+ msg = _("floating ip not found")
+ raise webob.exc.HTTPNotFound(explanation=msg)
+
# get the associated instance object (if any)
instance = get_instance_by_floating_ip_addr(self, context, address)
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 7f5583492..a789bbe96 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -346,6 +346,39 @@ class FloatingIpTest(test.TestCase):
rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
self.assertTrue(rsp.status_int == 404)
+ def test_floating_ip_associate_non_existent_ip(self):
+ def fake_network_api_associate(self, context, instance,
+ floating_address=None,
+ fixed_address=None):
+ floating_ips = ["10.10.10.10", "10.10.10.11"]
+ if floating_address not in floating_ips:
+ raise exception.FloatingIpNotFoundForAddress()
+
+ self.stubs.Set(network.api.API, "associate_floating_ip",
+ fake_network_api_associate)
+
+ body = dict(addFloatingIp=dict(address='1.1.1.1'))
+ req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.manager._add_floating_ip,
+ req, 'test_inst', body)
+
+ def test_floating_ip_disassociate_non_existent_ip(self):
+ def network_api_get_floating_ip_by_address(self, context,
+ floating_address):
+ floating_ips = ["10.10.10.10", "10.10.10.11"]
+ if floating_address not in floating_ips:
+ raise exception.FloatingIpNotFoundForAddress()
+
+ self.stubs.Set(network.api.API, "get_floating_ip_by_address",
+ network_api_get_floating_ip_by_address)
+
+ body = dict(removeFloatingIp=dict(address='1.1.1.1'))
+ req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.manager._remove_floating_ip,
+ req, 'test_inst', body)
+
def test_floating_ip_disassociate_wrong_instance_uuid(self):
def get_instance_by_floating_ip_addr(self, context, address):
if address == '10.10.10.10':