]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Don't instantiate RPC clients on import
authorIhar Hrachyshka <ihrachys@redhat.com>
Tue, 3 Jun 2014 11:30:58 +0000 (13:30 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Tue, 17 Jun 2014 19:56:24 +0000 (21:56 +0200)
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

neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py
neutron/db/l3_db.py
neutron/plugins/brocade/NeutronPlugin.py
neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/plugins/linuxbridge/lb_neutron_plugin.py
neutron/plugins/ml2/drivers/l2pop/mech_driver.py
neutron/plugins/ml2/drivers/l2pop/rpc.py
neutron/plugins/mlnx/mlnx_plugin.py
neutron/plugins/oneconvergence/plugin.py
neutron/plugins/openvswitch/ovs_neutron_plugin.py
neutron/services/l3_router/l3_router_plugin.py

index e9731c36e89ef84bc7acd20664aaac3ac29a1d1a..9bf1080dbbbf8bdb0402737e16d222b177a5b4bf 100644 (file)
@@ -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()
index 8575abf66c45a984005e31eeeb8cbb025b29aafe..547026277a34192e05610c3797dea0049afce2bc 100644 (file)
@@ -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()
index 9a654501e13e1cb7dbf67667dbc5e25e042bdce6..fc1d1ad5d79bfd9fb250ebb873d705ac9b89c482 100644 (file)
@@ -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):
index 1294a8581984facde3a33678a1e9b462e5b3a648..d3749f19dab819a3b39d51b36da411875edcff97 100644 (file)
@@ -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()
 
index ac7859966e09a7d103f4226681a7deb88b1d0f42..9af9a616d5622196a941bbcfc6fc7116d4250dd9 100644 (file)
@@ -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):
index 7c2719ddd6ccb7450f3868342bd552d1b18afef4..af4a427fcfac196fb7358d1a7a8f513187249fd8 100644 (file)
@@ -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):
index 925b18faad3496a6d4e30e8f15dcc36149246bca..b4f171a27f67a8154a9f2fd2b81341a4575b6588 100644 (file)
@@ -84,5 +84,3 @@ class L2populationAgentNotifyAPI(rpc_compat.RpcProxy):
             else:
                 self._notification_fanout(context, 'update_fdb_entries',
                                           fdb_entries)
-
-L2populationAgentNotify = L2populationAgentNotifyAPI()
index 371fe2d3877787e9735edda5c091d8cd329e0f25..f0a469bd55b501d85bd15793b309f314b730e518 100644 (file)
@@ -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):
index 33ff42a5c8b5d648e386ecb22805a766176ab6c1..7d7af13b0d0247a143f1901e2a803ce953e52042 100644 (file)
@@ -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()
index cfcaf44f879ac1cfdbb115a818bac3d49980e7f7..01867c4164c62014bf07911f3698d2ca8f1bc679 100644 (file)
@@ -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()
index 082553ec78ba8d3c3b46c35368e9e13c56fb7b8d..c5505817d59449e6d85719338fa57f10a22fd5af 100644 (file)
@@ -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,