]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
blueprint database-common
authorGary Kotton <gkotton@redhat.com>
Sun, 6 May 2012 11:36:47 +0000 (07:36 -0400)
committerGary Kotton <gkotton@redhat.com>
Thu, 10 May 2012 09:01:57 +0000 (05:01 -0400)
bug 995438

Updates after comments

Updates after comments

Updates after comments

Updates after comments - fix linux bridge tests

Change-Id: Iaee24b08e07a4f4dde5e27f31d3a5f81f5101466

etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini
etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
quantum/db/api.py
quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py
quantum/plugins/linuxbridge/db/l2network_db.py
quantum/plugins/linuxbridge/plugin_configuration.py
quantum/plugins/linuxbridge/tests/unit/_test_linuxbridgeAgent.py
quantum/plugins/openvswitch/agent/ovs_quantum_agent.py
quantum/plugins/openvswitch/ovs_quantum_plugin.py

index 93b66d4d741ed4255a5201accd251a0004fc798c..b2a3e3b8dcda3e711c41014e0837e55c03f73daa 100644 (file)
@@ -3,17 +3,14 @@ vlan_start=1000
 vlan_end=3000
 
 [DATABASE]
-# Use the following when running the tests for the in-memory DB
-connection = sqlite
-# Uncomment the following for using the MySQL DB when actually running the plugin,
-# also remove the earlier sqlite connection configuration
-#connection = mysql
-name = quantum_linux_bridge
-user = <mysql_user_name_here>
-pass = <mysql_password_here>
-host = <hostname_or_IP_address_of_Quantum_server>
-# If you use a non-default port for the DB, change the following
-port = 3306
+# This line MUST be changed to actually run the plugin.
+# Example:
+# sql_connection = mysql://root:nova@127.0.0.1:3306/quantum_linux_bridge
+# Replace 127.0.0.1 above with the IP address of the database used by the
+# main quantum server. (Leave it as is if the database runs on this host.)
+sql_connection = sqlite://
+# Database reconnection interval in seconds - in event connectivity is lost
+reconnect_interval = 2
 
 [LINUX_BRIDGE]
 # This is the interface connected to the switch on your Quantum network
@@ -22,8 +19,6 @@ physical_interface = eth1
 [AGENT]
 # Agent's polling interval in seconds
 polling_interval = 2
-# Agent's database reconnection interval in seconds - in event connectivity is lost
-reconnect_interval = 2
 # Change to "sudo quantum-rootwrap" to limit commands that can be run
 # as root.
 root_helper = sudo
index 12796aa0c53a949d06cb4db9025577e3dae4b577..2cb39b69c0dd310776f9d21c98081ce3e326e97a 100644 (file)
@@ -1,9 +1,12 @@
 [DATABASE]
 # This line MUST be changed to actually run the plugin.
-# Example: sql_connection = mysql://root:nova@127.0.0.1:3306/ovs_quantum
+# Example:
+# sql_connection = mysql://root:nova@127.0.0.1:3306/ovs_quantum
 # Replace 127.0.0.1 above with the IP address of the database used by the
 # main quantum server. (Leave it as is if the database runs on this host.)
 sql_connection = sqlite://
+# Database reconnection interval in seconds - in event connectivity is lost
+reconnect_interval = 2
 
 [OVS]
 # This enables the new OVSQuantumTunnelAgent which enables tunneling
@@ -34,8 +37,6 @@ integration-bridge = br-int
 [AGENT]
 # Agent's polling interval in seconds
 polling_interval = 2
-# Agent's database reconnection interval in seconds - in event connectivity is lost
-reconnect_interval = 2
 # Change to "sudo quantum-rootwrap" to limit commands that can be run
 # as root.
 root_helper = sudo
index 17b833477ca857136378ff86cb7e178c41817f4d..85a9c89dd1ac5afca66c18e7e20fa766a1156c8d 100644 (file)
@@ -18,6 +18,7 @@
 # @author: Dan Wendlandt, Nicira Networks, Inc.
 
 import logging
+import time
 
 import sqlalchemy as sql
 from sqlalchemy import create_engine
@@ -78,7 +79,9 @@ def configure_db(options):
             engine_args['listeners'] = [MySQLPingListener()]
 
         _ENGINE = create_engine(options['sql_connection'], **engine_args)
-        register_models()
+        if not register_models():
+            if 'reconnect_interval' in options:
+                retry_registration(options['reconnect_interval'])
 
 
 def clear_db():
@@ -99,11 +102,25 @@ def get_session(autocommit=True, expire_on_commit=False):
     return _MAKER()
 
 
+def retry_registration(reconnect_interval):
+    while True:
+        LOG.info("Unable to connect to database. Retrying in %s seconds" %
+                 reconnect_interval)
+        time.sleep(reconnect_interval)
+        if register_models():
+            break
+
+
 def register_models():
     """Register Models and create properties"""
     global _ENGINE
     assert _ENGINE
-    BASE.metadata.create_all(_ENGINE)
+    try:
+        BASE.metadata.create_all(_ENGINE)
+    except sql.exc.OperationalError as e:
+        LOG.info("Database registration exception: %s" % e)
+        return False
+    return True
 
 
 def unregister_models():
index 0c1a896df0cbb48894f8dbdf5f938b2c055d8e4e..a65b19dc76bec896697f0647dfe4474733c4464e 100755 (executable)
@@ -473,26 +473,17 @@ def main():
         else:
             polling_interval = DEFAULT_POLLING_INTERVAL
             LOG.info("Polling interval not defined. Using default.")
