예제 #1
0
    def create_alarm(self):
        self.patchobject(aodh.AodhClientPlugin,
                         '_create').return_value = self.fc

        self.m.StubOutWithMock(self.fc.alarm, 'create')
        self.fc.alarm.create({
            'alarm_actions': [],
            'description': 'Do stuff with gnocchi aggregation by resource',
            'enabled': True,
            'insufficient_data_actions': [],
            'ok_actions': [],
            'name': mox.IgnoreArg(),
            'type': 'gnocchi_aggregation_by_resources_threshold',
            'repeat_actions': True,
            'gnocchi_aggregation_by_resources_threshold_rule': {
                "aggregation_method": "mean",
                "granularity": 60,
                "evaluation_periods": 1,
                "threshold": 50,
                "comparison_operator": "gt",
                "metric": "cpu_util",
                "resource_type": "instance",
                "query": '{"=": {"server_group": "my_autoscaling_group"}}',
            },
            'time_constraints': [],
            'severity': 'low'
        }).AndReturn(FakeAodhAlarm)
        self.tmpl = template_format.parse(
            gnocchi_aggregation_by_resources_alarm_template)
        self.stack = utils.parse_stack(self.tmpl)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return gnocchi.AodhGnocchiAggregationByResourcesAlarm(
            'GnoAggregationByResourcesAlarm',
            resource_defns['GnoAggregationByResourcesAlarm'], self.stack)
예제 #2
0
    def create_alarm(self):
        self.patchobject(aodh.AodhClientPlugin,
                         '_create').return_value = self.fc

        self.fc.alarm.create.return_value = FakeAodhAlarm
        self.tmpl = template_format.parse(
            gnocchi_aggregation_by_resources_alarm_template)
        self.stack = utils.parse_stack(self.tmpl)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return gnocchi.AodhGnocchiAggregationByResourcesAlarm(
            'GnoAggregationByResourcesAlarm',
            resource_defns['GnoAggregationByResourcesAlarm'], self.stack)
예제 #3
0
    def test_gnocchi_alarm_aggr_by_resources_live_state(self):
        snippet = template_format.parse(
            gnocchi_aggregation_by_resources_alarm_template)
        self.stack = utils.parse_stack(snippet)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        self.rsrc_defn = resource_defns['GnoAggregationByResourcesAlarm']
        self.client = mock.Mock()
        self.patchobject(gnocchi.AodhGnocchiAggregationByResourcesAlarm,
                         'client',
                         return_value=self.client)

        alarm_res = gnocchi.AodhGnocchiAggregationByResourcesAlarm(
            'alarm', self.rsrc_defn, self.stack)
        alarm_res.create()
        value = {
            'description': 'Do stuff with gnocchi aggregation by resource',
            'alarm_actions': [],
            'time_constraints': [],
            'gnocchi_aggregation_by_resources_threshold_rule': {
                'metric': 'cpu_util',
                'resource_type': 'instance',
                'query': "{'=': {'server_group': 'my_autoscaling_group'}}",
                'evaluation_periods': 1,
                'aggregation_method': 'mean',
                'granularity': 60,
                'threshold': 50,
                'comparison_operator': 'gt'
            }
        }
        self.client.alarm.get.return_value = value
        expected_data = {
            'description': 'Do stuff with gnocchi aggregation by resource',
            'alarm_actions': [],
            'metric': 'cpu_util',
            'resource_type': 'instance',
            'query': "{'=': {'server_group': 'my_autoscaling_group'}}",
            'evaluation_periods': 1,
            'aggregation_method': 'mean',
            'granularity': 60,
            'threshold': 50,
            'comparison_operator': 'gt',
            'insufficient_data_actions': None,
            'enabled': None,
            'ok_actions': None,
            'repeat_actions': None,
            'severity': None
        }
        reality = alarm_res.get_live_state(alarm_res.properties)
        self.assertEqual(expected_data, reality)