mongodb: do not set replica_set as a global option
Rather use a per-connection parameter. Change-Id: I141f063f18993e69e6fb1da0d8ea6dd9821a248f
This commit is contained in:
		| @@ -35,6 +35,7 @@ import pymongo | |||||||
| from oslo.config import cfg | from oslo.config import cfg | ||||||
|  |  | ||||||
| from ceilometer.openstack.common import log | from ceilometer.openstack.common import log | ||||||
|  | from ceilometer.openstack.common import network_utils | ||||||
| from ceilometer.openstack.common import timeutils | from ceilometer.openstack.common import timeutils | ||||||
| from ceilometer import storage | from ceilometer import storage | ||||||
| from ceilometer.storage import base | 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): |     def register_opts(self, conf): | ||||||
|         """Register any configuration options used by this engine. |         """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): |     def get_connection(self, conf): | ||||||
|         """Return a Connection instance based on the configuration settings. |         """Return a Connection instance based on the configuration settings. | ||||||
| @@ -273,9 +262,6 @@ class Connection(base.Connection): | |||||||
|                     "export CEILOMETER_TEST_MONGODB_URL environment variable") |                     "export CEILOMETER_TEST_MONGODB_URL environment variable") | ||||||
|             opts = self._parse_connection_url(url) |             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. |         # NOTE(jd) Use our own connection pooling on top of the Pymongo one. | ||||||
|         # We need that otherwise we overflow the MongoDB instance with new |         # We need that otherwise we overflow the MongoDB instance with new | ||||||
|         # connection since we instanciate a Pymongo client each time someone |         # connection since we instanciate a Pymongo client each time someone | ||||||
| @@ -353,7 +339,9 @@ class Connection(base.Connection): | |||||||
|     @staticmethod |     @staticmethod | ||||||
|     def _parse_connection_url(url): |     def _parse_connection_url(url): | ||||||
|         opts = {} |         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['dbtype'] = result.scheme | ||||||
|         opts['dbname'] = result.path.replace('/', '') |         opts['dbname'] = result.path.replace('/', '') | ||||||
|         netloc_match = re.match(r'(?:(\w+:\w+)@)?(.*)', result.netloc) |         netloc_match = re.match(r'(?:(\w+:\w+)@)?(.*)', result.netloc) | ||||||
|   | |||||||
| @@ -47,6 +47,14 @@ class MongoDBConnection(MongoDBEngineTestBase): | |||||||
|         self.assertEqual(self.conn.conn, |         self.assertEqual(self.conn.conn, | ||||||
|                          impl_mongodb.Connection(cfg.CONF).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): | class IndexTest(MongoDBEngineTestBase): | ||||||
|     def test_meter_ttl_index_absent(self): |     def test_meter_ttl_index_absent(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Julien Danjou
					Julien Danjou