def create_aodh_alarm(resource_id=None, name=None, unic=True):
    if not name:
        name = '%s-%s' % ('test_', random.randrange(0, 100000, 1))
    elif unic:
        name = '%s-%s' % (name, random.randrange(0, 100000, 1))

    aodh_request = _aodh_request('event', resource_id=resource_id, name=name)
    TempestClients.aodh().alarm.create(aodh_request)
    time.sleep(20)
def create_aodh_metrics_threshold_alarm(resource_id=None, name=None):
    if not name:
        name = '%s-%s' % ('test_', random.randrange(0, 100000, 1))
    met = TempestClients.gnocchi().metric.create(resource_id=resource_id,
                                                 name='test',
                                                 archive_policy_name='high')
    metric = met[AodhProps.ID]
    rule_opts = dict(threshold='100',
                     aggregation_method='mean',
                     comparison_operator='lt',
                     metrics=[metric])
    rule = {AodhProps.METRICS_THRESHOLD_RULE: rule_opts}
    aodh_request = _aodh_request(AodhProps.METRICS_THRESHOLD,
                                 resource_id=resource_id,
                                 name=name,
                                 rule=rule)
    TempestClients.aodh().alarm.create(aodh_request)
    time.sleep(10)
    def test_validate_notifier(self):
        """validate_notifier test

        There tests validates work of aodh alarm notifier -
        all created vitrage alarms appears in ceilometer
        alarms-list.
        IMPORTANT: enable notifiers=aodh in vitrage.conf file
        """
        try:
            nova_utils.create_instances(num_instances=2,
                                        set_public_network=True)
            self._create_alarm(resource_id=self._get_hostname(),
                               alarm_name=RCA_ALARM_NAME)
            vitrage_alarms = TempestClients.vitrage().alarm.list(
                vitrage_id='all', all_tenants=True)
            aodh_alarms = TempestClients.aodh().alarm.list()

            self._validate_notifier(alarms=aodh_alarms,
                                    vitrage_alarms=vitrage_alarms)
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._clean_all()
def delete_all_aodh_alarms():
    alarms = TempestClients.aodh().alarm.list()
    for alarm in alarms:
        TempestClients.aodh().alarm.delete(alarm[AodhProps.ALARM_ID])
    time.sleep(10)
    def _check_num_alarms(self, num_alarms=0, state=''):
        if len(TempestClients.aodh().alarm.list()) != num_alarms:
            return False

        return all(alarm[AodhProps.STATE].upper() == state.upper()
                   for alarm in TempestClients.aodh().alarm.list())