From 26bab914a061342f9da3d926a979baa62419818f Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Mon, 27 Jun 2016 10:27:38 +0800 Subject: [PATCH] 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 --- etc/heat/environment.d/default.yaml | 3 +- .../resources/openstack/ceilometer/alarm.py | 78 ++++++++++--------- heat/tests/engine/test_resource_type.py | 3 +- .../ceilometer/test_ceilometer_alarm.py | 8 +- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/etc/heat/environment.d/default.yaml b/etc/heat/environment.d/default.yaml index 2092e84232..de98a756a2 100644 --- a/etc/heat/environment.d/default.yaml +++ b/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" \ No newline at end of file + "OS::Ceilometer::GnocchiAggregationByResourcesAlarm": "OS::Aodh::GnocchiAggregationByResourcesAlarm" + "OS::Ceilometer::CombinationAlarm": "OS::Aodh::CombinationAlarm" diff --git a/heat/engine/resources/openstack/ceilometer/alarm.py b/heat/engine/resources/openstack/ceilometer/alarm.py index d277a6bab8..4f1e5d0927 100644 --- a/heat/engine/resources/openstack/ceilometer/alarm.py +++ b/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, } diff --git a/heat/tests/engine/test_resource_type.py b/heat/tests/engine/test_resource_type.py index 9dd563ca48..ec8dd739e3 100644 --- a/heat/tests/engine/test_resource_type.py +++ b/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') diff --git a/heat/tests/openstack/ceilometer/test_ceilometer_alarm.py b/heat/tests/openstack/ceilometer/test_ceilometer_alarm.py index 8ba1ccd5ec..8626c0e6f9 100644 --- a/heat/tests/openstack/ceilometer/test_ceilometer_alarm.py +++ b/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'))