check metering_connection attribute by default

ensure we check metering_connection and only default to
database.connection if missing.

Change-Id: I985f66c145bc8795bc93f846413823c4fea2a6ac
Closes-Bug: #1419962
This commit is contained in:
gordon chung 2015-02-09 15:07:04 -05:00
parent 059d6b20e4
commit f80cd71d86
2 changed files with 19 additions and 6 deletions

View File

@ -88,7 +88,7 @@ class StorageBadAggregate(Exception):
code = 400 code = 400
def get_connection_from_config(conf, purpose=None): def get_connection_from_config(conf, purpose='metering'):
retries = conf.database.max_retries retries = conf.database.max_retries
# Convert retry_interval secs to msecs for retry decorator # 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: if conf.database_connection:
conf.set_override('connection', conf.database_connection, conf.set_override('connection', conf.database_connection,
group='database') group='database')
namespace = 'ceilometer.metering.storage' namespace = 'ceilometer.%s.storage' % purpose
url = conf.database.connection url = (getattr(conf.database, '%s_connection' % purpose) or
if purpose: conf.database.connection)
namespace = 'ceilometer.%s.storage' % purpose
url = getattr(conf.database, '%s_connection' % purpose) or url
return get_connection(url, namespace) return get_connection(url, namespace)
return _inner() return _inner()

View File

@ -100,6 +100,21 @@ class ConnectionConfigTest(base.BaseTestCase):
conn = storage.get_connection_from_config(self.CONF, 'event') conn = storage.get_connection_from_config(self.CONF, 'event')
self.assertIsInstance(conn, impl_hbase_event.Connection) 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): def test_sqlalchemy_driver(self):
self.CONF.set_override("connection", "sqlite+pysqlite://", self.CONF.set_override("connection", "sqlite+pysqlite://",
group="database") group="database")