From: Ihar Hrachyshka Date: Fri, 30 May 2014 13:26:45 +0000 (+0200) Subject: Introduced transition RPC exception types X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f003fe27cbf95fb127a8c5f7bf5ab1ea0362ba9f;p=openstack-build%2Fneutron-build.git Introduced transition RPC exception types These exception types will ease transition from oslo-rpc to oslo.messaging. blueprint oslo-messaging Change-Id: I48d214d676e863d7a60d78c49d2fa917d47c07d9 --- diff --git a/neutron/agent/dhcp_agent.py b/neutron/agent/dhcp_agent.py index eeb55fda8..bfdbca371 100644 --- a/neutron/agent/dhcp_agent.py +++ b/neutron/agent/dhcp_agent.py @@ -37,7 +37,6 @@ from neutron import manager from neutron.openstack.common import importutils from neutron.openstack.common import log as logging from neutron.openstack.common import loopingcall -from neutron.openstack.common.rpc import common from neutron.openstack.common import service from neutron import service as neutron_service @@ -136,7 +135,7 @@ class DhcpAgent(manager.Manager): % {'net_id': network.id, 'action': action}) except Exception as e: self.schedule_resync(e) - if (isinstance(e, common.RemoteError) + if (isinstance(e, rpc_compat.RemoteError) and e.exc_type == 'NetworkNotFound' or isinstance(e, exceptions.NetworkNotFound)): LOG.warning(_("Network %s has been deleted."), network.id) diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py index 0f2ae2bce..778b947cc 100644 --- a/neutron/agent/l3_agent.py +++ b/neutron/agent/l3_agent.py @@ -37,7 +37,6 @@ from neutron.openstack.common import log as logging from neutron.openstack.common import loopingcall from neutron.openstack.common import periodic_task from neutron.openstack.common import processutils -from neutron.openstack.common.rpc import common as rpc_common from neutron.openstack.common import service from neutron import service as neutron_service from neutron.services.firewall.agents.l3reference import firewall_l3_agent @@ -76,9 +75,9 @@ class L3PluginApi(rpc_compat.RpcProxy): def get_external_network_id(self, context): """Make a remote process call to retrieve the external network id. - @raise common.RemoteError: with TooManyExternalNetworks - as exc_type if there are - more than one external network + @raise rpc_compat.RemoteError: with TooManyExternalNetworks + as exc_type if there are + more than one external network """ return self.call(context, self.make_msg('get_external_network_id', @@ -324,7 +323,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager): self.target_ex_net_id = self.plugin_rpc.get_external_network_id( self.context) return self.target_ex_net_id - except rpc_common.RemoteError as e: + except rpc_compat.RemoteError as e: with excutils.save_and_reraise_exception() as ctx: if e.exc_type == 'TooManyExternalNetworks': ctx.reraise = False @@ -857,7 +856,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager): self._process_routers(routers, all_routers=True) self.fullsync = False LOG.debug(_("_sync_routers_task successfully completed")) - except rpc_common.RPCException: + except rpc_compat.RPCException: LOG.exception(_("Failed synchronizing routers due to RPC error")) self.fullsync = True return diff --git a/neutron/common/rpc_compat.py b/neutron/common/rpc_compat.py index 0e0eb1170..6854f5728 100644 --- a/neutron/common/rpc_compat.py +++ b/neutron/common/rpc_compat.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron.openstack.common.rpc import common as rpc_common from neutron.openstack.common.rpc import proxy @@ -23,3 +24,9 @@ class RpcProxy(proxy.RpcProxy): emulate RpcProxy class behaviour using oslo.messaging API once the migration is applied. ''' + + +# exceptions +RPCException = rpc_common.RPCException +RemoteError = rpc_common.RemoteError +MessagingTimeout = rpc_common.Timeout diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index 30008822a..5e5c15243 100755 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -37,12 +37,12 @@ from neutron.agent import securitygroups_rpc as sg_rpc from neutron.common import config as logging_config from neutron.common import constants from neutron.common import exceptions +from neutron.common import rpc_compat from neutron.common import topics from neutron.common import utils as q_utils from neutron import context from neutron.openstack.common import log as logging from neutron.openstack.common import loopingcall -from neutron.openstack.common.rpc import common as rpc_common from neutron.openstack.common.rpc import dispatcher from neutron.plugins.common import constants as p_const from neutron.plugins.linuxbridge.common import config # noqa @@ -725,7 +725,7 @@ class LinuxBridgeRpcCallbacks(sg_rpc.SecurityGroupAgentRpcCallbackMixin, tap_device_name, self.agent.agent_id, cfg.CONF.host) - except rpc_common.Timeout: + except rpc_compat.MessagingTimeout: LOG.error(_("RPC timeout while updating port %s"), port['id']) def fdb_add(self, context, fdb_entries): diff --git a/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py b/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py index 12915331e..35bc015f0 100644 --- a/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py +++ b/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py @@ -27,12 +27,12 @@ from neutron.agent import rpc as agent_rpc from neutron.agent import securitygroups_rpc as sg_rpc from neutron.common import config as logging_config from neutron.common import constants as q_constants +from neutron.common import rpc_compat from neutron.common import topics from neutron.common import utils as q_utils from neutron import context from neutron.openstack.common import log as logging from neutron.openstack.common import loopingcall -from neutron.openstack.common.rpc import common as rpc_common from neutron.openstack.common.rpc import dispatcher from neutron.plugins.common import constants as p_const from neutron.plugins.mlnx.agent import utils @@ -202,7 +202,7 @@ class MlnxEswitchRpcCallbacks(sg_rpc.SecurityGroupAgentRpcCallbackMixin): port['mac_address'], self.agent.agent_id, cfg.CONF.host) - except rpc_common.Timeout: + except rpc_compat.MessagingTimeout: LOG.error(_("RPC timeout while updating port %s"), port['id']) else: LOG.debug(_("No port %s defined on agent."), port['id']) diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index c367710f8..34671424a 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -25,7 +25,7 @@ from neutron.agent.linux import ip_lib from neutron.agent.linux import utils from neutron.common import constants from neutron.common import exceptions -from neutron.openstack.common.rpc import common as rpc_common +from neutron.common import rpc_compat from neutron.plugins.common import constants as p_const from neutron.plugins.linuxbridge.agent import linuxbridge_neutron_agent from neutron.plugins.linuxbridge.common import constants as lconst @@ -983,14 +983,15 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): port = {"admin_state_up": True, "id": "1234-5678", "network_id": "123-123"} - plugin_rpc.update_device_up.side_effect = rpc_common.Timeout + timeout_class = rpc_compat.MessagingTimeout + plugin_rpc.update_device_up.side_effect = timeout_class self.lb_rpc.port_update(mock.Mock(), port=port) self.assertTrue(plugin_rpc.update_device_up.called) self.assertEqual(log.call_count, 1) log.reset_mock() port["admin_state_up"] = False - plugin_rpc.update_device_down.side_effect = rpc_common.Timeout + plugin_rpc.update_device_down.side_effect = timeout_class self.lb_rpc.port_update(mock.Mock(), port=port) self.assertTrue(plugin_rpc.update_device_down.called) self.assertEqual(log.call_count, 1) diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 1401fd853..ae99dac6c 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -30,7 +30,7 @@ from neutron.agent.linux import dhcp from neutron.agent.linux import interface from neutron.common import constants as const from neutron.common import exceptions -from neutron.openstack.common.rpc import common +from neutron.common import rpc_compat from neutron.tests import base @@ -227,7 +227,7 @@ class TestDhcpAgent(base.BaseTestCase): def test_call_driver_remote_error_net_not_found(self): self._test_call_driver_failure( - exc=common.RemoteError(exc_type='NetworkNotFound'), + exc=rpc_compat.RemoteError(exc_type='NetworkNotFound'), trace_level='warning') def test_call_driver_network_not_found(self):