From b2911cb7c8b8065d03f4f3ec66a3ae192b29f1ef Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Sat, 20 Apr 2019 01:17:29 +1200 Subject: [PATCH] Add loadbalancer_member_health type alarm rule The loadbalancer_member_health_rule is used with loadbalancer_member_health evaluator that was introduced here[1]. [1]: https://review.opendev.org/#/c/652622/ Change-Id: Ic1b3d429d3233be0789f173fa8d3ef5ca5522b8b --- .../v2/alarm_rules/loadbalancer.py | 39 +++++++++++++++++++ .../functional/api/v2/test_alarm_scenarios.py | 20 ++++++++++ setup.cfg | 1 + 3 files changed, 60 insertions(+) create mode 100644 aodh/api/controllers/v2/alarm_rules/loadbalancer.py diff --git a/aodh/api/controllers/v2/alarm_rules/loadbalancer.py b/aodh/api/controllers/v2/alarm_rules/loadbalancer.py new file mode 100644 index 000000000..785ab8161 --- /dev/null +++ b/aodh/api/controllers/v2/alarm_rules/loadbalancer.py @@ -0,0 +1,39 @@ +# Copyright 2019 Catalyst Cloud Ltd. +# +# 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. + +import wsme +from wsme import types as wtypes + +from aodh.api.controllers.v2 import base + + +class LoadBalancerMemberHealthRule(base.AlarmRule): + pool_id = wsme.wsattr(wtypes.text, mandatory=True) + "ID of a load balancer pool the members belongs to." + + stack_id = wsme.wsattr(wtypes.text, mandatory=True) + "ID of a Heat stack which contains the load balancer member." + + autoscaling_group_id = wsme.wsattr(wtypes.text, mandatory=True) + "ID of a Heat autoscaling group that contains the load balancer member." + + def as_dict(self): + rule = self.as_dict_from_keys( + ['pool_id', 'stack_id', 'autoscaling_group_id'] + ) + return rule + + @staticmethod + def create_hook(alarm): + pass diff --git a/aodh/tests/functional/api/v2/test_alarm_scenarios.py b/aodh/tests/functional/api/v2/test_alarm_scenarios.py index 1bbf6d54f..bddb238f6 100644 --- a/aodh/tests/functional/api/v2/test_alarm_scenarios.py +++ b/aodh/tests/functional/api/v2/test_alarm_scenarios.py @@ -2401,6 +2401,26 @@ class TestAlarmsRuleGnocchi(TestAlarmsBase): self._verify_alarm(json, alarms[0]) +class TestAlarmsRuleLoadBalancer(TestAlarmsBase): + def test_post(self): + json = { + 'name': 'added_alarm_defaults', + 'type': 'loadbalancer_member_health', + 'loadbalancer_member_health_rule': { + "pool_id": "2177ccd8-b09c-417a-89a0-e8d2419be612", + "stack_id": "1b974012-ebcb-4888-8ae2-47714d4d2c4d", + "autoscaling_group_id": "681c9266-61d2-4c9a-ad18-526807f6adc0" + } + } + self.post_json('/alarms', params=json, status=201, + headers=self.auth_headers) + + alarms = list(self.alarm_conn.get_alarms()) + + self.assertEqual(1, len(alarms)) + self._verify_alarm(json, alarms[0]) + + class TestAlarmsEvent(TestAlarmsBase): def test_list_alarms(self): diff --git a/setup.cfg b/setup.cfg index 528dc8dfc..62485c63d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -73,6 +73,7 @@ aodh.alarm.rule = gnocchi_aggregation_by_resources_threshold = aodh.api.controllers.v2.alarm_rules.gnocchi:AggregationMetricByResourcesLookupRule event = aodh.api.controllers.v2.alarm_rules.event:AlarmEventRule composite = aodh.api.controllers.v2.alarm_rules.composite:composite_rule + loadbalancer_member_health = aodh.api.controllers.v2.alarm_rules.loadbalancer:LoadBalancerMemberHealthRule aodh.evaluator = gnocchi_resources_threshold = aodh.evaluator.gnocchi:GnocchiResourceThresholdEvaluator