diff --git a/aodh/api/controllers/v2/alarm_rules/gnocchi.py b/aodh/api/controllers/v2/alarm_rules/gnocchi.py index 9424ed51e..6576fc2bf 100644 --- a/aodh/api/controllers/v2/alarm_rules/gnocchi.py +++ b/aodh/api/controllers/v2/alarm_rules/gnocchi.py @@ -99,26 +99,6 @@ class MetricOfResourceRule(AlarmGnocchiThresholdRule): 'resource_type']) return rule - @classmethod - def validate_alarm(cls, alarm): - super(MetricOfResourceRule, - cls).validate_alarm(alarm) - - conf = pecan.request.cfg - gnocchi_client = client.Client( - '1', keystone_client.get_session(conf), - interface=conf.service_credentials.interface, - region_name=conf.service_credentials.region_name) - - rule = alarm.gnocchi_resources_threshold_rule - try: - gnocchi_client.resource.get(rule.resource_type, - rule.resource_id) - except exceptions.ClientException as e: - raise base.ClientSideError(e.message, status_code=e.code) - except Exception as e: - raise GnocchiUnavailable(e) - class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule): metric = wsme.wsattr(wtypes.text, mandatory=True) @@ -176,6 +156,11 @@ class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule): needed_overlap=0, resource_type=rule.resource_type) except exceptions.ClientException as e: + if e.code == 404: + # NOTE(sileht): We are fine here, we just want to ensure the + # 'query' payload is valid for Gnocchi If the metric + # doesn't exists yet, it doesn't matter + return raise base.ClientSideError(e.message, status_code=e.code) except Exception as e: raise GnocchiUnavailable(e) diff --git a/aodh/evaluator/gnocchi.py b/aodh/evaluator/gnocchi.py index 524b6627f..343cbfc9e 100644 --- a/aodh/evaluator/gnocchi.py +++ b/aodh/evaluator/gnocchi.py @@ -14,6 +14,7 @@ # under the License. from gnocchiclient import client +from gnocchiclient import exceptions from oslo_log import log from oslo_serialization import jsonutils @@ -61,9 +62,12 @@ class GnocchiResourceThresholdEvaluator(GnocchiBase): start=start, stop=end, resource_id=rule['resource_id'], aggregation=rule['aggregation_method']) + except exceptions.NotFound: + LOG.debug('metric %s or resource %s does not exists', + rule['metric'], rule['resource_id']) + return [] except Exception as e: - LOG.warning(_LW('alarm stats retrieval failed: %s'), - e) + LOG.warning(_LW('alarm stats retrieval failed: %s'), e) return [] @@ -83,6 +87,9 @@ class GnocchiAggregationMetricsThresholdEvaluator(GnocchiBase): start=start, stop=end, aggregation=rule['aggregation_method'], needed_overlap=0) + except exceptions.NotFound: + LOG.debug('metrics %s does not exists', rule['metrics']) + return [] except Exception as e: LOG.warning(_LW('alarm stats retrieval failed: %s'), e) return [] @@ -107,6 +114,9 @@ class GnocchiAggregationResourcesThresholdEvaluator(GnocchiBase): aggregation=rule['aggregation_method'], needed_overlap=0, ) + except exceptions.NotFound: + LOG.debug('metric %s does not exists', rule['metric']) + return [] except Exception as e: LOG.warning(_LW('alarm stats retrieval failed: %s'), e) return [] diff --git a/aodh/tests/functional/api/v2/test_alarm_scenarios.py b/aodh/tests/functional/api/v2/test_alarm_scenarios.py index c7b1cbff9..da4f8596b 100644 --- a/aodh/tests/functional/api/v2/test_alarm_scenarios.py +++ b/aodh/tests/functional/api/v2/test_alarm_scenarios.py @@ -2569,9 +2569,6 @@ class TestAlarmsRuleGnocchi(TestAlarmsBase): c.capabilities.list.return_value = { 'aggregation_methods': ['count']} self.post_json('/alarms', params=json, headers=self.auth_headers) - expected = mock.call.resource.get( - "instance", "209ef69c-c10c-4efb-90ff-46f4b2d90d2e") - self.assertIn(expected, c.mock_calls) alarms = list(self.alarm_conn.get_alarms(enabled=False)) self.assertEqual(1, len(alarms))