Пример #1
0
    def _do_test_action_add_causal_relationship(self, trigger_name,
                                                deduced_props,
                                                trigger_alarm_props):
        try:
            # Do
            self._trigger_do_action(trigger_name)
            alarms = self.vitrage_client.alarm.list(
                vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
                all_tenants=True)
            self.assertTrue(len(alarms) >= 2, 'alarms %s' % alarms)

            deduced = g_utils.first_match(alarms, **deduced_props)
            trigger = g_utils.first_match(alarms, **trigger_alarm_props)

            # Get Rca for the deduced
            rca = self.vitrage_client.rca.get(deduced[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger], deduced_props)

            # Get Rca for the trigger
            rca = self.vitrage_client.rca.get(trigger[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger], trigger_alarm_props)
        finally:
            self._trigger_undo_action(trigger_name)
    def test_action_add_causal_relationship(self):
        try:
            # Do
            self._trigger_do_action(TRIGGER_ALARM_2)
            alarms = TempestClients.vitrage().alarm.list(
                vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
                all_tenants=True)
            self.assertTrue(len(alarms) >= 2, 'alarms %s' % str(alarms))

            deduced = g_utils.first_match(alarms, **DEDUCED_PROPS)
            trigger = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)

            # Get Rca for the deduced
            rca = TempestClients.vitrage().rca.get(deduced[VProps.VITRAGE_ID],
                                                   all_tenants=True)
            self._check_rca(rca, [deduced, trigger], DEDUCED_PROPS)

            # Get Rca for the trigger
            rca = TempestClients.vitrage().rca.get(trigger[VProps.VITRAGE_ID],
                                                   all_tenants=True)
            self._check_rca(rca, [deduced, trigger], TRIGGER_ALARM_2_PROPS)
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._trigger_undo_action(TRIGGER_ALARM_2)
Пример #3
0
    def _validate_deduce_alarms(self, alarms, instances):
        """Validate alarm existence """
        self.assertThat(alarms, IsNotEmpty(), 'The alarms list is empty')
        LOG.debug("The alarms list is : %s", alarms)

        # Find the vitrage_id of the deduced alarms using their original id.
        vitrage_resources = self.vitrage_client.resource.list(
            all_tenants=False)
        vitrage_instance_0_id = g_utils.first_match(vitrage_resources,
                                                    id=instances[0].id)

        vitrage_instance_1_id = g_utils.first_match(vitrage_resources,
                                                    id=instances[1].id)

        # Find the deduced alarms based on their properties
        deduce_alarms_1 = g_utils.all_matches(
            alarms,
            vitrage_type=VITRAGE_DATASOURCE,
            name=VITRAGE_ALARM_NAME,
            vitrage_resource_type=NOVA_INSTANCE_DATASOURCE,
            vitrage_resource_id=vitrage_instance_0_id[VProps.VITRAGE_ID])

        deduce_alarms_2 = g_utils.all_matches(
            alarms,
            vitrage_type=VITRAGE_DATASOURCE,
            name=VITRAGE_ALARM_NAME,
            vitrage_resource_type=NOVA_INSTANCE_DATASOURCE,
            vitrage_resource_id=vitrage_instance_1_id[VProps.VITRAGE_ID])

        self.assertThat(alarms, matchers.HasLength(3),
                        "Expected 3 alarms - 1 on host and 2 deduced")
        self.assertThat(deduce_alarms_1, matchers.HasLength(1),
                        "Deduced alarm not found")
        self.assertThat(deduce_alarms_2, matchers.HasLength(1),
                        "Deduced alarm not found")
