storage: pass conf rather at __init__ than using a global one

Change-Id: Ic71f8cd08296bc2329ab235198020d5fa6f1670e
This commit is contained in:
Julien Danjou 2015-07-24 11:22:08 +02:00
parent 24c3d2ab52
commit 7b4b3749a1
10 changed files with 15 additions and 20 deletions

View File

@ -107,7 +107,7 @@ def get_connection(url):
LOG.debug('looking for %(name)r driver in %(namespace)r',
{'name': engine_name, 'namespace': _NAMESPACE})
mgr = driver.DriverManager(_NAMESPACE, engine_name)
return mgr.driver(url)
return mgr.driver(cfg.CONF, url)
class SampleFilter(object):

View File

@ -65,7 +65,7 @@ class Connection(object):
'storage': {'production_ready': False},
}
def __init__(self, url):
def __init__(self, conf, url):
pass
@staticmethod

View File

@ -29,7 +29,7 @@ class Connection(object):
_memory_instance = None
def __init__(self, url):
def __init__(self, conf, url):
"""Hbase Connection Initialization."""
opts = self._parse_connection_url(url)

View File

@ -33,7 +33,7 @@ class Connection(pymongo_base.Connection):
CONNECTION_POOL = pymongo_utils.ConnectionPool()
def __init__(self, url):
def __init__(self, conf, url):
# Since we are using pymongo, even though we are connecting to DB2
# we still have to make sure that the scheme which used to distinguish

View File

@ -73,9 +73,6 @@ class Connection(hbase_base.Connection, base.Connection):
ALARM_TABLE = "alarm"
ALARM_HISTORY_TABLE = "alarm_h"
def __init__(self, url):
super(Connection, self).__init__(url)
def upgrade(self):
tables = [self.ALARM_HISTORY_TABLE, self.ALARM_TABLE]
column_families = {'f': dict()}

View File

@ -39,9 +39,9 @@ class Connection(pymongo_base.Connection):
CONNECTION_POOL = pymongo_utils.ConnectionPool()
def __init__(self, url):
# NOTE(jd) Use our own connection pooling on top of the Pymongo one.
def __init__(self, conf, url):
self.conf = conf
# 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 instantiate a Pymongo client each time someone
# requires a new storage connection.
@ -90,7 +90,7 @@ class Connection(pymongo_base.Connection):
def upgrade(self):
super(Connection, self).upgrade()
# Establish indexes
ttl = cfg.CONF.database.alarm_history_time_to_live
ttl = self.conf.database.alarm_history_time_to_live
self.update_ttl(
ttl, 'alarm_history_ttl', 'timestamp', self.db.alarm_history)

View File

@ -15,7 +15,6 @@
from __future__ import absolute_import
import datetime
from oslo_config import cfg
from oslo_db.sqlalchemy import session as db_session
from oslo_log import log
from oslo_utils import timeutils
@ -52,12 +51,12 @@ class Connection(base.Connection):
AVAILABLE_STORAGE_CAPABILITIES,
)
def __init__(self, url):
def __init__(self, conf, url):
# Set max_retries to 0, since oslo.db in certain cases may attempt
# to retry making the db connection retried max_retries ^ 2 times
# in failure case and db reconnection has already been implemented
# in storage.__init__.get_connection_from_config function
options = dict(cfg.CONF.database.items())
options = dict(conf.database.items())
options['max_retries'] = 0
self._engine_facade = db_session.EngineFacade(url, **options)

View File

@ -51,7 +51,7 @@ class ConnectionTest(tests_db.TestBase,
with mock.patch.object(impl_hbase.Connection, '_get_connection_pool',
side_effect=get_connection_pool):
conn = impl_hbase.Connection('hbase://test_hbase:9090')
conn = impl_hbase.Connection(self.CONF, 'hbase://test_hbase:9090')
self.assertIsInstance(conn.conn_pool, TestConn)

View File

@ -12,8 +12,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for aodh/storage/impl_log.py
"""
from oslo_config import cfg
from oslotest import base
from aodh.storage import impl_log
@ -22,4 +21,4 @@ from aodh.storage import impl_log
class ConnectionTest(base.BaseTestCase):
@staticmethod
def test_get_connection():
impl_log.Connection(None)
impl_log.Connection(cfg.CONF, None)

View File

@ -30,12 +30,12 @@ from aodh.tests import db as tests_db
class MongoDBConnection(tests_db.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_connection_pooling(self):
test_conn = impl_mongodb.Connection(self.db_manager.url)
test_conn = impl_mongodb.Connection(self.CONF, self.db_manager.url)
self.assertEqual(self.alarm_conn.conn, test_conn.conn)
def test_replica_set(self):
url = self.db_manager._url + '?replicaSet=foobar'
conn = impl_mongodb.Connection(url)
conn = impl_mongodb.Connection(self.CONF, url)
self.assertTrue(conn.conn)