Made get_capabilities a classmethod instead of object method
Capabilities are the same for all objects so there is no need for them to be nonstatic. Another benefit is that we can check capabilities of the Connection without the need to create an object and open real connection. Change-Id: Ie9314cb49b4c2bffb2bae4d5eeca6f5d8e2637ce
This commit is contained in:
@@ -27,7 +27,6 @@ from six import moves
|
||||
|
||||
from ceilometer.openstack.common.gettextutils import _ # noqa
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer import utils
|
||||
|
||||
|
||||
def iter_period(start, end, period):
|
||||
@@ -121,7 +120,7 @@ class Connection(object):
|
||||
|
||||
"""A dictionary representing the capabilities of this driver.
|
||||
"""
|
||||
DEFAULT_CAPABILITIES = {
|
||||
CAPABILITIES = {
|
||||
'meters': {'pagination': False,
|
||||
'query': {'simple': False,
|
||||
'metadata': False,
|
||||
@@ -157,10 +156,9 @@ class Connection(object):
|
||||
'events': {'query': {'simple': False}},
|
||||
}
|
||||
|
||||
def __init__(self, conf, AVAILABLE_CAPABILITIES):
|
||||
def __init__(self, conf):
|
||||
"""Constructor."""
|
||||
self._CAPABILITIES = utils.update_nested(self.DEFAULT_CAPABILITIES,
|
||||
AVAILABLE_CAPABILITIES)
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def upgrade():
|
||||
@@ -397,7 +395,8 @@ class Connection(object):
|
||||
raise NotImplementedError('Complex query for alarms '
|
||||
'history is not implemented.')
|
||||
|
||||
def get_capabilities(self):
|
||||
@classmethod
|
||||
def get_capabilities(cls):
|
||||
"""Return an dictionary representing the capabilities of each driver.
|
||||
"""
|
||||
return self._CAPABILITIES
|
||||
return cls.CAPABILITIES
|
||||
|
||||
@@ -38,6 +38,7 @@ from ceilometer import storage
|
||||
from ceilometer.storage import base
|
||||
from ceilometer.storage import models
|
||||
from ceilometer.storage import pymongo_base
|
||||
from ceilometer import utils
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@@ -88,6 +89,8 @@ class Connection(pymongo_base.Connection):
|
||||
"""DB2 connection.
|
||||
"""
|
||||
|
||||
CAPABILITIES = utils.update_nested(pymongo_base.Connection.CAPABILITIES,
|
||||
AVAILABLE_CAPABILITIES)
|
||||
CONNECTION_POOL = pymongo_base.ConnectionPool()
|
||||
|
||||
GROUP = {'_id': '$counter_name',
|
||||
@@ -112,7 +115,6 @@ class Connection(pymongo_base.Connection):
|
||||
SECONDS_IN_A_DAY = 86400
|
||||
|
||||
def __init__(self, conf):
|
||||
super(Connection, self).__init__(conf, AVAILABLE_CAPABILITIES)
|
||||
url = conf.database.connection
|
||||
|
||||
# Since we are using pymongo, even though we are connecting to DB2
|
||||
|
||||
@@ -110,6 +110,8 @@ AVAILABLE_CAPABILITIES = {
|
||||
class Connection(base.Connection):
|
||||
"""HBase connection.
|
||||
"""
|
||||
CAPABILITIES = utils.update_nested(base.Connection.CAPABILITIES,
|
||||
AVAILABLE_CAPABILITIES)
|
||||
|
||||
_memory_instance = None
|
||||
|
||||
@@ -122,7 +124,6 @@ class Connection(base.Connection):
|
||||
|
||||
def __init__(self, conf):
|
||||
"""Hbase Connection Initialization."""
|
||||
super(Connection, self).__init__(conf, AVAILABLE_CAPABILITIES)
|
||||
opts = self._parse_connection_url(conf.database.connection)
|
||||
|
||||
if opts['host'] == '__test__':
|
||||
|
||||
@@ -39,9 +39,6 @@ class Connection(base.Connection):
|
||||
"""Base class for storage system connections.
|
||||
"""
|
||||
|
||||
def __init__(self, conf):
|
||||
super(Connection, self).__init__(conf, {})
|
||||
|
||||
def upgrade(self):
|
||||
pass
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ from ceilometer import storage
|
||||
from ceilometer.storage import base
|
||||
from ceilometer.storage import models
|
||||
from ceilometer.storage import pymongo_base
|
||||
from ceilometer import utils
|
||||
|
||||
cfg.CONF.import_opt('time_to_live', 'ceilometer.storage',
|
||||
group="database")
|
||||
@@ -101,6 +102,8 @@ AVAILABLE_CAPABILITIES = {
|
||||
class Connection(pymongo_base.Connection):
|
||||
"""MongoDB connection.
|
||||
"""
|
||||
CAPABILITIES = utils.update_nested(pymongo_base.Connection.CAPABILITIES,
|
||||
AVAILABLE_CAPABILITIES)
|
||||
|
||||
CONNECTION_POOL = pymongo_base.ConnectionPool()
|
||||
|
||||
@@ -407,7 +410,6 @@ class Connection(pymongo_base.Connection):
|
||||
hour=23, minute=59, second=59)
|
||||
|
||||
def __init__(self, conf):
|
||||
super(Connection, self).__init__(conf, AVAILABLE_CAPABILITIES)
|
||||
url = conf.database.connection
|
||||
|
||||
# NOTE(jd) Use our own connection pooling on top of the Pymongo one.
|
||||
|
||||
@@ -239,9 +239,10 @@ def make_query_from_filter(session, query, sample_filter, require_meter=True):
|
||||
|
||||
class Connection(base.Connection):
|
||||
"""SqlAlchemy connection."""
|
||||
CAPABILITIES = utils.update_nested(base.Connection.CAPABILITIES,
|
||||
AVAILABLE_CAPABILITIES)
|
||||
|
||||
def __init__(self, conf):
|
||||
super(Connection, self).__init__(conf, AVAILABLE_CAPABILITIES)
|
||||
self._engine_facade = sqlalchemy_session.EngineFacade.from_config(
|
||||
conf.database.connection, cfg.CONF)
|
||||
|
||||
|
||||
@@ -143,12 +143,8 @@ COMMON_AVAILABLE_CAPABILITIES = {
|
||||
class Connection(base.Connection):
|
||||
"""Base Connection class for MongoDB and DB2 drivers.
|
||||
"""
|
||||
|
||||
def __init__(self, conf, AVAILABLE_CAPABILITIES):
|
||||
super(Connection, self).__init__(
|
||||
conf,
|
||||
utils.update_nested(COMMON_AVAILABLE_CAPABILITIES,
|
||||
AVAILABLE_CAPABILITIES))
|
||||
CAPABILITIES = utils.update_nested(base.Connection.CAPABILITIES,
|
||||
COMMON_AVAILABLE_CAPABILITIES)
|
||||
|
||||
def get_users(self, source=None):
|
||||
"""Return an iterable of user id strings.
|
||||
|
||||
@@ -24,14 +24,11 @@
|
||||
|
||||
"""
|
||||
|
||||
from ceilometer.tests import db as tests_db
|
||||
from ceilometer.storage import impl_db2
|
||||
from ceilometer.tests import base as test_base
|
||||
|
||||
|
||||
class DB2EngineTestBase(tests_db.TestBase):
|
||||
db_manager = tests_db.DB2Manager()
|
||||
|
||||
|
||||
class CapabilitiesTest(DB2EngineTestBase):
|
||||
class CapabilitiesTest(test_base.BaseTestCase):
|
||||
# Check the returned capabilities list, which is specific to each DB
|
||||
# driver
|
||||
|
||||
@@ -72,5 +69,5 @@ class CapabilitiesTest(DB2EngineTestBase):
|
||||
'events': {'query': {'simple': False}}
|
||||
}
|
||||
|
||||
actual_capabilities = self.conn.get_capabilities()
|
||||
actual_capabilities = impl_db2.Connection.get_capabilities()
|
||||
self.assertEqual(expected_capabilities, actual_capabilities)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
from mock import patch
|
||||
|
||||
from ceilometer.storage import impl_hbase as hbase
|
||||
from ceilometer.tests import base as test_base
|
||||
from ceilometer.tests import db as tests_db
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ class ConnectionTest(HBaseEngineTestBase):
|
||||
self.assertIsInstance(conn.conn_pool, TestConn)
|
||||
|
||||
|
||||
class CapabilitiesTest(HBaseEngineTestBase):
|
||||
class CapabilitiesTest(test_base.BaseTestCase):
|
||||
# Check the returned capabilities list, which is specific to each DB
|
||||
# driver
|
||||
|
||||
@@ -99,5 +100,5 @@ class CapabilitiesTest(HBaseEngineTestBase):
|
||||
'events': {'query': {'simple': False}}
|
||||
}
|
||||
|
||||
actual_capabilities = self.conn.get_capabilities()
|
||||
actual_capabilities = hbase.Connection.get_capabilities()
|
||||
self.assertEqual(expected_capabilities, actual_capabilities)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
from ceilometer.storage import base
|
||||
from ceilometer.storage import impl_mongodb
|
||||
from ceilometer.tests import base as test_base
|
||||
from ceilometer.tests import db as tests_db
|
||||
from ceilometer.tests.storage import test_storage_scenarios
|
||||
|
||||
@@ -145,7 +146,7 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase,
|
||||
self.assertTrue(True)
|
||||
|
||||
|
||||
class CapabilitiesTest(MongoDBEngineTestBase):
|
||||
class CapabilitiesTest(test_base.BaseTestCase):
|
||||
# Check the returned capabilities list, which is specific to each DB
|
||||
# driver
|
||||
|
||||
@@ -186,5 +187,5 @@ class CapabilitiesTest(MongoDBEngineTestBase):
|
||||
'events': {'query': {'simple': False}}
|
||||
}
|
||||
|
||||
actual_capabilities = self.conn.get_capabilities()
|
||||
actual_capabilities = impl_mongodb.Connection.get_capabilities()
|
||||
self.assertEqual(expected_capabilities, actual_capabilities)
|
||||
|
||||
@@ -29,8 +29,11 @@ import repr
|
||||
from mock import patch
|
||||
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer.storage import impl_sqlalchemy
|
||||
from ceilometer.storage import models
|
||||
from ceilometer.storage.sqlalchemy import models as sql_models
|
||||
|
||||
from ceilometer.tests import base as test_base
|
||||
from ceilometer.tests import db as tests_db
|
||||
from ceilometer.tests.storage import test_storage_scenarios as scenarios
|
||||
|
||||
@@ -214,7 +217,7 @@ class RelationshipTest(scenarios.DBTestBase):
|
||||
)).count())
|
||||
|
||||
|
||||
class CapabilitiesTest(EventTestBase):
|
||||
class CapabilitiesTest(test_base.BaseTestCase):
|
||||
# Check the returned capabilities list, which is specific to each DB
|
||||
# driver
|
||||
|
||||
@@ -255,5 +258,5 @@ class CapabilitiesTest(EventTestBase):
|
||||
'events': {'query': {'simple': True}}
|
||||
}
|
||||
|
||||
actual_capabilities = self.conn.get_capabilities()
|
||||
actual_capabilities = impl_sqlalchemy.Connection.get_capabilities()
|
||||
self.assertEqual(expected_capabilities, actual_capabilities)
|
||||
|
||||
Reference in New Issue
Block a user