Change api mocks + rename 'node' to 'openstack.cluster'
Change-Id: I92c3e74f2fc386da2d6c5811f572565fb0402749
This commit is contained in:
parent
250f2bad76
commit
20e06e4c48
@ -252,10 +252,10 @@
|
|||||||
"category": "RESOURCE",
|
"category": "RESOURCE",
|
||||||
"is_placeholder": false,
|
"is_placeholder": false,
|
||||||
"is_deleted": false,
|
"is_deleted": false,
|
||||||
"name": "node",
|
"name": "openstack.node",
|
||||||
"type": "node",
|
"type": "openstack.node",
|
||||||
"id": "node",
|
"id": "openstack.node",
|
||||||
"vitrage_id": "RESOURCE:node"
|
"vitrage_id": "RESOURCE:openstack.node"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [
|
"links": [
|
||||||
|
@ -25,7 +25,6 @@ from pecan import rest
|
|||||||
|
|
||||||
from vitrage.api.controllers.v1 import mock_file
|
from vitrage.api.controllers.v1 import mock_file
|
||||||
from vitrage.api.controllers.v1 import RCA_QUERY
|
from vitrage.api.controllers.v1 import RCA_QUERY
|
||||||
|
|
||||||
from vitrage.api.policy import enforce
|
from vitrage.api.policy import enforce
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@ -34,7 +33,7 @@ from vitrage.i18n import _LI
|
|||||||
LOG = log.getLogger(__name__)
|
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)
|
linked_graph = json_graph.node_link_graph(graph)
|
||||||
if reverse:
|
if reverse:
|
||||||
linked_graph = linked_graph.reverse()
|
linked_graph = linked_graph.reverse()
|
||||||
@ -102,7 +101,7 @@ class TopologyController(rest.RestController):
|
|||||||
if graph_type == 'graph':
|
if graph_type == 'graph':
|
||||||
return graph
|
return graph
|
||||||
if graph_type == 'tree':
|
if graph_type == 'tree':
|
||||||
return as_tree(graph, root='node')
|
return as_tree(graph)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception('failed to open file %s', e)
|
LOG.exception('failed to open file %s', e)
|
||||||
|
@ -58,7 +58,7 @@ class SynchronizerProperties(object):
|
|||||||
|
|
||||||
|
|
||||||
class EntityType(object):
|
class EntityType(object):
|
||||||
NODE = 'node'
|
OPENSTACK_NODE = 'openstack.node'
|
||||||
NOVA_INSTANCE = 'nova.instance'
|
NOVA_INSTANCE = 'nova.instance'
|
||||||
NOVA_HOST = 'nova.host'
|
NOVA_HOST = 'nova.host'
|
||||||
NOVA_ZONE = 'nova.zone'
|
NOVA_ZONE = 'nova.zone'
|
||||||
|
@ -107,6 +107,9 @@ class EntityGraphApis(object):
|
|||||||
|
|
||||||
def get_topology(self, ctx, graph_type, depth, query, root):
|
def get_topology(self, ctx, graph_type, depth, query, root):
|
||||||
ga = create_algorithm(self.entity_graph)
|
ga = create_algorithm(self.entity_graph)
|
||||||
|
query = query if query else \
|
||||||
|
{'!=': {VProps.CATEGORY: EntityCategory.ALARM}}
|
||||||
found_graph = ga.graph_query_vertices(
|
found_graph = ga.graph_query_vertices(
|
||||||
{'!=': {VProps.CATEGORY: EntityCategory.ALARM}})
|
query_dict=query,
|
||||||
|
root_id=root)
|
||||||
return found_graph.output_graph()
|
return found_graph.output_graph()
|
||||||
|
@ -116,5 +116,5 @@ class ConsistencyEnforcer(object):
|
|||||||
def _filter_vertices_to_be_deleted(vertices):
|
def _filter_vertices_to_be_deleted(vertices):
|
||||||
return filter(
|
return filter(
|
||||||
lambda ver:
|
lambda ver:
|
||||||
not (ver.properties[VProps.CATEGORY] == EntityCategory.RESOURCE
|
not (ver[VProps.CATEGORY] == EntityCategory.RESOURCE and
|
||||||
and ver.properties[VProps.TYPE] == EntityType.NODE), vertices)
|
ver[VProps.TYPE] == EntityType.OPENSTACK_NODE), vertices)
|
||||||
|
@ -55,16 +55,17 @@ def build_key(key_values):
|
|||||||
|
|
||||||
|
|
||||||
def create_node_placeholder_vertex():
|
def create_node_placeholder_vertex():
|
||||||
key = build_key([cons.EntityCategory.RESOURCE, EntityType.NODE])
|
key = build_key([cons.EntityCategory.RESOURCE,
|
||||||
|
EntityType.OPENSTACK_NODE])
|
||||||
|
|
||||||
metadata = {
|
metadata = {
|
||||||
cons.VertexProperties.NAME: EntityType.NODE
|
cons.VertexProperties.NAME: EntityType.OPENSTACK_NODE
|
||||||
}
|
}
|
||||||
|
|
||||||
return graph_utils.create_vertex(
|
return graph_utils.create_vertex(
|
||||||
key,
|
key,
|
||||||
entity_category=cons.EntityCategory.RESOURCE,
|
entity_category=cons.EntityCategory.RESOURCE,
|
||||||
entity_type=EntityType.NODE,
|
entity_type=EntityType.OPENSTACK_NODE,
|
||||||
metadata=metadata
|
metadata=metadata
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import vitrage.graph.utils as graph_utils
|
|||||||
from vitrage.tests.unit.entity_graph import TestEntityGraphBase
|
from vitrage.tests.unit.entity_graph import TestEntityGraphBase
|
||||||
|
|
||||||
|
|
||||||
class TestConsistencyBase(TestEntityGraphBase):
|
class TestConsistency(TestEntityGraphBase):
|
||||||
|
|
||||||
OPTS = [
|
OPTS = [
|
||||||
cfg.IntOpt('consistency_interval',
|
cfg.IntOpt('consistency_interval',
|
||||||
@ -43,7 +43,7 @@ class TestConsistencyBase(TestEntityGraphBase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestConsistencyBase, self).setUp()
|
super(TestConsistency, self).setUp()
|
||||||
self.initialization_status = InitializationStatus()
|
self.initialization_status = InitializationStatus()
|
||||||
self.processor = Processor(self.initialization_status)
|
self.processor = Processor(self.initialization_status)
|
||||||
self.conf = cfg.ConfigOpts()
|
self.conf = cfg.ConfigOpts()
|
||||||
@ -88,11 +88,11 @@ class TestConsistencyBase(TestEntityGraphBase):
|
|||||||
|
|
||||||
def test_periodic_process(self):
|
def test_periodic_process(self):
|
||||||
# Setup
|
# Setup
|
||||||
consistency_inteval = self.conf.consistency.consistency_interval
|
consistency_interval = self.conf.consistency.consistency_interval
|
||||||
self._periodic_process_setup_stage(consistency_inteval)
|
self._periodic_process_setup_stage(consistency_interval)
|
||||||
|
|
||||||
# Action
|
# Action
|
||||||
time.sleep(2 * consistency_inteval + 1)
|
time.sleep(2 * consistency_interval + 1)
|
||||||
self.consistency_enforcer.periodic_process()
|
self.consistency_enforcer.periodic_process()
|
||||||
|
|
||||||
# Test Assertions
|
# Test Assertions
|
||||||
@ -104,14 +104,14 @@ class TestConsistencyBase(TestEntityGraphBase):
|
|||||||
self.assertEqual(self._num_total_expected_vertices() - 6,
|
self.assertEqual(self._num_total_expected_vertices() - 6,
|
||||||
len(self.processor.entity_graph.get_vertices()))
|
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)
|
self._create_processor_with_graph(processor=self.processor)
|
||||||
current_time = utcnow()
|
current_time = utcnow()
|
||||||
|
|
||||||
# set all vertices to be have timestamp that consistency won't get
|
# set all vertices to be have timestamp that consistency won't get
|
||||||
self._update_timestamp(self.processor.entity_graph.get_vertices(),
|
self._update_timestamp(self.processor.entity_graph.get_vertices(),
|
||||||
current_time +
|
current_time +
|
||||||
timedelta(seconds=1.5 * consistency_inteval))
|
timedelta(seconds=1.5 * consistency_interval))
|
||||||
|
|
||||||
# check number of instances in graph
|
# check number of instances in graph
|
||||||
instance_vertices = self.processor.entity_graph.get_vertices({
|
instance_vertices = self.processor.entity_graph.get_vertices({
|
||||||
@ -132,7 +132,7 @@ class TestConsistencyBase(TestEntityGraphBase):
|
|||||||
for i in range(6, 9):
|
for i in range(6, 9):
|
||||||
instance_vertices[i][VProps.IS_DELETED] = True
|
instance_vertices[i][VProps.IS_DELETED] = True
|
||||||
instance_vertices[i][VProps.UPDATE_TIMESTAMP] = str(
|
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])
|
self.processor.entity_graph.update_vertex(instance_vertices[i])
|
||||||
|
|
||||||
def _set_end_messages(self):
|
def _set_end_messages(self):
|
||||||
|
@ -43,7 +43,7 @@ ALARM = EntityCategory.ALARM
|
|||||||
|
|
||||||
HOST = EntityType.NOVA_HOST
|
HOST = EntityType.NOVA_HOST
|
||||||
INSTANCE = EntityType.NOVA_INSTANCE
|
INSTANCE = EntityType.NOVA_INSTANCE
|
||||||
NODE = EntityType.NODE
|
OPENSTACK_NODE = EntityType.OPENSTACK_NODE
|
||||||
TEST = 'TEST'
|
TEST = 'TEST'
|
||||||
SWITCH = EntityType.SWITCH
|
SWITCH = EntityType.SWITCH
|
||||||
ALARM_ON_VM = 'ALARM_ON_VM'
|
ALARM_ON_VM = 'ALARM_ON_VM'
|
||||||
@ -51,9 +51,9 @@ ALARM_ON_HOST = 'ALARM_ON_HOST'
|
|||||||
TEST_ON_HOST = 'TEST_ON_HOST'
|
TEST_ON_HOST = 'TEST_ON_HOST'
|
||||||
|
|
||||||
v_node = graph_utils.create_vertex(
|
v_node = graph_utils.create_vertex(
|
||||||
vitrage_id=NODE + '111111111111',
|
vitrage_id=OPENSTACK_NODE + '111111111111',
|
||||||
entity_id='111111111111',
|
entity_id='111111111111',
|
||||||
entity_type=NODE,
|
entity_type=OPENSTACK_NODE,
|
||||||
entity_category=RESOURCE)
|
entity_category=RESOURCE)
|
||||||
v_host = graph_utils.create_vertex(
|
v_host = graph_utils.create_vertex(
|
||||||
vitrage_id=HOST + '222222222222',
|
vitrage_id=HOST + '222222222222',
|
||||||
@ -140,7 +140,8 @@ class GraphTestBase(base.BaseTest):
|
|||||||
num_of_tests_per_host):
|
num_of_tests_per_host):
|
||||||
|
|
||||||
start = time.time()
|
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_node)
|
||||||
g.add_vertex(v_switch)
|
g.add_vertex(v_switch)
|
||||||
g.add_edge(e_node_to_switch)
|
g.add_edge(e_node_to_switch)
|
||||||
|
@ -347,17 +347,19 @@ class GraphTest(GraphTestBase):
|
|||||||
self.assertEqual(2, len(all_vertices),
|
self.assertEqual(2, len(all_vertices),
|
||||||
'get_vertices __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),
|
self.assertEqual(1, len(node_vertices),
|
||||||
'get_vertices __len__ node vertices')
|
'get_vertices __len__ node vertices')
|
||||||
found_vertex = node_vertices.pop()
|
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')
|
'get_vertices check node vertex')
|
||||||
|
|
||||||
node_vertices = g.get_vertices(
|
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),
|
self.assertEqual(1, len(node_vertices),
|
||||||
'get_vertices __len__ node vertices')
|
'get_vertices __len__ node vertices')
|
||||||
found_vertex = node_vertices.pop()
|
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')
|
'get_vertices check node vertex')
|
||||||
|
@ -28,7 +28,7 @@ class GraphAlgorithmTest(GraphTestBase):
|
|||||||
def test_graph_query_vertices(self):
|
def test_graph_query_vertices(self):
|
||||||
ga = create_algorithm(self.entity_graph)
|
ga = create_algorithm(self.entity_graph)
|
||||||
|
|
||||||
query = {'==': {VProps.TYPE: NODE}}
|
query = {'==': {VProps.TYPE: OPENSTACK_NODE}}
|
||||||
subgraph = ga.graph_query_vertices(query)
|
subgraph = ga.graph_query_vertices(query)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
1, # For NODE
|
1, # For NODE
|
||||||
@ -37,7 +37,7 @@ class GraphAlgorithmTest(GraphTestBase):
|
|||||||
query = {
|
query = {
|
||||||
'or': [
|
'or': [
|
||||||
{'==': {VProps.TYPE: HOST}},
|
{'==': {VProps.TYPE: HOST}},
|
||||||
{'==': {VProps.TYPE: NODE}}
|
{'==': {VProps.TYPE: OPENSTACK_NODE}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class GraphAlgorithmTest(GraphTestBase):
|
|||||||
{'==': {VProps.TYPE: INSTANCE}},
|
{'==': {VProps.TYPE: INSTANCE}},
|
||||||
{'==': {VProps.CATEGORY: ALARM}},
|
{'==': {VProps.CATEGORY: ALARM}},
|
||||||
{'==': {VProps.TYPE: HOST}},
|
{'==': {VProps.TYPE: HOST}},
|
||||||
{'==': {VProps.TYPE: NODE}}
|
{'==': {VProps.TYPE: OPENSTACK_NODE}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
subgraph = ga.graph_query_vertices(query)
|
subgraph = ga.graph_query_vertices(query)
|
||||||
@ -119,7 +119,7 @@ class GraphAlgorithmTest(GraphTestBase):
|
|||||||
|
|
||||||
query = {
|
query = {
|
||||||
'or': [
|
'or': [
|
||||||
{'==': {VProps.TYPE: NODE}},
|
{'==': {VProps.TYPE: OPENSTACK_NODE}},
|
||||||
{'==': {VProps.CATEGORY: ALARM}},
|
{'==': {VProps.CATEGORY: ALARM}},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -158,10 +158,12 @@ class GraphAlgorithmTest(GraphTestBase):
|
|||||||
t_v_switch = graph_utils.create_vertex(
|
t_v_switch = graph_utils.create_vertex(
|
||||||
vitrage_id='5', entity_category=RESOURCE, entity_type=SWITCH)
|
vitrage_id='5', entity_category=RESOURCE, entity_type=SWITCH)
|
||||||
t_v_node = graph_utils.create_vertex(
|
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(
|
t_v_node_not_in_graph = graph_utils.create_vertex(
|
||||||
vitrage_id='7', entity_category=RESOURCE,
|
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(
|
e_alarm_on_host = graph_utils.create_edge(
|
||||||
t_v_host_alarm.vertex_id, t_v_host.vertex_id, ELabel.ON)
|
t_v_host_alarm.vertex_id, t_v_host.vertex_id, ELabel.ON)
|
||||||
|
@ -128,7 +128,7 @@ class NovaZoneTransformerTest(base.BaseTest):
|
|||||||
for neighbor in neighbors:
|
for neighbor in neighbors:
|
||||||
vertex_type = neighbor.vertex.get(VertexProperties.TYPE)
|
vertex_type = neighbor.vertex.get(VertexProperties.TYPE)
|
||||||
|
|
||||||
if EntityType.NODE == vertex_type:
|
if EntityType.OPENSTACK_NODE == vertex_type:
|
||||||
node_neighbors_counter += 1
|
node_neighbors_counter += 1
|
||||||
self._validate_node_neighbor(neighbor, zone_vertex_id)
|
self._validate_node_neighbor(neighbor, zone_vertex_id)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user