Session does not use ceilometer.conf's database_connection

use [database]connection setting from openstack.common sqlalchemy session

Change-Id: I582d4cb7d51d6ddecc27ae5fcdedcfd19dc898af
Fixes: bug #1183106
This commit is contained in:
Gordon Chung 2013-05-28 11:48:43 -04:00
parent 0e2274253e
commit 9f6e3639fb
11 changed files with 40 additions and 33 deletions

View File

@ -35,13 +35,16 @@ STORAGE_ENGINE_NAMESPACE = 'ceilometer.storage'
STORAGE_OPTS = [ STORAGE_OPTS = [
cfg.StrOpt('database_connection', cfg.StrOpt('database_connection',
secret=True, secret=True,
default='mongodb://localhost:27017/ceilometer', default=None,
help='Database connection string', help='DEPRECATED - Database connection string',
), ),
] ]
cfg.CONF.register_opts(STORAGE_OPTS) cfg.CONF.register_opts(STORAGE_OPTS)
cfg.CONF.import_opt('connection',
'ceilometer.openstack.common.db.sqlalchemy.session',
group='database')
def register_opts(conf): def register_opts(conf):
@ -52,7 +55,9 @@ def register_opts(conf):
def get_engine(conf): def get_engine(conf):
"""Load the configured engine and return an instance.""" """Load the configured engine and return an instance."""
engine_name = urlparse.urlparse(conf.database_connection).scheme if conf.database_connection:
conf.database.connection = conf.database_connection
engine_name = urlparse.urlparse(conf.database.connection).scheme
LOG.debug('looking for %r driver in %r', LOG.debug('looking for %r driver in %r',
engine_name, STORAGE_ENGINE_NAMESPACE) engine_name, STORAGE_ENGINE_NAMESPACE)
mgr = driver.DriverManager(STORAGE_ENGINE_NAMESPACE, mgr = driver.DriverManager(STORAGE_ENGINE_NAMESPACE,

View File

@ -91,7 +91,7 @@ class Connection(base.Connection):
''' '''
Hbase Connection Initialization Hbase Connection Initialization
''' '''
opts = self._parse_connection_url(conf.database_connection) opts = self._parse_connection_url(conf.database.connection)
opts['table_prefix'] = conf.table_prefix opts['table_prefix'] = conf.table_prefix
if opts['host'] == '__test__': if opts['host'] == '__test__':

View File

@ -196,7 +196,7 @@ class Connection(base.Connection):
}""") }""")
def __init__(self, conf): def __init__(self, conf):
opts = self._parse_connection_url(conf.database_connection) opts = self._parse_connection_url(conf.database.connection)
LOG.info('connecting to MongoDB on %s:%s', opts['host'], opts['port']) LOG.info('connecting to MongoDB on %s:%s', opts['host'], opts['port'])
if opts['host'] == '__test__': if opts['host'] == '__test__':

View File

@ -132,11 +132,11 @@ class Connection(base.Connection):
"""SqlAlchemy connection.""" """SqlAlchemy connection."""
def __init__(self, conf): def __init__(self, conf):
url = conf.database_connection url = conf.database.connection
if url == 'sqlite://': if url == 'sqlite://':
url = os.environ.get('CEILOMETER_TEST_SQL_URL', url) url = os.environ.get('CEILOMETER_TEST_SQL_URL', url)
LOG.info('connecting to %s', url) LOG.info('connecting to %s', url)
self.session = sqlalchemy_session.get_session(url, conf) self.session = sqlalchemy_session.get_session()
def upgrade(self, version=None): def upgrade(self, version=None):
migration.db_sync(self.session.get_bind(), version=version) migration.db_sync(self.session.get_bind(), version=version)

View File

@ -43,7 +43,7 @@ cfg.CONF.register_opts(sql_opts)
def table_args(): def table_args():
engine_name = urlparse.urlparse(cfg.CONF.database_connection).scheme engine_name = urlparse.urlparse(cfg.CONF.database.connection).scheme
if engine_name == 'mysql': if engine_name == 'mysql':
return {'mysql_engine': cfg.CONF.mysql_engine, return {'mysql_engine': cfg.CONF.mysql_engine,
'mysql_charset': "utf8"} 'mysql_charset': "utf8"}

View File

@ -39,7 +39,8 @@ class TestBase(test_base.TestCase):
def setUp(self): def setUp(self):
super(TestBase, self).setUp() super(TestBase, self).setUp()
cfg.CONF.database_connection = self.database_connection cfg.CONF.set_override('connection', self.database_connection,
group='database')
self.conn = storage.get_connection(cfg.CONF) self.conn = storage.get_connection(cfg.CONF)
self.conn.upgrade() self.conn.upgrade()
self.conn.clear() self.conn.clear()

View File

