From fd4159b38f9768b739f4222b6c7c802e09339856 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 7 Sep 2017 13:45:44 +0000 Subject: [PATCH] Moving vitrage_id logic to transformer every event will receive real vitrage_id in the transformer instead of getting temporary vitrage_id in the transformer and then replaceing it in the processor Change-Id: I965bbe86be418df321b870a81bbf0ddab410a37e Closes-bug: #1707609 --- vitrage/api_handler/apis/rca.py | 8 +- vitrage/api_handler/apis/topology.py | 50 +++--- vitrage/cli/graph.py | 8 +- vitrage/datasources/aodh/transformer.py | 5 +- vitrage/datasources/nagios/transformer.py | 1 - vitrage/datasources/transformer_base.py | 52 ++++++- vitrage/entity_graph/processor/processor.py | 145 +----------------- .../entity_graph/processor/processor_utils.py | 10 -- .../actions/evaluator_event_transformer.py | 4 +- .../graph/algo_driver/networkx_algorithm.py | 5 +- vitrage/graph/driver/graph.py | 5 +- vitrage/graph/driver/networkx_graph.py | 29 +--- .../tests/functional/api_handler/test_apis.py | 2 +- vitrage/tests/functional/base.py | 5 +- .../functional/datasources/aodh/test_aodh.py | 2 +- .../datasources/cinder/test_cinder_volume.py | 2 +- .../datasources/collectd/test_collectd.py | 18 ++- .../datasources/heat/test_heat_stack.py | 2 +- .../datasources/nagios/test_nagios.py | 2 +- .../datasources/nova/test_nova_datasources.py | 2 +- .../static_physical/test_static_physical.py | 2 +- .../consistency/test_consistency.py | 8 +- .../entity_graph/processor/test_processor.py | 2 +- .../states/test_datasource_info_mapper.py | 3 +- .../evaluator/test_action_executor.py | 10 +- .../evaluator/test_scenario_evaluator.py | 59 ++++--- .../driver_zabbix_snapshot_dynamic.json | 3 +- .../datasources/aodh/test_aodh_transformer.py | 8 +- .../cinder/test_cinder_volume_transformer.py | 13 +- .../collectd/test_collectd_transformer.py | 16 +- .../doctor/test_doctor_transformer.py | 17 +- .../heat/test_heat_stack_transformer.py | 12 +- .../nagios/test_nagios_transformer.py | 36 +++-- .../nova/test_nova_host_transformer.py | 20 +-- .../nova/test_nova_instance_transformer.py | 27 ++-- .../nova/test_nova_zone_transformer.py | 13 +- .../static/test_static_transformer.py | 5 +- .../test_static_physical_transformer.py | 13 +- .../zabbix/test_zabbix_transformer.py | 17 +- vitrage/tests/unit/entity_graph/base.py | 8 +- .../entity_graph/processor/test_processor.py | 2 +- vitrage/tests/unit/graph/base.py | 5 +- vitrage/tests/unit/graph/test_graph_algo.py | 36 +++-- .../tests/api/topology/test_topology.py | 12 +- vitrage_tempest_tests/tests/base_mock.py | 2 +- 45 files changed, 329 insertions(+), 377 deletions(-) diff --git a/vitrage/api_handler/apis/rca.py b/vitrage/api_handler/apis/rca.py index 58f6fa38e..9dd3223ec 100644 --- a/vitrage/api_handler/apis/rca.py +++ b/vitrage/api_handler/apis/rca.py @@ -41,12 +41,12 @@ class RcaApis(EntityGraphApisBase): is_admin_project = ctx.get(self.IS_ADMIN_PROJECT_PROPERTY, False) ga = self.entity_graph.algo - found_graph_out = ga.graph_query_vertices(query_dict=RCA_QUERY, - root_id=root, + found_graph_out = ga.graph_query_vertices(root, + query_dict=RCA_QUERY, direction=Direction.OUT, edge_query_dict=EDGE_QUERY) - found_graph_in = ga.graph_query_vertices(query_dict=RCA_QUERY, - root_id=root, + found_graph_in = ga.graph_query_vertices(root, + query_dict=RCA_QUERY, direction=Direction.IN, edge_query_dict=EDGE_QUERY) diff --git a/vitrage/api_handler/apis/topology.py b/vitrage/api_handler/apis/topology.py index f8fe2e8bb..e723ee1ce 100644 --- a/vitrage/api_handler/apis/topology.py +++ b/vitrage/api_handler/apis/topology.py @@ -22,10 +22,9 @@ from vitrage.api_handler.apis.base import TOPOLOGY_AND_ALARMS_QUERY from vitrage.common.constants import EdgeProperties as EProps from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps +from vitrage.common.exception import VitrageError from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE -from vitrage.datasources.transformer_base\ - import create_cluster_placeholder_vertex -from vitrage.entity_graph.processor import processor_utils +from vitrage.datasources import OPENSTACK_CLUSTER LOG = log.getLogger(__name__) @@ -49,6 +48,14 @@ class TopologyApis(EntityGraphApisBase): LOG.debug('project_id = %s, is_admin_project %s', project_id, is_admin_project) + root_id = root + if not root: + root_vertex = self._get_root_vertex() + if not root_vertex: + LOG.warning("There is no openstack.cluster in the graph") + return + root_id = root_vertex.vertex_id + if graph_type == 'tree' or \ ((root is not None) and (depth is not None)): if not query: @@ -62,8 +69,8 @@ class TopologyApis(EntityGraphApisBase): {'==': {VProps.PROJECT_ID: None}}]} current_query = {'and': [query, project_query]} - graph = ga.graph_query_vertices(query_dict=current_query, - root_id=root, + graph = ga.graph_query_vertices(root_id, + query_dict=current_query, depth=depth, edge_query_dict=EDGE_QUERY) # By default the graph_type is 'graph' @@ -79,7 +86,7 @@ class TopologyApis(EntityGraphApisBase): query, project_id, is_admin_project, - root) + root_id) alarms = graph.get_vertices(query_dict=ALARMS_ALL_QUERY) graph.update_vertices(alarms) @@ -196,18 +203,8 @@ class TopologyApis(EntityGraphApisBase): entities = [] - if root: - root_vertex = \ - self.entity_graph.get_vertex(root) - else: - key_values_hash = processor_utils.get_defining_properties( - create_cluster_placeholder_vertex()) - tmp_vertices = self.entity_graph.get_vertices_by_key( - key_values_hash) - if not tmp_vertices: - LOG.debug("No root vertex found") - return set(entities) - root_vertex = tmp_vertices[0] + root_vertex = \ + self.entity_graph.get_vertex(root) local_connected_component_subgraphs = \ ga.connected_component_subgraphs(subgraph) @@ -224,10 +221,23 @@ class TopologyApis(EntityGraphApisBase): return set(entities) + def _get_root_vertex(self): + tmp_vertices = self.entity_graph.get_vertices( + vertex_attr_filter={VProps.VITRAGE_TYPE: OPENSTACK_CLUSTER}) + if not tmp_vertices: + LOG.debug("No root vertex found") + return None + if len(tmp_vertices) > 1: + raise VitrageError("Multiple root vertices found") + root_vertex = tmp_vertices[0] + return root_vertex + @staticmethod def _find_instance_in_graph(graph): for node, node_data in graph.nodes_iter(data=True): - if node_data[VProps.VITRAGE_CATEGORY] == EntityCategory.RESOURCE and \ - node_data[VProps.VITRAGE_TYPE] == NOVA_INSTANCE_DATASOURCE: + if node_data[VProps.VITRAGE_CATEGORY] == \ + EntityCategory.RESOURCE \ + and node_data[VProps.VITRAGE_TYPE] == \ + NOVA_INSTANCE_DATASOURCE: return node return None diff --git a/vitrage/cli/graph.py b/vitrage/cli/graph.py index 7e35c7448..ccf912246 100644 --- a/vitrage/cli/graph.py +++ b/vitrage/cli/graph.py @@ -20,9 +20,6 @@ from oslo_service import service as os_service from vitrage.api_handler.service import VitrageApiHandlerService from vitrage.cli import VITRAGE_TITLE -from vitrage.common.constants import EntityCategory -from vitrage.datasources import OPENSTACK_CLUSTER -from vitrage.datasources.transformer_base import CLUSTER_ID from vitrage import entity_graph from vitrage.entity_graph.consistency.service import VitrageConsistencyService from vitrage.entity_graph.service import VitrageGraphService @@ -59,10 +56,7 @@ def main(): def init(conf): evaluator_q = queue.Queue() - e_graph = entity_graph.get_graph_driver(conf)( - 'Entity Graph', - '%s:%s:%s' % (EntityCategory.RESOURCE, OPENSTACK_CLUSTER, CLUSTER_ID), - uuid=True) + e_graph = entity_graph.get_graph_driver(conf)('Entity Graph') # TODO(ihefetz) uncomment db connection creation # db_connection = storage.get_connection_from_config(conf) diff --git a/vitrage/datasources/aodh/transformer.py b/vitrage/datasources/aodh/transformer.py index 81b8d431d..777e8ff65 100644 --- a/vitrage/datasources/aodh/transformer.py +++ b/vitrage/datasources/aodh/transformer.py @@ -24,6 +24,7 @@ from vitrage.datasources.aodh.properties import AodhProperties as AodhProps from vitrage.datasources.aodh.properties import AodhState from vitrage.datasources import transformer_base as tbase from vitrage.datasources.transformer_base import Neighbor +from vitrage.datasources.transformer_base import TransformerBase from vitrage.evaluator.actions.evaluator_event_transformer \ import VITRAGE_DATASOURCE import vitrage.graph.utils as graph_utils @@ -62,6 +63,7 @@ class AodhTransformer(AlarmTransformerBase): 'alarm_type': entity_event[AodhProps.TYPE] } + # TODO(annarez): convert EVENT_TYPE to tuple if entity_event[AodhProps.TYPE] == AodhProps.EVENT: metadata[AodhProps.EVENT_TYPE] = entity_event[AodhProps.EVENT_TYPE] @@ -95,7 +97,8 @@ class AodhTransformer(AlarmTransformerBase): result = [] for vertex in graph_neighbors: edge = graph_utils.create_edge( - source_id=self._create_entity_key(entity_event), + source_id=TransformerBase.uuid_from_deprecated_vitrage_id( + self._create_entity_key(entity_event)), target_id=vertex.vertex_id, relationship_type=EdgeLabel.ON) result.append(Neighbor(vertex, edge)) diff --git a/vitrage/datasources/nagios/transformer.py b/vitrage/datasources/nagios/transformer.py index 73e54a1a5..3f4025a05 100644 --- a/vitrage/datasources/nagios/transformer.py +++ b/vitrage/datasources/nagios/transformer.py @@ -85,7 +85,6 @@ class NagiosTransformer(AlarmTransformerBase): return entity_event[NagiosProperties.STATUS] == NagiosTestStatus.OK def _create_entity_key(self, entity_event): - entity_type = entity_event[DSProps.ENTITY_TYPE] alarm_name = entity_event[NagiosProperties.SERVICE] resource_name = entity_event[NagiosProperties.RESOURCE_NAME] diff --git a/vitrage/datasources/transformer_base.py b/vitrage/datasources/transformer_base.py index 26fa5ea55..ab16006fa 100644 --- a/vitrage/datasources/transformer_base.py +++ b/vitrage/datasources/transformer_base.py @@ -18,6 +18,7 @@ from collections import namedtuple import six from oslo_log import log as logging +from oslo_utils import uuidutils import vitrage.common.constants as cons from vitrage.common.constants import DatasourceAction @@ -105,6 +106,8 @@ class TransformerBase(object): # graph actions which need to refer them differently GRAPH_ACTION_MAPPING = {} + key_to_uuid_cache = {} + def __init__(self, transformers, conf): self.conf = conf self.transformers = transformers @@ -128,6 +131,9 @@ class TransformerBase(object): neighbors = self._create_neighbors(entity_event) action = self._extract_graph_action(entity_event) + if action == GraphAction.DELETE_ENTITY: + self._delete_id_from_cache(entity_vertex.vertex_id) + return EntityWrapper(entity_vertex, neighbors, action) else: return EntityWrapper(self._create_end_vertex(entity_event), @@ -142,16 +148,48 @@ class TransformerBase(object): update_method = \ self.conf[self.get_vitrage_type()].update_method.lower() if update_method == UpdateMethod.PUSH: - return self._create_update_entity_vertex(entity_event) + vertex = self._create_update_entity_vertex(entity_event) + return self.update_uuid_in_vertex(vertex) elif update_method == UpdateMethod.PULL: - return self._create_snapshot_entity_vertex(entity_event) + vertex = self._create_snapshot_entity_vertex(entity_event) + return self.update_uuid_in_vertex(vertex) elif update_method == UpdateMethod.NONE: return None else: LOG.error('Update event arrived for dataresource that is ' 'defined without updates') else: - return self._create_snapshot_entity_vertex(entity_event) + vertex = self._create_snapshot_entity_vertex(entity_event) + return self.update_uuid_in_vertex(vertex) + + def update_uuid_in_vertex(self, vertex): + if not vertex: + return + # TODO(annarez): remove IS_REAL_VITRAGE_ID prop + if vertex.get(VProps.IS_REAL_VITRAGE_ID): + return vertex + new_uuid = self.uuid_from_deprecated_vitrage_id(vertex.vertex_id) + vertex.vertex_id = new_uuid + vertex.properties[VProps.VITRAGE_ID] = new_uuid + vertex.properties[VProps.IS_REAL_VITRAGE_ID] = True + return vertex + + @classmethod + def uuid_from_deprecated_vitrage_id(cls, vitrage_id): + old_vitrage_id = hash(vitrage_id) + new_uuid = cls.key_to_uuid_cache.get(old_vitrage_id) + if not new_uuid: + new_uuid = uuidutils.generate_uuid() + cls.key_to_uuid_cache[old_vitrage_id] = new_uuid + + return new_uuid + + @classmethod + def _delete_id_from_cache(cls, vitrage_id): + for key, value in cls.key_to_uuid_cache.items(): + if value == vitrage_id: + del cls.key_to_uuid_cache[key] + break @abc.abstractmethod def _create_snapshot_entity_vertex(self, entity_event): @@ -206,7 +244,9 @@ class TransformerBase(object): metadata=None): metadata = {} if metadata is None else metadata # create placeholder vertex - entity_vitrage_id = self._create_entity_key(entity_event) + entity_vitrage_id = \ + self.uuid_from_deprecated_vitrage_id( + self._create_entity_key(entity_event)) vitrage_sample_timestamp = entity_event[DSProps.SAMPLE_DATE] properties = { VProps.ID: neighbor_id, @@ -217,7 +257,6 @@ class TransformerBase(object): } neighbor_vertex = \ self.create_neighbor_placeholder_vertex(**properties) - # connect placeholder vertex to entity vertex edge_direction = self._get_edge_direction(entity_vitrage_id, neighbor_vertex.vertex_id, @@ -261,7 +300,7 @@ class TransformerBase(object): key_fields = self._key_values(kwargs[VProps.VITRAGE_TYPE], kwargs[VProps.ID]) - return graph_utils.create_vertex( + vertex = graph_utils.create_vertex( build_key(key_fields), vitrage_category=kwargs[VProps.VITRAGE_CATEGORY], vitrage_type=kwargs[VProps.VITRAGE_TYPE], @@ -270,6 +309,7 @@ class TransformerBase(object): True), entity_id=kwargs[VProps.ID], metadata=metadata) + return self.update_uuid_in_vertex(vertex) def _extract_graph_action(self, entity_event): """Extract graph action. diff --git a/vitrage/entity_graph/processor/processor.py b/vitrage/entity_graph/processor/processor.py index fd31eeb6e..036376d49 100644 --- a/vitrage/entity_graph/processor/processor.py +++ b/vitrage/entity_graph/processor/processor.py @@ -15,13 +15,9 @@ from oslo_log import log -from oslo_utils import uuidutils - from vitrage.common.constants import EntityCategory from vitrage.common.constants import GraphAction from vitrage.common.constants import VertexProperties as VProps -from vitrage.common.exception import VitrageError -from vitrage.datasources import OPENSTACK_CLUSTER from vitrage.datasources.transformer_base import TransformerBase from vitrage.entity_graph.mappings.datasource_info_mapper import \ DatasourceInfoMapper @@ -77,10 +73,7 @@ class Processor(processor.ProcessorBase): """ LOG.debug('Add entity to entity graph:\n%s', new_vertex) - # TODO(doffek): check if it's possible to move the - # _find_and_fix_graph_vertex method call to the process_event method - # so it will be done in one central place - self._find_and_fix_graph_vertex(new_vertex, neighbors) + self._add_resource_details_to_alarm(new_vertex, neighbors) self.entity_graph.add_vertex(new_vertex) self._connect_neighbors(neighbors, set(), GraphAction.CREATE_ENTITY) @@ -100,8 +93,6 @@ class Processor(processor.ProcessorBase): LOG.debug('Update entity in entity graph:\n%s', updated_vertex) - if not updated_vertex.get(VProps.IS_REAL_VITRAGE_ID, False): - self._find_and_fix_graph_vertex(updated_vertex, neighbors) graph_vertex = self.entity_graph.get_vertex(updated_vertex.vertex_id) if (not graph_vertex) or \ @@ -128,8 +119,7 @@ class Processor(processor.ProcessorBase): """ LOG.debug('Delete entity from entity graph:\n%s', deleted_vertex) - if not deleted_vertex.get(VProps.IS_REAL_VITRAGE_ID, False): - self._find_and_fix_graph_vertex(deleted_vertex, neighbors) + graph_vertex = self.entity_graph.get_vertex(deleted_vertex.vertex_id) if graph_vertex and (not PUtils.is_deleted(graph_vertex)) and \ @@ -154,39 +144,17 @@ class Processor(processor.ProcessorBase): def update_relationship(self, entity_vertex, neighbors): LOG.debug('Update relationship in entity graph:\n%s', neighbors) - if not entity_vertex: - for neighbor in neighbors: - self.entity_graph.update_edge(neighbor.edge) - return - - # TODO(doffek): check if we need here the update_vertex because the - # purpose of this method is to update the relationship - self._find_and_fix_graph_vertex(entity_vertex, []) - self.entity_graph.update_vertex(entity_vertex) + if entity_vertex: + self.entity_graph.update_vertex(entity_vertex) for neighbor in neighbors: - self._find_and_fix_relationship(entity_vertex, neighbor) self.entity_graph.update_edge(neighbor.edge) def delete_relationship(self, updated_vertex, neighbors): LOG.debug('Delete relationship from entity graph:\n%s', neighbors) - if not updated_vertex: - for neighbor in neighbors: - graph_edge = self.entity_graph.get_edge( - neighbor.edge.source_id, - neighbor.edge.target_id, - neighbor.edge.label) - if graph_edge: - PUtils.mark_deleted(self.entity_graph, graph_edge) - - return - - # TODO(doffek): check if we need here the update_vertex because the - # purpose of this method is to update the relationship - self._find_and_fix_graph_vertex(updated_vertex, []) - self.entity_graph.update_vertex(updated_vertex) + if updated_vertex: + self.entity_graph.update_vertex(updated_vertex) for neighbor in neighbors: - self._find_and_fix_relationship(updated_vertex, neighbor) graph_edge = self.entity_graph.get_edge(neighbor.edge.source_id, neighbor.edge.target_id, neighbor.edge.label) @@ -337,12 +305,8 @@ class Processor(processor.ProcessorBase): if action in [GraphAction.UPDATE_ENTITY, GraphAction.DELETE_ENTITY, GraphAction.CREATE_ENTITY]: - if vertex.get(VProps.IS_REAL_VITRAGE_ID, False): - graph_vertex = self.entity_graph.get_vertex( - vertex.vertex_id) - else: - graph_vertex = self._get_single_graph_vertex_by_props( - vertex) + graph_vertex = self.entity_graph.get_vertex( + vertex.vertex_id) elif action in [GraphAction.END_MESSAGE, GraphAction.REMOVE_DELETED_ENTITY, GraphAction.UPDATE_RELATIONSHIP, @@ -364,65 +328,6 @@ class Processor(processor.ProcessorBase): result = self.entity_graph.get_vertices(attr) event[TransformerBase.QUERY_RESULT] = result - def _find_and_fix_relationship(self, vertex, neighbor): - prev_neighbor_id = neighbor.vertex[VProps.VITRAGE_ID] - self._find_and_fix_graph_vertex(neighbor.vertex, []) - if neighbor.edge.source_id == prev_neighbor_id: - neighbor.edge.source_id = neighbor.vertex.vertex_id - neighbor.edge.target_id = vertex.vertex_id - else: - neighbor.edge.target_id = neighbor.vertex.vertex_id - neighbor.edge.source_id = vertex.vertex_id - - def _find_and_fix_graph_vertex(self, - vertex, - neighbors=None, - include_deleted=False): - """Search for vertex in graph, and update vertex id and vitrage ID - - Search for vertex in graph, and update vertex id and vitrage ID - Both in the Vertex itself, and in it's neighbors and edges - - :param new_vertex: The vertex to update - :type new_vertex: Vertex - - :param neighbors: The neighbors of the vertex - :type neighbors: list - - :param include_deleted: If True, Include deleted entities in the search - :type include_deleted: bool - """ - - previous_vitrage_id = vertex[VProps.VITRAGE_ID] - - graph_vertex = self._get_single_graph_vertex_by_props( - vertex, include_deleted) - - if not graph_vertex or (PUtils.is_deleted(graph_vertex) - and not include_deleted): - - vitrage_id = uuidutils.generate_uuid() - if vertex[VProps.VITRAGE_TYPE] == OPENSTACK_CLUSTER: - self.entity_graph.root_id = vitrage_id - else: - vitrage_id = graph_vertex[VProps.VITRAGE_ID] - - vertex[VProps.VITRAGE_ID] = vitrage_id - vertex.vertex_id = vitrage_id - - if not neighbors: - return - - for neighbor_vertex, edge in neighbors: - if not neighbor_vertex.get(VProps.IS_REAL_VITRAGE_ID, False): - self._find_and_fix_graph_vertex(neighbor_vertex) - if edge.target_id == previous_vitrage_id: - edge.target_id = vitrage_id - edge.source_id = neighbor_vertex.vertex_id - else: - edge.source_id = vitrage_id - edge.target_id = neighbor_vertex.vertex_id - @staticmethod def _add_resource_details_to_alarm(vertex, neighbors): @@ -442,37 +347,3 @@ class Processor(processor.ProcessorBase): neighbor.vertex.vertex_id vertex.properties[VProps.VITRAGE_RESOURCE_TYPE] = \ neighbor.vertex.get(VProps.VITRAGE_TYPE) - - def _get_single_graph_vertex_by_props(self, vertex, include_deleted=False): - """Returns a single vertex by it's defining properties - - Queries the graph DB for vertices according to the - vertice's "key" properties - In case multiple vertices return from the query, - an exception is issued - - :param updated_vertex: The vertex with the defining properties - :type vertex: Vertex - - :param include_deleted: Include deleted entities in the query - :type include_deleted: bool - """ - - received_graph_vertices = self.entity_graph.get_vertices_by_key( - PUtils.get_defining_properties(vertex)) - graph_vertices = [] - if include_deleted: - for tmp_vertex in received_graph_vertices: - graph_vertices.append(tmp_vertex) - else: - for tmp_vertex in received_graph_vertices: - if not tmp_vertex.get(VProps.VITRAGE_IS_DELETED, False): - graph_vertices.append(tmp_vertex) - - if len(graph_vertices) > 1: - raise VitrageError( - 'found too many vertices with same properties: %s ', - vertex) - graph_vertex = None if not graph_vertices else graph_vertices[0] - - return graph_vertex diff --git a/vitrage/entity_graph/processor/processor_utils.py b/vitrage/entity_graph/processor/processor_utils.py index 60d3cbcd7..4aa94683c 100644 --- a/vitrage/entity_graph/processor/processor_utils.py +++ b/vitrage/entity_graph/processor/processor_utils.py @@ -17,7 +17,6 @@ from dateutil import parser from oslo_log import log from vitrage.common.constants import EdgeProperties as EProps -from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.graph import Edge from vitrage.graph import Vertex @@ -86,15 +85,6 @@ def get_vertex_types(vertex): return vitrage_category, vitrage_type -def get_defining_properties(vertex): - if vertex.get(VProps.VITRAGE_CATEGORY) == EntityCategory.ALARM: - dp = (vertex.get(VProps.VITRAGE_TYPE), vertex.get(VProps.ID), - vertex.get(VProps.RESOURCE_ID), vertex.get(VProps.NAME)) - else: - dp = (vertex.get(VProps.VITRAGE_TYPE), vertex.get(VProps.ID)) - return hash(dp) - - def can_update_vertex(graph_vertex, new_vertex): return (not graph_vertex) or \ (not new_vertex[VProps.VITRAGE_IS_PLACEHOLDER]) diff --git a/vitrage/evaluator/actions/evaluator_event_transformer.py b/vitrage/evaluator/actions/evaluator_event_transformer.py index c0b215b4c..ba962adaf 100644 --- a/vitrage/evaluator/actions/evaluator_event_transformer.py +++ b/vitrage/evaluator/actions/evaluator_event_transformer.py @@ -22,6 +22,7 @@ from vitrage.common.constants import VertexProperties as VProps from vitrage.common.exception import VitrageTransformerError from vitrage.datasources import transformer_base from vitrage.datasources.transformer_base import Neighbor +from vitrage.datasources.transformer_base import TransformerBase from vitrage.evaluator.actions.recipes.action_steps import ADD_EDGE from vitrage.evaluator.actions.recipes.action_steps import ADD_VERTEX from vitrage.evaluator.actions.recipes.action_steps import REMOVE_EDGE @@ -124,7 +125,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase): if event_type == ADD_VERTEX: relation_edge = graph_utils.create_edge( - source_id=self._create_entity_key(event), + source_id=TransformerBase.uuid_from_deprecated_vitrage_id( + self._create_entity_key(event)), target_id=event[TFields.TARGET], relationship_type=EdgeLabel.ON, update_timestamp=timestamp) diff --git a/vitrage/graph/algo_driver/networkx_algorithm.py b/vitrage/graph/algo_driver/networkx_algorithm.py index cbaa25c81..8e3ddcd9d 100644 --- a/vitrage/graph/algo_driver/networkx_algorithm.py +++ b/vitrage/graph/algo_driver/networkx_algorithm.py @@ -47,15 +47,13 @@ class NXAlgorithm(GraphAlgorithm): return NXGraph(args, **kwargs) def graph_query_vertices(self, + root_id, query_dict=None, - root_id=None, depth=None, direction=Direction.BOTH, edge_query_dict=None): graph = self._create_new_graph('graph') - if not root_id: - root_id = self.graph.root_id root_data = self.graph._g.node[root_id] match_func = create_predicate(query_dict) if query_dict else None @@ -88,7 +86,6 @@ class NXAlgorithm(GraphAlgorithm): graph = self._create_new_graph( graph.name, - graph.root_id, vertices=self._vertex_result_to_list(n_result), edges=self._edge_result_to_list(e_result)) diff --git a/vitrage/graph/driver/graph.py b/vitrage/graph/driver/graph.py index 674b3bf85..d8bf0a691 100644 --- a/vitrage/graph/driver/graph.py +++ b/vitrage/graph/driver/graph.py @@ -36,8 +36,7 @@ class Direction(object): @six.add_metaclass(abc.ABCMeta) class Graph(object): - def __init__(self, name, graph_type, vertices=None, edges=None, - uuid=False): + def __init__(self, name, graph_type, vertices=None, edges=None): """Create a Graph instance :type name: str @@ -48,8 +47,6 @@ class Graph(object): """ self.name = name self.graph_type = graph_type - self.root_id = None - self.uuid = uuid self.notifier = Notifier() def subscribe(self, function): diff --git a/vitrage/graph/driver/networkx_graph.py b/vitrage/graph/driver/networkx_graph.py index 50de1c442..f6c6eac66 100644 --- a/vitrage/graph/driver/networkx_graph.py +++ b/vitrage/graph/driver/networkx_graph.py @@ -11,7 +11,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from collections import defaultdict import copy import json @@ -22,7 +21,6 @@ from networkx.readwrite import json_graph from oslo_log import log as logging from vitrage.common.constants import VertexProperties as VProps -from vitrage.entity_graph.processor import processor_utils as PUtils from vitrage.graph.algo_driver.networkx_algorithm import NXAlgorithm from vitrage.graph.driver.elements import Edge from vitrage.graph.driver.elements import Vertex @@ -50,15 +48,10 @@ class NXGraph(Graph): def __init__(self, name='networkx_graph', - root_id=None, vertices=None, - edges=None, - uuid=False): - super(NXGraph, self).__init__(name, NXGraph.GRAPH_TYPE, uuid=uuid) + edges=None): + super(NXGraph, self).__init__(name, NXGraph.GRAPH_TYPE) self._g = nx.MultiDiGraph() - if uuid: - self.key_to_vertex_ids = defaultdict(list) - self.root_id = root_id self.add_vertices(vertices) self.add_edges(edges) @@ -76,7 +69,7 @@ class NXGraph(Graph): edges_iter = self._g.edges_iter(data=True, keys=True) edges = [Edge(source_id=u, target_id=v, label=l, properties=data) for u, v, l, data in edges_iter] - return NXGraph(self.name, self.root_id, vertices, edges) + return NXGraph(self.name, vertices, edges) @Notifier.update_notify def add_vertex(self, v): @@ -90,13 +83,6 @@ class NXGraph(Graph): def _add_vertex(self, v): properties_copy = copy.copy(v.properties) self._g.add_node(n=v.vertex_id, attr_dict=properties_copy) - if self.uuid: - self._update_keys_map(v) - - def _update_keys_map(self, v): - key_hash = PUtils.get_defining_properties(v) - if v.vertex_id not in self.key_to_vertex_ids[key_hash]: - self.key_to_vertex_ids[key_hash].append(v.vertex_id) @Notifier.update_notify def add_edge(self, e): @@ -213,15 +199,6 @@ class NXGraph(Graph): :type v: Vertex """ - if self.uuid: - vertex = self.get_vertex(v.vertex_id) - if vertex: - key_hash = PUtils.get_defining_properties(vertex) - if key_hash in self.key_to_vertex_ids and\ - v.vertex_id in self.key_to_vertex_ids[key_hash]: - self.key_to_vertex_ids[key_hash].remove(v.vertex_id) - if len(self.key_to_vertex_ids[key_hash]) == 0: - del self.key_to_vertex_ids[key_hash] self._g.remove_node(n=v.vertex_id) diff --git a/vitrage/tests/functional/api_handler/test_apis.py b/vitrage/tests/functional/api_handler/test_apis.py index 0ac3e7a1d..bd4f3c430 100755 --- a/vitrage/tests/functional/api_handler/test_apis.py +++ b/vitrage/tests/functional/api_handler/test_apis.py @@ -429,7 +429,7 @@ class TestApis(TestEntityGraphUnitBase): self.assertEqual(resource[VProps.PROJECT_ID], project_id) def _create_graph(self): - graph = NXGraph('Multi tenancy graph', uuid=True) + graph = NXGraph('Multi tenancy graph') # create vertices cluster_vertex = create_cluster_placeholder_vertex() diff --git a/vitrage/tests/functional/base.py b/vitrage/tests/functional/base.py index 93b7131fd..fca317d80 100644 --- a/vitrage/tests/functional/base.py +++ b/vitrage/tests/functional/base.py @@ -20,12 +20,11 @@ from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase class TestFunctionalBase(TestEntityGraphUnitBase): - def _create_processor_with_graph(self, conf, processor=None, - uuid=False): + def _create_processor_with_graph(self, conf, processor=None): events = self._create_mock_events() if not processor: - processor = self.create_processor_and_graph(conf, uuid=uuid) + processor = self.create_processor_and_graph(conf) for event in events: processor.process_event(event) diff --git a/vitrage/tests/functional/datasources/aodh/test_aodh.py b/vitrage/tests/functional/datasources/aodh/test_aodh.py index 9829dd72d..1c178648c 100644 --- a/vitrage/tests/functional/datasources/aodh/test_aodh.py +++ b/vitrage/tests/functional/datasources/aodh/test_aodh.py @@ -53,7 +53,7 @@ class TestAodhAlarms(TestDataSourcesBase): def test_aodh_alarms_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) diff --git a/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py index 97be1eadf..fc563e959 100644 --- a/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py +++ b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py @@ -52,7 +52,7 @@ class TestCinderVolume(TestDataSourcesBase): def test_cinder_volume_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) diff --git a/vitrage/tests/functional/datasources/collectd/test_collectd.py b/vitrage/tests/functional/datasources/collectd/test_collectd.py index 3955e9fe9..b2ee72ee7 100644 --- a/vitrage/tests/functional/datasources/collectd/test_collectd.py +++ b/vitrage/tests/functional/datasources/collectd/test_collectd.py @@ -62,17 +62,19 @@ class TestCollectd(TestDataSourcesBase): def _test_collectd_alarm(self, resource_type, resource_name, host_name): # Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) time1 = time.time() severity1 = 'WARNING' + link_down_message = 'link state of "qvo818dd156-be" is "DOWN"' collectd_event = self._create_collectd_event(time1, resource_type, resource_name, host_name, - severity1) + severity1, + link_down_message) # Action processor.process_event(collectd_event) @@ -109,7 +111,8 @@ class TestCollectd(TestDataSourcesBase): resource_type, resource_name, host_name, - severity2) + severity2, + link_down_message) processor.process_event(collectd_event) @@ -131,11 +134,13 @@ class TestCollectd(TestDataSourcesBase): # Action 3 - clear the alarm time3 = time.time() severity3 = 'OK' + link_up_message = 'link state of "qvo818dd156-be" is "UP"' collectd_event = self._create_collectd_event(time3, resource_type, resource_name, host_name, - severity3) + severity3, + link_up_message) processor.process_event(collectd_event) @@ -153,13 +158,14 @@ class TestCollectd(TestDataSourcesBase): resource_type, resource_name, host_name, - severity): + severity, + message): update_vals = {CProps.TIME: time, DSProps.SAMPLE_DATE: format_unix_timestamp(time), CProps.HOST: host_name, CProps.RESOURCE_TYPE: resource_type, CProps.RESOURCE_NAME: resource_name, - CProps.MESSAGE: 'A message for you', + CProps.MESSAGE: message, CProps.SEVERITY: severity} spec_list = mock_transformer.simple_collectd_alarm_generators( diff --git a/vitrage/tests/functional/datasources/heat/test_heat_stack.py b/vitrage/tests/functional/datasources/heat/test_heat_stack.py index a03d2b4ee..0916611ff 100644 --- a/vitrage/tests/functional/datasources/heat/test_heat_stack.py +++ b/vitrage/tests/functional/datasources/heat/test_heat_stack.py @@ -52,7 +52,7 @@ class TestHeatStack(TestDataSourcesBase): def test_heat_stack_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) diff --git a/vitrage/tests/functional/datasources/nagios/test_nagios.py b/vitrage/tests/functional/datasources/nagios/test_nagios.py index b14b442bc..9cfa799a9 100644 --- a/vitrage/tests/functional/datasources/nagios/test_nagios.py +++ b/vitrage/tests/functional/datasources/nagios/test_nagios.py @@ -52,7 +52,7 @@ class TestNagios(TestDataSourcesBase): def test_nagios_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) diff --git a/vitrage/tests/functional/datasources/nova/test_nova_datasources.py b/vitrage/tests/functional/datasources/nova/test_nova_datasources.py index 141052ede..67e11d1a2 100644 --- a/vitrage/tests/functional/datasources/nova/test_nova_datasources.py +++ b/vitrage/tests/functional/datasources/nova/test_nova_datasources.py @@ -30,7 +30,7 @@ class TestNovaDatasources(TestDataSourcesBase): cls.load_datasources(cls.conf) def test_nova_datasources(self): - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), processor.entity_graph.num_vertices()) diff --git a/vitrage/tests/functional/datasources/static_physical/test_static_physical.py b/vitrage/tests/functional/datasources/static_physical/test_static_physical.py index 8a7bf9c81..20635bad0 100644 --- a/vitrage/tests/functional/datasources/static_physical/test_static_physical.py +++ b/vitrage/tests/functional/datasources/static_physical/test_static_physical.py @@ -55,7 +55,7 @@ class TestStaticPhysical(TestDataSourcesBase): def test_static_physical_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) transformers = processor.transformer_manager.transformers transformers[SWITCH] = transformers[STATIC_PHYSICAL_DATASOURCE] self.assertEqual(self._num_total_expected_vertices(), diff --git a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py index b256d7f03..e73370460 100644 --- a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py +++ b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py @@ -78,7 +78,7 @@ class TestConsistencyFunctional(TestFunctionalBase): cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') cls.load_datasources(cls.conf) - cls.graph = NXGraph("Entity Graph", uuid=True) + cls.graph = NXGraph("Entity Graph") cls.initialization_status = VitrageInit(cls.conf, cls.graph) cls.processor = Processor(cls.conf, cls.initialization_status, cls.graph) @@ -99,8 +99,7 @@ class TestConsistencyFunctional(TestFunctionalBase): # Setup num_of_host_alarms = self.NUM_HOSTS - 2 num_instances_per_host = 4 - self._create_processor_with_graph(self.conf, processor=self.processor, - uuid=True) + self._create_processor_with_graph(self.conf, processor=self.processor) self._add_alarms() self._set_end_messages() self.assertEqual(self._num_total_expected_vertices() + @@ -175,8 +174,7 @@ class TestConsistencyFunctional(TestFunctionalBase): self.assertEqual(6, len(deleted_instance_vertices)) def _periodic_process_setup_stage(self, consistency_interval): - self._create_processor_with_graph(self.conf, processor=self.processor, - uuid=True) + self._create_processor_with_graph(self.conf, processor=self.processor) current_time = utcnow() # set all vertices to be have timestamp that consistency won't get diff --git a/vitrage/tests/functional/entity_graph/processor/test_processor.py b/vitrage/tests/functional/entity_graph/processor/test_processor.py index 032719def..37aafff19 100644 --- a/vitrage/tests/functional/entity_graph/processor/test_processor.py +++ b/vitrage/tests/functional/entity_graph/processor/test_processor.py @@ -34,7 +34,7 @@ class TestProcessorFunctional(TestFunctionalBase): cls.load_datasources(cls.conf) def test_create_entity_graph(self): - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), processor.entity_graph.num_vertices()) diff --git a/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py b/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py index 85c733cc1..a96c55876 100644 --- a/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py +++ b/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py @@ -35,7 +35,7 @@ class TestDatasourceInfoMapperFunctional(TestFunctionalBase): def test_state_on_update(self): # setup - processor = self.create_processor_and_graph(self.conf, uuid=True) + processor = self.create_processor_and_graph(self.conf) event = self._create_event(spec_type='INSTANCE_SPEC', datasource_action=DSAction.INIT_SNAPSHOT) @@ -44,7 +44,6 @@ class TestDatasourceInfoMapperFunctional(TestFunctionalBase): # test assertions entity = processor.transformer_manager.transform(event) - processor._find_and_fix_graph_vertex(entity.vertex, []) vertex = processor.entity_graph.get_vertex(entity.vertex.vertex_id) self.assertEqual('ACTIVE', vertex[VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.OK, diff --git a/vitrage/tests/functional/evaluator/test_action_executor.py b/vitrage/tests/functional/evaluator/test_action_executor.py index 62accfeef..7d461c6d0 100644 --- a/vitrage/tests/functional/evaluator/test_action_executor.py +++ b/vitrage/tests/functional/evaluator/test_action_executor.py @@ -59,7 +59,7 @@ class TestActionExecutor(TestFunctionalBase): def test_execute_set_state(self): # Test Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -110,7 +110,7 @@ class TestActionExecutor(TestFunctionalBase): def test_execute_mark_down(self): # Test Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -147,7 +147,7 @@ class TestActionExecutor(TestFunctionalBase): def test_execute_add_edge(self): # Test Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -197,7 +197,7 @@ class TestActionExecutor(TestFunctionalBase): def test_execute_add_vertex(self): # Test Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -255,7 +255,7 @@ class TestActionExecutor(TestFunctionalBase): def test_execute_add_and_remove_vertex(self): # Test Setup - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index ad34b1332..b862e4d47 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -527,9 +527,9 @@ class TestScenarioEvaluator(TestFunctionalBase): # test asserts self.assertEqual(num_orig_vertices + num_added_vertices + num_deduced_vertices + num_nagios_alarm_vertices + - # This is due to keeping alarm history : - # new alarm doesn't update same deleted alarm. - # Instead, it keeps the old one and creates a new one + # a new uuid is created for every new vertex, + # even if it existed before with another uuid. + # new alarm doesn't override old one 1, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_added_edges + num_deduced_edges + @@ -543,14 +543,14 @@ class TestScenarioEvaluator(TestFunctionalBase): port_neighbors = entity_graph.neighbors(port_vertex.vertex_id, vertex_attr_filter=query) self.assertEqual(1, len(port_neighbors)) - self.assertEqual(EntityCategory.ALARM, - port_neighbors[0][VProps.VITRAGE_CATEGORY]) - self.assertEqual(VITRAGE_DATASOURCE, - port_neighbors[0][VProps.VITRAGE_TYPE]) - self.assertEqual('simple_port_deduced_alarm', - port_neighbors[0][VProps.NAME]) - self.assertEqual(vitrage_is_deleted, - port_neighbors[0][VProps.VITRAGE_IS_DELETED]) + self.assertEqual(port_neighbors[0][VProps.VITRAGE_CATEGORY], + EntityCategory.ALARM) + self.assertEqual(port_neighbors[0][VProps.VITRAGE_TYPE], + VITRAGE_DATASOURCE) + self.assertEqual(port_neighbors[0][VProps.NAME], + 'simple_port_deduced_alarm') + self.assertEqual(port_neighbors[0][VProps.VITRAGE_IS_DELETED], + vitrage_is_deleted) query = {VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE, VProps.VITRAGE_IS_DELETED: False} @@ -583,9 +583,9 @@ class TestScenarioEvaluator(TestFunctionalBase): # test asserts self.assertEqual(num_orig_vertices + num_added_vertices + num_deduced_vertices + num_nagios_alarm_vertices + - # This is due to keeping alarm history : - # new alarm doesn't update same deleted alarm. - # Instead, it keeps the old one and creates a new one + # a new uuid is created for every new vertex, + # even if it existed before with another uuid. + # new alarm doesn't override old one 1, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_added_edges + num_deduced_edges + @@ -638,11 +638,9 @@ class TestScenarioEvaluator(TestFunctionalBase): # test asserts self.assertEqual(num_orig_vertices + num_added_vertices + num_deduced_vertices + num_nagios_alarm_vertices + - # This is due to keeping alarm history : - # new alarm doesn't update same deleted alarm. - # Instead, it keeps the old one and creates a new one - # Since this is the second test, there are already two - # alarms of this vitrage_type + # a new uuid is created for every new vertex, + # even if it existed before with another uuid. + # new alarm doesn't override old one 2, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_added_edges + num_deduced_edges + @@ -660,7 +658,8 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual( EntityCategory.ALARM, port_neighbors[in_counter][VProps.VITRAGE_CATEGORY]) - self.assertEqual(VITRAGE_DATASOURCE, port_neighbors[in_counter] + self.assertEqual(VITRAGE_DATASOURCE, + port_neighbors[in_counter] [VProps.VITRAGE_TYPE]) self.assertEqual('simple_port_deduced_alarm', port_neighbors[in_counter][VProps.NAME]) @@ -825,9 +824,9 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(num_orig_vertices + num_added_vertices + num_deduced_vertices + num_network_alarm_vertices + - # This is due to keeping alarm history : - # new alarm doesn't update same deleted alarm. - # Instead, it keeps the old one and creates a new one + # a new uuid is created for every new vertex, + # even if it existed before with another uuid. + # new alarm doesn't override old one 1, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_added_edges + num_deduced_edges + @@ -1021,9 +1020,9 @@ class TestScenarioEvaluator(TestFunctionalBase): # test asserts self.assertEqual(num_orig_vertices + num_volumes + num_deduced_alarms + - # This is due to keeping alarm history : - # new alarm doesn't update same deleted alarm. - # Instead, it keeps the old one and creates a new one + # a new uuid is created for every new vertex, + # even if it existed before with another uuid. + # new alarm doesn't override old one 1, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_volumes + num_deduced_alarms + 1, @@ -1106,9 +1105,9 @@ class TestScenarioEvaluator(TestFunctionalBase): # test asserts self.assertEqual(num_orig_vertices + num_volumes + num_deduced_alarms + - # This is due to keeping alarm history : - # new alarm doesn't update same deleted alarm. - # Instead, it keeps the old one and creates a new one + # a new uuid is created for every new vertex, + # even if it existed before with another uuid. + # new alarm doesn't override old one 1, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_volumes + num_deduced_alarms + 1, @@ -1357,7 +1356,7 @@ class TestScenarioEvaluator(TestFunctionalBase): return host_v def _init_system(self): - processor = self._create_processor_with_graph(self.conf, uuid=True) + processor = self._create_processor_with_graph(self.conf) event_queue = queue.Queue() evaluator = ScenarioEvaluator(self.conf, processor.entity_graph, self.scenario_repository, event_queue, diff --git a/vitrage/tests/resources/mock_configurations/driver/driver_zabbix_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/driver/driver_zabbix_snapshot_dynamic.json index 0354516bd..244c43ec9 100644 --- a/vitrage/tests/resources/mock_configurations/driver/driver_zabbix_snapshot_dynamic.json +++ b/vitrage/tests/resources/mock_configurations/driver/driver_zabbix_snapshot_dynamic.json @@ -13,5 +13,6 @@ "value": "1", "priority": "1", "vitrage_datasource_action": "snapshot", - "rawtext": "CPU utilization" + "rawtext": "CPU utilization", + "vitrage_category": "ALARM" } diff --git a/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py b/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py index a69a2fe66..b12009fe9 100644 --- a/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py +++ b/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py @@ -90,7 +90,9 @@ class TestAodhAlarmTransformer(AodhTransformerBaseTest): neighbors = event[TransformerBase.QUERY_RESULT] vertices = [] for neighbor in neighbors: - vertices.append(self._convert_dist_to_vertex(neighbor)) + neighbor_vertex = self._convert_dist_to_vertex(neighbor) + vertices.append(self.transformers[AODH_DATASOURCE]. + update_uuid_in_vertex(neighbor_vertex)) event[TransformerBase.QUERY_RESULT] = vertices # Test action @@ -137,7 +139,9 @@ class TestAodhAlarmPushTransformer(AodhTransformerBaseTest): neighbors = event[TransformerBase.QUERY_RESULT] vertices = [] for neighbor in neighbors: - vertices.append(self._convert_dist_to_vertex(neighbor)) + neighbor_vertex = self._convert_dist_to_vertex(neighbor) + vertices.append(self.transformers[AODH_DATASOURCE]. + update_uuid_in_vertex(neighbor_vertex)) event[TransformerBase.QUERY_RESULT] = vertices # Test action diff --git a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py index 24e9322fb..ba0fdbbe2 100644 --- a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py +++ b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py @@ -75,12 +75,13 @@ class TestCinderVolumeTransformer(base.BaseTest): placeholder = \ transformer.create_neighbor_placeholder_vertex(**properties) - # Test assertions - observed_id_values = placeholder.vertex_id.split( - TransformerBase.KEY_SEPARATOR) - expected_id_values = transformer._key_values(CINDER_VOLUME_DATASOURCE, - volume_id) - self.assertEqual(expected_id_values, tuple(observed_id_values)) + # Test assertions) + expected_key = \ + tbase.build_key(transformer._key_values(CINDER_VOLUME_DATASOURCE, + volume_id)) + expected_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(expected_key) + self.assertEqual(expected_uuid, placeholder.vertex_id) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) self.assertEqual(timestamp, observed_time) diff --git a/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py b/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py index b9525867d..50b1296ba 100644 --- a/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py +++ b/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py @@ -67,10 +67,12 @@ class TestCollectdTransformer(BaseAlarmTransformerTest): # Test assertions self._validate_vertex_props(wrapper.vertex, event) + entity_key = transformer._create_entity_key(event) + entity_uuid = TransformerBase.uuid_from_deprecated_vitrage_id( + entity_key) + # Validate the neighbors: only one valid host neighbor - self._validate_host_neighbor(wrapper, - transformer._create_entity_key(event), - host1) + self._validate_host_neighbor(wrapper, entity_uuid, host1) # Validate the expected action on the graph - update or delete self._validate_graph_action(wrapper) @@ -82,14 +84,16 @@ class TestCollectdTransformer(BaseAlarmTransformerTest): self.assertIsNotNone(event) # Test action + entity_key = transformer._create_entity_key(event) + entity_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(entity_key) + transformer = self.transformers[COLLECTD_DATASOURCE] wrapper = transformer.transform(event) # Test assertions self._validate_vertex_props(wrapper.vertex, event) - self._validate_host_neighbor(wrapper, - transformer._create_entity_key(event), - host2) + self._validate_host_neighbor(wrapper, entity_uuid, host2) self._validate_graph_action(wrapper) def _validate_vertex_props(self, vertex, event): diff --git a/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py b/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py index 5b1739067..055579654 100644 --- a/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py +++ b/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py @@ -27,6 +27,7 @@ from vitrage.datasources.doctor.properties import DoctorStatus from vitrage.datasources.doctor.transformer import DoctorTransformer from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests.mocks import mock_transformer from vitrage.tests.unit.datasources.test_alarm_transformer_base import \ BaseAlarmTransformerTest @@ -65,11 +66,10 @@ class DoctorTransformerTest(BaseAlarmTransformerTest): # Test assertions self._validate_vertex_props(wrapper.vertex, event) - + entity_key1 = transformer._create_entity_key(event) + entity_uuid1 = transformer.uuid_from_deprecated_vitrage_id(entity_key1) # Validate the neighbors: only one valid host neighbor - self._validate_host_neighbor(wrapper, - transformer._create_entity_key(event), - host1) + self._validate_host_neighbor(wrapper, entity_uuid1, host1) # Validate the expected action on the graph - update or delete self._validate_graph_action(wrapper) @@ -81,14 +81,17 @@ class DoctorTransformerTest(BaseAlarmTransformerTest): self.assertIsNotNone(event) # Test action + # after transform vitrage uuid will be deleted from uuid cache + entity_key2 = transformer._create_entity_key(event) + entity_uuid2 = \ + TransformerBase.uuid_from_deprecated_vitrage_id(entity_key2) + transformer = self.transformers[DOCTOR_DATASOURCE] wrapper = transformer.transform(event) # Test assertions self._validate_vertex_props(wrapper.vertex, event) - self._validate_host_neighbor(wrapper, - transformer._create_entity_key(event), - host2) + self._validate_host_neighbor(wrapper, entity_uuid2, host2) self._validate_graph_action(wrapper) def _validate_vertex_props(self, vertex, event): diff --git a/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py b/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py index 5f99d91b1..95f200db6 100644 --- a/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py +++ b/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py @@ -77,11 +77,13 @@ class TestHeatStackTransformer(base.BaseTest): transformer.create_neighbor_placeholder_vertex(**properties) # Test assertions - observed_id_values = placeholder.vertex_id.split( - TransformerBase.KEY_SEPARATOR) - expected_id_values = transformer._key_values(HEAT_STACK_DATASOURCE, - stack_id) - self.assertEqual(expected_id_values, tuple(observed_id_values)) + observed_uuid = placeholder.vertex_id + expected_key = tbase.build_key(transformer._key_values( + HEAT_STACK_DATASOURCE, + stack_id)) + expected_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(expected_key) + self.assertEqual(expected_uuid, observed_uuid) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) self.assertEqual(timestamp, observed_time) diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py index c7afd5baa..1357cf80a 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py @@ -88,10 +88,20 @@ class NagiosTransformerTest(base.BaseTest): events_num=10) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) + transformer = NagiosTransformer(self.transformers, self.conf) + for alarm in nagios_alarms: + + cur_alarm_uuid = None + + if alarm.get(NagiosProperties.STATUS) == NagiosTestStatus.OK: + alarm_key = transformer._create_entity_key(alarm) + cur_alarm_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id( + alarm_key) + # Test action - wrapper = NagiosTransformer(self.transformers, self.conf).\ - transform(alarm) + wrapper = transformer.transform(alarm) self._validate_vertex(wrapper.vertex, alarm) @@ -101,7 +111,8 @@ class NagiosTransformerTest(base.BaseTest): # Right now we are support only host as a resource if neighbor.vertex[VProps.VITRAGE_TYPE] == NOVA_HOST_DATASOURCE: - self._validate_host_neighbor(neighbors[0], alarm) + self._validate_host_neighbor( + neighbors[0], alarm, cur_alarm_uuid) self._validate_action(alarm, wrapper) @@ -147,15 +158,19 @@ class NagiosTransformerTest(base.BaseTest): self.assertFalse(vertex[VProps.VITRAGE_IS_DELETED]) self.assertFalse(vertex[VProps.VITRAGE_IS_PLACEHOLDER]) - def _validate_host_neighbor(self, neighbor, event): + def _validate_host_neighbor(self, neighbor, event, cur_alarm_uuid=None): host_vertex = neighbor.vertex - key_fields = host_vertex.vertex_id.split(TransformerBase.KEY_SEPARATOR) + expected_key = tbase.build_key((EntityCategory.RESOURCE, + NOVA_HOST_DATASOURCE, + event[NagiosProperties.RESOURCE_NAME])) + expected_uuid = self.transformers[NOVA_HOST_DATASOURCE].\ + uuid_from_deprecated_vitrage_id(expected_key) - self.assertEqual(EntityCategory.RESOURCE, key_fields[0]) - self.assertEqual(NOVA_HOST_DATASOURCE, key_fields[1]) - self.assertEqual(event[NagiosProperties.RESOURCE_NAME], key_fields[2]) + self.assertEqual(expected_uuid, host_vertex.vertex_id) + self.assertEqual(expected_uuid, + host_vertex.properties.get(VProps.VITRAGE_ID)) self.assertFalse(host_vertex[VProps.VITRAGE_IS_DELETED]) self.assertTrue(host_vertex[VProps.VITRAGE_IS_PLACEHOLDER]) @@ -172,5 +187,8 @@ class NagiosTransformerTest(base.BaseTest): alarm_key = NagiosTransformer(self.transformers, self.conf).\ _create_entity_key(event) - self.assertEqual(alarm_key, edge.source_id) + alarm_uuid = cur_alarm_uuid if cur_alarm_uuid else\ + TransformerBase.uuid_from_deprecated_vitrage_id(alarm_key) + + self.assertEqual(alarm_uuid, edge.source_id) self.assertEqual(host_vertex.vertex_id, edge.target_id) diff --git a/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py index 0167372fc..61f73e0b0 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py @@ -75,12 +75,13 @@ class NovaHostTransformerTest(base.BaseTest): host_transformer.create_neighbor_placeholder_vertex(**properties) # Test assertions - observed_id_values = placeholder.vertex_id.split( - TransformerBase.KEY_SEPARATOR) - expected_id_values = host_transformer._key_values( + observed_uuid = placeholder.vertex_id + expected_key = tbase.build_key(host_transformer._key_values( NOVA_HOST_DATASOURCE, - host_name) - self.assertEqual(expected_id_values, tuple(observed_id_values)) + host_name)) + expected_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(expected_key) + self.assertEqual(expected_uuid, observed_uuid) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) self.assertEqual(timestamp, observed_time) @@ -159,11 +160,12 @@ class NovaHostTransformerTest(base.BaseTest): # Validate neighbor edge edge = zone.edge + transformer = self.transformers[NOVA_HOST_DATASOURCE] + entity_key = transformer._create_entity_key(event) + entity_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(entity_key) self.assertEqual(edge.source_id, zone.vertex.vertex_id) - self.assertEqual( - edge.target_id, - self.transformers[NOVA_HOST_DATASOURCE]._create_entity_key(event) - ) + self.assertEqual(edge.target_id, entity_uuid) self.assertEqual(edge.label, EdgeLabel.CONTAINS) def _validate_vertex_props(self, vertex, event): diff --git a/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py index 5a8fad186..2010ba13f 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py @@ -75,11 +75,13 @@ class NovaInstanceTransformerTest(base.BaseTest): transformer.create_neighbor_placeholder_vertex(**properties) # Test assertions - observed_id_values = placeholder.vertex_id.split( - TransformerBase.KEY_SEPARATOR) - expected_id_values = transformer._key_values(NOVA_INSTANCE_DATASOURCE, - instance_id) - self.assertEqual(expected_id_values, tuple(observed_id_values)) + observed_uuid = placeholder.vertex_id + expected_key = tbase.build_key(transformer._key_values( + NOVA_INSTANCE_DATASOURCE, + instance_id)) + expected_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(expected_key) + self.assertEqual(expected_uuid, observed_uuid) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) self.assertEqual(timestamp, observed_time) @@ -160,7 +162,7 @@ class NovaInstanceTransformerTest(base.BaseTest): def _validate_vertex_props(self, vertex, event): - self.assertEqual(12, len(vertex.properties)) + self.assertEqual(13, len(vertex.properties)) is_update_event = tbase.is_update_event(event) @@ -224,8 +226,11 @@ class NovaInstanceTransformerTest(base.BaseTest): # Validate neighbor edge edge = h_neighbor.edge + entity_key = it._create_entity_key(event) + entity_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(entity_key) self.assertEqual(edge.source_id, h_neighbor.vertex.vertex_id) - self.assertEqual(edge.target_id, it._create_entity_key(event)) + self.assertEqual(edge.target_id, entity_uuid) self.assertEqual(edge.label, EdgeLabel.CONTAINS) def test_extract_key(self): @@ -288,7 +293,9 @@ class NovaInstanceTransformerTest(base.BaseTest): # Test setup host_name = 'host123' - vertex_id = 'RESOURCE:nova.instance:instance321' + vertex_key = 'RESOURCE:nova.instance:instance321' + vertex_id = \ + TransformerBase.uuid_from_deprecated_vitrage_id(vertex_key) time = datetime.datetime.utcnow() entity_event = { '_info': { @@ -309,7 +316,9 @@ class NovaInstanceTransformerTest(base.BaseTest): is_entity_source=False) # Test assertions - host_vertex_id = 'RESOURCE:nova.host:host123' + host_vertex_id = \ + TransformerBase.uuid_from_deprecated_vitrage_id( + 'RESOURCE:nova.host:host123') self.assertEqual(host_vertex_id, neighbor.vertex.vertex_id) self.assertEqual( time, diff --git a/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py index 907831a41..af2ce47f4 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py @@ -30,7 +30,6 @@ from vitrage.datasources.nova.zone.transformer import ZoneTransformer from vitrage.datasources import OPENSTACK_CLUSTER from vitrage.datasources import transformer_base as tbase from vitrage.datasources.transformer_base import CLUSTER_ID -from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base from vitrage.tests.mocks import mock_driver as mock_sync @@ -76,11 +75,13 @@ class NovaZoneTransformerTest(base.BaseTest): zone_transformer.create_neighbor_placeholder_vertex(**properties) # Test assertions - observed_id_values = placeholder.vertex_id.split( - TransformerBase.KEY_SEPARATOR) - expected_id_values = self.transformers[NOVA_ZONE_DATASOURCE].\ - _key_values(NOVA_ZONE_DATASOURCE, zone_name) - self.assertEqual(expected_id_values, tuple(observed_id_values)) + observed_uuid = placeholder.vertex_id + expected_key = tbase.build_key(zone_transformer._key_values( + NOVA_ZONE_DATASOURCE, + zone_name)) + expected_uuid = \ + zone_transformer.uuid_from_deprecated_vitrage_id(expected_key) + self.assertEqual(expected_uuid, observed_uuid) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) self.assertEqual(timestamp, observed_time) diff --git a/vitrage/tests/unit/datasources/static/test_static_transformer.py b/vitrage/tests/unit/datasources/static/test_static_transformer.py index 537f15401..d1ee28e4a 100644 --- a/vitrage/tests/unit/datasources/static/test_static_transformer.py +++ b/vitrage/tests/unit/datasources/static/test_static_transformer.py @@ -26,6 +26,7 @@ from vitrage.datasources.nova.host.transformer import HostTransformer from vitrage.datasources.static import STATIC_DATASOURCE from vitrage.datasources.static import StaticFields from vitrage.datasources.static.transformer import StaticTransformer +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base from vitrage.tests.mocks import mock_driver @@ -66,7 +67,9 @@ class TestStaticTransformer(base.BaseTest): **properties) observed_entity_id = placeholder.vertex_id - expected_entity_id = 'RESOURCE:static:12345' + expected_entity_id = \ + TransformerBase.uuid_from_deprecated_vitrage_id( + 'RESOURCE:static:12345') self.assertEqual(expected_entity_id, observed_entity_id) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) diff --git a/vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py b/vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py index c14137dce..d42eff715 100644 --- a/vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py +++ b/vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py @@ -29,6 +29,7 @@ from vitrage.datasources.static import StaticFields from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE from vitrage.datasources.static_physical.transformer \ import StaticPhysicalTransformer +from vitrage.datasources import transformer_base as tbase from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base from vitrage.tests.mocks import mock_driver as mock_sync @@ -76,12 +77,12 @@ class TestStaticPhysicalTransformer(base.BaseTest): static_transformer.create_neighbor_placeholder_vertex(**properties) # Test assertions - observed_id_values = placeholder.vertex_id.split( - TransformerBase.KEY_SEPARATOR) - expected_id_values = \ - self.transformers[STATIC_PHYSICAL_DATASOURCE]._key_values( - switch_type, switch_name) - self.assertEqual(expected_id_values, tuple(observed_id_values)) + observed_uuid = placeholder.vertex_id + expected_key = tbase.build_key(static_transformer._key_values( + switch_type, switch_name)) + expected_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(expected_key) + self.assertEqual(expected_uuid, observed_uuid) observed_time = placeholder.get(VProps.VITRAGE_SAMPLE_TIMESTAMP) self.assertEqual(timestamp, observed_time) diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py index c778933fa..5b7f2a6b0 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py @@ -146,11 +146,17 @@ class ZabbixTransformerTest(base.BaseTest): host_vertex = neighbor.vertex - key_fields = host_vertex.vertex_id.split(TransformerBase.KEY_SEPARATOR) + observed_key = host_vertex.vertex_id - self.assertEqual(EntityCategory.RESOURCE, key_fields[0]) - self.assertEqual(NOVA_HOST_DATASOURCE, key_fields[1]) - self.assertEqual(event[ZabbixProps.RESOURCE_NAME], key_fields[2]) + expected_key = tbase.build_key((EntityCategory.RESOURCE, + NOVA_HOST_DATASOURCE, + event[ZabbixProps.RESOURCE_NAME])) + expected_uuid = \ + TransformerBase.uuid_from_deprecated_vitrage_id(expected_key) + + self.assertEqual(expected_uuid, observed_key) + self.assertEqual(expected_uuid, + host_vertex.properties.get(VProps.VITRAGE_ID)) self.assertFalse(host_vertex[VProps.VITRAGE_IS_DELETED]) self.assertTrue(host_vertex[VProps.VITRAGE_IS_PLACEHOLDER]) @@ -167,7 +173,8 @@ class ZabbixTransformerTest(base.BaseTest): alarm_key = ZabbixTransformer(self.transformers, self.conf).\ _create_entity_key(event) - self.assertEqual(alarm_key, edge.source_id) + alarm_uuid = TransformerBase.uuid_from_deprecated_vitrage_id(alarm_key) + self.assertEqual(alarm_uuid, edge.source_id) self.assertEqual(host_vertex.vertex_id, edge.target_id) @staticmethod diff --git a/vitrage/tests/unit/entity_graph/base.py b/vitrage/tests/unit/entity_graph/base.py index e1b64c950..d4273846c 100644 --- a/vitrage/tests/unit/entity_graph/base.py +++ b/vitrage/tests/unit/entity_graph/base.py @@ -75,7 +75,7 @@ class TestEntityGraphUnitBase(base.BaseTest): events = self._create_mock_events() if not processor: - processor = self.create_processor_and_graph(conf, uuid=False) + processor = self.create_processor_and_graph(conf) for event in events: processor.process_event(event) @@ -117,7 +117,7 @@ class TestEntityGraphUnitBase(base.BaseTest): # add instance entity with host if processor is None: - processor = self.create_processor_and_graph(self.conf, True) + processor = self.create_processor_and_graph(self.conf) vertex, neighbors, event_type = processor.transformer_manager\ .transform(event) @@ -126,8 +126,8 @@ class TestEntityGraphUnitBase(base.BaseTest): return vertex, neighbors, processor @staticmethod - def create_processor_and_graph(conf, uuid): - e_graph = NXGraph("Entity Graph", uuid=uuid) + def create_processor_and_graph(conf): + e_graph = NXGraph("Entity Graph") init = VitrageInit(conf) return proc.Processor(conf, init, e_graph) diff --git a/vitrage/tests/unit/entity_graph/processor/test_processor.py b/vitrage/tests/unit/entity_graph/processor/test_processor.py index dc5769d0b..aca95e7ff 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_processor.py +++ b/vitrage/tests/unit/entity_graph/processor/test_processor.py @@ -49,7 +49,7 @@ class TestProcessor(TestEntityGraphUnitBase): def test_process_event(self): # check create instance event - processor = self.create_processor_and_graph(self.conf, uuid=True) + processor = self.create_processor_and_graph(self.conf) event = self._create_event(spec_type=self.INSTANCE_SPEC, datasource_action=DSAction.INIT_SNAPSHOT) processor.process_event(event) diff --git a/vitrage/tests/unit/graph/base.py b/vitrage/tests/unit/graph/base.py index 9046b0bcb..a057d14ce 100644 --- a/vitrage/tests/unit/graph/base.py +++ b/vitrage/tests/unit/graph/base.py @@ -139,10 +139,7 @@ class GraphTestBase(base.BaseTest): num_of_tests_per_host): start = time.time() - g = NXGraph(name, EntityCategory.RESOURCE + ':' + - OPENSTACK_CLUSTER + ':' + - CLUSTER_ID, - uuid=True) + g = NXGraph(name) g.add_vertex(v_node) g.add_vertex(v_switch) g.add_edge(e_node_to_switch) diff --git a/vitrage/tests/unit/graph/test_graph_algo.py b/vitrage/tests/unit/graph/test_graph_algo.py index 442114cfa..76b70384a 100644 --- a/vitrage/tests/unit/graph/test_graph_algo.py +++ b/vitrage/tests/unit/graph/test_graph_algo.py @@ -31,6 +31,8 @@ from vitrage.graph.driver.elements import Edge from vitrage.graph.driver.graph import Direction from vitrage.tests.unit.graph.base import * # noqa +ROOT_ID = EntityCategory.RESOURCE + ':' + OPENSTACK_CLUSTER + ':' + CLUSTER_ID + class GraphAlgorithmTest(GraphTestBase): @@ -54,7 +56,7 @@ class GraphAlgorithmTest(GraphTestBase): ga = self.entity_graph.algo query = {'==': {VProps.VITRAGE_TYPE: OPENSTACK_CLUSTER}} - subgraph = ga.graph_query_vertices(query) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, query_dict=query) self.assertEqual( 1, # For Cluster subgraph.num_vertices(), 'num of vertex node') @@ -66,7 +68,7 @@ class GraphAlgorithmTest(GraphTestBase): ] } - subgraph = ga.graph_query_vertices(query) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, query_dict=query) self.assertEqual( ENTITY_GRAPH_HOSTS_PER_CLUSTER, subgraph.num_edges(), 'num of edges Host <-- NODE') @@ -79,7 +81,7 @@ class GraphAlgorithmTest(GraphTestBase): {'==': {VProps.VITRAGE_TYPE: OPENSTACK_CLUSTER}} ] } - subgraph = ga.graph_query_vertices(query) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, query_dict=query) self.assertEqual( ENTITY_GRAPH_HOSTS_PER_CLUSTER + ENTITY_GRAPH_HOSTS_PER_CLUSTER * ENTITY_GRAPH_ALARMS_PER_HOST + @@ -95,7 +97,7 @@ class GraphAlgorithmTest(GraphTestBase): query = {'!=': {'NOTHING': 'IS EVERYTHING'}} subgraph = ga.graph_query_vertices( - query_dict=query, root_id=first_host_id, depth=1) + root_id=first_host_id, query_dict=query, depth=1) self.assertEqual( 1 + # For host 1 + # For Cluster @@ -111,7 +113,7 @@ class GraphAlgorithmTest(GraphTestBase): ] } subgraph = ga.graph_query_vertices( - query_dict=query, root_id=first_host_id, depth=1) + root_id=first_host_id, query_dict=query, depth=1) self.assertEqual( 1, # For SWITCH subgraph.num_edges(), 'num of BOTH edges Host (depth 1)') @@ -140,7 +142,9 @@ class GraphAlgorithmTest(GraphTestBase): {'!=': {VProps.VITRAGE_CATEGORY: ALARM}} ] } - subgraph = ga.graph_query_vertices(query_dict=query, depth=3) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, + query_dict=query, + depth=3) self.assertEqual( 1 + # Cluster to switch ENTITY_GRAPH_HOSTS_PER_CLUSTER * 2 + @@ -154,7 +158,9 @@ class GraphAlgorithmTest(GraphTestBase): {'==': {VProps.VITRAGE_CATEGORY: ALARM}}, ] } - subgraph = ga.graph_query_vertices(query_dict=query, depth=3) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, + query_dict=query, + depth=3) self.assertEqual(0, subgraph.num_edges(), 'num of BOTH edges Node (depth 3)') self.assertEqual(1, subgraph.num_vertices(), @@ -163,8 +169,10 @@ class GraphAlgorithmTest(GraphTestBase): # check the edge_query_dict parameter query = {'!=': {'NOTHING': 'IS EVERYTHING'}} edge_query = {'==': {EProps.RELATIONSHIP_TYPE: EdgeLabel.CONTAINS}} - subgraph = ga.graph_query_vertices( - query_dict=query, depth=5, edge_query_dict=edge_query) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, + query_dict=query, + depth=5, + edge_query_dict=edge_query) alarms = subgraph.get_vertices( vertex_attr_filter={VProps.VITRAGE_CATEGORY: ALARM}) self.assertEqual(len(alarms), 0, 'We filtered the ON relationship,' @@ -201,8 +209,10 @@ class GraphAlgorithmTest(GraphTestBase): query = {'!=': {'NOTHING': 'IS EVERYTHING'}} edge_query = {'==': {EProps.VITRAGE_IS_DELETED: False}} - subgraph = ga.graph_query_vertices( - query_dict=query, depth=5, edge_query_dict=edge_query) + subgraph = ga.graph_query_vertices(root_id=ROOT_ID, + query_dict=query, + depth=5, + edge_query_dict=edge_query) self.assertEqual(self.entity_graph.num_edges() - 1, subgraph.num_edges(), 'We filtered the ON relationship, so no alarms ' @@ -215,7 +225,9 @@ class GraphAlgorithmTest(GraphTestBase): def test_no_match_graph_query_vertices(self): query = {'==': {VProps.VITRAGE_TYPE: 'test'}} - subgraph = self.entity_graph.algo.graph_query_vertices(query) + subgraph = self.entity_graph.algo.graph_query_vertices( + root_id=ROOT_ID, + query_dict=query) self.assertEqual( 0, subgraph.num_vertices(), 'num of vertex node') diff --git a/vitrage_tempest_tests/tests/api/topology/test_topology.py b/vitrage_tempest_tests/tests/api/topology/test_topology.py index edd5d1dff..ce804f85d 100644 --- a/vitrage_tempest_tests/tests/api/topology/test_topology.py +++ b/vitrage_tempest_tests/tests/api/topology/test_topology.py @@ -14,6 +14,8 @@ from oslo_log import log as logging +from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources import OPENSTACK_CLUSTER from vitrage_tempest_tests.tests.api.topology.base import BaseTopologyTest import vitrage_tempest_tests.tests.utils as utils from vitrageclient.exceptions import ClientException @@ -29,7 +31,6 @@ NOVA_QUERY = '{"and": [{"==": {"vitrage_category": "RESOURCE"}},' \ '{"==": {"vitrage_type": "nova.instance"}},' \ '{"==": {"vitrage_type": "nova.host"}},' \ '{"==": {"vitrage_type": "nova.zone"}}]}]}' -CLUSTER_VERTEX_ID = 'RESOURCE:openstack.cluster:OpenStack Cluster' class TestTopology(BaseTopologyTest): @@ -42,6 +43,11 @@ class TestTopology(BaseTopologyTest): def setUpClass(cls): super(TestTopology, cls).setUpClass() + def _get_root_vertex_id(self): + items = self.vitrage_client.resource.list( + resource_type=OPENSTACK_CLUSTER) + return items[0][VProps.VITRAGE_ID] + @utils.tempest_logger def test_compare_api_and_cli(self): """compare_api_and_cli @@ -274,7 +280,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( limit=2, - root=CLUSTER_VERTEX_ID, + root=self._get_root_vertex_id(), all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( @@ -306,7 +312,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( limit=3, - root=CLUSTER_VERTEX_ID, + root=self._get_root_vertex_id(), all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( diff --git a/vitrage_tempest_tests/tests/base_mock.py b/vitrage_tempest_tests/tests/base_mock.py index cc92838cd..5d65c3121 100644 --- a/vitrage_tempest_tests/tests/base_mock.py +++ b/vitrage_tempest_tests/tests/base_mock.py @@ -38,7 +38,7 @@ class BaseMock(testtools.TestCase): conf = cfg.ConfigOpts() conf.register_opts(self.PROCESSOR_OPTS, group='entity_graph') events = self._create_mock_events() - e_graph = NXGraph("Entity Graph", uuid=False) + e_graph = NXGraph("Entity Graph") init = VitrageInit(conf) processor = proc.Processor(conf, init, e_graph)