Merge "Gnocchi: don't fail to create valid alarm"

This commit is contained in:
Jenkins 2017-03-13 23:17:39 +00:00 committed by Gerrit Code Review
commit 85f4fda458
3 changed files with 17 additions and 25 deletions

View File

@ -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)

View File

@ -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 []

View File

@ -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))