@ -444,7 +444,7 @@
# Name of this node. Must be a valid hostname, FQDN, or IP # Name of this node. Must be a valid hostname, FQDN, or IP
# address. Must match "host" option, if running Nova. (string # address. Must match "host" option, if running Nova. (string
# value) # value)
#rpc_zmq_host=dex #rpc_zmq_host=ceilometer
# #
@ -462,8 +462,8 @@
# Options defined in ceilometer.storage # Options defined in ceilometer.storage
# #
# Database connection string (string value) # DEPRECATED - Database connection string (string value)
#database_connection=mongodb://localhost:27017/ceilometer #database_connection=<None>
# #
@ -482,19 +482,6 @@
#cinder_control_exchange=cinder #cinder_control_exchange=cinder
[api]
#
# Options defined in ceilometer.api
#
# The port for the ceilometer API server (integer value)
#port=8777
# The listen IP for the ceilometer API server (string value)
#host=0.0.0.0
[publisher_udp] [publisher_udp]
# #
@ -588,6 +575,19 @@
#topics=notifications #topics=notifications
[api]
#
# Options defined in ceilometer.api
#
# The port for the ceilometer API server (integer value)
#port=8777
# The listen IP for the ceilometer API server (string value)
#host=0.0.0.0
[matchmaker_redis] [matchmaker_redis]
# #
@ -631,4 +631,4 @@
#ringfile=/etc/oslo/matchmaker_ring.json #ringfile=/etc/oslo/matchmaker_ring.json
# Total option count: 119 # Total option count: 120

View File

@ -89,7 +89,7 @@ TEST_NOTICE = {
class TestCollector(tests_base.TestCase): class TestCollector(tests_base.TestCase):
def setUp(self): def setUp(self):
super(TestCollector, self).setUp() super(TestCollector, self).setUp()
cfg.CONF.set_override("database_connection", "log://") cfg.CONF.set_override("connection", "log://", group='database')
class TestUDPCollectorService(TestCollector): class TestUDPCollectorService(TestCollector):

View File

@ -26,14 +26,14 @@ from ceilometer.storage import impl_log
def test_get_engine(): def test_get_engine():
conf = mox.Mox().CreateMockAnything() conf = mox.Mox().CreateMockAnything()
conf.database_connection = 'log://localhost' conf.database.connection = 'log://localhost'
engine = storage.get_engine(conf) engine = storage.get_engine(conf)
assert isinstance(engine, impl_log.LogStorage) assert isinstance(engine, impl_log.LogStorage)
def test_get_engine_no_such_engine(): def test_get_engine_no_such_engine():
conf = mox.Mox().CreateMockAnything() conf = mox.Mox().CreateMockAnything()
conf.database_connection = 'no-such-engine://localhost' conf.database.connection = 'no-such-engine://localhost'
try: try:
storage.get_engine(conf) storage.get_engine(conf)
except RuntimeError as err: except RuntimeError as err:

View File

@ -98,5 +98,5 @@ class GetEventTest(base.GetEventTest, EventTestBase):
def test_model_table_args(): def test_model_table_args():
cfg.CONF.database_connection = 'mysql://localhost' cfg.CONF.database.connection = 'mysql://localhost'
assert table_args() assert table_args()

View File

@ -32,8 +32,8 @@ class BinDbsyncTestCase(base.TestCase):
super(BinDbsyncTestCase, self).setUp() super(BinDbsyncTestCase, self).setUp()
self.tempfile = self.temp_config_file_path() self.tempfile = self.temp_config_file_path()
with open(self.tempfile, 'w') as tmp: with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n") tmp.write("[database]\n")
tmp.write("database_connection=log://localhost\n") tmp.write("connection=log://localhost\n")
def test_dbsync_run(self): def test_dbsync_run(self):
subp = subprocess.Popen([self.path_get('bin/ceilometer-dbsync'), subp = subprocess.Popen([self.path_get('bin/ceilometer-dbsync'),
@ -74,7 +74,6 @@ class BinApiTestCase(base.TestCase):
tmp.write("[DEFAULT]\n") tmp.write("[DEFAULT]\n")
tmp.write( tmp.write(
"rpc_backend=ceilometer.openstack.common.rpc.impl_fake\n") "rpc_backend=ceilometer.openstack.common.rpc.impl_fake\n")
tmp.write("database_connection=log://localhost\n")
tmp.write( tmp.write(
"auth_strategy=noauth\n") "auth_strategy=noauth\n")
tmp.write( tmp.write(
@ -86,6 +85,8 @@ class BinApiTestCase(base.TestCase):
tmp.write("[api]\n") tmp.write("[api]\n")
tmp.write( tmp.write(
"port=%s\n" % self.api_port) "port=%s\n" % self.api_port)
tmp.write("[database]\n")
tmp.write("connection=log://localhost\n")
self.subp = subprocess.Popen([self.path_get('bin/ceilometer-api'), self.subp = subprocess.Popen([self.path_get('bin/ceilometer-api'),
"--config-file=%s" % self.tempfile]) "--config-file=%s" % self.tempfile])