示例#1
0
    def setUp(self):
        super(TestRPCAlarmPartitionCoordination, self).setUp()
        self.CONF = self.useFixture(fixture_config.Config()).conf
        self.setup_messaging(self.CONF)

        self.coordinator_server = FakeCoordinator(self.transport)
        self.coordinator_server.rpc.start()
        eventlet.sleep()  # must be sure that fanout queue is created

        self.coordination = rpc_alarm.RPCAlarmPartitionCoordination()
        self.alarms = [
            alarms.Alarm(None,
                         info={
                             'name': 'instance_running_hot',
                             'meter_name': 'cpu_util',
                             'comparison_operator': 'gt',
                             'threshold': 80.0,
                             'evaluation_periods': 5,
                             'statistic': 'avg',
                             'state': 'ok',
                             'ok_actions': ['http://host:8080/path'],
                             'user_id': 'foobar',
                             'project_id': 'snafu',
                             'period': 60,
                             'alarm_id': str(uuid.uuid4()),
                             'matching_metadata': {
                                 'resource_id': 'my_instance'
                             }
                         }),
            alarms.Alarm(None,
                         info={
                             'name':
                             'group_running_idle',
                             'meter_name':
                             'cpu_util',
                             'comparison_operator':
                             'le',
                             'threshold':
                             10.0,
                             'statistic':
                             'max',
                             'evaluation_periods':
                             4,
                             'state':
                             'insufficient data',
                             'insufficient_data_actions':
                             ['http://other_host/path'],
                             'user_id':
                             'foobar',
                             'project_id':
                             'snafu',
                             'period':
                             300,
                             'alarm_id':
                             str(uuid.uuid4()),
                             'matching_metadata': {
                                 'metadata.user_metadata.AS': 'my_group'
                             }
                         }),
        ]
示例#2
0
    def setUp(self):
        super(TestRPCAlarmNotifier, self).setUp()
        messaging.setup('fake://')
        self.addCleanup(messaging.cleanup)

        self.notifier_server = FakeNotifier()
        self.notifier = rpc_alarm.RPCAlarmNotifier()
        self.alarms = [
            alarms.Alarm(None,
                         info={
                             'name': 'instance_running_hot',
                             'meter_name': 'cpu_util',
                             'comparison_operator': 'gt',
                             'threshold': 80.0,
                             'evaluation_periods': 5,
                             'statistic': 'avg',
                             'state': 'ok',
                             'ok_actions': ['http://host:8080/path'],
                             'user_id': 'foobar',
                             'project_id': 'snafu',
                             'period': 60,
                             'alarm_id': str(uuid.uuid4()),
                             'matching_metadata': {
                                 'resource_id': 'my_instance'
                             }
                         }),
            alarms.Alarm(None,
                         info={
                             'name':
                             'group_running_idle',
                             'meter_name':
                             'cpu_util',
                             'comparison_operator':
                             'le',
                             'threshold':
                             10.0,
                             'statistic':
                             'max',
                             'evaluation_periods':
                             4,
                             'state':
                             'insufficient data',
                             'insufficient_data_actions':
                             ['http://other_host/path'],
                             'user_id':
                             'foobar',
                             'project_id':
                             'snafu',
                             'period':
                             300,
                             'alarm_id':
                             str(uuid.uuid4()),
                             'matching_metadata': {
                                 'metadata.user_metadata.AS': 'my_group'
                             }
                         }),
        ]
