storage: pass conf rather at __init__ than using a global one
Change-Id: Ic71f8cd08296bc2329ab235198020d5fa6f1670e
This commit is contained in:
parent
24c3d2ab52
commit
7b4b3749a1
@ -107,7 +107,7 @@ def get_connection(url):
|
|||||||
LOG.debug('looking for %(name)r driver in %(namespace)r',
|
LOG.debug('looking for %(name)r driver in %(namespace)r',
|
||||||
{'name': engine_name, 'namespace': _NAMESPACE})
|
{'name': engine_name, 'namespace': _NAMESPACE})
|
||||||
mgr = driver.DriverManager(_NAMESPACE, engine_name)
|
mgr = driver.DriverManager(_NAMESPACE, engine_name)
|
||||||
return mgr.driver(url)
|
return mgr.driver(cfg.CONF, url)
|
||||||
|
|
||||||
|
|
||||||
class SampleFilter(object):
|
class SampleFilter(object):
|
||||||
|
@ -65,7 +65,7 @@ class Connection(object):
|
|||||||
'storage': {'production_ready': False},
|
'storage': {'production_ready': False},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, conf, url):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -29,7 +29,7 @@ class Connection(object):
|
|||||||
|
|
||||||
_memory_instance = None
|
_memory_instance = None
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, conf, url):
|
||||||
"""Hbase Connection Initialization."""
|
"""Hbase Connection Initialization."""
|
||||||
opts = self._parse_connection_url(url)
|
opts = self._parse_connection_url(url)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
|
|
||||||
CONNECTION_POOL = pymongo_utils.ConnectionPool()
|
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
|
# 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
|
# we still have to make sure that the scheme which used to distinguish
|
||||||
|
@ -73,9 +73,6 @@ class Connection(hbase_base.Connection, base.Connection):
|
|||||||
ALARM_TABLE = "alarm"
|
ALARM_TABLE = "alarm"
|
||||||
ALARM_HISTORY_TABLE = "alarm_h"
|
ALARM_HISTORY_TABLE = "alarm_h"
|
||||||
|
|
||||||
def __init__(self, url):
|
|
||||||
super(Connection, self).__init__(url)
|
|
||||||
|
|
||||||
def upgrade(self):
|
def upgrade(self):
|
||||||
tables = [self.ALARM_HISTORY_TABLE, self.ALARM_TABLE]
|
tables = [self.ALARM_HISTORY_TABLE, self.ALARM_TABLE]
|
||||||
column_families = {'f': dict()}
|
column_families = {'f': dict()}
|
||||||
|
@ -39,9 +39,9 @@ class Connection(pymongo_base.Connection):
|
|||||||
|
|
||||||
CONNECTION_POOL = pymongo_utils.ConnectionPool()
|
CONNECTION_POOL = pymongo_utils.ConnectionPool()
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, conf, url):
|
||||||
|
self.conf = conf
|
||||||
# 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 instantiate a Pymongo client each time someone
|
# connection since we instantiate a Pymongo client each time someone
|
||||||
# requires a new storage connection.
|
# requires a new storage connection.
|
||||||
@ -90,7 +90,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
def upgrade(self):
|
def upgrade(self):
|
||||||
super(Connection, self).upgrade()
|
super(Connection, self).upgrade()
|
||||||
# Establish indexes
|
# Establish indexes
|
||||||
ttl = cfg.CONF.database.alarm_history_time_to_live
|
ttl = self.conf.database.alarm_history_time_to_live
|
||||||
self.update_ttl(
|
self.update_ttl(
|
||||||
ttl, 'alarm_history_ttl', 'timestamp', self.db.alarm_history)
|
ttl, 'alarm_history_ttl', 'timestamp', self.db.alarm_history)
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from oslo_config import cfg
|
|
||||||
from oslo_db.sqlalchemy import session as db_session
|
from oslo_db.sqlalchemy import session as db_session
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
@ -52,12 +51,12 @@ class Connection(base.Connection):
|
|||||||
AVAILABLE_STORAGE_CAPABILITIES,
|
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
|
# Set max_retries to 0, since oslo.db in certain cases may attempt
|
||||||
# to retry making the db connection retried max_retries ^ 2 times
|
# to retry making the db connection retried max_retries ^ 2 times
|
||||||
# in failure case and db reconnection has already been implemented
|
# in failure case and db reconnection has already been implemented
|
||||||
# in storage.__init__.get_connection_from_config function
|
# in storage.__init__.get_connection_from_config function
|
||||||
options = dict(cfg.CONF.database.items())
|
options = dict(conf.database.items())
|
||||||
options['max_retries'] = 0
|
options['max_retries'] = 0
|
||||||
self._engine_facade = db_session.EngineFacade(url, **options)
|
self._engine_facade = db_session.EngineFacade(url, **options)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class ConnectionTest(tests_db.TestBase,
|
|||||||
|
|
||||||
with mock.patch.object(impl_hbase.Connection, '_get_connection_pool',
|
with mock.patch.object(impl_hbase.Connection, '_get_connection_pool',
|
||||||
side_effect=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)
|
self.assertIsInstance(conn.conn_pool, TestConn)
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,8 +12,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
"""Tests for aodh/storage/impl_log.py
|
from oslo_config import cfg
|
||||||
"""
|
|
||||||
from oslotest import base
|
from oslotest import base
|
||||||
|
|
||||||
from aodh.storage import impl_log
|
from aodh.storage import impl_log
|
||||||
@ -22,4 +21,4 @@ from aodh.storage import impl_log
|
|||||||
class ConnectionTest(base.BaseTestCase):
|
class ConnectionTest(base.BaseTestCase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def test_get_connection():
|
def test_get_connection():
|
||||||
impl_log.Connection(None)
|
impl_log.Connection(cfg.CONF, None)
|
||||||
|
@ -30,12 +30,12 @@ from aodh.tests import db as tests_db
|
|||||||
class MongoDBConnection(tests_db.TestBase,
|
class MongoDBConnection(tests_db.TestBase,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
def test_connection_pooling(self):
|
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)
|
self.assertEqual(self.alarm_conn.conn, test_conn.conn)
|
||||||
|
|
||||||
def test_replica_set(self):
|
def test_replica_set(self):
|
||||||
url = self.db_manager._url + '?replicaSet=foobar'
|
url = self.db_manager._url + '?replicaSet=foobar'
|
||||||
conn = impl_mongodb.Connection(url)
|
conn = impl_mongodb.Connection(self.CONF, url)
|
||||||
self.assertTrue(conn.conn)
|
self.assertTrue(conn.conn)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user