From f2df5304f1de961ea2c9e1f4101f201b7b99ff53 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 11 Dec 2012 09:32:36 -0800 Subject: Allow rpc-silent FloatingIP exceptions in n-net This patch uses the new client_exceptions functionality to squelch some errant exception dumps in the RPC layer. Fixes bug 1084707 Change-Id: I31a783a67d7722751fcfeafab40e781dc762dd65 --- nova/network/manager.py | 5 +++++ nova/tests/network/test_manager.py | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'nova') diff --git a/nova/network/manager.py b/nova/network/manager.py index 6680634c9..80f40b801 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -68,6 +68,7 @@ from nova.openstack.common import importutils 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 @@ -459,6 +460,7 @@ class FloatingIP(object): return floating_ip + @rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress) @wrap_check_policy def deallocate_floating_ip(self, context, address, affect_auto_assigned=False): @@ -505,6 +507,7 @@ class FloatingIP(object): 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): @@ -584,6 +587,7 @@ class FloatingIP(object): '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): @@ -654,6 +658,7 @@ class FloatingIP(object): '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""" diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index cab684767..1a0ef2d37 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -30,6 +30,7 @@ from nova.network import manager as network_manager 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 @@ -1929,6 +1930,49 @@ class FloatingIPTestCase(test.TestCase): 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): -- cgit