示例#3
0
 def setUp(self):
     super(TestRPCAlarmNotifier, self).setUp()
     self.notified = []
     self.useFixture(
         mockpatch.PatchObject(rpc, 'cast', side_effect=self.fake_cast))
     self.notifier = rpc_alarm.RPCAlarmNotifier()
     self.alarms = [
         alarms.Alarm(None,
                      info={
                          'name': 'instance_running_hot',
                          'meter_name': 'cpu_util',
                          'comparison_operator': 'gt',
                          'threshold': 80.0,
                          'evaluation_periods': 5,
                          'statistic': 'avg',
                          'state': 'ok',
                          'ok_actions': ['http://host:8080/path'],
                          'user_id': 'foobar',
                          'project_id': 'snafu',
                          'period': 60,
                          'alarm_id': str(uuid.uuid4()),
                          'matching_metadata': {
                              'resource_id': 'my_instance'
                          }
                      }),
         alarms.Alarm(None,
                      info={
                          'name':
                          'group_running_idle',
                          'meter_name':
                          'cpu_util',
                          'comparison_operator':
                          'le',
                          'threshold':
                          10.0,
                          'statistic':
                          'max',
                          'evaluation_periods':
                          4,
                          'state':
                          'insufficient data',
                          'insufficient_data_actions':
                          ['http://other_host/path'],
                          'user_id':
                          'foobar',
                          'project_id':
                          'snafu',
                          'period':
                          300,
                          'alarm_id':
                          str(uuid.uuid4()),
                          'matching_metadata': {
                              'metadata.user_metadata.AS': 'my_group'
                          }
                      }),
     ]
示例#4
0
    def test_query(self):
        ret_alarm = [alarms.Alarm(mock.Mock(), alarm) for alarm in self.ALARM]
        self.cc.query_alarms.query.return_value = ret_alarm

        ceilometer_shell.do_query_alarms(self.cc, self.args)

        self.assertEqual(
            '''\
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+-------------------------------\
-+
| Alarm ID                             | Name             | State | Severity \
| Enabled | Continuous | Alarm condition                                     \
                                                 | Time constraints          \
     |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+--------------------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok    | critical \
| True    | False      | combinated states (OR) of \
739e99cb-c2ec-4718-b900-332502355f38, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 |\
 test at 0 23 * * *  for 10800s |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------------------\
--+
''', sys.stdout.getvalue())
示例#5
0
    def test_time_constraints_compatibility(self):
        # client should be backwards compatible
        alarm_without_tc = dict(self.ALARM[0])
        del alarm_without_tc['time_constraints']

        # NOTE(nsaje): Since we're accessing a nonexisting key in the resource,
        # the resource is looking it up with the manager (which is a mock).
        manager_mock = mock.Mock()
        del manager_mock.get
        ret_alarm = [alarms.Alarm(manager_mock, alarm_without_tc)]
        self.cc.query_alarms.query.return_value = ret_alarm

        ceilometer_shell.do_query_alarms(self.cc, self.args)

        self.assertEqual(
            '''\
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------+
| Alarm ID                             | Name             | State | Severity \
| Enabled | Continuous | Alarm condition                                     \
                                                 | Time constraints |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok    | critical \
| True    | False      | combinated states (OR) of \
739e99cb-c2ec-4718-b900-332502355f38, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 \
| None             |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------+
''', sys.stdout.getvalue())
示例#6
0
    def test_alarm_create_time_constraints(self):
        shell = base_shell.CeilometerShell()
        argv = [
            'alarm-threshold-create',
            '--name',
            'cpu_high',
            '--meter-name',
            'cpu_util',
            '--threshold',
            '70.0',
            '--time-constraint',
            'name=cons1;start="0 11 * * *";duration=300',
            '--time-constraint',
            'name=cons2;start="0 23 * * *";duration=600',
        ]
        _, args = shell.parse_args(argv)

        alarm = alarms.Alarm(mock.Mock(), self.ALARM)
        self.cc.alarms.create.return_value = alarm

        ceilometer_shell.do_alarm_threshold_create(self.cc, args)
        _, kwargs = self.cc.alarms.create.call_args
        time_constraints = [
            dict(name='cons1', start='0 11 * * *', duration='300'),
            dict(name='cons2', start='0 23 * * *', duration='600')
        ]
        self.assertEqual(time_constraints, kwargs['time_constraints'])
    def test_query(self):

        ret_alarm = [alarms.Alarm(mock.Mock(), alarm) for alarm in self.ALARM]
        self.cc.query_alarms.query.return_value = ret_alarm
        org_stdout = sys.stdout
        try:
            sys.stdout = output = six.StringIO()
            ceilometer_shell.do_query_alarms(self.cc, self.args)
        finally:
            sys.stdout = org_stdout

        self.assertEqual(
            '''\
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+
| Alarm ID                             | Name             | State | Enabled \
| Continuous | Alarm condition                                              \
                                        |
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok    | True    \
| False      | combinated states (OR) of 739e99cb-c2ec-4718-b900-332502355f3\
8, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 |
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+
''', output.getvalue())
示例#8
0
    def _test_alarm_threshold_action_args(self, action, argv):
        shell = base_shell.CeilometerShell()
        _, args = shell.parse_args(argv)

        alarm = alarms.Alarm(mock.Mock(), self.ALARM)
        getattr(self.cc.alarms, action).return_value = alarm

        func = getattr(ceilometer_shell, 'do_alarm_threshold_' + action)
        func(self.cc, args)
        _, kwargs = getattr(self.cc.alarms, action).call_args
        self._check_alarm_threshold_args(kwargs)
