diff --git a/ceilometer/storage/__init__.py b/ceilometer/storage/__init__.py index f4c803f91..abfcf3dc7 100644 --- a/ceilometer/storage/__init__.py +++ b/ceilometer/storage/__init__.py @@ -88,7 +88,7 @@ class StorageBadAggregate(Exception): code = 400 -def get_connection_from_config(conf, purpose=None): +def get_connection_from_config(conf, purpose='metering'): retries = conf.database.max_retries # Convert retry_interval secs to msecs for retry decorator @@ -98,11 +98,9 @@ def get_connection_from_config(conf, purpose=None): if conf.database_connection: conf.set_override('connection', conf.database_connection, group='database') - namespace = 'ceilometer.metering.storage' - url = conf.database.connection - if purpose: - namespace = 'ceilometer.%s.storage' % purpose - url = getattr(conf.database, '%s_connection' % purpose) or url + namespace = 'ceilometer.%s.storage' % purpose + url = (getattr(conf.database, '%s_connection' % purpose) or + conf.database.connection) return get_connection(url, namespace) return _inner() diff --git a/ceilometer/tests/storage/test_get_connection.py b/ceilometer/tests/storage/test_get_connection.py index f8d86036d..55439ebb0 100644 --- a/ceilometer/tests/storage/test_get_connection.py +++ b/ceilometer/tests/storage/test_get_connection.py @@ -100,6 +100,21 @@ class ConnectionConfigTest(base.BaseTestCase): conn = storage.get_connection_from_config(self.CONF, 'event') self.assertIsInstance(conn, impl_hbase_event.Connection) + def test_three_urls_no_default(self): + self.CONF.set_override("connection", None, group="database") + self.CONF.set_override("metering_connection", "log://", + group="database") + self.CONF.set_override("alarm_connection", "sqlite://", + group="database") + self.CONF.set_override("event_connection", "hbase://__test__", + group="database") + conn = storage.get_connection_from_config(self.CONF) + self.assertIsInstance(conn, impl_log.Connection) + conn = storage.get_connection_from_config(self.CONF, 'alarm') + self.assertIsInstance(conn, impl_sqlalchemy_alarm.Connection) + conn = storage.get_connection_from_config(self.CONF, 'event') + self.assertIsInstance(conn, impl_hbase_event.Connection) + def test_sqlalchemy_driver(self): self.CONF.set_override("connection", "sqlite+pysqlite://", group="database")