summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-01-24 22:24:57 +0000
committerGerrit Code Review <review@openstack.org>2012-01-24 22:24:57 +0000
commitbf5f01ce637ad80c46c2d30bd563829f1e5bf18f (patch)
tree8f088591fefe9601b85f27571fb5c5213aadfeb6 /nova
parentb328b0422035212c844ff5bbcc03f648fb7a2779 (diff)
parent8279240ee30d55d127e4d964a9861b721ac7cc74 (diff)
downloadnova-bf5f01ce637ad80c46c2d30bd563829f1e5bf18f.tar.gz
nova-bf5f01ce637ad80c46c2d30bd563829f1e5bf18f.tar.xz
nova-bf5f01ce637ad80c46c2d30bd563829f1e5bf18f.zip
Merge "Handle error in associate floating IP (bug 845507)"
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/compute/contrib/floating_ips.py3
-rw-r--r--nova/exception.py4
-rw-r--r--nova/network/api.py2
-rw-r--r--nova/network/manager.py27
-rw-r--r--nova/tests/test_network.py17
5 files changed, 46 insertions, 7 deletions
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py
index afbdcf83a..46e2fe6fd 100644
--- a/nova/api/openstack/compute/contrib/floating_ips.py
+++ b/nova/api/openstack/compute/contrib/floating_ips.py
@@ -212,6 +212,9 @@ class FloatingIPActionController(wsgi.Controller):
raise webob.exc.HTTPBadRequest(explanation=e.message)
except exception.NotAuthorized, e:
raise webob.exc.HTTPUnauthorized()
+ except rpc.RemoteError:
+ msg = _("Associate floating ip failed")
+ raise webob.exc.HTTPInternalServerError(explanation=msg)
return webob.Response(status_int=202)
diff --git a/nova/exception.py b/nova/exception.py
index 42ec908d7..8eda6bfc6 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -588,6 +588,10 @@ class NoFloatingIpsDefined(NotFound):
message = _("Zero floating ips exist.")
+class NoFloatingIpInterface(NotFound):
+ message = _("Interface %(interface)s not found.")
+
+
class KeypairNotFound(NotFound):
message = _("Keypair %(name)s not found for user %(user_id)s")
diff --git a/nova/network/api.py b/nova/network/api.py
index 83ef7a566..dac012e1c 100644
--- a/nova/network/api.py
+++ b/nova/network/api.py
@@ -123,7 +123,7 @@ class API(base.Base):
ensures floating ip is allocated to the project in context
"""
- rpc.cast(context,
+ rpc.call(context,
FLAGS.network_topic,
{'method': 'associate_floating_ip',
'args': {'floating_address': floating_address,
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 5e9035a12..f1a07cd81 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -226,10 +226,15 @@ class FloatingIP(object):
for floating_ip in floating_ips:
if floating_ip.get('fixed_ip', None):
fixed_address = floating_ip['fixed_ip']['address']
- # NOTE(vish): The False here is because we ignore the case
- # that the ip is already bound.
- self.driver.bind_floating_ip(floating_ip['address'],
- floating_ip['interface'])
+ interface = floating_ip['interface']
+ try:
+ self.driver.bind_floating_ip(floating_ip['address'],
+ interface)
+ except exception.ProcessExecutionError:
+ msg = _('Interface %(interface)s not found' % locals())
+ LOG.debug(msg)
+ raise exception.NoFloatingIpInterface(interface=interface)
+
self.driver.ensure_floating_forward(floating_ip['address'],
fixed_address)
@@ -415,8 +420,18 @@ class FloatingIP(object):
floating_address,
fixed_address,
self.host)
- # gogo driver time
- self.driver.bind_floating_ip(floating_address, interface)
+ try:
+ # gogo driver time
+ self.driver.bind_floating_ip(floating_address, interface)
+ except exception.ProcessExecutionError as e:
+ fixed_address = self.db.floating_ip_disassociate(context,
+ floating_address)
+ if "Cannot find device" in str(e):
+ msg = _('Interface %(interface)s not found' % locals())
+ LOG.error(msg)
+ raise exception.NoFloatingIpInterface(interface=interface)
+ raise
+
self.driver.ensure_floating_forward(floating_address, fixed_address)
@wrap_check_policy
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index 573a308e1..200251b7e 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -636,6 +636,23 @@ class VlanNetworkTestCase(test.TestCase):
def fake7(*args, **kwargs):
self.local = True
+ def fake8(*args, **kwargs):
+ raise exception.ProcessExecutionError('',
+ 'Cannot find device "em0"\n')
+
+ # raises because interface doesn't exist
+ self.stubs.Set(self.network.db,
+ 'floating_ip_fixed_ip_associate',
+ fake1)
+ self.stubs.Set(self.network.db, 'floating_ip_disassociate', fake1)
+ self.stubs.Set(self.network.driver, 'bind_floating_ip', fake8)
+ self.assertRaises(exception.NoFloatingIpInterface,
+ self.network._associate_floating_ip,
+ ctxt,
+ mox.IgnoreArg(),
+ mox.IgnoreArg(),
+ mox.IgnoreArg())
+
self.stubs.Set(self.network, '_floating_ip_owned_by_project', fake1)
# raises because floating_ip is already associated to a fixed_ip