示例#9
0
    def _do_test_alarm_update_repeat_actions(self, method, repeat_actions):
        self.args.threshold = 42.0
        if repeat_actions is not None:
            self.args.repeat_actions = repeat_actions
        alarm = [alarms.Alarm(mock.Mock(), self.ALARM)]
        self.cc.alarms.get.return_value = alarm
        self.cc.alarms.update.return_value = alarm[0]

        method(self.cc, self.args)
        args, kwargs = self.cc.alarms.update.call_args
        self.assertEqual(self.ALARM_ID, args[0])
        self.assertEqual(42.0, kwargs.get('threshold'))
        if repeat_actions is not None:
            self.assertEqual(repeat_actions, kwargs.get('repeat_actions'))
        else:
            self.assertNotIn('repeat_actions', kwargs)
示例#10
0
 def test_notify_no_actions(self):
     alarm = alarms.Alarm(None, info={
         'name': 'instance_running_hot',
         'meter_name': 'cpu_util',
         'comparison_operator': 'gt',
         'threshold': 80.0,
         'evaluation_periods': 5,
         'statistic': 'avg',
         'state': 'ok',
         'user_id': 'foobar',
         'project_id': 'snafu',
         'period': 60,
         'ok_actions': [],
         'alarm_id': str(uuid.uuid4()),
         'matching_metadata': {'resource_id':
                               'my_instance'}
     })
     self.notifier.notify(alarm, 'alarm', "what?")
     self.assertEqual(len(self.notified), 0)
示例#11
0
    def test_alarm_threshold_create_args(self):
        shell = base_shell.CeilometerShell()
        argv = [
            'alarm-threshold-create', '--name', 'cpu_high', '--description',
            'instance running hot', '--meter-name', 'cpu_util', '--threshold',
            '70.0', '--comparison-operator', 'gt', '--statistic', 'avg',
            '--period', '600', '--evaluation-periods', '3', '--alarm-action',
            'log://', '--alarm-action', 'http://example.com/alarm/state',
            '--query', 'resource_id=INSTANCE_ID'
        ]
        _, args = shell.parse_args(argv)

        orig = sys.stdout
        sys.stdout = six.StringIO()
        alarm = alarms.Alarm(mock.Mock(), self.ALARM)
        self.cc.alarms.create.return_value = alarm

        try:
            ceilometer_shell.do_alarm_threshold_create(self.cc, args)
            _, kwargs = self.cc.alarms.create.call_args
            self.assertEqual('cpu_high', kwargs.get('name'))
            self.assertEqual('instance running hot', kwargs.get('description'))
            actions = ['log://', 'http://example.com/alarm/state']
            self.assertEqual(actions, kwargs.get('alarm_actions'))
            self.assertTrue('threshold_rule' in kwargs)
            rule = kwargs['threshold_rule']
            self.assertEqual('cpu_util', rule.get('meter_name'))
            self.assertEqual(70.0, rule.get('threshold'))
            self.assertEqual('gt', rule.get('comparison_operator'))
            self.assertEqual('avg', rule.get('statistic'))
            self.assertEqual(600, rule.get('period'))
            self.assertEqual(3, rule.get('evaluation_periods'))
            query = dict(field='resource_id',
                         type='',
                         value='INSTANCE_ID',
                         op='eq')
            self.assertEqual([query], rule['query'])
        finally:
            sys.stdout.close()
            sys.stdout = orig
