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")
def _validate_set_state(self, topology, instances): self.assertNotEqual(len(topology), 0, 'The topology graph is empty') host = g_utils.all_matches( topology, vitrage_type=NOVA_HOST_DATASOURCE, id=self._get_hostname(), vitrage_state=OperationalResourceState.ERROR, vitrage_aggregated_state=OperationalResourceState.ERROR) vm1 = g_utils.all_matches( topology, vitrage_type=NOVA_INSTANCE_DATASOURCE, id=instances[0].id, vitrage_state=OperationalResourceState.SUBOPTIMAL, vitrage_aggregated_state=OperationalResourceState.SUBOPTIMAL) vm2 = g_utils.all_matches( topology, vitrage_type=NOVA_INSTANCE_DATASOURCE, id=instances[1].id, vitrage_state=OperationalResourceState.SUBOPTIMAL, vitrage_aggregated_state=OperationalResourceState.SUBOPTIMAL) self.assertEqual(1, len(host)) self.assertEqual(1, len(vm1)) self.assertEqual(1, len(vm2))
def _check_deduced(self, deduced_count, deduced_props, resource_id): alarms = TempestClients.vitrage().alarm.list(vitrage_id=resource_id, all_tenants=True) deduces = g_utils.all_matches(alarms, **deduced_props) self.assertEqual( deduced_count, len(deduces), 'Expected %s deduces\n - \n%s\n - \n%s' % (str(deduced_count), str(alarms), str(deduces)))
def _validate_rca(self, rca): self.assertNotEqual(len(rca), 0, 'The rca is empty') LOG.info("The rca alarms list is : " + str(json.dumps(rca))) resource_alarm = g_utils.all_matches(rca, vitrage_type=AODH_DATASOURCE, name=RCA_ALARM_NAME) deduce_alarms = g_utils.all_matches( rca, vitrage_type=VITRAGE_DATASOURCE, name=VITRAGE_ALARM_NAME, severity=OperationalAlarmSeverity.WARNING) self.assertEqual(3, len(rca)) self.assertEqual(1, len(resource_alarm)) self.assertEqual(2, len(deduce_alarms))
def delete_all_instances(**kwargs): instances = TempestClients.nova().servers.list() instances_to_delete = g_utils.all_matches(instances, **kwargs) for item in instances_to_delete: try: TempestClients.nova().servers.force_delete(item) except Exception: pass wait_for_status(30, _check_num_instances, num_instances=len(instances) - len(instances_to_delete)) time.sleep(2)
def _create_alarm(self, resource_id, alarm_name, unic=False): aodh_utils.create_aodh_alarm(resource_id=resource_id, name=alarm_name, unic=unic) list_alarms = self.vitrage_client.alarm.list(vitrage_id='all', all_tenants=True) expected_alarm = g_utils.all_matches(list_alarms, resource_id=resource_id, vitrage_type=AODH_DATASOURCE) if not expected_alarm: return None return expected_alarm[0]
def _compare_alarms_lists(self, api_alarms, cli_alarms, resource_type, resource_id): """Validate alarm existence """ self.assertNotEqual(len(api_alarms), 0, 'The alarms list taken from api is empty') self.assertIsNotNone(cli_alarms, 'The alarms list taken from cli is empty') LOG.info("The alarms list taken from cli is : " + str(cli_alarms)) LOG.info("The alarms list taken by api is : " + str(json.dumps(api_alarms))) cli_items = cli_alarms.splitlines() api_by_type = g_utils.all_matches(api_alarms, vitrage_type=resource_type) cli_by_type = cli_alarms.count(' ' + resource_type + ' ') api_by_id = g_utils.all_matches(api_alarms, resource_id=resource_id) cli_by_id = cli_alarms.count(resource_id) self.assertEqual(len(cli_items), len(api_alarms) + 4) self.assertEqual(cli_by_type, len(api_by_type)) self.assertEqual(cli_by_id, len(api_by_id))
def _validate_passed_templates_length(self, api_templates, cli_templates): api_passes_templates = g_utils.all_matches( api_templates, **{'status details': self.OK_MSG}) cli_passes_templates = cli_templates.count(' ' + self.OK_MSG + ' ') self.assertEqual(cli_passes_templates, len(api_passes_templates))
def _port_to_network_edges(self, networks, ports): counter = 0 for net in networks: counter += len(g_utils.all_matches(ports, network_id=net['id'])) return counter
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)