def get_first_host(**kwargs):
    try:
        hosts = TempestClients.vitrage().resource.list(
            NOVA_HOST_DATASOURCE, all_tenants=True)
    except Exception as e:
        LOG.exception("get_first_host failed with %s", e)
        hosts = TempestClients.vitrage().resource.list(
            NOVA_HOST_DATASOURCE, all_tenants=True)
    return g_utils.first_match(hosts, **kwargs)
 def _check_rca(self, rca, expected_alarms, inspected):
     rca_nodes = [n for n in rca['nodes'] if not n.get('end_timestamp')]
     self.assertEqual(len(expected_alarms), len(rca_nodes))
     for expected_alarm in expected_alarms:
         self.assertIsNotNone(
             g_utils.first_match(rca_nodes, **expected_alarm),
             'expected_alarm is not in the rca %s' % expected_alarm)
     rca_inspected = rca['nodes'][rca['inspected_index']]
     self.assertTrue(
         g_utils.is_subset(inspected, rca_inspected),
         'Invalid inspected item \n%s\n%s' % (rca_inspected, inspected))
def get_first_template(**kwargs):
    templates = TempestClients.vitrage().template.list()
    return g_utils.first_match(templates, **kwargs)
def get_first_instance(**kwargs):
    instances = TempestClients.vitrage().resource.list(
        NOVA_INSTANCE_DATASOURCE, all_tenants=True)
    return g_utils.first_match(instances, **kwargs)
    def test_overlapping_action_add_causal_relationship(self):
        try:
            # ---- Do first & second ----
            self._trigger_do_action(TRIGGER_ALARM_1)
            self._trigger_do_action(TRIGGER_ALARM_2)
            alarms = self.vitrage_client.alarm.list(
                vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
                all_tenants=True)

            deduced = g_utils.first_match(alarms, **DEDUCED_PROPS)
            trigger1 = g_utils.first_match(alarms, **TRIGGER_ALARM_1_PROPS)
            trigger2 = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)

            # Get Rca for the deduced
            rca = self.vitrage_client.rca.get(deduced[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger1, trigger2], DEDUCED_PROPS)

            # Get Rca for trigger 1
            rca = self.vitrage_client.rca.get(trigger1[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger1], TRIGGER_ALARM_1_PROPS)

            # Get Rca for trigger 2
            rca = self.vitrage_client.rca.get(trigger2[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger2], TRIGGER_ALARM_2_PROPS)

            # ---- Undo - first ----
            self._trigger_undo_action(TRIGGER_ALARM_1)
            alarms = self.vitrage_client.alarm.list(
                vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
                all_tenants=True)

            deduced = g_utils.first_match(alarms, **DEDUCED_PROPS)
            trigger2 = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)

            # Get Rca for the deduced
            rca = self.vitrage_client.rca.get(deduced[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger2], DEDUCED_PROPS)

            # Get Rca for trigger 2
            rca = self.vitrage_client.rca.get(trigger2[VProps.VITRAGE_ID],
                                              all_tenants=True)
            self._check_rca(rca, [deduced, trigger2], TRIGGER_ALARM_2_PROPS)

            # ---- Undo - second ----
            self._trigger_undo_action(TRIGGER_ALARM_2)
            alarms = self.vitrage_client.alarm.list(
                vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
                all_tenants=True)
            self.assertThat(
                g_utils.all_matches(alarms, **TRIGGER_ALARM_1_PROPS),
                IsEmpty(),
                'trigger alarm 1 should have been removed')
            self.assertThat(
                g_utils.all_matches(alarms, **TRIGGER_ALARM_2_PROPS),
                IsEmpty(),
                'trigger alarm 2 should have been removed')
            self.assertThat(
                g_utils.all_matches(alarms, **DEDUCED_PROPS),
                IsEmpty(),
                'deduced alarm should have been removed')
        finally:
            self._trigger_undo_action(TRIGGER_ALARM_1)
            self._trigger_undo_action(TRIGGER_ALARM_2)
Пример #9
0
def get_shared_network():
    nets = TempestClients.neutron().list_networks()
    return g_utils.first_match(nets['networks'], name='shared')
Пример #10
0
def get_public_network():
    nets = TempestClients.neutron().list_networks()
    return g_utils.first_match(nets['networks'], name='public')
Пример #11
0
def get_first_host(**kwargs):
    hosts = TempestClients.vitrage().resource.list(
        NOVA_HOST_DATASOURCE, all_tenants=True)
    return g_utils.first_match(hosts, **kwargs)