示例#12
0
    def _do_test_alarm_update_repeat_actions(self, method, repeat_actions):
        self.args.threshold = 42.0
        if repeat_actions is not None:
            self.args.repeat_actions = repeat_actions
        orig = sys.stdout
        sys.stdout = six.StringIO()
        alarm = [alarms.Alarm(mock.Mock(), self.ALARM)]
        self.cc.alarms.get.return_value = alarm
        self.cc.alarms.update.return_value = alarm[0]

        try:
            method(self.cc, self.args)
            args, kwargs = self.cc.alarms.update.call_args
            self.assertEqual(self.ALARM_ID, args[0])
            self.assertEqual(42.0, kwargs.get('threshold'))
            if repeat_actions is not None:
                self.assertEqual(repeat_actions, kwargs.get('repeat_actions'))
            else:
                self.assertFalse('repeat_actions' in kwargs)
        finally:
            sys.stdout.close()
            sys.stdout = orig
示例#13
0
 def _get_alarm(state):
     return alarms.Alarm(None, {'state': state})
示例#14
0
def data(TEST):
    TEST.ceilometer_users = utils.TestDataContainer()
    TEST.ceilometer_tenants = utils.TestDataContainer()
    TEST.resources = utils.TestDataContainer()
    TEST.api_resources = utils.TestDataContainer()
    TEST.samples = utils.TestDataContainer()
    TEST.meters = utils.TestDataContainer()
    TEST.alarms = utils.TestDataContainer()
    TEST.statistics = utils.TestDataContainer()
    TEST.global_disk_usages = utils.TestDataContainer()
    TEST.global_network_usages = utils.TestDataContainer()
    TEST.global_network_traffic_usages = utils.TestDataContainer()
    TEST.global_object_store_usages = utils.TestDataContainer()
    TEST.statistics_array = utils.TestDataContainer()

    # users
    ceilometer_user_dict1 = {
        'id': "1",
        'name': 'user',
        'email': '*****@*****.**',
        'password': '******',
        'token': 'test_token',
        'project_id': '1',
        'enabled': True,
        'domain_id': "1"
    }
    ceilometer_user_dict2 = {
        'id': "2",
        'name': 'user2',
        'email': '*****@*****.**',
        'password': '******',
        'token': 'test_token',
        'project_id': '2',
        'enabled': True,
        'domain_id': "2"
    }
    TEST.ceilometer_users.add(users.User(None, ceilometer_user_dict1))
    TEST.ceilometer_users.add(users.User(None, ceilometer_user_dict2))

    # Tenants.
    tenant_dict = {
        'id': "1",
        'name': 'test_tenant',
        'description': "a test tenant.",
        'enabled': True,
        'domain_id': '1'
    }
    tenant_dict_2 = {
        'id': "2",
        'name': 'disabled_tenant',
        'description': "a disabled test tenant.",
        'enabled': False,
        'domain_id': '2'
    }
    tenant_dict_3 = {
        'id': "3",
        'name': u'\u4e91\u89c4\u5219',
        'description': "an unicode-named tenant.",
        'enabled': True,
        'domain_id': '2'
    }
    ceilometer_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict)
    ceilometer_disabled_tenant = tenants.Tenant(tenants.TenantManager,
                                                tenant_dict_2)
    ceilometer_tenant_unicode = tenants.Tenant(tenants.TenantManager,
                                               tenant_dict_3)

    TEST.ceilometer_tenants.add(ceilometer_tenant, ceilometer_disabled_tenant,
                                ceilometer_tenant_unicode)

    # resources
    resource_dict_1 = dict(
        resource_id='fake_resource_id',
        project_id='fake_project_id',
        user_id="fake_user_id",
        timestamp='2012-07-02T10:42:00.000000',
        metadata={
            'tag': 'self.counter3',
            'display_name': 'test-server'
        },
        links=[{
            'url': 'test_url',
            'rel': 'storage.objects'
        }],
    )
    resource_dict_2 = dict(
        resource_id='fake_resource_id2',
        project_id='fake_project_id',
        user_id="fake_user_id",
        timestamp='2012-07-02T10:42:00.000000',
        metadata={
            'tag': 'self.counter3',
            'display_name': 'test-server'
        },
        links=[{
            'url': 'test_url',
            'rel': 'storage.objects'
        }],
    )
    resource_dict_3 = dict(
        resource_id='fake_resource_id3',
        project_id='fake_project_id',
        user_id="fake_user_id",
        timestamp='2012-07-02T10:42:00.000000',
        metadata={
            'tag': 'self.counter3',
            'display_name': 'test-server'
        },
        links=[{
            'url': 'test_url',
            'rel': 'instance'
        }],
    )
    resource_dict_4 = dict(
        resource_id='fake_resource_id3',
        project_id='fake_project_id',
        user_id="fake_user_id",
        timestamp='2012-07-02T10:42:00.000000',
        metadata={
            'tag': 'self.counter3',
            'display_name': 'test-server'
        },
        links=[{
            'url': 'test_url',
            'rel': 'memory'
        }],
    )

    resource_1 = resources.Resource(resources.ResourceManager(None),
                                    resource_dict_1)
    resource_2 = resources.Resource(resources.ResourceManager(None),
                                    resource_dict_2)
    resource_3 = resources.Resource(resources.ResourceManager(None),
                                    resource_dict_3)
    resource_4 = resources.Resource(resources.ResourceManager(None),
                                    resource_dict_4)

    TEST.resources.add(resource_1)
    TEST.resources.add(resource_2)
    TEST.resources.add(resource_3)

    # Having a separate set of fake objects for openstack_dashboard
    # api Resource class. This is required because of additional methods
    # defined in openstack_dashboard.api.ceilometer.Resource

    api_resource_1 = ceilometer.Resource(resource_1)
    api_resource_2 = ceilometer.Resource(resource_2)
    api_resource_3 = ceilometer.Resource(resource_3)
    api_resource_4 = ceilometer.Resource(resource_4)

    TEST.api_resources.add(api_resource_1)
    TEST.api_resources.add(api_resource_2)
    TEST.api_resources.add(api_resource_3)
    TEST.api_resources.add(api_resource_4)

    # samples
    sample_dict_1 = {
        'resource_id': 'fake_resource_id',
        'project_id': 'fake_project_id',
        'user_id': 'fake_user_id',
        'counter_name': 'image',
        'counter_type': 'gauge',
        'counter_unit': 'image',
        'counter_volume': 1,
        'timestamp': '2012-12-21T11:00:55.000000',
        'metadata': {
            'name1': 'value1',
            'name2': 'value2'
        },
        'message_id': 'fake_message_id'
    }
    sample_dict_2 = {
        'resource_id': 'fake_resource_id2',
        'project_id': 'fake_project_id',
        'user_id': 'fake_user_id',
        'counter_name': 'image',
        'counter_type': 'gauge',
        'counter_unit': 'image',
        'counter_volume': 1,
        'timestamp': '2012-12-21T11:00:55.000000',
        'metadata': {
            'name1': 'value1',
            'name2': 'value2'
        },
        'message_id': 'fake_message_id'
    }
    sample_1 = samples.Sample(samples.SampleManager(None), sample_dict_1)
    sample_2 = samples.Sample(samples.SampleManager(None), sample_dict_2)
    TEST.samples.add(sample_1)
    TEST.samples.add(sample_2)

    # alarms
    alarm_dict_1 = {
        'alarm_actions': ['alarm_action1', 'alarm_action2'],
        'ok_actions': ['ok_action_1', 'ok_action_2'],
        'name': 'fake_alarm_name',
        'timestamp': '2015-08-07T05:32:20.970341',
        'description': 'fake_random_description',
        'time_constraints': [],
        'enabled': True,
        'state_timestamp': '2015-08-07T17:59:11.351033',
        'threshold_rule': {
            'meter_name': 'fake_meter_name',
            'evaluation_periods': 1,
            'period': 300,
            'statistic': 'avg',
            'threshold': 2.0,
            'query': [],
            'comparison_operator': 'ge',
            'exclude_outliers': False
        },
        'alarm_id': 'fake_alarm_id',
        'state': 'ok',
        'insufficient_data_actions': ['fake_action_1', 'fake_action_2'],
        'repeat_actions': True,
        'user_id': 'fake_user_id',
        'project_id': 'fake_project_id',
        'type': 'threshold',
        'severity': 'low'
    }
    alarm_dict_2 = {
        'alarm_actions': ['alarm_action1', 'alarm_action2'],
        'ok_actions': ['ok_action_1', 'ok_action_2'],
        'name': 'fake_alarm_name',
        'timestamp': '2015-08-07T05:32:20.970341',
        'description': 'New',
        'time_constraints': [],
        'enabled': True,
        'state_timestamp': '2015-08-07T17:59:11.351033',
        'threshold_rule': {
            'meter_name': 'fake_meter_name',
            'evaluation_periods': 1,
            'period': 300,
            'statistic': 'avg',
            'threshold': 2.0,
            'query': [],
            'comparison_operator': 'ge',
            'exclude_outliers': False
        },
        'alarm_id': 'fake_alarm_id2',
        'state': 'ok',
        'insufficient_data_actions': ['fake_action_1', 'fake_action_2'],
        'repeat_actions': True,
        'user_id': 'fake_user_id',
        'project_id': 'fake_project_id',
        'type': 'threshold',
        'severity': 'low'
    }
    alarm_dict_3 = {
        'alarm_actions': ['alarm_action1', 'alarm_action2'],
        'ok_actions': ['ok_action_1', 'ok_action_2'],
        'name': 'fake_alarm_name',
        'timestamp': '2015-08-07T05:32:20.970341',
        'description': 'fake_random_description',
        'time_constraints': [],
        'enabled': True,
        'state_timestamp': '2015-08-07T17:59:11.351033',
        'threshold_rule': {
            'meter_name': 'fake_meter_name',
            'evaluation_periods': 2,
            'period': 300,
            'statistic': 'avg',
            'threshold': 2.0,
            'query': [{
                'field': 'resource_id',
                'value': ''
            }],
            'comparison_operator': 'ge',
            'exclude_outliers': False
        },
        'alarm_id': 'fake_alarm_id3',
        'state': 'ok',
        'insufficient_data_actions': ['fake_action_1', 'fake_action_2'],
        'repeat_actions': True,
        'user_id': '',
        'project_id': '',
        'type': 'threshold',
        'severity': 'low'
    }
    alarm_dict_4 = {
        'alarm_actions': ['alarm_action1', 'alarm_action2'],
        'ok_actions': ['ok_action_1', 'ok_action_2'],
        'name': 'fake_alarm_name4',
        'timestamp': '2015-08-07T05:32:20.970341',
        'description': 'fake_random_description',
        'time_constraints': [],
        'enabled': True,
        'state_timestamp': '2015-08-07T17:59:11.351033',
        'threshold_rule': {
            'meter_name': '',
            'evaluation_periods': -10,
            'period': -1,
            'statistic': 'avg',
            'threshold': '',
            'query': [{
                'field': 'resource_id',
                'value': ''
            }],
            'comparison_operator': 'ge',
            'exclude_outliers': False
        },
        'alarm_id': 'fake_alarm_id4',
        'state': 'ok',
        'insufficient_data_actions': ['fake_action_1', 'fake_action_2'],
        'repeat_actions': True,
        'user_id': 'fake_user_id',
        'project_id': 'fake_project_id',
        'type': 'threshold',
        'severity': 'low'
    }

    alarm_1 = alarms.Alarm(alarms.AlarmManager(None), alarm_dict_1)
    alarm_2 = alarms.Alarm(alarms.AlarmManager(None), alarm_dict_2)
    alarm_3 = alarms.Alarm(alarms.AlarmManager(None), alarm_dict_3)
    alarm_4 = alarms.Alarm(alarms.AlarmManager(None), alarm_dict_4)
    TEST.alarms.add(alarm_1)
    TEST.alarms.add(alarm_2)
    TEST.alarms.add(alarm_3)
    TEST.alarms.add(alarm_4)

    # meters
    meter_dict_1 = {
        'name': 'instance',
        'type': 'gauge',
        'unit': 'instance',
        'resource_id': 'fake_resource_id',
        'project_id': 'fake_project_id',
        'user_id': 'fake_user_id'
    }
    meter_dict_2 = {
        'name': 'instance',
        'type': 'gauge',
        'unit': 'instance',
        'resource_id': 'fake_resource_id',
        'project_id': 'fake_project_id',
        'user_id': 'fake_user_id'
    }
    meter_dict_3 = {
        'name': 'disk.read.bytes',
        'type': 'gauge',
        'unit': 'instance',
        'resource_id': 'fake_resource_id',
        'project_id': 'fake_project_id',
        'user_id': 'fake_user_id'
    }
    meter_dict_4 = {
        'name': 'disk.write.bytes',
        'type': 'gauge',
        'unit': 'instance',
        'resource_id': 'fake_resource_id',
        'project_id': 'fake_project_id',
        'user_id': 'fake_user_id'
    }
    meter_1 = meters.Meter(meters.MeterManager(None), meter_dict_1)
    meter_2 = meters.Meter(meters.MeterManager(None), meter_dict_2)
    meter_3 = meters.Meter(meters.MeterManager(None), meter_dict_3)
    meter_4 = meters.Meter(meters.MeterManager(None), meter_dict_4)
    TEST.meters.add(meter_1)
    TEST.meters.add(meter_2)
    TEST.meters.add(meter_3)
    TEST.meters.add(meter_4)

    # statistic
    statistic_dict_1 = {
        'min': 1,
        'max': 9,
        'avg': 4.55,
        'sum': 45,
        'count': 10,
        'duration_start': '2012-12-21T11:00:55.000000',
        'duration_end': '2012-12-21T11:00:55.000000',
        'period': 7200,
        'period_start': '2012-12-21T11:00:55.000000',
        'period_end': '2012-12-21T11:00:55.000000'
    }
    statistic_1 = statistics.Statistics(statistics.StatisticsManager(None),
                                        statistic_dict_1)
    TEST.statistics.add(statistic_1)
