diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index 7dd5d3606b..3acfdc6552 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -35,6 +35,7 @@ import pymongo from oslo.config import cfg from ceilometer.openstack.common import log +from ceilometer.openstack.common import network_utils from ceilometer.openstack.common import timeutils from ceilometer import storage from ceilometer.storage import base @@ -72,21 +73,9 @@ class MongoDBStorage(base.StorageEngine): } """ - OPTIONS = [ - cfg.StrOpt('replica_set_name', - default='', - help='Used to identify the replication set name', - ), - ] - - OPTION_GROUP = cfg.OptGroup(name='storage_mongodb', - title='Options for the mongodb storage') - def register_opts(self, conf): """Register any configuration options used by this engine. """ - conf.register_group(self.OPTION_GROUP) - conf.register_opts(self.OPTIONS, self.OPTION_GROUP) def get_connection(self, conf): """Return a Connection instance based on the configuration settings. @@ -273,9 +262,6 @@ class Connection(base.Connection): "export CEILOMETER_TEST_MONGODB_URL environment variable") opts = self._parse_connection_url(url) - # FIXME(jd) This should be a parameter in the database URL, not global - opts['replica_set'] = conf.storage_mongodb.replica_set_name - # NOTE(jd) Use our own connection pooling on top of the Pymongo one. # We need that otherwise we overflow the MongoDB instance with new # connection since we instanciate a Pymongo client each time someone @@ -353,7 +339,9 @@ class Connection(base.Connection): @staticmethod def _parse_connection_url(url): opts = {} - result = urlparse.urlparse(url) + result = network_utils.urlsplit(url) + opts['replica_set'] = urlparse.parse_qs( + result.query).get('replica_set', [""])[0] opts['dbtype'] = result.scheme opts['dbname'] = result.path.replace('/', '') netloc_match = re.match(r'(?:(\w+:\w+)@)?(.*)', result.netloc) diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index 6d73b168d6..eb2856cda9 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -47,6 +47,14 @@ class MongoDBConnection(MongoDBEngineTestBase): self.assertEqual(self.conn.conn, impl_mongodb.Connection(cfg.CONF).conn) + def test_replica_set(self): + cfg.CONF.set_override( + 'connection', + 'mongodb://__test__?replica_set=foobar', + group='database') + conn = impl_mongodb.Connection(cfg.CONF) + self.assertTrue(conn.conn) + class IndexTest(MongoDBEngineTestBase): def test_meter_ttl_index_absent(self):