示例#1
0
 def get_matching_watches():
     if watch_name:
         yield watchrule.WatchRule.load(cnxt, watch_name)
     else:
         for wr in db_api.watch_rule_get_all(cnxt):
             if watchrule.rule_can_use_sample(wr, stats_data):
                 yield watchrule.WatchRule.load(cnxt, watch=wr)
示例#2
0
    def test_create_watch_data_match(self):
        rule = {
            u'EvaluationPeriods': u'1',
            u'AlarmDescription': u'test alarm',
            u'Period': u'300',
            u'ComparisonOperator': u'GreaterThanThreshold',
            u'Statistic': u'SampleCount',
            u'Threshold': u'2',
            u'Dimensions': [{
                u'Name': 'AutoScalingGroupName',
                u'Value': 'group_x'
            }],
            u'MetricName': u'CreateDataMetric'
        }
        self.wr = watchrule.WatchRule(context=self.ctx,
                                      watch_name='create_data_test',
                                      stack_id=self.stack_id,
                                      rule=rule)
        self.wr.store()

        data = {
            u'CreateDataMetric': {
                "Unit": "Counter",
                "Value": "1",
                "Dimensions": [{
                    u'AutoScalingGroupName': u'group_x'
                }]
            }
        }
        self.assertTrue(watchrule.rule_can_use_sample(self.wr, data))
示例#3
0
 def get_matching_watches():
     if watch_name:
         yield watchrule.WatchRule.load(cnxt, watch_name)
     else:
         for wr in db_api.watch_rule_get_all(cnxt):
             if watchrule.rule_can_use_sample(wr, stats_data):
                 yield watchrule.WatchRule.load(cnxt, watch=wr)
示例#4
0
    def test_create_watch_data_not_match_dimensions(self):
        rule = {u'EvaluationPeriods': u'1',
                u'AlarmDescription': u'test alarm',
                u'Period': u'300',
                u'ComparisonOperator': u'GreaterThanThreshold',
                u'Statistic': u'SampleCount',
                u'Threshold': u'2',
                u'Dimensions': [{u'Name': 'AutoScalingGroupName',
                                 u'Value': 'group_x'}],
                u'MetricName': u'CreateDataMetric'}
        self.wr = watchrule.WatchRule(context=self.ctx,
                                      watch_name='create_data_test',
                                      stack_id=self.stack_id, rule=rule)
        self.wr.store()

        data = {u'CreateDataMetric': {"Unit": "Counter",
                                      "Value": "1",
                                      "Dimensions": [
                                          {u'AutoScalingGroupName':
                                           u'not_this'}]},
                u'CreateDataMetric': {"Unit": "Counter",
                                      "Value": "1",
                                      "Dimensions": [
                                          {u'wrong_key':
                                           u'group_x'}]}}
        self.assertFalse(watchrule.rule_can_use_sample(self.wr, data))
示例#5
0
文件: test_watch.py 项目: jirwin/heat
    def test_create_watch_data_not_match_dimensions(self):
        rule = {
            u"EvaluationPeriods": u"1",
            u"AlarmDescription": u"test alarm",
            u"Period": u"300",
            u"ComparisonOperator": u"GreaterThanThreshold",
            u"Statistic": u"SampleCount",
            u"Threshold": u"2",
            u"Dimensions": [{u"Name": "AutoScalingGroupName", u"Value": "group_x"}],
            u"MetricName": u"CreateDataMetric",
        }
        self.wr = watchrule.WatchRule(
            context=self.ctx, watch_name="create_data_test", stack_id=self.stack_id, rule=rule
        )
        self.wr.store()

        data = {
            u"CreateDataMetric": {
                "Unit": "Counter",
                "Value": "1",
                "Dimensions": [{u"AutoScalingGroupName": u"not_this"}],
            },
            u"CreateDataMetric": {"Unit": "Counter", "Value": "1", "Dimensions": [{u"wrong_key": u"group_x"}]},
        }
        self.assertFalse(watchrule.rule_can_use_sample(self.wr, data))