Change api mocks + rename 'node' to 'openstack.cluster'

Change-Id: I92c3e74f2fc386da2d6c5811f572565fb0402749
This commit is contained in:
Alexey Weyl 2016-02-22 14:22:49 +02:00
parent 250f2bad76
commit 20e06e4c48
11 changed files with 45 additions and 37 deletions

View File

@ -252,10 +252,10 @@
"category": "RESOURCE",
"is_placeholder": false,
"is_deleted": false,
"name": "node",
"type": "node",
"id": "node",
"vitrage_id": "RESOURCE:node"
"name": "openstack.node",
"type": "openstack.node",
"id": "openstack.node",
"vitrage_id": "RESOURCE:openstack.node"
}
],
"links": [

View File

@ -25,7 +25,6 @@ from pecan import rest
from vitrage.api.controllers.v1 import mock_file
from vitrage.api.controllers.v1 import RCA_QUERY
from vitrage.api.policy import enforce
# noinspection PyProtectedMember
@ -34,7 +33,7 @@ from vitrage.i18n import _LI
LOG = log.getLogger(__name__)
def as_tree(graph, root='RESOURCE:node', reverse=False):
def as_tree(graph, root='RESOURCE:openstack.node', reverse=False):
linked_graph = json_graph.node_link_graph(graph)
if reverse:
linked_graph = linked_graph.reverse()
@ -102,7 +101,7 @@ class TopologyController(rest.RestController):
if graph_type == 'graph':
return graph
if graph_type == 'tree':
return as_tree(graph, root='node')
return as_tree(graph)
except Exception as e:
LOG.exception('failed to open file %s', e)

View File

@ -58,7 +58,7 @@ class SynchronizerProperties(object):
class EntityType(object):
NODE = 'node'
OPENSTACK_NODE = 'openstack.node'
NOVA_INSTANCE = 'nova.instance'
NOVA_HOST = 'nova.host'
NOVA_ZONE = 'nova.zone'

View File

@ -107,6 +107,9 @@ class EntityGraphApis(object):
def get_topology(self, ctx, graph_type, depth, query, root):
ga = create_algorithm(self.entity_graph)
query = query if query else \
{'!=': {VProps.CATEGORY: EntityCategory.ALARM}}
found_graph = ga.graph_query_vertices(
{'!=': {VProps.CATEGORY: EntityCategory.ALARM}})
query_dict=query,
root_id=root)
return found_graph.output_graph()

View File

@ -116,5 +116,5 @@ class ConsistencyEnforcer(object):
def _filter_vertices_to_be_deleted(vertices):
return filter(
lambda ver:
not (ver.properties[VProps.CATEGORY] == EntityCategory.RESOURCE
and ver.properties[VProps.TYPE] == EntityType.NODE), vertices)
not (ver[VProps.CATEGORY] == EntityCategory.RESOURCE and
ver[VProps.TYPE] == EntityType.OPENSTACK_NODE), vertices)

View File

@ -55,16 +55,17 @@ def build_key(key_values):
def create_node_placeholder_vertex():
key = build_key([cons.EntityCategory.RESOURCE, EntityType.NODE])
key = build_key([cons.EntityCategory.RESOURCE,
EntityType.OPENSTACK_NODE])
metadata = {
cons.VertexProperties.NAME: EntityType.NODE
cons.VertexProperties.NAME: EntityType.OPENSTACK_NODE
}
return graph_utils.create_vertex(
key,
entity_category=cons.EntityCategory.RESOURCE,
entity_type=EntityType.NODE,
entity_type=EntityType.OPENSTACK_NODE,
metadata=metadata
)

View File

