From 9f6e3639fb4a0b6701b65e2d7ffba80db0b935c3 Mon Sep 17 00:00:00 2001 From: Gordon Chung Date: Tue, 28 May 2013 11:48:43 -0400 Subject: [PATCH] Session does not use ceilometer.conf's database_connection use [database]connection setting from openstack.common sqlalchemy session Change-Id: I582d4cb7d51d6ddecc27ae5fcdedcfd19dc898af Fixes: bug #1183106 --- ceilometer/storage/__init__.py | 11 +++++--- ceilometer/storage/impl_hbase.py | 2 +- ceilometer/storage/impl_mongodb.py | 2 +- ceilometer/storage/impl_sqlalchemy.py | 4 +-- ceilometer/storage/sqlalchemy/models.py | 2 +- ceilometer/tests/db.py | 3 ++- etc/ceilometer/ceilometer.conf.sample | 34 ++++++++++++------------- tests/collector/test_manager.py | 2 +- tests/storage/test_get_engine.py | 4 +-- tests/storage/test_impl_sqlalchemy.py | 2 +- tests/test_bin.py | 7 ++--- 11 files changed, 40 insertions(+), 33 deletions(-) diff --git a/ceilometer/storage/__init__.py b/ceilometer/storage/__init__.py index 85b852e44..322aff280 100644 --- a/ceilometer/storage/__init__.py +++ b/ceilometer/storage/__init__.py @@ -35,13 +35,16 @@ STORAGE_ENGINE_NAMESPACE = 'ceilometer.storage' STORAGE_OPTS = [ cfg.StrOpt('database_connection', secret=True, - default='mongodb://localhost:27017/ceilometer', - help='Database connection string', + default=None, + help='DEPRECATED - Database connection string', ), ] cfg.CONF.register_opts(STORAGE_OPTS) +cfg.CONF.import_opt('connection', + 'ceilometer.openstack.common.db.sqlalchemy.session', + group='database') def register_opts(conf): @@ -52,7 +55,9 @@ def register_opts(conf): def get_engine(conf): """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', engine_name, STORAGE_ENGINE_NAMESPACE) mgr = driver.DriverManager(STORAGE_ENGINE_NAMESPACE, diff --git a/ceilometer/storage/impl_hbase.py b/ceilometer/storage/impl_hbase.py index a06f16f74..8fb21109d 100644 --- a/ceilometer/storage/impl_hbase.py +++ b/ceilometer/storage/impl_hbase.py @@ -91,7 +91,7 @@ class Connection(base.Connection): ''' 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 if opts['host'] == '__test__': diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index 216b0cf29..e886a4f35 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -196,7 +196,7 @@ class Connection(base.Connection): }""") 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']) if opts['host'] == '__test__': diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index 3481dd760..a587aa340 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -132,11 +132,11 @@ class Connection(base.Connection): """SqlAlchemy connection.""" def __init__(self, conf): - url = conf.database_connection + url = conf.database.connection if url == 'sqlite://': url = os.environ.get('CEILOMETER_TEST_SQL_URL', 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): migration.db_sync(self.session.get_bind(), version=version) diff --git a/ceilometer/storage/sqlalchemy/models.py b/ceilometer/storage/sqlalchemy/models.py index 6334b2256..7a7a10275 100644 --- a/ceilometer/storage/sqlalchemy/models.py +++ b/ceilometer/storage/sqlalchemy/models.py @@ -43,7 +43,7 @@ cfg.CONF.register_opts(sql_opts) 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': return {'mysql_engine': cfg.CONF.mysql_engine, 'mysql_charset': "utf8"} diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index ac486a902..2e62ab7ee 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -39,7 +39,8 @@ class TestBase(test_base.TestCase): def setUp(self): 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.upgrade() self.conn.clear() diff --git a/etc/ceilometer/ceilometer.conf.sample b/etc/ceilometer/ceilometer.conf.sample index e0b600dfd..aaea5b3ea 100644 --- a/etc/ceilometer/ceilometer.conf.sample +++ b/etc/ceilometer/ceilometer.conf.sample @@ -444,7 +444,7 @@ # Name of this node. Must be a valid hostname, FQDN, or IP # address. Must match "host" option, if running Nova. (string # value) -#rpc_zmq_host=dex +#rpc_zmq_host=ceilometer # @@ -462,8 +462,8 @@ # Options defined in ceilometer.storage # -# Database connection string (string value) -#database_connection=mongodb://localhost:27017/ceilometer +# DEPRECATED - Database connection string (string value) +#database_connection= # @@ -482,19 +482,6 @@ #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] # @@ -588,6 +575,19 @@ #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] # @@ -631,4 +631,4 @@ #ringfile=/etc/oslo/matchmaker_ring.json -# Total option count: 119 +# Total option count: 120 diff --git a/tests/collector/test_manager.py b/tests/collector/test_manager.py index a4e36ca39..11b308432 100644 --- a/tests/collector/test_manager.py +++ b/tests/collector/test_manager.py @@ -89,7 +89,7 @@ TEST_NOTICE = { class TestCollector(tests_base.TestCase): def setUp(self): super(TestCollector, self).setUp() - cfg.CONF.set_override("database_connection", "log://") + cfg.CONF.set_override("connection", "log://", group='database') class TestUDPCollectorService(TestCollector): diff --git a/tests/storage/test_get_engine.py b/tests/storage/test_get_engine.py index 951ae03a8..0ce2bd180 100644 --- a/tests/storage/test_get_engine.py +++ b/tests/storage/test_get_engine.py @@ -26,14 +26,14 @@ from ceilometer.storage import impl_log def test_get_engine(): conf = mox.Mox().CreateMockAnything() - conf.database_connection = 'log://localhost' + conf.database.connection = 'log://localhost' engine = storage.get_engine(conf) assert isinstance(engine, impl_log.LogStorage) def test_get_engine_no_such_engine(): conf = mox.Mox().CreateMockAnything() - conf.database_connection = 'no-such-engine://localhost' + conf.database.connection = 'no-such-engine://localhost' try: storage.get_engine(conf) except RuntimeError as err: diff --git a/tests/storage/test_impl_sqlalchemy.py b/tests/storage/test_impl_sqlalchemy.py index 9de03de58..9d095f5c2 100644 --- a/tests/storage/test_impl_sqlalchemy.py +++ b/tests/storage/test_impl_sqlalchemy.py @@ -98,5 +98,5 @@ class GetEventTest(base.GetEventTest, EventTestBase): def test_model_table_args(): - cfg.CONF.database_connection = 'mysql://localhost' + cfg.CONF.database.connection = 'mysql://localhost' assert table_args() diff --git a/tests/test_bin.py b/tests/test_bin.py index 3b1d1f6a0..7bf897096 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -32,8 +32,8 @@ class BinDbsyncTestCase(base.TestCase): super(BinDbsyncTestCase, self).setUp() self.tempfile = self.temp_config_file_path() with open(self.tempfile, 'w') as tmp: - tmp.write("[DEFAULT]\n") - tmp.write("database_connection=log://localhost\n") + tmp.write("[database]\n") + tmp.write("connection=log://localhost\n") def test_dbsync_run(self): subp = subprocess.Popen([self.path_get('bin/ceilometer-dbsync'), @@ -74,7 +74,6 @@ class BinApiTestCase(base.TestCase): tmp.write("[DEFAULT]\n") tmp.write( "rpc_backend=ceilometer.openstack.common.rpc.impl_fake\n") - tmp.write("database_connection=log://localhost\n") tmp.write( "auth_strategy=noauth\n") tmp.write( @@ -86,6 +85,8 @@ class BinApiTestCase(base.TestCase): tmp.write("[api]\n") tmp.write( "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'), "--config-file=%s" % self.tempfile])