Skip to content

Commit

Permalink
Allow rpc-silent FloatingIP exceptions in n-net
Browse files Browse the repository at this point in the history
This patch uses the new client_exceptions functionality to squelch
some errant exception dumps in the RPC layer.

Fixes bug 1084707

Change-Id: I31a783a67d7722751fcfeafab40e781dc762dd65
  • Loading branch information
kk7ds committed Dec 11, 2012
1 parent 405c67b commit f2df530
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nova/network/manager.py
Expand Up @@ -68,6 +68,7 @@
from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier
from nova.openstack.common.rpc import common as rpc_common
from nova.openstack.common import timeutils
from nova.openstack.common import uuidutils
import nova.policy
Expand Down Expand Up @@ -459,6 +460,7 @@ def allocate_floating_ip(self, context, project_id, auto_assigned=False,

return floating_ip

@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress)
@wrap_check_policy
def deallocate_floating_ip(self, context, address,
affect_auto_assigned=False):
Expand Down Expand Up @@ -505,6 +507,7 @@ def deallocate_floating_ip(self, context, address,
if reservations:
QUOTAS.commit(context, reservations)

@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress)
@wrap_check_policy
def associate_floating_ip(self, context, floating_address, fixed_address,
affect_auto_assigned=False):
Expand Down Expand Up @@ -584,6 +587,7 @@ def _associate_floating_ip(self, context, floating_address, fixed_address,
'network.floating_ip.associate',
notifier.INFO, payload=payload)

@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress)
@wrap_check_policy
def disassociate_floating_ip(self, context, address,
affect_auto_assigned=False):
Expand Down Expand Up @@ -654,6 +658,7 @@ def _disassociate_floating_ip(self, context, address, interface,
'network.floating_ip.disassociate',
notifier.INFO, payload=payload)

@rpc_common.client_exceptions(exception.FloatingIpNotFound)
@wrap_check_policy
def get_floating_ip(self, context, id):
"""Returns a floating IP as a dict"""
Expand Down
44 changes: 44 additions & 0 deletions nova/tests/network/test_manager.py
Expand Up @@ -30,6 +30,7 @@
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.openstack.common import rpc
from nova.openstack.common.rpc import common as rpc_common
import nova.policy
from nova import test
from nova.tests import fake_ldap
Expand Down Expand Up @@ -1929,6 +1930,49 @@ def fake_vif_save(vif):
self.network.add_virtual_interface(ctxt, 'fake_uuid', 'fake_net')
self.assertEqual(macs, [])

def test_deallocate_client_exceptions(self):
"""Ensure that FloatingIpNotFoundForAddress is wrapped"""
self.mox.StubOutWithMock(self.network.db, 'floating_ip_get_by_address')
self.network.db.floating_ip_get_by_address(
self.context, '1.2.3.4').AndRaise(
exception.FloatingIpNotFoundForAddress)
self.mox.ReplayAll()
self.assertRaises(rpc_common.ClientException,
self.network.deallocate_floating_ip,
self.context, '1.2.3.4')

def test_associate_client_exceptions(self):
"""Ensure that FloatingIpNotFoundForAddress is wrapped"""
self.mox.StubOutWithMock(self.network.db, 'floating_ip_get_by_address')
self.network.db.floating_ip_get_by_address(
self.context, '1.2.3.4').AndRaise(
exception.FloatingIpNotFoundForAddress)
self.mox.ReplayAll()
self.assertRaises(rpc_common.ClientException,
self.network.associate_floating_ip,
self.context, '1.2.3.4', '10.0.0.1')

def test_disassociate_client_exceptions(self):
"""Ensure that FloatingIpNotFoundForAddress is wrapped"""
self.mox.StubOutWithMock(self.network.db, 'floating_ip_get_by_address')
self.network.db.floating_ip_get_by_address(
self.context, '1.2.3.4').AndRaise(
exception.FloatingIpNotFoundForAddress)
self.mox.ReplayAll()
self.assertRaises(rpc_common.ClientException,
self.network.disassociate_floating_ip,
self.context, '1.2.3.4')

def test_get_floating_ip_client_exceptions(self):
"""Ensure that FloatingIpNotFoundForAddress is wrapped"""
self.mox.StubOutWithMock(self.network.db, 'floating_ip_get')
self.network.db.floating_ip_get(self.context, 'fake-id').AndRaise(
exception.FloatingIpNotFound)
self.mox.ReplayAll()
self.assertRaises(rpc_common.ClientException,
self.network.get_floating_ip,
self.context, 'fake-id')


class NetworkPolicyTestCase(test.TestCase):
def setUp(self):
Expand Down

0 comments on commit f2df530

Please sign in to comment.