示例#15
0
    def setUp(self):
        super(TestRPCAlarmNotifier, self).setUp()
        conf = service.prepare_service(argv=[], config_files=[])
        self.CONF = self.useFixture(fixture_config.Config(conf)).conf
        self.setup_messaging(self.CONF)

        self.notifier_server = FakeNotifier(self.CONF, self.transport)
        self.notifier = rpc.RPCAlarmNotifier(self.CONF)
        self.alarms = [
            alarms.Alarm(None,
                         info={
                             'name': 'instance_running_hot',
                             'meter_name': 'cpu_util',
                             'comparison_operator': 'gt',
                             'threshold': 80.0,
                             'evaluation_periods': 5,
                             'statistic': 'avg',
                             'state': 'ok',
                             'ok_actions': ['http://host:8080/path'],
                             'user_id': 'foobar',
                             'project_id': 'snafu',
                             'period': 60,
                             'alarm_id': str(uuid.uuid4()),
                             'severity': 'critical',
                             'matching_metadata': {
                                 'resource_id': 'my_instance'
                             }
                         }),
            alarms.Alarm(None,
                         info={
                             'name':
                             'group_running_idle',
                             'meter_name':
                             'cpu_util',
                             'comparison_operator':
                             'le',
                             'threshold':
                             10.0,
                             'statistic':
                             'max',
                             'evaluation_periods':
                             4,
                             'state':
                             'insufficient data',
                             'insufficient_data_actions':
                             ['http://other_host/path'],
                             'user_id':
                             'foobar',
                             'project_id':
                             'snafu',
                             'period':
                             300,
                             'alarm_id':
                             str(uuid.uuid4()),
                             'severity':
                             'critical',
                             'matching_metadata': {
                                 'metadata.user_metadata.AS': 'my_group'
                             }
                         }),
        ]