-        if config.has_option("AGENT", "reconnect_interval"):
-            reconnect_interval = config.getint("AGENT", "reconnect_interval")
+        if config.has_option("DATABASE", "reconnect_interval"):
+            reconnect_interval = config.getint("DATABASE",
+                                               "reconnect_interval")
         else:
             reconnect_interval = DEFAULT_RECONNECT_INTERVAL
             LOG.info("Reconnect interval not defined. Using default.")
         root_helper = config.get("AGENT", "root_helper")
         'Establish database connection and load models'
-        connection = config.get("DATABASE", "connection")
-        if connection == 'sqlite':
-            LOG.info("Connecting to sqlite DB")
-            db_connection_url = "sqlite:///:memory:"
-        else:
-            db_name = config.get("DATABASE", "name")
-            db_user = config.get("DATABASE", "user")
-            db_pass = config.get("DATABASE", "pass")
-            db_host = config.get("DATABASE", "host")
-            db_port = int(config.get("DATABASE", "port"))
-            LOG.info("Connecting to database %s on %s" % (db_name, db_host))
-            db_connection_url = ("%s://%s:%s@%s:%d/%s" %
-                    (connection, db_user, db_pass, db_host, db_port, db_name))
+        db_connection_url = config.get("DATABASE", "sql_connection")
+        LOG.info("Connecting to %s" % (db_connection_url))
+
     except Exception as e:
         LOG.error("Unable to parse config file \"%s\": \nException %s" %
                   (config_file, str(e)))
index 5b02419fa4cc874db0a2f9a9983329956781d8ce..16b83ce0aa34fa4bac7fa3d33f66486a8047f44d 100644 (file)
@@ -31,16 +31,8 @@ LOG = logging.getLogger(__name__)
 
 
 def initialize():
-    'Establish database connection and load models'
-    if conf.DB_CONNECTION == 'sqlite':
-        options = {"sql_connection": "sqlite://"}
-    else:
-        options = {"sql_connection": "mysql://%s:%s@%s:%s/%s" % (conf.DB_USER,
-                                                                 conf.DB_PASS,
-                                                                 conf.DB_HOST,
-                                                                 conf.DB_PORT,
-                                                                 conf.DB_NAME)}
-
+    options = {"sql_connection": "%s" % conf.DB_SQL_CONNECTION}
+    options.update({"reconnect_interval": conf.DB_RECONNECT_INTERVAL})
     db.configure_db(options)
     create_vlanids()
 
index a5bacb134b8ac10b78265fb6c9837389c0b44698..a647c798723306234582674f0e47acc96b0b7d70 100644 (file)
@@ -37,10 +37,8 @@ VLAN_END = SECTION_CONF['vlan_end']
 
 
 SECTION_CONF = CONF_PARSER_OBJ['DATABASE']
-DB_CONNECTION = SECTION_CONF['connection']
-if DB_CONNECTION != 'sqlite':
-    DB_NAME = SECTION_CONF['name']
-    DB_USER = SECTION_CONF['user']
-    DB_PASS = SECTION_CONF['pass']
-    DB_HOST = SECTION_CONF['host']
-    DB_PORT = SECTION_CONF['port']
+DB_SQL_CONNECTION = SECTION_CONF['sql_connection']
+if 'reconnect_interval' in SECTION_CONF:
+    DB_RECONNECT_INTERVAL = int(SECTION_CONF['reconnect_interval'])
+else:
+    DB_RECONNECT_INTERVAL = 2
index 21b142acb248c34dc6125c8a5e66e8ce3074bf35..63acd55a0d6146240a4609e176a2c1592d59c72e 100644 (file)
@@ -394,6 +394,8 @@ class LinuxBridgeAgentTest(unittest.TestCase):
             self.physical_interface = config.get("LINUX_BRIDGE",
                                                  "physical_interface")
             self.polling_interval = config.get("AGENT", "polling_interval")
+            self.reconnect_interval = config.get("DATABASE",
+                                                 "reconnect_interval")
             self.root_helper = config.get("AGENT", "root_helper")
         except Exception, e:
             LOG.error("Unable to parse config file \"%s\": \nException%s"
@@ -406,6 +408,7 @@ class LinuxBridgeAgentTest(unittest.TestCase):
             self.br_name_prefix,
             self.physical_interface,
             self.polling_interval,
+            self.reconnect_interval,
             self.root_helper)
 
     def run_cmd(self, args):
index f1a41fced92c6faf6c6b2161332f03ce2b42b61b..8d62758aa010551aae9ae31fd7bd9bca9c11261a 100755 (executable)
@@ -699,8 +699,9 @@ def main():
         else:
             polling_interval = DEFAULT_POLLING_INTERVAL
             LOG.info("Polling interval not defined. Using default.")
-        if config.has_option("AGENT", "reconnect_interval"):
-            reconnect_interval = config.getint("AGENT", "reconnect_interval")
+        if config.has_option("DATABASE", "reconnect_interval"):
+            reconnect_interval = config.getint("DATABASE",
+                                               "reconnect_interval")
         else:
             reconnect_interval = DEFAULT_RECONNECT_INTERVAL
             LOG.info("Reconnect interval not defined. Using default.")
index 6bb9f81732c0fec71be0b1f2c5a5d13c5764a5c0..4fcf9a3c8da168bd38dbcf77eb402b7e5389c60e 100644 (file)
@@ -104,6 +104,12 @@ class OVSQuantumPlugin(QuantumPluginBase):
         LOG.debug("Config: %s" % config)
 
         options = {"sql_connection": config.get("DATABASE", "sql_connection")}
+        if config.has_option("DATABASE", "reconnect_interval"):
+            reconnect_interval = config.getint("DATABASE",
+                                               "reconnect_interval")
+        else:
+            reconnect_interval = 2
+        options.update({"reconnect_interval": reconnect_interval})
         db.configure_db(options)
 
         self.vmap = VlanMap()