@ -31,7 +31,7 @@ import vitrage.graph.utils as graph_utils
from vitrage.tests.unit.entity_graph import TestEntityGraphBase
class TestConsistencyBase(TestEntityGraphBase):
class TestConsistency(TestEntityGraphBase):
OPTS = [
cfg.IntOpt('consistency_interval',
@ -43,7 +43,7 @@ class TestConsistencyBase(TestEntityGraphBase):
]
def setUp(self):
super(TestConsistencyBase, self).setUp()
super(TestConsistency, self).setUp()
self.initialization_status = InitializationStatus()
self.processor = Processor(self.initialization_status)
self.conf = cfg.ConfigOpts()
@ -88,11 +88,11 @@ class TestConsistencyBase(TestEntityGraphBase):
def test_periodic_process(self):
# Setup
consistency_inteval = self.conf.consistency.consistency_interval
self._periodic_process_setup_stage(consistency_inteval)
consistency_interval = self.conf.consistency.consistency_interval
self._periodic_process_setup_stage(consistency_interval)
# Action
time.sleep(2 * consistency_inteval + 1)
time.sleep(2 * consistency_interval + 1)
self.consistency_enforcer.periodic_process()
# Test Assertions
@ -104,14 +104,14 @@ class TestConsistencyBase(TestEntityGraphBase):
self.assertEqual(self._num_total_expected_vertices() - 6,
len(self.processor.entity_graph.get_vertices()))
def _periodic_process_setup_stage(self, consistency_inteval):
def _periodic_process_setup_stage(self, consistency_interval):
self._create_processor_with_graph(processor=self.processor)
current_time = utcnow()
# set all vertices to be have timestamp that consistency won't get
self._update_timestamp(self.processor.entity_graph.get_vertices(),
current_time +
timedelta(seconds=1.5 * consistency_inteval))
timedelta(seconds=1.5 * consistency_interval))
# check number of instances in graph
instance_vertices = self.processor.entity_graph.get_vertices({
@ -132,7 +132,7 @@ class TestConsistencyBase(TestEntityGraphBase):
for i in range(6, 9):
instance_vertices[i][VProps.IS_DELETED] = True
instance_vertices[i][VProps.UPDATE_TIMESTAMP] = str(
current_time + timedelta(seconds=2 * consistency_inteval + 1))
current_time + timedelta(seconds=2 * consistency_interval + 1))
self.processor.entity_graph.update_vertex(instance_vertices[i])
def _set_end_messages(self):

View File

@ -43,7 +43,7 @@ ALARM = EntityCategory.ALARM
HOST = EntityType.NOVA_HOST
INSTANCE = EntityType.NOVA_INSTANCE
NODE = EntityType.NODE
OPENSTACK_NODE = EntityType.OPENSTACK_NODE
TEST = 'TEST'
SWITCH = EntityType.SWITCH
ALARM_ON_VM = 'ALARM_ON_VM'
@ -51,9 +51,9 @@ ALARM_ON_HOST = 'ALARM_ON_HOST'
TEST_ON_HOST = 'TEST_ON_HOST'
v_node = graph_utils.create_vertex(
vitrage_id=NODE + '111111111111',
vitrage_id=OPENSTACK_NODE + '111111111111',
entity_id='111111111111',
entity_type=NODE,
entity_type=OPENSTACK_NODE,
entity_category=RESOURCE)
v_host = graph_utils.create_vertex(
vitrage_id=HOST + '222222222222',
@ -140,7 +140,8 @@ class GraphTestBase(base.BaseTest):
num_of_tests_per_host):
start = time.time()
g = create_graph(name, EntityCategory.RESOURCE + ':' + EntityType.NODE)
g = create_graph(name, EntityCategory.RESOURCE + ':' +
EntityType.OPENSTACK_NODE)
g.add_vertex(v_node)
g.add_vertex(v_switch)
g.add_edge(e_node_to_switch)

View File

@ -347,17 +347,19 @@ class GraphTest(GraphTestBase):
self.assertEqual(2, len(all_vertices),
'get_vertices __len__ all vertices')
node_vertices = g.get_vertices(vertex_attr_filter={VProps.TYPE: NODE})
node_vertices = g.get_vertices(
vertex_attr_filter={VProps.TYPE: OPENSTACK_NODE})
self.assertEqual(1, len(node_vertices),
'get_vertices __len__ node vertices')
found_vertex = node_vertices.pop()
self.assertEqual(NODE, found_vertex[VProps.TYPE],
self.assertEqual(OPENSTACK_NODE, found_vertex[VProps.TYPE],
'get_vertices check node vertex')
node_vertices = g.get_vertices(
vertex_attr_filter={VProps.TYPE: NODE, VProps.CATEGORY: RESOURCE})
vertex_attr_filter={VProps.TYPE: OPENSTACK_NODE,
VProps.CATEGORY: RESOURCE})
self.assertEqual(1, len(node_vertices),
'get_vertices __len__ node vertices')
found_vertex = node_vertices.pop()
self.assertEqual(NODE, found_vertex[VProps.TYPE],
self.assertEqual(OPENSTACK_NODE, found_vertex[VProps.TYPE],
'get_vertices check node vertex')

View File

@ -28,7 +28,7 @@ class GraphAlgorithmTest(GraphTestBase):
def test_graph_query_vertices(self):
ga = create_algorithm(self.entity_graph)
query = {'==': {VProps.TYPE: NODE}}
query = {'==': {VProps.TYPE: OPENSTACK_NODE}}
subgraph = ga.graph_query_vertices(query)
self.assertEqual(
1, # For NODE
@ -37,7 +37,7 @@ class GraphAlgorithmTest(GraphTestBase):
query = {
'or': [
{'==': {VProps.TYPE: HOST}},
{'==': {VProps.TYPE: NODE}}
{'==': {VProps.TYPE: OPENSTACK_NODE}}
]
}
@ -51,7 +51,7 @@ class GraphAlgorithmTest(GraphTestBase):
{'==': {VProps.TYPE: INSTANCE}},
{'==': {VProps.CATEGORY: ALARM}},
{'==': {VProps.TYPE: HOST}},
{'==': {VProps.TYPE: NODE}}
{'==': {VProps.TYPE: OPENSTACK_NODE}}
]
}
subgraph = ga.graph_query_vertices(query)
@ -119,7 +119,7 @@ class GraphAlgorithmTest(GraphTestBase):
query = {
'or': [
{'==': {VProps.TYPE: NODE}},
{'==': {VProps.TYPE: OPENSTACK_NODE}},
{'==': {VProps.CATEGORY: ALARM}},
]
}
@ -158,10 +158,12 @@ class GraphAlgorithmTest(GraphTestBase):
t_v_switch = graph_utils.create_vertex(
vitrage_id='5', entity_category=RESOURCE, entity_type=SWITCH)
t_v_node = graph_utils.create_vertex(
vitrage_id='6', entity_category=RESOURCE, entity_type=NODE)
vitrage_id='6',
entity_category=RESOURCE,
entity_type=OPENSTACK_NODE)
t_v_node_not_in_graph = graph_utils.create_vertex(
vitrage_id='7', entity_category=RESOURCE,
entity_type=NODE + ' not in graph')
entity_type=OPENSTACK_NODE + ' not in graph')
e_alarm_on_host = graph_utils.create_edge(
t_v_host_alarm.vertex_id, t_v_host.vertex_id, ELabel.ON)

View File

@ -128,7 +128,7 @@ class NovaZoneTransformerTest(base.BaseTest):
for neighbor in neighbors:
vertex_type = neighbor.vertex.get(VertexProperties.TYPE)
if EntityType.NODE == vertex_type:
if EntityType.OPENSTACK_NODE == vertex_type:
node_neighbors_counter += 1
self._validate_node_neighbor(neighbor, zone_vertex_id)
else: