]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Load all the necessary database tables when running cisco plugin
authorBaodong (Robert) Li <baoli@cisco.com>
Tue, 19 Mar 2013 17:06:03 +0000 (10:06 -0700)
committerBaodong (Robert) Li <baoli@cisco.com>
Tue, 19 Mar 2013 17:26:43 +0000 (10:26 -0700)
In Cisco plugin, Remove redundant/unnecessary calls to configure_db().
Make sure that all the database models are loaded before calling
configure_db()

fixes bug #1155121

Change-Id: I27d5dda512140f0553b311b35678c82f729fa854

quantum/plugins/cisco/db/network_db_v2.py
quantum/plugins/cisco/db/nexus_db_v2.py
quantum/plugins/cisco/models/virt_phy_sw_v2.py
quantum/plugins/cisco/network_plugin.py
quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
quantum/tests/unit/cisco/test_network_plugin.py

index d69c6098801d44f04ab3f070a75f7f47de909156..5c91aabfe2b401c29ec281420b893e97b1c26f7c 100644 (file)
@@ -31,11 +31,6 @@ from quantum.plugins.openvswitch import ovs_models_v2
 LOG = logging.getLogger(__name__)
 
 
-def initialize():
-    """Establish database connection and load models"""
-    db.configure_db()
-
-
 def create_vlanids():
     """Prepopulates the vlan_bindings table"""
     LOG.debug(_("create_vlanids() called"))
index 3dc5d0bd28ee7c823eb1ce8f49ae4a223521d47c..0f951204846824101771704299b31cc18c7f4178 100644 (file)
@@ -29,11 +29,6 @@ from quantum.plugins.cisco.db import nexus_models_v2
 LOG = logging.getLogger(__name__)
 
 
-def initialize():
-    """Establish database connection and load models"""
-    db.configure_db()
-
-
 def get_all_nexusport_bindings():
     """Lists all the nexusport bindings"""
     LOG.debug(_("get_all_nexusport_bindings() called"))
index 0387b261a89341663f167088a7bfb3007eb410ad..fd084b746fd5a4db58e4d7c51258b3c0ebbfbfcf 100644 (file)
@@ -35,6 +35,7 @@ from quantum.plugins.cisco.db import network_db_v2 as cdb
 from quantum.plugins.cisco import l2network_plugin_configuration as conf
 from quantum.plugins.openvswitch import ovs_db_v2 as odb
 from quantum import quantum_plugin_base_v2
+from quantum.db import api as db_api
 
 
 LOG = logging.getLogger(__name__)
@@ -64,8 +65,6 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
         configured, and load the inventories those device plugins for which the
         inventory is configured
         """
-        cdb.initialize()
-        cred.Store.initialize()
         for key in conf.PLUGINS[const.PLUGINS].keys():
             plugin_obj = conf.PLUGINS[const.PLUGINS][key]
             self._plugins[key] = importutils.import_object(plugin_obj)
@@ -77,12 +76,21 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                 LOG.debug(_("Loaded device inventory %s\n"),
                           conf.PLUGINS[const.INVENTORY][key])
 
-        if hasattr(self._plugins[const.VSWITCH_PLUGIN],
-                   "supported_extension_aliases"):
+        if ((const.VSWITCH_PLUGIN in self._plugins) and
+            hasattr(self._plugins[const.VSWITCH_PLUGIN],
+                    "supported_extension_aliases")):
             self.supported_extension_aliases.extend(
                 self._plugins[const.VSWITCH_PLUGIN].
                 supported_extension_aliases)
 
+        # At this point, all the database models should have been loaded. It's
+        # possible that configure_db() may have been called by one of the
+        # plugins loaded in above. Otherwise, this call is to make sure that
+        # the database is initialized
+        db_api.configure_db()
+
+        # Initialize credential store after database initialization
+        cred.Store.initialize()
         LOG.debug(_("%(module)s.%(name)s init done"),
                   {'module': __name__,
                    'name': self.__class__.__name__})
index 123b314d96e93ed950a42d6a70aa0988cbc13797..270136cfc820d5dfb863637fe96965866a5f8f07 100644 (file)
@@ -66,7 +66,6 @@ class PluginV2(db_base_plugin_v2.QuantumDbPluginV2):
             self.supported_extension_aliases.extend(
                 self._model.supported_extension_aliases)
 
-        super(PluginV2, self).__init__()
         LOG.debug(_("Plugin initialization complete"))
 
     def __getattribute__(self, name):
index 232bad945d7c6ceafbb8909d2b19bffe1a366cc2..5138c65cf8e5bef91315db3c4fcbf55229a4d456 100644 (file)
@@ -50,8 +50,6 @@ class NexusPlugin(L2DevicePluginBase):
         """
         Extracts the configuration parameters from the configuration file
         """
-        # Initialize the nxos db
-        nxos_db.initialize()
         self._client = importutils.import_object(conf.NEXUS_DRIVER)
         LOG.debug(_("Loaded driver %s"), conf.NEXUS_DRIVER)
         self._nexus_switches = conf.NEXUS_DETAILS
index d79a6293a0141596524d211d0f98829f3a7729cd..4fbec2095a286bca0c0b8ae41a3956d13ec3eff0 100644 (file)
@@ -32,12 +32,7 @@ class CiscoNetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase):
     _plugin_name = 'quantum.plugins.cisco.network_plugin.PluginV2'
 
     def setUp(self):
-        def new_init():
-            db.configure_db()
-
-        with mock.patch.object(network_db_v2,
-                               'initialize', new=new_init):
-            super(CiscoNetworkPluginV2TestCase, self).setUp(self._plugin_name)
+        super(CiscoNetworkPluginV2TestCase, self).setUp(self._plugin_name)
         self.port_create_status = 'DOWN'
 
     def _get_plugin_ref(self):