Browse Source

Deprecate combination alarm

The combination alarm is deprecated and disabled
by default in Aodh, and will removed after two release
cycles in Aodh. Keep the same with Aodh, this change
deprecates combination alarm resource, before hidden it
we use ceilometer client as before because aodh client doesn't
support to manage combination alarm.

Blueprint migrate-to-use-aodh-for-alarms

Change-Id: Ibe8fe35a0cf9efe3d2809041ee480c99a75166cd
changes/74/334274/5
huangtianhua 5 years ago
parent
commit
26bab914a0
  1. 3
      etc/heat/environment.d/default.yaml
  2. 78
      heat/engine/resources/openstack/ceilometer/alarm.py
  3. 3
      heat/tests/engine/test_resource_type.py
  4. 8
      heat/tests/openstack/ceilometer/test_ceilometer_alarm.py

3
etc/heat/environment.d/default.yaml

@ -10,4 +10,5 @@ resource_registry:
"OS::Ceilometer::Alarm": "OS::Aodh::Alarm"
"OS::Ceilometer::GnocchiResourcesAlarm": "OS::Aodh::GnocchiResourcesAlarm"
"OS::Ceilometer::GnocchiAggregationByMetricsAlarm": "OS::Aodh::GnocchiAggregationByMetricsAlarm"
"OS::Ceilometer::GnocchiAggregationByResourcesAlarm": "OS::Aodh::GnocchiAggregationByResourcesAlarm"
"OS::Ceilometer::GnocchiAggregationByResourcesAlarm": "OS::Aodh::GnocchiAggregationByResourcesAlarm"
"OS::Ceilometer::CombinationAlarm": "OS::Aodh::CombinationAlarm"

78
heat/engine/resources/openstack/ceilometer/alarm.py

@ -220,11 +220,51 @@ class AodhAlarm(alarm_base.BaseAlarm):
return self.client().alarm.get(self.resource_id)
class BaseCeilometerAlarm(alarm_base.BaseAlarm):
class CombinationAlarm(alarm_base.BaseAlarm):
"""A resource that implements combination of Aodh alarms.
Allows to use alarm as a combination of other alarms with some operator:
activate this alarm if any alarm in combination has been activated or
if all alarms in combination have been activated.
"""
alarm_type = 'combination'
# aodhclient doesn't support to manage combination-alarm,
# so we use ceilometerclient to manage this resource as before,
# after two release cycles, to hidden this resource.
default_client_name = 'ceilometer'
entity = 'alarms'
support_status = support.SupportStatus(
status=support.DEPRECATED,
version='7.0.0',
message=_('The combination alarm is deprecated and '
'disabled by default in Aodh.'),
previous_status=support.SupportStatus(version='2014.1'))
PROPERTIES = (
ALARM_IDS, OPERATOR,
) = (
'alarm_ids', 'operator',
)
properties_schema = {
ALARM_IDS: properties.Schema(
properties.Schema.LIST,
_('List of alarm identifiers to combine.'),
required=True,
constraints=[constraints.Length(min=1)],
update_allowed=True),
OPERATOR: properties.Schema(
properties.Schema.STRING,
_('Operator used to combine the alarms.'),
constraints=[constraints.AllowedValues(['and', 'or'])],
update_allowed=True)
}
properties_schema.update(alarm_base.common_properties_schema)
def handle_create(self):
props = self.actions_to_urls(self.properties)
props['name'] = self.physical_resource_name()
@ -253,42 +293,8 @@ class BaseCeilometerAlarm(alarm_base.BaseAlarm):
self.client().alarms.get(self.resource_id)
class CombinationAlarm(BaseCeilometerAlarm):
"""A resource that implements combination of Ceilometer alarms.
Allows to use alarm as a combination of other alarms with some operator:
activate this alarm if any alarm in combination has been activated or
if all alarms in combination have been activated.
"""
support_status = support.SupportStatus(version='2014.1')
PROPERTIES = (
ALARM_IDS, OPERATOR,
) = (
'alarm_ids', 'operator',
)
properties_schema = {
ALARM_IDS: properties.Schema(
properties.Schema.LIST,
_('List of alarm identifiers to combine.'),
required=True,
constraints=[constraints.Length(min=1)],
update_allowed=True),
OPERATOR: properties.Schema(
properties.Schema.STRING,
_('Operator used to combine the alarms.'),
constraints=[constraints.AllowedValues(['and', 'or'])],
update_allowed=True)
}
properties_schema.update(alarm_base.common_properties_schema)
alarm_type = 'combination'
def resource_mapping():
return {
'OS::Aodh::Alarm': AodhAlarm,
'OS::Ceilometer::CombinationAlarm': CombinationAlarm,
'OS::Aodh::CombinationAlarm': CombinationAlarm,
}

3
heat/tests/engine/test_resource_type.py

@ -49,7 +49,8 @@ class ResourceTypeTest(common.HeatTestCase):
'OS::Neutron::HealthMonitor',
'OS::Neutron::LoadBalancer',
'OS::Neutron::Pool',
'OS::Neutron::PoolMember']),
'OS::Neutron::PoolMember',
'OS::Aodh::CombinationAlarm']),
set(resources))
@mock.patch.object(res.Resource, 'is_service_available')

8
heat/tests/openstack/ceilometer/test_ceilometer_alarm.py

@ -126,7 +126,7 @@ combination_alarm_template = '''
"Description" : "Combination Alarm Test",
"Resources" : {
"CombinAlarm": {
"Type": "OS::Ceilometer::CombinationAlarm",
"Type": "OS::Aodh::CombinationAlarm",
"Properties": {
"description": "Do stuff in combination",
"alarm_ids": ["alarm1", "alarm2"],
@ -139,7 +139,7 @@ combination_alarm_template = '''
'''
class FakeCeilometerAlarm(object):
class FakeCombinationAlarm(object):
alarm_id = 'foo'
def __init__(self):
@ -620,7 +620,7 @@ class CombinationAlarmTest(common.HeatTestCase):
'operator': u'and'},
time_constraints=[],
severity='low'
).AndReturn(FakeCeilometerAlarm())
).AndReturn(FakeCombinationAlarm())
self.tmpl = template_format.parse(combination_alarm_template)
self.stack = utils.parse_stack(self.tmpl)
resource_defns = self.stack.t.resource_definitions(self.stack)
@ -722,6 +722,6 @@ class CombinationAlarmTest(common.HeatTestCase):
res = self._prepare_check_resource()
res.client().alarms.create.return_value = mock.MagicMock(
alarm_id='2')
res.client().alarms.get.return_value = FakeCeilometerAlarm()
res.client().alarms.get.return_value = FakeCombinationAlarm()
scheduler.TaskRunner(res.create)()
self.assertEqual({'attr': 'val'}, res.FnGetAtt('show'))
Loading…
Cancel
Save