blueprint database-common
bug 995438 Updates after comments Updates after comments Updates after comments Updates after comments - fix linux bridge tests Change-Id: Iaee24b08e07a4f4dde5e27f31d3a5f81f5101466
This commit is contained in:
parent
faf8c9bfeb
commit
bb7f491310
@ -3,17 +3,14 @@ vlan_start=1000
|
|||||||
vlan_end=3000
|
vlan_end=3000
|
||||||
|
|
||||||
[DATABASE]
|
[DATABASE]
|
||||||
# Use the following when running the tests for the in-memory DB
|
# This line MUST be changed to actually run the plugin.
|
||||||
connection = sqlite
|
# Example:
|
||||||
# Uncomment the following for using the MySQL DB when actually running the plugin,
|
# sql_connection = mysql://root:nova@127.0.0.1:3306/quantum_linux_bridge
|
||||||
# also remove the earlier sqlite connection configuration
|
# Replace 127.0.0.1 above with the IP address of the database used by the
|
||||||
#connection = mysql
|
# main quantum server. (Leave it as is if the database runs on this host.)
|
||||||
name = quantum_linux_bridge
|
sql_connection = sqlite://
|
||||||
user = <mysql_user_name_here>
|
# Database reconnection interval in seconds - in event connectivity is lost
|
||||||
pass = <mysql_password_here>
|
reconnect_interval = 2
|
||||||
host = <hostname_or_IP_address_of_Quantum_server>
|
|
||||||
# If you use a non-default port for the DB, change the following
|
|
||||||
port = 3306
|
|
||||||
|
|
||||||
[LINUX_BRIDGE]
|
[LINUX_BRIDGE]
|
||||||
# This is the interface connected to the switch on your Quantum network
|
# This is the interface connected to the switch on your Quantum network
|
||||||
@ -22,8 +19,6 @@ physical_interface = eth1
|
|||||||
[AGENT]
|
[AGENT]
|
||||||
# Agent's polling interval in seconds
|
# Agent's polling interval in seconds
|
||||||
polling_interval = 2
|
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
|
# Change to "sudo quantum-rootwrap" to limit commands that can be run
|
||||||
# as root.
|
# as root.
|
||||||
root_helper = sudo
|
root_helper = sudo
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
[DATABASE]
|
[DATABASE]
|
||||||
# This line MUST be changed to actually run the plugin.
|
# 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
|
# 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.)
|
# main quantum server. (Leave it as is if the database runs on this host.)
|
||||||
sql_connection = sqlite://
|
sql_connection = sqlite://
|
||||||
|
# Database reconnection interval in seconds - in event connectivity is lost
|
||||||
|
reconnect_interval = 2
|
||||||
|
|
||||||
[OVS]
|
[OVS]
|
||||||
# This enables the new OVSQuantumTunnelAgent which enables tunneling
|
# This enables the new OVSQuantumTunnelAgent which enables tunneling
|
||||||
@ -34,8 +37,6 @@ integration-bridge = br-int
|
|||||||
[AGENT]
|
[AGENT]
|
||||||
# Agent's polling interval in seconds
|
# Agent's polling interval in seconds
|
||||||
polling_interval = 2
|
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
|
# Change to "sudo quantum-rootwrap" to limit commands that can be run
|
||||||
# as root.
|
# as root.
|
||||||
root_helper = sudo
|
root_helper = sudo
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
# @author: Dan Wendlandt, Nicira Networks, Inc.
|
# @author: Dan Wendlandt, Nicira Networks, Inc.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
import sqlalchemy as sql
|
import sqlalchemy as sql
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
@ -78,7 +79,9 @@ def configure_db(options):
|
|||||||
engine_args['listeners'] = [MySQLPingListener()]
|
engine_args['listeners'] = [MySQLPingListener()]
|
||||||
|
|
||||||
_ENGINE = create_engine(options['sql_connection'], **engine_args)
|
_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():
|
def clear_db():
|
||||||
@ -99,11 +102,25 @@ def get_session(autocommit=True, expire_on_commit=False):
|
|||||||
return _MAKER()
|
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():
|
def register_models():
|
||||||
"""Register Models and create properties"""
|
"""Register Models and create properties"""
|
||||||
global _ENGINE
|
global _ENGINE
|
||||||
assert _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():
|
def unregister_models():
|
||||||
|
@ -473,26 +473,17 @@ def main():
|
|||||||
else:
|
else:
|
||||||
polling_interval = DEFAULT_POLLING_INTERVAL
|
polling_interval = DEFAULT_POLLING_INTERVAL
|
||||||
LOG.info("Polling interval not defined. Using default.")
|
LOG.info("Polling interval not defined. Using default.")
|
||||||
if config.has_option("AGENT", "reconnect_interval"):
|
if config.has_option("DATABASE", "reconnect_interval"):
|
||||||
reconnect_interval = config.getint("AGENT", "reconnect_interval")
|
reconnect_interval = config.getint("DATABASE",
|
||||||
|
"reconnect_interval")
|
||||||
else:
|
else:
|
||||||
reconnect_interval = DEFAULT_RECONNECT_INTERVAL
|
reconnect_interval = DEFAULT_RECONNECT_INTERVAL
|
||||||
LOG.info("Reconnect interval not defined. Using default.")
|
LOG.info("Reconnect interval not defined. Using default.")
|
||||||
root_helper = config.get("AGENT", "root_helper")
|
root_helper = config.get("AGENT", "root_helper")
|
||||||
'Establish database connection and load models'
|
'Establish database connection and load models'
|
||||||
connection = config.get("DATABASE", "connection")
|
db_connection_url = config.get("DATABASE", "sql_connection")
|
||||||
if connection == 'sqlite':
|
LOG.info("Connecting to %s" % (db_connection_url))
|
||||||
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))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("Unable to parse config file \"%s\": \nException %s" %
|
LOG.error("Unable to parse config file \"%s\": \nException %s" %
|
||||||
(config_file, str(e)))
|
(config_file, str(e)))
|
||||||
|
@ -31,16 +31,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def initialize():
|
def initialize():
|
||||||
'Establish database connection and load models'
|
options = {"sql_connection": "%s" % conf.DB_SQL_CONNECTION}
|
||||||
if conf.DB_CONNECTION == 'sqlite':
|
options.update({"reconnect_interval": conf.DB_RECONNECT_INTERVAL})
|
||||||
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)}
|
|
||||||
|
|
||||||
db.configure_db(options)
|
db.configure_db(options)
|
||||||
create_vlanids()
|
create_vlanids()
|
||||||
|
|
||||||
|
@ -37,10 +37,8 @@ VLAN_END = SECTION_CONF['vlan_end']
|
|||||||
|
|
||||||
|
|
||||||
SECTION_CONF = CONF_PARSER_OBJ['DATABASE']
|
SECTION_CONF = CONF_PARSER_OBJ['DATABASE']
|
||||||
DB_CONNECTION = SECTION_CONF['connection']
|
DB_SQL_CONNECTION = SECTION_CONF['sql_connection']
|
||||||
if DB_CONNECTION != 'sqlite':
|
if 'reconnect_interval' in SECTION_CONF:
|
||||||
DB_NAME = SECTION_CONF['name']
|
DB_RECONNECT_INTERVAL = int(SECTION_CONF['reconnect_interval'])
|
||||||
DB_USER = SECTION_CONF['user']
|
else:
|
||||||
DB_PASS = SECTION_CONF['pass']
|
DB_RECONNECT_INTERVAL = 2
|
||||||
DB_HOST = SECTION_CONF['host']
|
|
||||||
DB_PORT = SECTION_CONF['port']
|
|
||||||
|
@ -394,6 +394,8 @@ class LinuxBridgeAgentTest(unittest.TestCase):
|
|||||||
self.physical_interface = config.get("LINUX_BRIDGE",
|
self.physical_interface = config.get("LINUX_BRIDGE",
|
||||||
"physical_interface")
|
"physical_interface")
|
||||||
self.polling_interval = config.get("AGENT", "polling_interval")
|
self.polling_interval = config.get("AGENT", "polling_interval")
|
||||||
|
self.reconnect_interval = config.get("DATABASE",
|
||||||
|
"reconnect_interval")
|
||||||
self.root_helper = config.get("AGENT", "root_helper")
|
self.root_helper = config.get("AGENT", "root_helper")
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
LOG.error("Unable to parse config file \"%s\": \nException%s"
|
LOG.error("Unable to parse config file \"%s\": \nException%s"
|
||||||
@ -406,6 +408,7 @@ class LinuxBridgeAgentTest(unittest.TestCase):
|
|||||||
self.br_name_prefix,
|
self.br_name_prefix,
|
||||||
self.physical_interface,
|
self.physical_interface,
|
||||||
self.polling_interval,
|
self.polling_interval,
|
||||||
|
self.reconnect_interval,
|
||||||
self.root_helper)
|
self.root_helper)
|
||||||
|
|
||||||
def run_cmd(self, args):
|
def run_cmd(self, args):
|
||||||
|
@ -699,8 +699,9 @@ def main():
|
|||||||
else:
|
else:
|
||||||
polling_interval = DEFAULT_POLLING_INTERVAL
|
polling_interval = DEFAULT_POLLING_INTERVAL
|
||||||
LOG.info("Polling interval not defined. Using default.")
|
LOG.info("Polling interval not defined. Using default.")
|
||||||
if config.has_option("AGENT", "reconnect_interval"):
|
if config.has_option("DATABASE", "reconnect_interval"):
|
||||||
reconnect_interval = config.getint("AGENT", "reconnect_interval")
|
reconnect_interval = config.getint("DATABASE",
|
||||||
|
"reconnect_interval")
|
||||||
else:
|
else:
|
||||||
reconnect_interval = DEFAULT_RECONNECT_INTERVAL
|
reconnect_interval = DEFAULT_RECONNECT_INTERVAL
|
||||||
LOG.info("Reconnect interval not defined. Using default.")
|
LOG.info("Reconnect interval not defined. Using default.")
|
||||||
|
@ -104,6 +104,12 @@ class OVSQuantumPlugin(QuantumPluginBase):
|
|||||||
LOG.debug("Config: %s" % config)
|
LOG.debug("Config: %s" % config)
|
||||||
|
|
||||||
options = {"sql_connection": config.get("DATABASE", "sql_connection")}
|
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)
|
db.configure_db(options)
|
||||||
|
|
||||||
self.vmap = VlanMap()
|
self.vmap = VlanMap()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user