diff --git a/etc/vitrage/states_plugins/vitrage.yaml b/etc/vitrage/states_plugins/vitrage.yaml new file mode 100644 index 000000000..6f74fc23d --- /dev/null +++ b/etc/vitrage/states_plugins/vitrage.yaml @@ -0,0 +1,27 @@ +category: ALARM +states: + - normalized state: + name: CRITICAL + priority: 50 + original states: + - name: CRITICAL + - normalized state: + name: SEVERE + priority: 40 + original states: + - name: SEVERE + - normalized state: + name: WARNING + priority: 30 + original states: + - name: WARNING + - normalized state: + name: UNKNOWN + priority: 20 + original states: + - name: UNKNOWN + - normalized state: + name: DISABLED + priority: 10 + original states: + - name: OK diff --git a/vitrage/synchronizer/plugins/__init__.py b/vitrage/synchronizer/plugins/__init__.py index dd0f5fd73..3b1c97e2b 100644 --- a/vitrage/synchronizer/plugins/__init__.py +++ b/vitrage/synchronizer/plugins/__init__.py @@ -22,6 +22,7 @@ from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN from vitrage.synchronizer.plugins.static_physical import STATIC_PHYSICAL_PLUGIN + OPENSTACK_NODE = 'openstack.node' # Register options for the service diff --git a/vitrage/tests/functional/entity_graph/base.py b/vitrage/tests/functional/base.py similarity index 97% rename from vitrage/tests/functional/entity_graph/base.py rename to vitrage/tests/functional/base.py index 3a8e50388..354f8aab3 100644 --- a/vitrage/tests/functional/entity_graph/base.py +++ b/vitrage/tests/functional/base.py @@ -20,7 +20,7 @@ from vitrage.tests.mocks import mock_syncronizer as mock_sync from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase -class TestEntityGraphFunctionalBase(TestEntityGraphUnitBase): +class TestFunctionalBase(TestEntityGraphUnitBase): def _create_processor_with_graph(self, conf, processor=None): events = self._create_mock_events() diff --git a/vitrage/tests/functional/data_sources/__init__.py b/vitrage/tests/functional/data_sources/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/aodh/__init__.py b/vitrage/tests/functional/data_sources/aodh/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/aodh/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/aodh/test_aodh.py b/vitrage/tests/functional/data_sources/aodh/test_aodh.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/aodh/test_aodh.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/base.py b/vitrage/tests/functional/data_sources/base.py new file mode 100644 index 000000000..1c9c4f2a1 --- /dev/null +++ b/vitrage/tests/functional/data_sources/base.py @@ -0,0 +1,29 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 vitrage.common.constants import EntityCategory +from vitrage.common.constants import VertexProperties as VProps +from vitrage.tests.functional.base import TestFunctionalBase + + +class TestDataSourcesBase(TestFunctionalBase): + + def _find_entity_id_by_type(self, graph, type): + entity_vertices = graph.get_vertices(vertex_attr_filter={ + VProps.CATEGORY: EntityCategory.RESOURCE, + VProps.TYPE: type + }) + self.assertTrue(len(entity_vertices) > 0) + + return entity_vertices[0][VProps.ID] diff --git a/vitrage/tests/functional/data_sources/cinder/__init__.py b/vitrage/tests/functional/data_sources/cinder/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/cinder/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/cinder/test_cinder_volume.py b/vitrage/tests/functional/data_sources/cinder/test_cinder_volume.py new file mode 100644 index 000000000..2e17ba8f0 --- /dev/null +++ b/vitrage/tests/functional/data_sources/cinder/test_cinder_volume.py @@ -0,0 +1,88 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 oslo_config import cfg + +from vitrage.common.constants import EntityCategory +from vitrage.common.constants import VertexProperties as VProps +from vitrage.synchronizer.plugins import CINDER_VOLUME_PLUGIN +from vitrage.synchronizer.plugins import NAGIOS_PLUGIN +from vitrage.synchronizer.plugins import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins import NOVA_INSTANCE_PLUGIN +from vitrage.synchronizer.plugins import NOVA_ZONE_PLUGIN +from vitrage.tests.functional.data_sources.base import \ + TestDataSourcesBase +from vitrage.tests.mocks import mock_syncronizer as mock_sync + + +class TestCinderVolume(TestDataSourcesBase): + + PLUGINS_OPTS = [ + cfg.ListOpt('plugin_type', + default=[NAGIOS_PLUGIN, + NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN, + CINDER_VOLUME_PLUGIN], + help='Names of supported driver data sources'), + + cfg.ListOpt('plugin_path', + default=['vitrage.synchronizer.plugins'], + help='base path for data sources') + ] + + @classmethod + def setUpClass(cls): + super(TestCinderVolume, cls).setUpClass() + cls.conf = cfg.ConfigOpts() + cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') + cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') + cls.load_plugins(cls.conf) + + def test_cinder_volume_validity(self): + # Setup + processor = self._create_processor_with_graph(self.conf) + self.assertEqual(self._num_total_expected_vertices(), + len(processor.entity_graph)) + + spec_list = mock_sync.simple_volume_generators( + volume_num=1, + instance_num=1, + snapshot_events=1) + static_events = mock_sync.generate_random_events_list(spec_list) + cinder_volume_event = static_events[0] + cinder_volume_event['attachments'][0]['server_id'] = \ + self._find_entity_id_by_type(processor.entity_graph, + NOVA_INSTANCE_PLUGIN) + + # Action + processor.process_event(cinder_volume_event) + + # Test assertions + self.assertEqual(self._num_total_expected_vertices() + 1, + len(processor.entity_graph)) + + cinder_vertices = processor.entity_graph.get_vertices( + vertex_attr_filter={ + VProps.CATEGORY: EntityCategory.RESOURCE, + VProps.TYPE: CINDER_VOLUME_PLUGIN + }) + self.assertEqual(1, len(cinder_vertices)) + + cinder_neighbors = processor.entity_graph.neighbors( + cinder_vertices[0].vertex_id) + self.assertEqual(1, len(cinder_neighbors)) + + self.assertEqual(NOVA_INSTANCE_PLUGIN, + cinder_neighbors[0][VProps.TYPE]) diff --git a/vitrage/tests/functional/data_sources/nagios/__init__.py b/vitrage/tests/functional/data_sources/nagios/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/nagios/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/nagios/test_nagios.py b/vitrage/tests/functional/data_sources/nagios/test_nagios.py new file mode 100644 index 000000000..c71af3d51 --- /dev/null +++ b/vitrage/tests/functional/data_sources/nagios/test_nagios.py @@ -0,0 +1,87 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 oslo_config import cfg + +from vitrage.common.constants import EntityCategory +from vitrage.common.constants import VertexProperties as VProps +from vitrage.synchronizer.plugins import NAGIOS_PLUGIN +from vitrage.synchronizer.plugins import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins import NOVA_INSTANCE_PLUGIN +from vitrage.synchronizer.plugins import NOVA_ZONE_PLUGIN +from vitrage.tests.functional.data_sources.base import \ + TestDataSourcesBase +from vitrage.tests.mocks import mock_syncronizer as mock_sync + + +class TestNagios(TestDataSourcesBase): + + PLUGINS_OPTS = [ + cfg.ListOpt('plugin_type', + default=[NAGIOS_PLUGIN, + NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN, + NAGIOS_PLUGIN], + help='Names of supported driver data sources'), + + cfg.ListOpt('plugin_path', + default=['vitrage.synchronizer.plugins'], + help='base path for data sources') + ] + + @classmethod + def setUpClass(cls): + super(TestNagios, cls).setUpClass() + cls.conf = cfg.ConfigOpts() + cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') + cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') + cls.load_plugins(cls.conf) + + def test_nagios_validity(self): + # Setup + processor = self._create_processor_with_graph(self.conf) + self.assertEqual(self._num_total_expected_vertices(), + len(processor.entity_graph)) + + spec_list = mock_sync.simple_nagios_alarm_generators( + host_num=1, + events_num=1) + static_events = mock_sync.generate_random_events_list(spec_list) + nagios_event = static_events[0] + nagios_event['resource_name'] = \ + self._find_entity_id_by_type(processor.entity_graph, + NOVA_HOST_PLUGIN) + nagios_event['status'] = 'critical' + + # Action + processor.process_event(nagios_event) + + # Test assertions + self.assertEqual(self._num_total_expected_vertices() + 1, + len(processor.entity_graph)) + + nagios_vertices = processor.entity_graph.get_vertices( + vertex_attr_filter={ + VProps.CATEGORY: EntityCategory.ALARM, + VProps.TYPE: NAGIOS_PLUGIN + }) + self.assertEqual(1, len(nagios_vertices)) + + nagios_neighbors = processor.entity_graph.neighbors( + nagios_vertices[0].vertex_id) + self.assertEqual(1, len(nagios_neighbors)) + + self.assertEqual(NOVA_HOST_PLUGIN, + nagios_neighbors[0][VProps.TYPE]) diff --git a/vitrage/tests/functional/data_sources/neutron/__init__.py b/vitrage/tests/functional/data_sources/neutron/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/neutron/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/neutron/test_neutron_network.py b/vitrage/tests/functional/data_sources/neutron/test_neutron_network.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/neutron/test_neutron_network.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/neutron/test_neutron_port.py b/vitrage/tests/functional/data_sources/neutron/test_neutron_port.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/neutron/test_neutron_port.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/nova/__init__.py b/vitrage/tests/functional/data_sources/nova/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/nova/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/nova/test_nova_plugins.py b/vitrage/tests/functional/data_sources/nova/test_nova_plugins.py new file mode 100644 index 000000000..2d5d88da7 --- /dev/null +++ b/vitrage/tests/functional/data_sources/nova/test_nova_plugins.py @@ -0,0 +1,45 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 oslo_config import cfg + +from vitrage.tests.functional.data_sources.base import \ + TestDataSourcesBase + + +class TestNovaPlugins(TestDataSourcesBase): + + @classmethod + def setUpClass(cls): + super(TestNovaPlugins, cls).setUpClass() + cls.conf = cfg.ConfigOpts() + cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') + cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') + cls.load_plugins(cls.conf) + + def test_nova_plugins(self): + processor = self._create_processor_with_graph(self.conf) + + self.assertEqual(self._num_total_expected_vertices(), + processor.entity_graph.num_vertices()) + + self.assertEqual(self._num_total_expected_edges(), + processor.entity_graph.num_edges()) + + # 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 data source + # vertex = graph.find_vertex_in_graph() + # bfs_list = graph.algo.bfs(graph) + # self.assertEqual(num_vertices, len(bfs_list)) diff --git a/vitrage/tests/functional/data_sources/static_physical/__init__.py b/vitrage/tests/functional/data_sources/static_physical/__init__.py new file mode 100644 index 000000000..dd32b852f --- /dev/null +++ b/vitrage/tests/functional/data_sources/static_physical/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +__author__ = 'stack' diff --git a/vitrage/tests/functional/data_sources/static_physical/test_static_physical.py b/vitrage/tests/functional/data_sources/static_physical/test_static_physical.py new file mode 100644 index 000000000..e70b4f018 --- /dev/null +++ b/vitrage/tests/functional/data_sources/static_physical/test_static_physical.py @@ -0,0 +1,93 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 oslo_config import cfg + +from vitrage.common.constants import EntityCategory +from vitrage.common.constants import SynchronizerProperties as SyncProps +from vitrage.common.constants import VertexProperties as VProps +from vitrage.synchronizer.plugins import NAGIOS_PLUGIN +from vitrage.synchronizer.plugins import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins import NOVA_INSTANCE_PLUGIN +from vitrage.synchronizer.plugins import NOVA_ZONE_PLUGIN +from vitrage.synchronizer.plugins.static_physical import STATIC_PHYSICAL_PLUGIN +from vitrage.synchronizer.plugins.static_physical import SWITCH +from vitrage.tests.functional.data_sources.base import \ + TestDataSourcesBase +from vitrage.tests.mocks import mock_syncronizer as mock_sync + + +class TestStaticPhysical(TestDataSourcesBase): + + PLUGINS_OPTS = [ + cfg.ListOpt('plugin_type', + default=[NAGIOS_PLUGIN, + NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN, + STATIC_PHYSICAL_PLUGIN], + help='Names of supported driver data sources'), + + cfg.ListOpt('plugin_path', + default=['vitrage.synchronizer.plugins'], + help='base path for data sources') + ] + + @classmethod + def setUpClass(cls): + super(TestStaticPhysical, cls).setUpClass() + cls.conf = cfg.ConfigOpts() + cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') + cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') + cls.load_plugins(cls.conf) + + def test_static_physical_validity(self): + # Setup + processor = self._create_processor_with_graph(self.conf) + processor.transformer_manager.transformers[SWITCH] = \ + processor.transformer_manager.transformers[STATIC_PHYSICAL_PLUGIN] + self.assertEqual(self._num_total_expected_vertices(), + len(processor.entity_graph)) + + spec_list = mock_sync.simple_switch_generators( + switch_num=1, + host_num=1, + snapshot_events=1) + static_events = mock_sync.generate_random_events_list(spec_list) + static_physical_event = static_events[0] + static_physical_event[SyncProps.SYNC_TYPE] = SWITCH + static_physical_event['relationships'][0]['name'] = \ + self._find_entity_id_by_type(processor.entity_graph, + NOVA_HOST_PLUGIN) + + # Action + processor.process_event(static_physical_event) + + # Test assertions + self.assertEqual(self._num_total_expected_vertices() + 1, + len(processor.entity_graph)) + + static_physical_vertices = processor.entity_graph.get_vertices( + vertex_attr_filter={ + VProps.CATEGORY: EntityCategory.RESOURCE, + VProps.TYPE: SWITCH + }) + self.assertEqual(1, len(static_physical_vertices)) + + static_physical_neighbors = processor.entity_graph.neighbors( + static_physical_vertices[0].vertex_id) + self.assertEqual(1, len(static_physical_neighbors)) + + self.assertEqual(NOVA_HOST_PLUGIN, + static_physical_neighbors[0][VProps.TYPE]) diff --git a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py index b49226ed2..d2e572a21 100644 --- a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py +++ b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py @@ -12,14 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. +from datetime import timedelta import threading import time import unittest -from datetime import timedelta from oslo_config import cfg -from six.moves import queue +from six.moves import queue from vitrage.common.constants import EdgeLabels from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -36,12 +36,12 @@ from vitrage.synchronizer.plugins.nagios import NAGIOS_PLUGIN from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN -from vitrage.tests.functional.entity_graph.base import \ - TestEntityGraphFunctionalBase +from vitrage.tests.functional.base import \ + TestFunctionalBase from vitrage.tests.mocks import utils -class TestConsistencyFunctional(TestEntityGraphFunctionalBase): +class TestConsistencyFunctional(TestFunctionalBase): CONSISTENCY_OPTS = [ cfg.IntOpt('min_time_to_delete', diff --git a/vitrage/tests/functional/entity_graph/processor/test_processor.py b/vitrage/tests/functional/entity_graph/processor/test_processor.py index 4e9a8c5f2..6ea638853 100644 --- a/vitrage/tests/functional/entity_graph/processor/test_processor.py +++ b/vitrage/tests/functional/entity_graph/processor/test_processor.py @@ -14,19 +14,15 @@ from oslo_config import cfg -from vitrage.tests.functional.entity_graph.base import \ - TestEntityGraphFunctionalBase +from vitrage.tests.functional.base import \ + TestFunctionalBase -class TestProcessorFunctional(TestEntityGraphFunctionalBase): +class TestProcessorFunctional(TestFunctionalBase): ZONE_SPEC = 'ZONE_SPEC' HOST_SPEC = 'HOST_SPEC' INSTANCE_SPEC = 'INSTANCE_SPEC' - NUM_VERTICES_AFTER_CREATION = 2 - NUM_EDGES_AFTER_CREATION = 1 - NUM_VERTICES_AFTER_DELETION = 1 - NUM_EDGES_AFTER_DELETION = 0 # noinspection PyAttributeOutsideInit,PyPep8Naming @classmethod @@ -40,9 +36,12 @@ class TestProcessorFunctional(TestEntityGraphFunctionalBase): def test_create_entity_graph(self): processor = self._create_processor_with_graph(self.conf) - # check number of entities - num_vertices = len(processor.entity_graph) - self.assertEqual(self._num_total_expected_vertices(), num_vertices) + self.assertEqual(self._num_total_expected_vertices(), + processor.entity_graph.num_vertices()) + + self.assertEqual(self._num_total_expected_edges(), + processor.entity_graph.num_edges()) + # 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 diff --git a/vitrage/tests/functional/entity_graph/states/test_state_manager.py b/vitrage/tests/functional/entity_graph/states/test_state_manager.py index 01fa4f840..293846445 100644 --- a/vitrage/tests/functional/entity_graph/states/test_state_manager.py +++ b/vitrage/tests/functional/entity_graph/states/test_state_manager.py @@ -23,11 +23,11 @@ from vitrage.entity_graph.states.normalized_resource_state import \ NormalizedResourceState from vitrage.synchronizer.plugins.nova.instance.transformer import \ InstanceTransformer -from vitrage.tests.functional.entity_graph.base import \ - TestEntityGraphFunctionalBase +from vitrage.tests.functional.base import \ + TestFunctionalBase -class TestStateManagerFunctional(TestEntityGraphFunctionalBase): +class TestStateManagerFunctional(TestFunctionalBase): # noinspection PyAttributeOutsideInit,PyPep8Naming @classmethod diff --git a/vitrage/tests/functional/evaluator/test_action_executor.py b/vitrage/tests/functional/evaluator/test_action_executor.py index 08b4a7c27..dcabc9e6b 100644 --- a/vitrage/tests/functional/evaluator/test_action_executor.py +++ b/vitrage/tests/functional/evaluator/test_action_executor.py @@ -15,8 +15,8 @@ from oslo_config import cfg from oslo_log import log as logging -from six.moves import queue +from six.moves import queue from vitrage.common.constants import EdgeLabels from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -33,13 +33,13 @@ from vitrage.synchronizer.plugins.base.alarm.properties \ import AlarmProperties as AlarmProps from vitrage.synchronizer.plugins.nagios import NAGIOS_PLUGIN from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN -from vitrage.tests.functional.entity_graph.base import \ - TestEntityGraphFunctionalBase +from vitrage.tests.functional.base import \ + TestFunctionalBase LOG = logging.getLogger(__name__) -class TestActionExecutor(TestEntityGraphFunctionalBase): +class TestActionExecutor(TestFunctionalBase): # noinspection PyPep8Naming @classmethod diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index 4ff5a93f9..748565625 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -14,21 +14,20 @@ from oslo_config import cfg from oslo_log import log as logging -from six.moves import queue +from six.moves import queue from vitrage.common.constants import VertexProperties as VProps from vitrage.evaluator.scenario_evaluator import ScenarioEvaluator from vitrage.evaluator.scenario_repository import ScenarioRepository from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN -from vitrage.tests.functional.entity_graph.base import \ - TestEntityGraphFunctionalBase +from vitrage.tests.functional.base import \ + TestFunctionalBase from vitrage.tests.mocks import utils - LOG = logging.getLogger(__name__) -class TestScenarioEvaluator(TestEntityGraphFunctionalBase): +class TestScenarioEvaluator(TestFunctionalBase): EVALUATOR_OPTS = [ cfg.StrOpt('templates_dir', diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_switch_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/sync_switch_snapshot_dynamic.json index 5d57c805b..c67f063c4 100644 --- a/vitrage/tests/resources/mock_configurations/synchronizer/sync_switch_snapshot_dynamic.json +++ b/vitrage/tests/resources/mock_configurations/synchronizer/sync_switch_snapshot_dynamic.json @@ -1,7 +1,7 @@ { "relationships": [ {"type": "nova\\.host", - "name": "host-[1-9]|switch-[1-9]", + "name": "host-[1-9]", "id": "[1-9]{5}", "relation_type": "contains" } diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_snapshot_dynamic.json index e54066e83..c06ca011d 100644 --- a/vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_snapshot_dynamic.json +++ b/vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_snapshot_dynamic.json @@ -1,5 +1,5 @@ { - "attachments": [{"server_id": "54321"}], + "attachments": [{"server_id": "vm-1"}], "display_name": "volume-0", "created_at": "2015-12-01T12:46:41Z", "status": "In-use", diff --git a/vitrage/tests/unit/entity_graph/base.py b/vitrage/tests/unit/entity_graph/base.py index 811619111..9373e7632 100644 --- a/vitrage/tests/unit/entity_graph/base.py +++ b/vitrage/tests/unit/entity_graph/base.py @@ -145,3 +145,7 @@ class TestEntityGraphUnitBase(base.BaseTest): def _num_total_expected_vertices(self): return self.NUM_NODES + self.NUM_ZONES + self.NUM_HOSTS + \ self.NUM_INSTANCES + + def _num_total_expected_edges(self): + return self.NUM_NODES + self.NUM_ZONES + self.NUM_HOSTS + \ + self.NUM_INSTANCES - 1