vitrage-graph integration
1. with host transformer 2. with zone transformer 3. create graph test Implements: blueprint vitrage-resource-processor Change-Id: I37c490c9b3795cb5860979206bdcb7cb713a6503
This commit is contained in:
parent
99f63dab43
commit
0725f40d6f
@ -63,6 +63,31 @@ def generate_random_events_list(generator_spec_list):
|
||||
return data
|
||||
|
||||
|
||||
def generate_sequential_events_list(generator_spec_list):
|
||||
"""Generates random events for the generators given.
|
||||
|
||||
Each element in the list of generators includes a generator and
|
||||
number of events to generate for it's entities
|
||||
|
||||
:param generator_spec_list: list of generators
|
||||
:type generator_spec_list: list
|
||||
|
||||
:param default_num: default number of events to generate
|
||||
:type default_num: list
|
||||
|
||||
:return list of synchronizer events
|
||||
:rtype list
|
||||
|
||||
"""
|
||||
|
||||
data = []
|
||||
for spec in generator_spec_list:
|
||||
generator = spec[tg.GENERATOR]
|
||||
data += tg.generate_round_robin_data_stream(generator.models,
|
||||
spec[tg.NUM_EVENTS])
|
||||
return data
|
||||
|
||||
|
||||
def simple_instance_generators(host_num, vm_num,
|
||||
snapshot_events=0, update_events=0,
|
||||
snap_vals=None, update_vals=None):
|
||||
|
@ -133,6 +133,23 @@ def generate_data_stream(models, event_num=100):
|
||||
return data_stream
|
||||
|
||||
|
||||
def generate_round_robin_data_stream(models, event_num=100):
|
||||
"""Generates a list of events.
|
||||
|
||||
:param event_num: number of events to generate
|
||||
:type event_num: int
|
||||
:return: list of generated events
|
||||
:rtype: list
|
||||
"""
|
||||
|
||||
instance_num = len(models)
|
||||
data_stream = []
|
||||
for i in xrange(event_num):
|
||||
next_model = models[i % instance_num]
|
||||
data_stream.append(next_model.params)
|
||||
return data_stream
|
||||
|
||||
|
||||
def _get_sync_vm_snapshot_values(spec):
|
||||
"""Generates the static synchronizer values for each vm.
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"OS-EXT-STS:task_state": null,
|
||||
"sync_mode": "snapshot|init_snapshot",
|
||||
"sync_type": "nova\\.instance",
|
||||
"addresses": {
|
||||
"public": [
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
},
|
||||
"_loaded": "True",
|
||||
"hosts": {},
|
||||
"sample_date": "2016-01-05 06:40:07",
|
||||
"sample_date": "2015-12-01T12:46:41Z",
|
||||
"sync_type": "nova\\.zone",
|
||||
"sync_mode": "snapshot|init_snapshot",
|
||||
"zoneName": "zone0",
|
||||
|
@ -15,10 +15,11 @@
|
||||
import unittest
|
||||
|
||||
from vitrage.common.constants import SyncMode
|
||||
|
||||
from vitrage.common.constants import VertexProperties
|
||||
from vitrage.common.utils import get_timezone_aware_time
|
||||
from vitrage.entity_graph.processor import processor as proc
|
||||
from vitrage.tests.mocks import mock_transformer as mock_trans
|
||||
from vitrage.tests.mocks import mock_syncronizer as mock_sync
|
||||
from vitrage.tests.unit import base
|
||||
|
||||
|
||||
@ -27,7 +28,7 @@ class TestProcessor(base.BaseTest):
|
||||
NUM_NODES = 1
|
||||
NUM_ZONES = 2
|
||||
NUM_HOSTS = 4
|
||||
NUM_INSTANCES = 20
|
||||
NUM_INSTANCES = 15
|
||||
ZONE_SPEC = 'ZONE_SPEC'
|
||||
HOST_SPEC = 'HOST_SPEC'
|
||||
INSTANCE_SPEC = 'INSTANCE_SPEC'
|
||||
@ -39,8 +40,6 @@ class TestProcessor(base.BaseTest):
|
||||
def setUp(self):
|
||||
super(TestProcessor, self).setUp()
|
||||
|
||||
# TODO(Alexey): un skip this test when host and zone transformers are ready
|
||||
@unittest.skip('Not ready yet')
|
||||
def test_create_entity_graph(self):
|
||||
processor = self._create_processor_with_graph()
|
||||
|
||||
@ -48,6 +47,7 @@ class TestProcessor(base.BaseTest):
|
||||
num_vertices = len(processor.entity_graph)
|
||||
self.assertEqual(self._num_resources_in_initial_graph(), num_vertices)
|
||||
|
||||
# TODO(Alexey): add this check and to check also the number of edges
|
||||
# check all entities create a tree and no free floating vertices exists
|
||||
# it will be done only after we will have zone plugin
|
||||
# vertex = graph.find_vertex_in_graph()
|
||||
@ -115,9 +115,9 @@ class TestProcessor(base.BaseTest):
|
||||
# update instance event with state running
|
||||
(neighbor_vertex, neighbor_edge) = neighbors[0]
|
||||
old_neighbor_id = neighbor_vertex.vertex_id
|
||||
neighbor_vertex.properties[VertexProperties.ID] = 'host-2'
|
||||
neighbor_vertex.vertex_id = 'RESOURCE_HOST_host-2'
|
||||
neighbor_edge.source_id = 'RESOURCE_HOST_host-2'
|
||||
neighbor_vertex.properties[VertexProperties.ID] = 'newhost-2'
|
||||
neighbor_vertex.vertex_id = 'RESOURCE_HOST_newhost-2'
|
||||
neighbor_edge.source_id = 'RESOURCE_HOST_newhost-2'
|
||||
processor.update_entity(vertex, neighbors)
|
||||
|
||||
# check state
|
||||
@ -146,9 +146,9 @@ class TestProcessor(base.BaseTest):
|
||||
# update instance event with state running
|
||||
(neighbor_vertex, neighbor_edge) = neighbors[0]
|
||||
old_neighbor_id = neighbor_vertex.vertex_id
|
||||
neighbor_vertex.properties[VertexProperties.ID] = 'host-2'
|
||||
neighbor_vertex.vertex_id = 'RESOURCE_HOST_host-2'
|
||||
neighbor_edge.source_id = 'RESOURCE_HOST_host-2'
|
||||
neighbor_vertex.properties[VertexProperties.ID] = 'newhost-2'
|
||||
neighbor_vertex.vertex_id = 'RESOURCE_HOST_newhost-2'
|
||||
neighbor_edge.source_id = 'RESOURCE_HOST_newhost-2'
|
||||
processor._update_neighbors(vertex, neighbors)
|
||||
|
||||
# check state
|
||||
@ -226,16 +226,19 @@ class TestProcessor(base.BaseTest):
|
||||
|
||||
@staticmethod
|
||||
def _create_mock_events():
|
||||
gen_list = mock_trans.simple_zone_generators(2, 10)
|
||||
gen_list.append(mock_trans.simple_host_generators(2, 4, 15))
|
||||
gen_list.append(mock_trans.simple_instance_generators(4, 15, 150))
|
||||
return mock_trans.generate_random_events_list(gen_list)
|
||||
gen_list = mock_sync.simple_zone_generators(
|
||||
2, 4, snapshot_events=2, snap_vals={'sync_mode': 'init_snapshot'})
|
||||
gen_list += mock_sync.simple_host_generators(
|
||||
2, 4, 4, snap_vals={'sync_mode': 'init_snapshot'})
|
||||
gen_list += mock_sync.simple_instance_generators(
|
||||
4, 15, 15, snap_vals={'sync_mode': 'init_snapshot'})
|
||||
return mock_sync.generate_sequential_events_list(gen_list)
|
||||
|
||||
def _create_event(self, spec_type=None, sync_mode=None,
|
||||
event_type=None, properties=None):
|
||||
# generate event
|
||||
spec_list = mock_trans.simple_instance_generators(1, 1, 1)
|
||||
events_list = mock_trans.generate_random_events_list(
|
||||
spec_list = mock_sync.simple_instance_generators(1, 1, 1)
|
||||
events_list = mock_sync.generate_random_events_list(
|
||||
spec_list)
|
||||
|
||||
# update properties
|
||||
|
Loading…
x
Reference in New Issue
Block a user