Beispiel #1
0
    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.assertEqual(True, 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)
Beispiel #2
0
    def _validate_deduce_alarms(self, alarms, instances):
        """Validate alarm existence """
        self.assertNotEqual(len(alarms), 0, 'The alarms list is empty')
        LOG.info("The alarms list is : " + str(json.dumps(alarms)))

        # Find the vitrage_id of the deduced alarms using their original id.
        vitrage_resources = TempestClients.vitrage().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.assertEqual(3, len(alarms), "Expected 3 alarms - 1 on host and "
                         "2 deduced")
        self.assertEqual(1, len(deduce_alarms_1), "Deduced alarm not found")
        self.assertEqual(1, len(deduce_alarms_2), "Deduced alarm not found")
Beispiel #3
0
 def _check_rca(self, rca, expected_alarms, inspected):
     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' % str(expected_alarm))
     rca_inspected = rca['nodes'][rca['inspected_index']]
     self.assertEqual(
         True, g_utils.is_subset(inspected, rca_inspected),
         'Invalid inspected item \n%s\n%s' %
         (str(rca_inspected), str(inspected)))
    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 = TempestClients.vitrage().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 = TempestClients.vitrage().rca.get(deduced[VProps.VITRAGE_ID],
                                                   all_tenants=True)
            self._check_rca(rca, [deduced, trigger1, trigger2], DEDUCED_PROPS)

            # Get Rca for trigger 1
            rca = TempestClients.vitrage().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 = TempestClients.vitrage().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 = TempestClients.vitrage().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 = TempestClients.vitrage().rca.get(deduced[VProps.VITRAGE_ID],
                                                   all_tenants=True)
            self._check_rca(rca, [deduced, trigger2], DEDUCED_PROPS)

            # Get Rca for trigger 2
            rca = TempestClients.vitrage().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 = TempestClients.vitrage().alarm.list(
                vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
                all_tenants=True)
            self.assertEqual(
                0, len(g_utils.all_matches(alarms, **TRIGGER_ALARM_1_PROPS)),
                'trigger alarm 1 should have been removed')
            self.assertEqual(
                0, len(g_utils.all_matches(alarms, **TRIGGER_ALARM_2_PROPS)),
                'trigger alarm 2 should have been removed')
            self.assertEqual(0,
                             len(g_utils.all_matches(alarms, **DEDUCED_PROPS)),
                             'deduced alarm should have been removed')

        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._trigger_undo_action(TRIGGER_ALARM_1)
            self._trigger_undo_action(TRIGGER_ALARM_2)
Beispiel #5
0
def get_first_instance(**kwargs):
    instances = TempestClients.vitrage().resource.list(
        NOVA_INSTANCE_DATASOURCE, all_tenants=True)
    return g_utils.first_match(instances, **kwargs)
Beispiel #6
0
def get_first_host(**kwargs):
    hosts = TempestClients.vitrage().resource.list(NOVA_HOST_DATASOURCE,
                                                   all_tenants=True)
    return g_utils.first_match(hosts, **kwargs)