Move 'alarm_connection' to 'connection'
- Removes the specific alarm_connection option - Simplify get_connection*() functions and hardcode the namespace Change-Id: I9ac13c6e9356867a815e0b8afec4815916bf3a65
This commit is contained in:
parent
a16fa7ae8a
commit
7a5bddd6d9
@ -64,7 +64,7 @@ def setup_app(pecan_config=None, extra_hooks=None):
|
|||||||
# FIXME: Replace DBHook with a hooks.TransactionHook
|
# FIXME: Replace DBHook with a hooks.TransactionHook
|
||||||
app_hooks = [hooks.ConfigHook(),
|
app_hooks = [hooks.ConfigHook(),
|
||||||
hooks.DBHook(
|
hooks.DBHook(
|
||||||
storage.get_connection_from_config(cfg.CONF, 'alarm'),),
|
storage.get_connection_from_config(cfg.CONF)),
|
||||||
hooks.TranslationHook()]
|
hooks.TranslationHook()]
|
||||||
if extra_hooks:
|
if extra_hooks:
|
||||||
app_hooks.extend(extra_hooks)
|
app_hooks.extend(extra_hooks)
|
||||||
|
@ -28,7 +28,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def dbsync():
|
def dbsync():
|
||||||
service.prepare_service()
|
service.prepare_service()
|
||||||
storage.get_connection_from_config(cfg.CONF, 'alarm').upgrade()
|
storage.get_connection_from_config(cfg.CONF).upgrade()
|
||||||
|
|
||||||
|
|
||||||
def expirer():
|
def expirer():
|
||||||
@ -36,7 +36,7 @@ def expirer():
|
|||||||
|
|
||||||
if cfg.CONF.database.alarm_history_time_to_live > 0:
|
if cfg.CONF.database.alarm_history_time_to_live > 0:
|
||||||
LOG.debug("Clearing expired alarm history data")
|
LOG.debug("Clearing expired alarm history data")
|
||||||
storage_conn = storage.get_connection_from_config(cfg.CONF, 'alarm')
|
storage_conn = storage.get_connection_from_config(cfg.CONF)
|
||||||
storage_conn.clear_expired_alarm_history_data(
|
storage_conn.clear_expired_alarm_history_data(
|
||||||
cfg.CONF.database.alarm_history_time_to_live)
|
cfg.CONF.database.alarm_history_time_to_live)
|
||||||
else:
|
else:
|
||||||
|
@ -24,6 +24,8 @@ from stevedore import driver
|
|||||||
|
|
||||||
from aodh import utils
|
from aodh import utils
|
||||||
|
|
||||||
|
_NAMESPACE = 'aodh.storage'
|
||||||
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
@ -38,11 +40,6 @@ cfg.CONF.register_opts(OLD_OPTS)
|
|||||||
|
|
||||||
|
|
||||||
OPTS = [
|
OPTS = [
|
||||||
cfg.StrOpt('alarm_connection',
|
|
||||||
secret=True,
|
|
||||||
default=None,
|
|
||||||
help='The connection string used to connect to the alarm '
|
|
||||||
'database. (if unset, connection is used)'),
|
|
||||||
cfg.IntOpt('alarm_history_time_to_live',
|
cfg.IntOpt('alarm_history_time_to_live',
|
||||||
default=-1,
|
default=-1,
|
||||||
help=("Number of seconds that alarm histories are kept "
|
help=("Number of seconds that alarm histories are kept "
|
||||||
@ -88,25 +85,19 @@ class StorageBadAggregate(Exception):
|
|||||||
code = 400
|
code = 400
|
||||||
|
|
||||||
|
|
||||||
def get_connection_from_config(conf, purpose='alarm'):
|
def get_connection_from_config(conf):
|
||||||
retries = conf.database.max_retries
|
retries = conf.database.max_retries
|
||||||
|
|
||||||
# Convert retry_interval secs to msecs for retry decorator
|
# Convert retry_interval secs to msecs for retry decorator
|
||||||
@retrying.retry(wait_fixed=conf.database.retry_interval * 1000,
|
@retrying.retry(wait_fixed=conf.database.retry_interval * 1000,
|
||||||
stop_max_attempt_number=retries if retries >= 0 else None)
|
stop_max_attempt_number=retries if retries >= 0 else None)
|
||||||
def _inner():
|
def _inner():
|
||||||
if conf.database_connection:
|
return get_connection(conf.database.connection)
|
||||||
conf.set_override('connection', conf.database_connection,
|
|
||||||
group='database')
|
|
||||||
namespace = 'aodh.%s.storage' % purpose
|
|
||||||
url = (getattr(conf.database, '%s_connection' % purpose) or
|
|
||||||
conf.database.connection)
|
|
||||||
return get_connection(url, namespace)
|
|
||||||
|
|
||||||
return _inner()
|
return _inner()
|
||||||
|
|
||||||
|
|
||||||
def get_connection(url, namespace):
|
def get_connection(url):
|
||||||
"""Return an open connection to the database."""
|
"""Return an open connection to the database."""
|
||||||
connection_scheme = urlparse.urlparse(url).scheme
|
connection_scheme = urlparse.urlparse(url).scheme
|
||||||
# SqlAlchemy connections specify may specify a 'dialect' or
|
# SqlAlchemy connections specify may specify a 'dialect' or
|
||||||
@ -114,8 +105,8 @@ def get_connection(url, namespace):
|
|||||||
engine_name = connection_scheme.split('+')[0]
|
engine_name = connection_scheme.split('+')[0]
|
||||||
# NOTE: translation not applied bug #1446983
|
# NOTE: translation not applied bug #1446983
|
||||||
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(url)
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class MongoDbManager(fixtures.Fixture):
|
|||||||
message='.*you must provide a username and password.*')
|
message='.*you must provide a username and password.*')
|
||||||
try:
|
try:
|
||||||
self.alarm_connection = storage.get_connection(
|
self.alarm_connection = storage.get_connection(
|
||||||
self.url, 'aodh.alarm.storage')
|
self.url)
|
||||||
except storage.StorageBadVersion as e:
|
except storage.StorageBadVersion as e:
|
||||||
raise testcase.TestSkipped(six.text_type(e))
|
raise testcase.TestSkipped(six.text_type(e))
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class SQLManager(fixtures.Fixture):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SQLManager, self).setUp()
|
super(SQLManager, self).setUp()
|
||||||
self.alarm_connection = storage.get_connection(
|
self.alarm_connection = storage.get_connection(
|
||||||
self.url, 'aodh.alarm.storage')
|
self.url)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
@ -104,7 +104,7 @@ class HBaseManager(fixtures.Fixture):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(HBaseManager, self).setUp()
|
super(HBaseManager, self).setUp()
|
||||||
self.alarm_connection = storage.get_connection(
|
self.alarm_connection = storage.get_connection(
|
||||||
self.url, 'aodh.alarm.storage')
|
self.url)
|
||||||
# Unique prefix for each test to keep data is distinguished because
|
# Unique prefix for each test to keep data is distinguished because
|
||||||
# all test data is stored in one table
|
# all test data is stored in one table
|
||||||
data_prefix = str(uuid.uuid4().hex)
|
data_prefix = str(uuid.uuid4().hex)
|
||||||
@ -141,7 +141,7 @@ class SQLiteManager(fixtures.Fixture):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SQLiteManager, self).setUp()
|
super(SQLiteManager, self).setUp()
|
||||||
self.alarm_connection = storage.get_connection(
|
self.alarm_connection = storage.get_connection(
|
||||||
self.url, 'aodh.alarm.storage')
|
self.url)
|
||||||
|
|
||||||
|
|
||||||
class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
||||||
@ -193,7 +193,7 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
|||||||
self.alarm_conn = None
|
self.alarm_conn = None
|
||||||
super(TestBase, self).tearDown()
|
super(TestBase, self).tearDown()
|
||||||
|
|
||||||
def _get_connection(self, url, namespace):
|
def _get_connection(self, url):
|
||||||
return self.alarm_conn
|
return self.alarm_conn
|
||||||
|
|
||||||
def _get_driver_manager(self, engine):
|
def _get_driver_manager(self, engine):
|
||||||
|
@ -60,7 +60,7 @@ class ConfigFixture(fixture.GabbiFixture):
|
|||||||
group='oslo_policy')
|
group='oslo_policy')
|
||||||
|
|
||||||
database_name = '%s-%s' % (db_url, str(uuid.uuid4()))
|
database_name = '%s-%s' % (db_url, str(uuid.uuid4()))
|
||||||
conf.set_override('alarm_connection', database_name, group='database')
|
conf.set_override('connection', database_name, group='database')
|
||||||
|
|
||||||
conf.set_override('pecan_debug', True, group='api')
|
conf.set_override('pecan_debug', True, group='api')
|
||||||
|
|
||||||
|
@ -27,14 +27,12 @@ import six
|
|||||||
|
|
||||||
class EngineTest(base.BaseTestCase):
|
class EngineTest(base.BaseTestCase):
|
||||||
def test_get_connection(self):
|
def test_get_connection(self):
|
||||||
engine = storage.get_connection('log://localhost',
|
engine = storage.get_connection('log://localhost')
|
||||||
'aodh.alarm.storage')
|
|
||||||
self.assertIsInstance(engine, impl_log.Connection)
|
self.assertIsInstance(engine, impl_log.Connection)
|
||||||
|
|
||||||
def test_get_connection_no_such_engine(self):
|
def test_get_connection_no_such_engine(self):
|
||||||
try:
|
try:
|
||||||
storage.get_connection('no-such-engine://localhost',
|
storage.get_connection('no-such-engine://localhost')
|
||||||
'aodh.metering.storage')
|
|
||||||
except RuntimeError as err:
|
except RuntimeError as err:
|
||||||
self.assertIn('no-such-engine', six.text_type(err))
|
self.assertIn('no-such-engine', six.text_type(err))
|
||||||
|
|
||||||
@ -63,5 +61,5 @@ class ConnectionConfigTest(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_only_default_url(self):
|
def test_only_default_url(self):
|
||||||
self.CONF.set_override("connection", "log://", group="database")
|
self.CONF.set_override("connection", "log://", group="database")
|
||||||
conn = storage.get_connection_from_config(self.CONF, 'alarm')
|
conn = storage.get_connection_from_config(self.CONF)
|
||||||
self.assertIsInstance(conn, impl_log.Connection)
|
self.assertIsInstance(conn, impl_log.Connection)
|
||||||
|
@ -26,7 +26,7 @@ packages =
|
|||||||
aodh
|
aodh
|
||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
aodh.alarm.storage =
|
aodh.storage =
|
||||||
log = aodh.storage.impl_log:Connection
|
log = aodh.storage.impl_log:Connection
|
||||||
mongodb = aodh.storage.impl_mongodb:Connection
|
mongodb = aodh.storage.impl_mongodb:Connection
|
||||||
mysql = aodh.storage.impl_sqlalchemy:Connection
|
mysql = aodh.storage.impl_sqlalchemy:Connection
|
||||||
|
@ -24,7 +24,7 @@ def main(argv):
|
|||||||
url = ("%s?table_prefix=%s" %
|
url = ("%s?table_prefix=%s" %
|
||||||
(os.getenv("AODH_TEST_HBASE_URL"),
|
(os.getenv("AODH_TEST_HBASE_URL"),
|
||||||
os.getenv("AODH_TEST_HBASE_TABLE_PREFIX", "test")))
|
os.getenv("AODH_TEST_HBASE_TABLE_PREFIX", "test")))
|
||||||
alarm_conn = storage.get_connection(url, 'AODH.alarm.storage')
|
alarm_conn = storage.get_connection(url)
|
||||||
for arg in argv:
|
for arg in argv:
|
||||||
if arg == "--upgrade":
|
if arg == "--upgrade":
|
||||||
alarm_conn.upgrade()
|
alarm_conn.upgrade()
|
||||||
|
Loading…
Reference in New Issue
Block a user