From 469a1ca64b2c64fe270859ce927f0c0eba6ee8bd Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Tue, 3 Jun 2014 13:30:58 +0200 Subject: [PATCH] Don't instantiate RPC clients on import In oslo.messaging port, we'll need to make sure no RPC clients or servers or notifiers are created before RPC layer is initialized using n_rpc.init(). This means that there should be no global objects that create those objects on __init__. There should also be no such class attributes because in that case import will itself instantiate the object, probably before RPC layer is ready. blueprint oslo-messaging Change-Id: Ia8a9fd39777c75e4253f5518c2de6be551cc365b --- .../api/rpc/agentnotifiers/l3_rpc_agent_api.py | 2 -- neutron/db/l3_db.py | 11 ++++++++++- neutron/plugins/brocade/NeutronPlugin.py | 2 +- .../plugins/cisco/n1kv/n1kv_neutron_plugin.py | 2 +- .../plugins/linuxbridge/lb_neutron_plugin.py | 2 +- .../plugins/ml2/drivers/l2pop/mech_driver.py | 18 +++++++++++------- neutron/plugins/ml2/drivers/l2pop/rpc.py | 2 -- neutron/plugins/mlnx/mlnx_plugin.py | 2 +- neutron/plugins/oneconvergence/plugin.py | 2 +- .../plugins/openvswitch/ovs_neutron_plugin.py | 2 +- neutron/services/l3_router/l3_router_plugin.py | 2 +- 11 files changed, 28 insertions(+), 19 deletions(-) diff --git a/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py index e9731c36e..9bf1080db 100644 --- a/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py @@ -119,5 +119,3 @@ class L3AgentNotifyAPI(rpc_compat.RpcProxy): def router_added_to_agent(self, context, router_ids, host): self._notification_host(context, 'router_added_to_agent', router_ids, host) - -L3AgentNotify = L3AgentNotifyAPI() diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 8575abf66..547026277 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -81,13 +81,22 @@ class FloatingIP(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): class L3_NAT_db_mixin(l3.RouterPluginBase): """Mixin class to add L3/NAT router methods to db_base_plugin_v2.""" - l3_rpc_notifier = l3_rpc_agent_api.L3AgentNotify router_device_owners = ( DEVICE_OWNER_ROUTER_INTF, DEVICE_OWNER_ROUTER_GW, DEVICE_OWNER_FLOATINGIP ) + @property + def l3_rpc_notifier(self): + if not hasattr(self, '_l3_rpc_notifier'): + self._l3_rpc_notifier = l3_rpc_agent_api.L3AgentNotifyAPI() + return self._l3_rpc_notifier + + @l3_rpc_notifier.setter + def l3_rpc_notifier(self, value): + self._l3_rpc_notifier = value + @property def _core_plugin(self): return manager.NeutronManager.get_plugin() diff --git a/neutron/plugins/brocade/NeutronPlugin.py b/neutron/plugins/brocade/NeutronPlugin.py index 9a654501e..fc1d1ad5d 100644 --- a/neutron/plugins/brocade/NeutronPlugin.py +++ b/neutron/plugins/brocade/NeutronPlugin.py @@ -275,7 +275,7 @@ class BrocadePluginV2(db_base_plugin_v2.NeutronDbPluginV2, dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) self.agent_notifiers[q_const.AGENT_TYPE_L3] = ( - l3_rpc_agent_api.L3AgentNotify + l3_rpc_agent_api.L3AgentNotifyAPI() ) def create_network(self, context, network): diff --git a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py index 1294a8581..d3749f19d 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py +++ b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py @@ -141,7 +141,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, for svc_topic in self.service_topics.values(): self.conn.create_consumer(svc_topic, self.dispatcher, fanout=False) self.dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI() - self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify + self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotifyAPI() # Consume from all consumers in a thread self.conn.consume_in_thread() diff --git a/neutron/plugins/linuxbridge/lb_neutron_plugin.py b/neutron/plugins/linuxbridge/lb_neutron_plugin.py index ac7859966..9af9a616d 100644 --- a/neutron/plugins/linuxbridge/lb_neutron_plugin.py +++ b/neutron/plugins/linuxbridge/lb_neutron_plugin.py @@ -294,7 +294,7 @@ class LinuxBridgePluginV2(db_base_plugin_v2.NeutronDbPluginV2, dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) self.agent_notifiers[q_const.AGENT_TYPE_L3] = ( - l3_rpc_agent_api.L3AgentNotify + l3_rpc_agent_api.L3AgentNotifyAPI() ) def _parse_network_vlan_ranges(self): diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py index 7c2719ddd..af4a427fc 100644 --- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py +++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py @@ -34,6 +34,10 @@ LOG = logging.getLogger(__name__) class L2populationMechanismDriver(api.MechanismDriver, l2pop_db.L2populationDbMixin): + def __init__(self): + super(L2populationMechanismDriver, self).__init__() + self.L2populationAgentNotify = l2pop_rpc.L2populationAgentNotifyAPI() + def initialize(self): LOG.debug(_("Experimental L2 population driver")) self.rpc_ctx = n_context.get_admin_context_without_session() @@ -56,7 +60,7 @@ class L2populationMechanismDriver(api.MechanismDriver, def delete_port_postcommit(self, context): fanout_msg = self.deleted_ports.pop(context.current['id'], None) if fanout_msg: - l2pop_rpc.L2populationAgentNotify.remove_fdb_entries( + self.L2populationAgentNotify.remove_fdb_entries( self.rpc_ctx, fanout_msg) def _get_diff_ips(self, orig, port): @@ -90,7 +94,7 @@ class L2populationMechanismDriver(api.MechanismDriver, if port_mac_ip: ports['after'] = port_mac_ip - l2pop_rpc.L2populationAgentNotify.update_fdb_entries( + self.L2populationAgentNotify.update_fdb_entries( self.rpc_ctx, {'chg_ip': upd_fdb_entries}) return True @@ -114,14 +118,14 @@ class L2populationMechanismDriver(api.MechanismDriver, self._update_port_up(context) elif port['status'] == const.PORT_STATUS_DOWN: fdb_entries = self._update_port_down(context, port) - l2pop_rpc.L2populationAgentNotify.remove_fdb_entries( + self.L2populationAgentNotify.remove_fdb_entries( self.rpc_ctx, fdb_entries) elif port['status'] == const.PORT_STATUS_BUILD: orig = self.migrated_ports.pop(port['id'], None) if orig: # this port has been migrated : remove its entries from fdb fdb_entries = self._update_port_down(context, orig) - l2pop_rpc.L2populationAgentNotify.remove_fdb_entries( + self.L2populationAgentNotify.remove_fdb_entries( self.rpc_ctx, fdb_entries) def _get_port_infos(self, context, port): @@ -206,14 +210,14 @@ class L2populationMechanismDriver(api.MechanismDriver, const.FLOODING_ENTRY) if ports.keys(): - l2pop_rpc.L2populationAgentNotify.add_fdb_entries( + self.L2populationAgentNotify.add_fdb_entries( self.rpc_ctx, agent_fdb_entries, agent_host) # Notify other agents to add fdb rule for current port other_fdb_entries[network_id]['ports'][agent_ip] += port_fdb_entries - l2pop_rpc.L2populationAgentNotify.add_fdb_entries(self.rpc_ctx, - other_fdb_entries) + self.L2populationAgentNotify.add_fdb_entries(self.rpc_ctx, + other_fdb_entries) def _update_port_down(self, context, port_context, agent_active_ports_count_for_flooding=0): diff --git a/neutron/plugins/ml2/drivers/l2pop/rpc.py b/neutron/plugins/ml2/drivers/l2pop/rpc.py index 925b18faa..b4f171a27 100644 --- a/neutron/plugins/ml2/drivers/l2pop/rpc.py +++ b/neutron/plugins/ml2/drivers/l2pop/rpc.py @@ -84,5 +84,3 @@ class L2populationAgentNotifyAPI(rpc_compat.RpcProxy): else: self._notification_fanout(context, 'update_fdb_entries', fdb_entries) - -L2populationAgentNotify = L2populationAgentNotifyAPI() diff --git a/neutron/plugins/mlnx/mlnx_plugin.py b/neutron/plugins/mlnx/mlnx_plugin.py index 371fe2d38..f0a469bd5 100644 --- a/neutron/plugins/mlnx/mlnx_plugin.py +++ b/neutron/plugins/mlnx/mlnx_plugin.py @@ -131,7 +131,7 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.NeutronDbPluginV2, dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) self.agent_notifiers[q_const.AGENT_TYPE_L3] = ( - l3_rpc_agent_api.L3AgentNotify + l3_rpc_agent_api.L3AgentNotifyAPI() ) def _parse_network_config(self): diff --git a/neutron/plugins/oneconvergence/plugin.py b/neutron/plugins/oneconvergence/plugin.py index 33ff42a5c..7d7af13b0 100644 --- a/neutron/plugins/oneconvergence/plugin.py +++ b/neutron/plugins/oneconvergence/plugin.py @@ -165,7 +165,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2, dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) self.agent_notifiers[q_const.AGENT_TYPE_L3] = ( - l3_rpc_agent_api.L3AgentNotify + l3_rpc_agent_api.L3AgentNotifyAPI() ) self.callbacks = NVSDPluginRpcCallbacks() self.dispatcher = self.callbacks.create_rpc_dispatcher() diff --git a/neutron/plugins/openvswitch/ovs_neutron_plugin.py b/neutron/plugins/openvswitch/ovs_neutron_plugin.py index cfcaf44f8..01867c416 100644 --- a/neutron/plugins/openvswitch/ovs_neutron_plugin.py +++ b/neutron/plugins/openvswitch/ovs_neutron_plugin.py @@ -341,7 +341,7 @@ class OVSNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) self.agent_notifiers[q_const.AGENT_TYPE_L3] = ( - l3_rpc_agent_api.L3AgentNotify + l3_rpc_agent_api.L3AgentNotifyAPI() ) self.callbacks = OVSRpcCallbacks(self.notifier, self.tunnel_type) self.dispatcher = self.callbacks.create_rpc_dispatcher() diff --git a/neutron/services/l3_router/l3_router_plugin.py b/neutron/services/l3_router/l3_router_plugin.py index 082553ec7..c5505817d 100644 --- a/neutron/services/l3_router/l3_router_plugin.py +++ b/neutron/services/l3_router/l3_router_plugin.py @@ -76,7 +76,7 @@ class L3RouterPlugin(db_base_plugin_v2.CommonDbMixin, self.topic = topics.L3PLUGIN self.conn = rpc_compat.create_connection(new=True) self.agent_notifiers.update( - {q_const.AGENT_TYPE_L3: l3_rpc_agent_api.L3AgentNotify}) + {q_const.AGENT_TYPE_L3: l3_rpc_agent_api.L3AgentNotifyAPI()}) self.callbacks = L3RouterPluginRpcCallbacks() self.dispatcher = self.callbacks.create_rpc_dispatcher() self.conn.create_consumer(self.topic, self.dispatcher, -- 2.45.2