Allow to have different DB for alarm and metering

This changes splits the internal DB API in two parts, alarm and metering.
It also adds a new configuration options to set a different database
for alarm than the 'metering' one.

Example:

 [database]
 connection = mongodb://localhost/ceilometer
 alarm_connection = mysql://localhost/ceilometer

This changes don't take care of the drivers storaged.
They will be splitted in later changes
The ceilometer.storage.ConnectionProxy object ensure that only alarm methods
are available when the namespace is the alarm one, same for the metering
namespace.

Partial implements blueprint dedicated-alarm-database

Change-Id: I1e118e4adc59ca5cd3781dbb18865818c3cc2300
This commit is contained in:
Mehdi Abaakouk 2014-07-16 20:16:13 +02:00
parent 33d3a96822
commit 7533bc6ff6
19 changed files with 411 additions and 217 deletions

View File

@ -0,0 +1,144 @@
#
# Copyright 2012 New Dream Network, LLC (DreamHost)
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
# Author: Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Base classes for storage engines
"""
class Connection(object):
"""Base class for alarm storage system connections."""
"""A dictionary representing the capabilities of this driver.
"""
CAPABILITIES = {
'alarms': {'query': {'simple': False,
'complex': False},
'history': {'query': {'simple': False,
'complex': False}}},
}
STORAGE_CAPABILITIES = {
'storage': {'production_ready': False},
}
def __init__(self, url):
"""Constructor."""
pass
@staticmethod
def upgrade():
"""Migrate the database to `version` or the most recent version."""
@staticmethod
def get_alarms(name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None):
"""Yields a lists of alarms that match filters."""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def create_alarm(alarm):
"""Create an alarm. Returns the alarm as created.
:param alarm: The alarm to create.
"""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def update_alarm(alarm):
"""Update alarm."""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def delete_alarm(alarm_id):
"""Delete an alarm."""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def get_alarm_changes(alarm_id, on_behalf_of,
user=None, project=None, type=None,
start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None):
"""Yields list of AlarmChanges describing alarm history
Changes are always sorted in reverse order of occurrence, given
the importance of currency.
Segregation for non-administrative users is done on the basis
of the on_behalf_of parameter. This allows such users to have
visibility on both the changes initiated by themselves directly
(generally creation, rule changes, or deletion) and also on those
changes initiated on their behalf by the alarming service (state
transitions after alarm thresholds are crossed).
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
:param user: Optional ID of user to return changes for
:param project: Optional ID of project to return changes for
:project type: Optional change type
:param start_timestamp: Optional modified timestamp start range
:param start_timestamp_op: Optional timestamp start range operation
:param end_timestamp: Optional modified timestamp end range
:param end_timestamp_op: Optional timestamp end range operation
"""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def record_alarm_change(alarm_change):
"""Record alarm change event."""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def clear():
"""Clear database."""
@staticmethod
def query_alarms(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.Alarm objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise NotImplementedError('Complex query for alarms '
'is not implemented.')
@staticmethod
def query_alarm_history(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.AlarmChange objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise NotImplementedError('Complex query for alarms '
'history is not implemented.')
@classmethod
def get_capabilities(cls):
"""Return an dictionary with the capabilities of each driver."""
return cls.CAPABILITIES
@classmethod
def get_storage_capabilities(cls):
"""Return a dictionary representing the performance capabilities.
This is needed to evaluate the performance of each driver.
"""
return cls.STORAGE_CAPABILITIES

View File

@ -54,7 +54,8 @@ def setup_app(pecan_config=None, extra_hooks=None):
# FIXME: Replace DBHook with a hooks.TransactionHook
app_hooks = [hooks.ConfigHook(),
hooks.DBHook(
storage.get_connection_from_config(cfg.CONF),),
storage.get_connection_from_config(cfg.CONF, 'metering'),
storage.get_connection_from_config(cfg.CONF, 'alarm'),),
hooks.PipelineHook(),
hooks.TranslationHook()]
if extra_hooks:

View File

@ -1764,7 +1764,7 @@ class Alarm(_Base):
if alarm.project_id != wtypes.Unset
else None)
for id in alarm.combination_rule.alarm_ids:
alarms = list(pecan.request.storage_conn.get_alarms(
alarms = list(pecan.request.alarm_storage_conn.get_alarms(
alarm_id=id, project=project))
if not alarms:
raise EntityNotFound(_('Alarm'), id)
@ -1876,7 +1876,7 @@ class AlarmController(rest.RestController):
self._id = alarm_id
def _alarm(self):
self.conn = pecan.request.storage_conn
self.conn = pecan.request.alarm_storage_conn
auth_project = acl.get_limited_to_project(pecan.request.headers)
alarms = list(self.conn.get_alarms(alarm_id=self._id,
project=auth_project))
@ -1999,7 +1999,7 @@ class AlarmController(rest.RestController):
# returned to those carried out on behalf of the auth'd tenant, to
# avoid inappropriate cross-tenant visibility of alarm history
auth_project = acl.get_limited_to_project(pecan.request.headers)
conn = pecan.request.storage_conn
conn = pecan.request.alarm_storage_conn
kwargs = _query_to_kwargs(q, conn.get_alarm_changes, ['on_behalf_of',
'alarm_id'])
return [AlarmChange.from_db_model(ac)
@ -2073,7 +2073,7 @@ class AlarmsController(rest.RestController):
:param data: an alarm within the request body.
"""
conn = pecan.request.storage_conn
conn = pecan.request.alarm_storage_conn
now = timeutils.utcnow()
data.alarm_id = str(uuid.uuid4())
@ -2127,10 +2127,10 @@ class AlarmsController(rest.RestController):
q = q or []
# Timestamp is not supported field for Simple Alarm queries
kwargs = _query_to_kwargs(q,
pecan.request.storage_conn.get_alarms,
pecan.request.alarm_storage_conn.get_alarms,
allow_timestamps=False)
return [Alarm.from_db_model(m)
for m in pecan.request.storage_conn.get_alarms(**kwargs)]
for m in pecan.request.alarm_storage_conn.get_alarms(**kwargs)]
class TraitDescription(_Base):
@ -2401,7 +2401,7 @@ class QueryAlarmHistoryController(rest.RestController):
query = ValidatedComplexQuery(body,
alarm_models.AlarmChange)
query.validate(visibility_field="on_behalf_of")
conn = pecan.request.storage_conn
conn = pecan.request.alarm_storage_conn
return [AlarmChange.from_db_model(s)
for s in conn.query_alarm_history(query.filter_expr,
query.orderby,
@ -2421,7 +2421,7 @@ class QueryAlarmsController(rest.RestController):
query = ValidatedComplexQuery(body,
alarm_models.Alarm)
query.validate(visibility_field="project_id")
conn = pecan.request.storage_conn
conn = pecan.request.alarm_storage_conn
return [Alarm.from_db_model(s)
for s in conn.query_alarms(query.filter_expr,
query.orderby,
@ -2448,6 +2448,8 @@ class Capabilities(_Base):
"A flattened dictionary of API capabilities"
storage = {wtypes.text: bool}
"A flattened dictionary of storage capabilities"
alarm_storage = {wtypes.text: bool}
"A flattened dictionary of storage capabilities"
@classmethod
def sample(cls):
@ -2488,6 +2490,7 @@ class Capabilities(_Base):
'events': {'query': {'simple': True}},
}),
storage=_flatten_capabilities({'production_ready': True}),
alarm_storage=_flatten_capabilities({'production_ready': True}),
)
@ -2502,10 +2505,16 @@ class CapabilitiesController(rest.RestController):
"""
# variation in API capabilities is effectively determined by
# the lack of strict feature parity across storage drivers
driver_capabilities = pecan.request.storage_conn.get_capabilities()
driver_perf = pecan.request.storage_conn.get_storage_capabilities()
conn = pecan.request.storage_conn
alarm_conn = pecan.request.alarm_storage_conn
driver_capabilities = conn.get_capabilities().copy()
driver_capabilities['alarms'] = alarm_conn.get_capabilities()['alarms']
driver_perf = conn.get_storage_capabilities()
alarm_driver_perf = alarm_conn.get_storage_capabilities()
return Capabilities(api=_flatten_capabilities(driver_capabilities),
storage=_flatten_capabilities(driver_perf))
storage=_flatten_capabilities(driver_perf),
alarm_storage=_flatten_capabilities(
alarm_driver_perf))
class V2Controller(object):

View File

@ -36,11 +36,13 @@ class ConfigHook(hooks.PecanHook):
class DBHook(hooks.PecanHook):
def __init__(self, storage_connection):
def __init__(self, storage_connection, alarm_storage_connection):
self.storage_connection = storage_connection
self.alarm_storage_connection = alarm_storage_connection
def before(self, state):
state.request.storage_conn = self.storage_connection
state.request.alarm_storage_conn = self.alarm_storage_connection
class PipelineHook(hooks.PecanHook):

View File

@ -29,8 +29,6 @@ from ceilometer import utils
LOG = log.getLogger(__name__)
STORAGE_ENGINE_NAMESPACE = 'ceilometer.storage'
OLD_STORAGE_OPTS = [
cfg.StrOpt('database_connection',
secret=True,
@ -46,6 +44,14 @@ STORAGE_OPTS = [
default=-1,
help="Number of seconds that samples are kept "
"in the database for (<= 0 means forever)."),
cfg.StrOpt('metering_connection',
default=None,
help='The connection string used to connect to the meteting '
'database. (if unset, connection is used)'),
cfg.StrOpt('alarm_connection',
default=None,
help='The connection string used to connect to the alarm '
'database. (if unset, connection is used)'),
]
cfg.CONF.register_opts(STORAGE_OPTS, group='database')
@ -64,21 +70,76 @@ class StorageBadAggregate(Exception):
code = 400
def get_connection_from_config(conf):
STORAGE_ALARM_METHOD = [
'get_alarms', 'create_alarm', 'update_alarm', 'delete_alarm',
'get_alarm_changes', 'record_alarm_change',
'query_alarms', 'query_alarm_history',
]
class ConnectionProxy(object):
"""Proxy to the real connection object
This proxy filter out method that must not be available for a driver
namespace for driver not yet moved to the ceilometer/alarm/storage subtree.
This permit to migrate each driver in a different patch.
This class will be removed when all drivers have been splitted and moved to
the new subtree.
"""
def __init__(self, conn, namespace):
self._conn = conn
self._namespace = namespace
# NOTE(sileht): private object used in pymongo storage tests
if hasattr(self._conn, 'db'):
self.db = self._conn.db
def get_meter_statistics(self, *args, **kwargs):
# NOTE(sileht): must be defined to have mock working in
# test_compute_duration_by_resource_scenarios
method = self.__getattr__('get_meter_statistics')
return method(*args, **kwargs)
def __getattr__(self, attr):
# NOTE(sileht): this can raise the real AttributeError
value = getattr(self._conn, attr)
is_shared = attr in ['upgrade', 'clear', 'get_capabilities',
'get_storage_capabilities']
is_alarm = (self._namespace == 'ceilometer.alarm.storage'
and attr in STORAGE_ALARM_METHOD)
is_metering = (self._namespace == 'ceilometer.metering.storage'
and attr not in STORAGE_ALARM_METHOD)
if is_shared or is_alarm or is_metering:
return value
# NOTE(sileht): we try to access to an attribute not allowed for
# this namespace
raise AttributeError(
'forbidden access to the hidden attribute %s for %s',
attr, self._namespace)
def get_connection_from_config(conf, purpose=None):
if conf.database_connection:
conf.set_override('connection', conf.database_connection,
group='database')
return get_connection(conf.database.connection)
namespace = 'ceilometer.metering.storage'
url = conf.database.connection
if purpose:
namespace = 'ceilometer.%s.storage' % purpose
url = getattr(conf.database, '%s_connection' % purpose) or url
return get_connection(url, namespace)
def get_connection(url):
def get_connection(url, namespace):
"""Return an open connection to the database."""
engine_name = urlparse.urlparse(url).scheme
LOG.debug(_('looking for %(name)r driver in %(namespace)r') % (
{'name': engine_name,
'namespace': STORAGE_ENGINE_NAMESPACE}))
mgr = driver.DriverManager(STORAGE_ENGINE_NAMESPACE, engine_name)
return mgr.driver(url)
{'name': engine_name, 'namespace': namespace}))
mgr = driver.DriverManager(namespace, engine_name)
return ConnectionProxy(mgr.driver(url), namespace)
class SampleFilter(object):

View File

@ -165,10 +165,6 @@ class Connection(object):
'stddev': False,
'cardinality': False}}
},
'alarms': {'query': {'simple': False,
'complex': False},
'history': {'query': {'simple': False,
'complex': False}}},
'events': {'query': {'simple': False}},
}
@ -259,65 +255,6 @@ class Connection(object):
"""
raise NotImplementedError('Statistics not implemented')
@staticmethod
def get_alarms(name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None):
"""Yields a lists of alarms that match filters."""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def create_alarm(alarm):
"""Create an alarm. Returns the alarm as created.
:param alarm: The alarm to create.
"""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def update_alarm(alarm):
"""Update alarm."""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def delete_alarm(alarm_id):
"""Delete an alarm."""
raise NotImplementedError('Alarms not implemented')
@staticmethod
def get_alarm_changes(alarm_id, on_behalf_of,
user=None, project=None, type=None,
start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None):
"""Yields list of AlarmChanges describing alarm history
Changes are always sorted in reverse order of occurrence, given
the importance of currency.
Segregation for non-administrative users is done on the basis
of the on_behalf_of parameter. This allows such users to have
visibility on both the changes initiated by themselves directly
(generally creation, rule changes, or deletion) and also on those
changes initiated on their behalf by the alarming service (state
transitions after alarm thresholds are crossed).
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
:param user: Optional ID of user to return changes for
:param project: Optional ID of project to return changes for
:project type: Optional change type
:param start_timestamp: Optional modified timestamp start range
:param start_timestamp_op: Optional timestamp start range operation
:param end_timestamp: Optional modified timestamp end range
:param end_timestamp_op: Optional timestamp end range operation
"""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def record_alarm_change(alarm_change):
"""Record alarm change event."""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def clear():
"""Clear database."""
@ -373,30 +310,6 @@ class Connection(object):
raise NotImplementedError('Complex query for samples '
'is not implemented.')
@staticmethod
def query_alarms(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.Alarm objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise NotImplementedError('Complex query for alarms '
'is not implemented.')
@staticmethod
def query_alarm_history(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.AlarmChange objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise NotImplementedError('Complex query for alarms '
'history is not implemented.')
@classmethod
def get_capabilities(cls):
"""Return an dictionary with the capabilities of each driver."""

View File

@ -21,6 +21,7 @@ import time
import happybase
from six.moves.urllib import parse as urlparse
from ceilometer.alarm.storage import base as alarm_base
from ceilometer.alarm.storage import models as alarm_models
from ceilometer.openstack.common.gettextutils import _
from ceilometer.openstack.common import log
@ -58,7 +59,7 @@ AVAILABLE_STORAGE_CAPABILITIES = {
}
class Connection(base.Connection):
class Connection(base.Connection, alarm_base.Connection):
"""Put the data into a HBase database
Collections:

View File

@ -17,6 +17,7 @@
"""Simple logging storage backend.
"""
from ceilometer.alarm.storage import base as alarm_base
from ceilometer.openstack.common.gettextutils import _
from ceilometer.openstack.common import log
from ceilometer.storage import base
@ -24,7 +25,7 @@ from ceilometer.storage import base
LOG = log.getLogger(__name__)
class Connection(base.Connection):
class Connection(base.Connection, alarm_base.Connection):
"""Log the data."""
def upgrade(self):

View File

@ -32,6 +32,7 @@ from sqlalchemy import not_
from sqlalchemy import or_
from sqlalchemy.orm import aliased
from ceilometer.alarm.storage import base as alarm_base
from ceilometer.alarm.storage import models as alarm_api_models
from ceilometer.openstack.common.db import exception as dbexc
from ceilometer.openstack.common.db.sqlalchemy import migration
@ -220,7 +221,9 @@ class Connection(base.Connection):
}
"""
CAPABILITIES = utils.update_nested(base.Connection.CAPABILITIES,
AVAILABLE_CAPABILITIES)
utils.update_nested(
alarm_base.Connection.CAPABILITIES,
AVAILABLE_CAPABILITIES))
STORAGE_CAPABILITIES = utils.update_nested(
base.Connection.STORAGE_CAPABILITIES,
AVAILABLE_STORAGE_CAPABILITIES,

View File

@ -23,6 +23,7 @@ import operator
import pymongo
from ceilometer.alarm.storage import base as alarm_base
from ceilometer.alarm.storage import models as alarm_models
from ceilometer.openstack.common.gettextutils import _
from ceilometer.openstack.common import log
@ -53,10 +54,12 @@ AVAILABLE_STORAGE_CAPABILITIES = {
}
class Connection(base.Connection):
class Connection(base.Connection, alarm_base.Connection):
"""Base Connection class for MongoDB and DB2 drivers."""
CAPABILITIES = utils.update_nested(base.Connection.CAPABILITIES,
COMMON_AVAILABLE_CAPABILITIES)
utils.update_nested(
alarm_base.Connection.CAPABILITIES,
COMMON_AVAILABLE_CAPABILITIES))
STORAGE_CAPABILITIES = utils.update_nested(
base.Connection.STORAGE_CAPABILITIES,

View File

@ -147,7 +147,7 @@ class TestAlarms(v2.FunctionalTest,
rule=dict(alarm_ids=['a', 'b'],
operator='or')
)]:
self.conn.update_alarm(alarm)
self.alarm_conn.update_alarm(alarm)
@staticmethod
def _add_default_threshold_rule(alarm):
@ -222,7 +222,7 @@ class TestAlarms(v2.FunctionalTest,
project_id=self.auth_headers['X-Project-Id'],
time_constraints=[],
rule=dict(alarm_ids=['a', 'b'], operator='or'))
self.conn.update_alarm(alarm)
self.alarm_conn.update_alarm(alarm)
resp = self.get_json('/alarms',
q=[{'field': 'state',
'op': 'eq',
@ -272,7 +272,7 @@ class TestAlarms(v2.FunctionalTest,
project_id=self.auth_headers['X-Project-Id'],
time_constraints=[],
rule=dict(alarm_ids=['a', 'b'], operator='or'))
self.conn.update_alarm(alarm)
self.alarm_conn.update_alarm(alarm)
alarms = self.get_json('/alarms',
q=[{'field': 'enabled',
@ -393,7 +393,7 @@ class TestAlarms(v2.FunctionalTest,
" Value: \'None\'. Mandatory field missing."
% field.split('/', 1)[-1],
resp.json['error_message']['faultstring'])
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_time_constraint_start(self):
@ -414,7 +414,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, expect_errors=True, status=400,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_duplicate_time_constraint_name(self):
@ -443,7 +443,7 @@ class TestAlarms(v2.FunctionalTest,
self.assertEqual(
"Time constraint names must be unique for a given alarm.",
resp.json['error_message']['faultstring'])
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_time_constraint_duration(self):
@ -464,7 +464,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, expect_errors=True, status=400,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_time_constraint_timezone(self):
@ -486,7 +486,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, expect_errors=True, status=400,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_period(self):
@ -504,7 +504,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, expect_errors=True, status=400,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_null_threshold_rule(self):
@ -533,7 +533,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, expect_errors=True, status=400,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_query(self):
@ -552,7 +552,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, expect_errors=True, status=400,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_query_field_type(self):
@ -576,7 +576,7 @@ class TestAlarms(v2.FunctionalTest,
resp_string = jsonutils.loads(resp.body)
fault_string = resp_string['error_message']['faultstring']
self.assertTrue(fault_string.startswith(expected_error_message))
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
def test_post_invalid_alarm_have_multiple_rules(self):
@ -597,7 +597,7 @@ class TestAlarms(v2.FunctionalTest,
}
resp = self.post_json('/alarms', params=json, expect_errors=True,
status=400, headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
self.assertEqual('threshold_rule and combination_rule cannot '
'be set at the same time',
@ -621,7 +621,7 @@ class TestAlarms(v2.FunctionalTest,
}
resp = self.post_json('/alarms', params=json, expect_errors=True,
status=400, headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(4, len(alarms))
self.assertEqual(
'Unknown argument: "timestamp": '
@ -665,7 +665,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, status=201,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(5, len(alarms))
for alarm in alarms:
if alarm.name == 'added_alarm_defaults':
@ -737,7 +737,7 @@ class TestAlarms(v2.FunctionalTest,
self.post_json('/alarms', params=json, status=201,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
json['threshold_rule']['query'].append({
'field': 'project_id', 'op': 'eq',
@ -781,7 +781,7 @@ class TestAlarms(v2.FunctionalTest,
}
}
self.post_json('/alarms', params=json, status=201)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
# to check to BoundedInt type conversion
json['threshold_rule']['evaluation_periods'] = 3
@ -828,7 +828,7 @@ class TestAlarms(v2.FunctionalTest,
headers['X-Roles'] = 'admin'
self.post_json('/alarms', params=json, status=201,
headers=headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
self.assertEqual('auseridthatisnotmine', alarms[0].user_id)
self.assertEqual('aprojectidthatisnotmine', alarms[0].project_id)
@ -900,7 +900,7 @@ class TestAlarms(v2.FunctionalTest,
headers['X-Roles'] = 'admin'
self.post_json('/alarms', params=json, status=201,
headers=headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
self.assertEqual(self.auth_headers['X-User-Id'], alarms[0].user_id)
self.assertEqual('aprojectidthatisnotmine', alarms[0].project_id)
@ -938,7 +938,7 @@ class TestAlarms(v2.FunctionalTest,
headers['X-Roles'] = 'admin'
self.post_json('/alarms', params=json, status=201,
headers=headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
self.assertEqual('auseridthatisnotmine', alarms[0].user_id)
self.assertEqual(self.auth_headers['X-Project-Id'],
@ -1013,7 +1013,7 @@ class TestAlarms(v2.FunctionalTest,
headers.update(self.auth_headers)
headers['X-Roles'] = 'demo'
self.post_json('/alarms', params=json, status=201, headers=headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
self.assertEqual(alarms[0].user_id,
self.auth_headers['X-User-Id'])
@ -1051,7 +1051,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, status=201,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
if alarms[0].name == 'added_alarm':
for key in json:
@ -1148,7 +1148,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, status=201,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(1, len(alarms))
self.assertEqual(u'Combined state of alarms a and b',
alarms[0].description)
@ -1244,7 +1244,7 @@ class TestAlarms(v2.FunctionalTest,
self.post_json('/alarms', params=json, status=201,
headers=an_other_admin_auth)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
if alarms[0].name == 'added_alarm':
for key in json:
if key.endswith('_rule'):
@ -1274,7 +1274,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json, status=404,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(0, len(alarms))
def test_post_alarm_combination_duplicate_alarm_ids(self):
@ -1288,7 +1288,7 @@ class TestAlarms(v2.FunctionalTest,
}
self.post_json('/alarms', params=json_body, status=201,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms(name='dup_alarm_id'))
alarms = list(self.alarm_conn.get_alarms(name='dup_alarm_id'))
self.assertEqual(1, len(alarms))
self.assertEqual(['a', 'd', 'c', 'b'],
alarms[0].rule.get('alarm_ids'))
@ -1354,7 +1354,8 @@ class TestAlarms(v2.FunctionalTest,
self.put_json('/alarms/%s' % alarm_id,
params=json,
headers=self.auth_headers)
alarm = list(self.conn.get_alarms(alarm_id=alarm_id, enabled=False))[0]
alarm = list(self.alarm_conn.get_alarms(alarm_id=alarm_id,
enabled=False))[0]
json['threshold_rule']['query'].append({
'field': 'project_id', 'op': 'eq',
'value': self.auth_headers['X-Project-Id']})
@ -1402,7 +1403,8 @@ class TestAlarms(v2.FunctionalTest,
self.put_json('/alarms/%s' % alarm_id,
params=json,
headers=headers)
alarm = list(self.conn.get_alarms(alarm_id=alarm_id, enabled=False))[0]
alarm = list(self.alarm_conn.get_alarms(alarm_id=alarm_id,
enabled=False))[0]
self.assertEqual('myuserid', alarm.user_id)
self.assertEqual('myprojectid', alarm.project_id)
self._verify_alarm(json, alarm)
@ -1563,7 +1565,7 @@ class TestAlarms(v2.FunctionalTest,
params=json_body, status=200,
headers=self.auth_headers)
alarms = list(self.conn.get_alarms(alarm_id=alarm_id))
alarms = list(self.alarm_conn.get_alarms(alarm_id=alarm_id))
self.assertEqual(1, len(alarms))
self.assertEqual(['c', 'a', 'b'], alarms[0].rule.get('alarm_ids'))
@ -1575,7 +1577,7 @@ class TestAlarms(v2.FunctionalTest,
headers=self.auth_headers,
status=204)
self.assertEqual('', resp.body)
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(3, len(alarms))
def test_get_state_alarm(self):
@ -1593,7 +1595,7 @@ class TestAlarms(v2.FunctionalTest,
resp = self.put_json('/alarms/%s/state' % data[0]['alarm_id'],
headers=self.auth_headers,
params='alarm')
alarms = list(self.conn.get_alarms(alarm_id=data[0]['alarm_id']))
alarms = list(self.alarm_conn.get_alarms(alarm_id=data[0]['alarm_id']))
self.assertEqual(1, len(alarms))
self.assertEqual('alarm', alarms[0].state)
self.assertEqual('alarm', resp.json)

View File

@ -324,7 +324,7 @@ class TestQueryAlarmsController(tests_api.FunctionalTest,
'op': 'eq',
'value':
project_id}]))
self.conn.update_alarm(alarm)
self.alarm_conn.update_alarm(alarm)
def test_query_all(self):
data = self.post_json(self.alarm_url,
@ -471,7 +471,7 @@ class TestQueryAlarmsHistoryController(
"on_behalf_of": "project-id%d" % id,
"timestamp": date}
self.conn.record_alarm_change(alarm_change)
self.alarm_conn.record_alarm_change(alarm_change)
def test_query_all(self):
data = self.post_json(self.url,

View File

@ -46,7 +46,10 @@ class MongoDbManager(fixtures.Fixture):
action='ignore',
message='.*you must provide a username and password.*')
try:
self.connection = storage.get_connection(self.url)
self.connection = storage.get_connection(
self.url, 'ceilometer.metering.storage')
self.alarm_connection = storage.get_connection(
self.url, 'ceilometer.alarm.storage')
except storage.StorageBadVersion as e:
raise testcase.TestSkipped(six.text_type(e))
@ -64,7 +67,10 @@ class HBaseManager(fixtures.Fixture):
def setUp(self):
super(HBaseManager, self).setUp()
self.connection = storage.get_connection(self.url)
self.connection = storage.get_connection(
self.url, 'ceilometer.metering.storage')
self.alarm_connection = storage.get_connection(
self.url, 'ceilometer.alarm.storage')
@property
def url(self):
@ -81,7 +87,10 @@ class SQLiteManager(fixtures.Fixture):
def setUp(self):
super(SQLiteManager, self).setUp()
self.connection = storage.get_connection(self.url)
self.connection = storage.get_connection(
self.url, 'ceilometer.metering.storage')
self.alarm_connection = storage.get_connection(
self.url, 'ceilometer.alarm.storage')
class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
@ -113,8 +122,11 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
self.conn = self.db_manager.connection
self.conn.upgrade()
self.alarm_conn = self.db_manager.alarm_connection
self.alarm_conn.upgrade()
self.useFixture(oslo_mock.Patch('ceilometer.storage.get_connection',
return_value=self.conn))
side_effect=self._get_connection))
self.CONF = self.useFixture(config.Config()).conf
self.CONF([], project='ceilometer')
@ -129,10 +141,17 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
)
def tearDown(self):
self.alarm_conn.clear()
self.alarm_conn = None
self.conn.clear()
self.conn = None
super(TestBase, self).tearDown()
def _get_connection(self, url, namespace):
if namespace == "ceilometer.alarm.storage":
return self.alarm_conn
return self.conn
def _get_driver_manager(self, engine):
manager = self.DRIVER_MANAGERS.get(engine)
if not manager:

View File

@ -17,9 +17,11 @@
"""Tests for ceilometer/storage/
"""
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common import test
from ceilometer import storage
from ceilometer.storage import impl_log
from ceilometer.storage import impl_sqlalchemy
import six
@ -27,11 +29,39 @@ import six
class EngineTest(test.BaseTestCase):
def test_get_connection(self):
engine = storage.get_connection('log://localhost')
engine = storage.get_connection('log://localhost',
'ceilometer.metering.storage')._conn
self.assertIsInstance(engine, impl_log.Connection)
def test_get_connection_no_such_engine(self):
try:
storage.get_connection('no-such-engine://localhost')
storage.get_connection('no-such-engine://localhost',
'ceilometer.metering.storage')
except RuntimeError as err:
self.assertIn('no-such-engine', six.text_type(err))
class ConnectionConfigTest(test.BaseTestCase):
def setUp(self):
super(ConnectionConfigTest, self).setUp()
self.CONF = self.useFixture(config.Config()).conf
def test_only_default_url(self):
self.CONF.set_override("connection", "log://", group="database")
conn = storage.get_connection_from_config(self.CONF)._conn
self.assertIsInstance(conn, impl_log.Connection)
conn = storage.get_connection_from_config(self.CONF, 'metering')._conn
self.assertIsInstance(conn, impl_log.Connection)
conn = storage.get_connection_from_config(self.CONF, 'alarm')._conn
self.assertIsInstance(conn, impl_log.Connection)
def test_two_urls(self):
self.CONF.set_override("connection", "log://", group="database")
self.CONF.set_override("alarm_connection", "sqlite://",
group="database")
conn = storage.get_connection_from_config(self.CONF)._conn
self.assertIsInstance(conn, impl_log.Connection)
conn = storage.get_connection_from_config(self.CONF, 'metering')._conn
self.assertIsInstance(conn, impl_log.Connection)
conn = storage.get_connection_from_config(self.CONF, 'alarm')._conn
self.assertIsInstance(conn, impl_sqlalchemy.Connection)

View File

@ -115,7 +115,7 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase):
def test_alarm_get_marker(self):
self.add_some_alarms()
marker_pairs = {'name': 'red-alert'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.alarm,
ret = impl_mongodb.Connection._get_marker(self.alarm_conn.db.alarm,
marker_pairs=marker_pairs)
self.assertEqual('test.one', ret['rule']['meter_name'])
@ -123,7 +123,7 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase):
self.add_some_alarms()
try:
marker_pairs = {'name': 'user-id-foo'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.alarm,
ret = impl_mongodb.Connection._get_marker(self.alarm_conn.db.alarm,
marker_pairs)
self.assertEqual('meter_name-foo', ret['rule']['meter_name'])
except base.NoResultFound:
@ -133,7 +133,7 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase):
self.add_some_alarms()
try:
marker_pairs = {'user_id': 'me'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.alarm,
ret = impl_mongodb.Connection._get_marker(self.alarm_conn.db.alarm,
marker_pairs)
self.assertEqual('counter-name-foo', ret['rule']['meter_name'])
except base.MultipleResultsFound:

View File

@ -153,7 +153,7 @@ class EventTest(tests_db.TestBase):
m = [models.Event("1", "Foo", now, []),
models.Event("2", "Zoo", now, [])]
with mock.patch.object(self.conn, "_record_event") as mock_save:
with mock.patch.object(self.conn._conn, "_record_event") as mock_save:
mock_save.side_effect = MyException("Boom")
problem_events = self.conn.record_events(m)
self.assertEqual(2, len(problem_events))

View File

@ -117,7 +117,7 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
repeat_actions=False,
matching_metadata={'key': 'value'})
self.conn.db.alarm.update(
self.alarm_conn.db.alarm.update(
{'alarm_id': alarm['alarm_id']},
{'$set': alarm},
upsert=True)
@ -126,13 +126,13 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
alarm['name'] = 'other-old-alaert'
alarm['matching_metadata'] = [{'key': 'key1', 'value': 'value1'},
{'key': 'key2', 'value': 'value2'}]
self.conn.db.alarm.update(
self.alarm_conn.db.alarm.update(
{'alarm_id': alarm['alarm_id']},
{'$set': alarm},
upsert=True)
def test_alarm_get_old_format_matching_metadata_dict(self):
old = list(self.conn.get_alarms(name='old-alert'))[0]
old = list(self.alarm_conn.get_alarms(name='old-alert'))[0]
self.assertEqual('threshold', old.type)
self.assertEqual([{'field': 'key',
'op': 'eq',
@ -147,7 +147,7 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
self.assertEqual(36, old.rule['threshold'])
def test_alarm_get_old_format_matching_metadata_array(self):
old = list(self.conn.get_alarms(name='other-old-alaert'))[0]
old = list(self.alarm_conn.get_alarms(name='other-old-alaert'))[0]
self.assertEqual('threshold', old.type)
self.assertEqual(sorted([{'field': 'key1',
'op': 'eq',

View File

@ -29,7 +29,6 @@ from ceilometer.publisher import utils
from ceilometer import sample
from ceilometer import storage
from ceilometer.storage import base
from ceilometer.storage import impl_mongodb as mongodb
from ceilometer.storage import models
from ceilometer.tests import db as tests_db
@ -621,11 +620,10 @@ class RawSampleTest(DBTestBase,
results = list(self.conn.get_samples(f))
self.assertEqual(len(results), 2)
@tests_db.run_with('sqlite', 'hbase', 'db2')
def test_clear_metering_data(self):
# NOTE(jd) Override this test in MongoDB because our code doesn't clear
# the collections, this is handled by MongoDB TTL feature.
if isinstance(self.conn, mongodb.Connection):
return
self.mock_utcnow.return_value = datetime.datetime(2012, 7, 2, 10, 45)
self.conn.clear_expired_metering_data(3 * 60)
@ -635,11 +633,10 @@ class RawSampleTest(DBTestBase,
results = list(self.conn.get_resources())
self.assertEqual(len(results), 5)
@tests_db.run_with('sqlite', 'hbase', 'db2')
def test_clear_metering_data_no_data_to_remove(self):
# NOTE(jd) Override this test in MongoDB because our code doesn't clear
# the collections, this is handled by MongoDB TTL feature.
if isinstance(self.conn, mongodb.Connection):
return
self.mock_utcnow.return_value = datetime.datetime(2010, 7, 2, 10, 45)
self.conn.clear_expired_metering_data(3 * 60)
@ -649,11 +646,10 @@ class RawSampleTest(DBTestBase,
results = list(self.conn.get_resources())
self.assertEqual(len(results), 9)
@tests_db.run_with('sqlite', 'hbase', 'db2')
def test_clear_metering_data_with_alarms(self):
# NOTE(jd) Override this test in MongoDB because our code doesn't clear
# the collections, this is handled by MongoDB TTL feature.
if isinstance(self.conn, mongodb.Connection):
return
alarm = alarm_models.Alarm(alarm_id='r3d',
enabled=True,
@ -682,7 +678,7 @@ class RawSampleTest(DBTestBase,
'type': 'string'}]),
)
self.conn.create_alarm(alarm)
self.alarm_conn.create_alarm(alarm)
self.mock_utcnow.return_value = datetime.datetime(2012, 7, 2, 10, 45)
self.conn.clear_expired_metering_data(5)
f = storage.SampleFilter(meter='instance')
@ -2393,34 +2389,34 @@ class AlarmTestBase(DBTestBase):
)]
for a in alarms:
self.conn.create_alarm(a)
self.alarm_conn.create_alarm(a)
class AlarmTest(AlarmTestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual([], alarms)
def test_list(self):
self.add_some_alarms()
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(len(alarms), 3)
def test_list_enabled(self):
self.add_some_alarms()
alarms = list(self.conn.get_alarms(enabled=True))
alarms = list(self.alarm_conn.get_alarms(enabled=True))
self.assertEqual(len(alarms), 2)
def test_list_disabled(self):
self.add_some_alarms()
alarms = list(self.conn.get_alarms(enabled=False))
alarms = list(self.alarm_conn.get_alarms(enabled=False))
self.assertEqual(len(alarms), 1)
def test_add(self):
self.add_some_alarms()
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
self.assertEqual(len(alarms), 3)
meter_names = sorted([a.rule['meter_name'] for a in alarms])
@ -2429,7 +2425,7 @@ class AlarmTest(AlarmTestBase,
def test_update(self):
self.add_some_alarms()
orange = list(self.conn.get_alarms(name='orange-alert'))[0]
orange = list(self.alarm_conn.get_alarms(name='orange-alert'))[0]
orange.enabled = False
orange.state = alarm_models.Alarm.ALARM_INSUFFICIENT_DATA
query = [{'field': 'metadata.group',
@ -2438,7 +2434,7 @@ class AlarmTest(AlarmTestBase,
'type': 'string'}]
orange.rule['query'] = query
orange.rule['meter_name'] = 'new_meter_name'
updated = self.conn.update_alarm(orange)
updated = self.alarm_conn.update_alarm(orange)
self.assertEqual(updated.enabled, False)
self.assertEqual(updated.state,
alarm_models.Alarm.ALARM_INSUFFICIENT_DATA)
@ -2469,19 +2465,19 @@ class AlarmTest(AlarmTestBase,
meter_name='llt',
query=[])
)
updated = self.conn.update_alarm(llu)
updated = self.alarm_conn.update_alarm(llu)
updated.state = alarm_models.Alarm.ALARM_OK
updated.description = ':)'
self.conn.update_alarm(updated)
self.alarm_conn.update_alarm(updated)
all = list(self.conn.get_alarms())
all = list(self.alarm_conn.get_alarms())
self.assertEqual(len(all), 1)
def test_delete(self):
self.add_some_alarms()
victim = list(self.conn.get_alarms(name='orange-alert'))[0]
self.conn.delete_alarm(victim.alarm_id)
survivors = list(self.conn.get_alarms())
victim = list(self.alarm_conn.get_alarms(name='orange-alert'))[0]
self.alarm_conn.delete_alarm(victim.alarm_id)
survivors = list(self.alarm_conn.get_alarms())
self.assertEqual(len(survivors), 2)
for s in survivors:
self.assertNotEqual(victim.name, s.name)
@ -2493,26 +2489,26 @@ class AlarmTestPagination(AlarmTestBase,
def test_get_alarm_all_limit(self):
self.add_some_alarms()
pagination = base.Pagination(limit=2)
alarms = list(self.conn.get_alarms(pagination=pagination))
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 2)
pagination = base.Pagination(limit=1)
alarms = list(self.conn.get_alarms(pagination=pagination))
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 1)
def test_get_alarm_all_marker(self):
self.add_some_alarms()
pagination = base.Pagination(marker_value='orange-alert')
alarms = list(self.conn.get_alarms(pagination=pagination))
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 0)
pagination = base.Pagination(marker_value='red-alert')
alarms = list(self.conn.get_alarms(pagination=pagination))
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 1)
pagination = base.Pagination(marker_value='yellow-alert')
alarms = list(self.conn.get_alarms(pagination=pagination))
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 2)
def test_get_alarm_paginate(self):
@ -2520,12 +2516,12 @@ class AlarmTestPagination(AlarmTestBase,
self.add_some_alarms()
pagination = base.Pagination(limit=4, marker_value='yellow-alert')
page = list(self.conn.get_alarms(pagination=pagination))
page = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(['red-alert', 'orange-alert'], [i.name for i in page])
pagination = base.Pagination(limit=2, marker_value='orange-alert',
primary_sort_dir='asc')
page1 = list(self.conn.get_alarms(pagination=pagination))
page1 = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(['red-alert', 'yellow-alert'],
[i.name for i in page1])
@ -2535,12 +2531,12 @@ class ComplexAlarmQueryTest(AlarmTestBase,
def test_no_filter(self):
self.add_some_alarms()
result = list(self.conn.query_alarms())
result = list(self.alarm_conn.query_alarms())
self.assertEqual(3, len(result))
def test_no_filter_with_limit(self):
self.add_some_alarms()
result = list(self.conn.query_alarms(limit=2))
result = list(self.alarm_conn.query_alarms(limit=2))
self.assertEqual(2, len(result))
def test_filter(self):
@ -2551,7 +2547,7 @@ class ComplexAlarmQueryTest(AlarmTestBase,
{"=": {"name": "red-alert"}}]},
{"=": {"enabled": True}}]}
result = list(self.conn.query_alarms(filter_expr=filter_expr))
result = list(self.alarm_conn.query_alarms(filter_expr=filter_expr))
self.assertEqual(1, len(result))
for a in result:
@ -2562,7 +2558,7 @@ class ComplexAlarmQueryTest(AlarmTestBase,
self.add_some_alarms()
filter_expr = {"=": {"alarm_id": "0r4ng3"}}
result = list(self.conn.query_alarms(filter_expr=filter_expr))
result = list(self.alarm_conn.query_alarms(filter_expr=filter_expr))
self.assertEqual(1, len(result))
for a in result:
@ -2570,9 +2566,9 @@ class ComplexAlarmQueryTest(AlarmTestBase,
def test_filter_and_orderby(self):
self.add_some_alarms()
result = list(self.conn.query_alarms(filter_expr=(
{"=": {"enabled": True}}),
orderby=[{"name": "asc"}]))
result = list(self.alarm_conn.query_alarms(filter_expr=(
{"=": {"enabled": True}}),
orderby=[{"name": "asc"}]))
self.assertEqual(2, len(result))
self.assertEqual(["orange-alert", "red-alert"],
[a.name for a in result])
@ -2593,7 +2589,7 @@ class ComplexAlarmHistoryQueryTest(AlarmTestBase,
self.prepare_alarm_history()
def prepare_alarm_history(self):
alarms = list(self.conn.get_alarms())
alarms = list(self.alarm_conn.get_alarms())
for alarm in alarms:
i = alarms.index(alarm)
alarm_change = dict(event_id=(
@ -2607,7 +2603,7 @@ class ComplexAlarmHistoryQueryTest(AlarmTestBase,
timestamp=datetime.datetime(2012, 9, 24,
7 + i,
30 + i))
self.conn.record_alarm_change(alarm_change=alarm_change)
self.alarm_conn.record_alarm_change(alarm_change=alarm_change)
alarm_change2 = dict(event_id=(
"16fd2706-8baf-433b-82eb-8c7fada847d%s" % i),
@ -2620,7 +2616,7 @@ class ComplexAlarmHistoryQueryTest(AlarmTestBase,
timestamp=datetime.datetime(2012, 9, 25,
10 + i,
30 + i))
self.conn.record_alarm_change(alarm_change=alarm_change2)
self.alarm_conn.record_alarm_change(alarm_change=alarm_change2)
alarm_change3 = dict(
event_id="16fd2706-8baf-433b-82eb-8c7fada847e%s" % i,
@ -2636,7 +2632,7 @@ class ComplexAlarmHistoryQueryTest(AlarmTestBase,
if alarm.name == "red-alert":
alarm_change3['on_behalf_of'] = 'and-da-girls'
self.conn.record_alarm_change(alarm_change=alarm_change3)
self.alarm_conn.record_alarm_change(alarm_change=alarm_change3)
if alarm.name in ["red-alert", "yellow-alert"]:
alarm_change4 = dict(event_id=(
@ -2651,50 +2647,50 @@ class ComplexAlarmHistoryQueryTest(AlarmTestBase,
timestamp=datetime.datetime(2012, 9, 27,
10 + i,
30 + i))
self.conn.record_alarm_change(alarm_change=alarm_change4)
self.alarm_conn.record_alarm_change(alarm_change=alarm_change4)
def test_alarm_history_with_no_filter(self):
history = list(self.conn.query_alarm_history())
history = list(self.alarm_conn.query_alarm_history())
self.assertEqual(11, len(history))
def test_alarm_history_with_no_filter_and_limit(self):
history = list(self.conn.query_alarm_history(limit=3))
history = list(self.alarm_conn.query_alarm_history(limit=3))
self.assertEqual(3, len(history))
def test_alarm_history_with_filter(self):
history = list(
self.conn.query_alarm_history(filter_expr=self.filter_expr))
self.alarm_conn.query_alarm_history(filter_expr=self.filter_expr))
self.assertEqual(2, len(history))
def test_alarm_history_with_filter_and_orderby(self):
history = list(
self.conn.query_alarm_history(filter_expr=self.filter_expr,
orderby=[{"timestamp":
"asc"}]))
self.alarm_conn.query_alarm_history(filter_expr=self.filter_expr,
orderby=[{"timestamp":
"asc"}]))
self.assertEqual([alarm_models.AlarmChange.RULE_CHANGE,
alarm_models.AlarmChange.STATE_TRANSITION],
[h.type for h in history])
def test_alarm_history_with_filter_and_orderby_and_limit(self):
history = list(
self.conn.query_alarm_history(filter_expr=self.filter_expr,
orderby=[{"timestamp":
"asc"}],
limit=1))
self.alarm_conn.query_alarm_history(filter_expr=self.filter_expr,
orderby=[{"timestamp":
"asc"}],
limit=1))
self.assertEqual(alarm_models.AlarmChange.RULE_CHANGE, history[0].type)
def test_alarm_history_with_on_behalf_of_filter(self):
filter_expr = {"=": {"on_behalf_of": "and-da-girls"}}
history = list(self.conn.query_alarm_history(filter_expr=filter_expr))
history = list(self.alarm_conn.query_alarm_history(
filter_expr=filter_expr))
self.assertEqual(1, len(history))
self.assertEqual("16fd2706-8baf-433b-82eb-8c7fada847e0",
history[0].event_id)
def test_alarm_history_with_alarm_id_as_filter(self):
filter_expr = {"=": {"alarm_id": "r3d"}}
history = list(self.conn.query_alarm_history(filter_expr=filter_expr,
orderby=[{"timestamp":
"asc"}]))
history = list(self.alarm_conn.query_alarm_history(
filter_expr=filter_expr, orderby=[{"timestamp": "asc"}]))
self.assertEqual(4, len(history))
self.assertEqual([alarm_models.AlarmChange.CREATION,
alarm_models.AlarmChange.RULE_CHANGE,

View File

@ -144,7 +144,16 @@ ceilometer.poll.central =
network.services.lb.incoming.bytes = ceilometer.network.services.lbaas:LBBytesInPollster
network.services.lb.outgoing.bytes = ceilometer.network.services.lbaas:LBBytesOutPollster
ceilometer.storage =
ceilometer.alarm.storage =
log = ceilometer.storage.impl_log:Connection
mongodb = ceilometer.storage.impl_mongodb:Connection
mysql = ceilometer.storage.impl_sqlalchemy:Connection
postgresql = ceilometer.storage.impl_sqlalchemy:Connection
sqlite = ceilometer.storage.impl_sqlalchemy:Connection
hbase = ceilometer.storage.impl_hbase:Connection
db2 = ceilometer.storage.impl_db2:Connection
ceilometer.metering.storage =
log = ceilometer.storage.impl_log:Connection
mongodb = ceilometer.storage.impl_mongodb:Connection
mysql = ceilometer.storage.impl_sqlalchemy:Connection