From 9a77a2255a77684e9c612275749f12dc49dfe64f Mon Sep 17 00:00:00 2001 From: Alexey Weyl Date: Wed, 23 Mar 2016 15:42:09 +0200 Subject: [PATCH] transformer + synchronizer changes Change-Id: I5567af06e8d43da4fb64f7b2032ac363726b84f3 --- vitrage/api/controllers/rest.py | 4 ++- vitrage/cmd/graph.py | 2 +- vitrage/common/constants.py | 4 --- .../api_handler/entity_graph_api.py | 12 ++++--- .../consistency/consistency_enforcer.py | 8 ++--- vitrage/entity_graph/transformer_manager.py | 4 +-- vitrage/evaluator/actions/action_executor.py | 4 +-- vitrage/synchronizer/plugins/__init__.py | 21 +++++++---- vitrage/synchronizer/plugins/aodh/__init__.py | 2 ++ .../synchronizer/plugins/aodh/synchronizer.py | 4 +-- .../synchronizer/plugins/nagios/__init__.py | 2 ++ vitrage/synchronizer/plugins/nagios/config.py | 1 + .../plugins/nagios/synchronizer.py | 4 +-- .../plugins/nagios/transformer.py | 5 +-- vitrage/synchronizer/plugins/nova/base.py | 5 --- .../plugins/nova/host/__init__.py | 2 ++ .../plugins/nova/host/synchronizer.py | 3 +- .../plugins/nova/host/transformer.py | 16 ++++----- .../plugins/nova/instance/__init__.py | 2 ++ .../plugins/nova/instance/synchronizer.py | 3 +- .../plugins/nova/instance/transformer.py | 16 ++++----- .../plugins/nova/zone/__init__.py | 2 ++ .../plugins/nova/zone/synchronizer.py | 3 +- .../plugins/nova/zone/transformer.py | 18 +++++----- .../plugins/static_physical/__init__.py | 5 ++- .../plugins/static_physical/synchronizer.py | 7 ++-- .../plugins/static_physical/transformer.py | 8 ++--- .../synchronizer/plugins/transformer_base.py | 2 +- .../consistency/test_consistency.py | 23 +++++++----- .../evaluator/test_action_executor.py | 24 +++++++------ .../evaluator/test_scenario_evaluator.py | 7 ++-- vitrage/tests/mocks/trace_generator.py | 3 +- vitrage/tests/unit/entity_graph/base.py | 17 +++++---- .../entity_graph/states/test_state_manager.py | 33 +++++++++-------- .../entity_graph/test_transformer_manager.py | 24 ++++++------- vitrage/tests/unit/graph/base.py | 36 ++++++++++++------- vitrage/tests/unit/graph/test_graph.py | 25 +++++++------ vitrage/tests/unit/graph/test_graph_algo.py | 18 ++++++---- .../nagios/test_nagios_alarm_transformer.py | 11 +++--- .../plugins/nagios/test_nagios_config.py | 31 ++++++++++------ .../nova/test_nova_host_transformer.py | 17 ++++----- .../nova/test_nova_instance_transformers.py | 21 +++++------ .../nova/test_nova_zone_transformer.py | 17 ++++----- .../test_static_physical_synchronizer.py | 15 ++++---- .../test_static_physical_transformer.py | 14 ++++---- 45 files changed, 281 insertions(+), 224 deletions(-) diff --git a/vitrage/api/controllers/rest.py b/vitrage/api/controllers/rest.py index 015a0f282..fea939094 100644 --- a/vitrage/api/controllers/rest.py +++ b/vitrage/api/controllers/rest.py @@ -20,13 +20,15 @@ import pecan as pecan from pecan import abort from pecan import rest +from vitrage.synchronizer.plugins import OPENSTACK_NODE + LOG = log.getLogger(__name__) class RootRestController(rest.RestController): @staticmethod - def as_tree(graph, root='openstack.node', reverse=False): + def as_tree(graph, root=OPENSTACK_NODE, reverse=False): linked_graph = json_graph.node_link_graph(graph) if reverse: linked_graph = linked_graph.reverse() diff --git a/vitrage/cmd/graph.py b/vitrage/cmd/graph.py index 91d96f1bc..4241f3de1 100644 --- a/vitrage/cmd/graph.py +++ b/vitrage/cmd/graph.py @@ -19,7 +19,6 @@ import sys from oslo_service import service as os_service from vitrage.common.constants import EntityCategory -from vitrage.common.constants import OPENSTACK_NODE from vitrage.entity_graph.api_handler import service as api_handler_svc from vitrage.entity_graph.consistency import service as consistency_svc from vitrage.entity_graph.initialization_status import InitializationStatus @@ -29,6 +28,7 @@ from vitrage.evaluator.scenario_evaluator import ScenarioEvaluator from vitrage.evaluator.scenario_repository import ScenarioRepository from vitrage import service from vitrage.synchronizer import launcher as synchronizers_launcher +from vitrage.synchronizer.plugins import OPENSTACK_NODE def main(): diff --git a/vitrage/common/constants.py b/vitrage/common/constants.py index 2a405811e..0550c0e39 100644 --- a/vitrage/common/constants.py +++ b/vitrage/common/constants.py @@ -14,10 +14,6 @@ # under the License. -OPENSTACK_NODE = 'openstack.node' -VITRAGE = 'vitrage' - - class VertexProperties(object): CATEGORY = 'category' TYPE = 'type' diff --git a/vitrage/entity_graph/api_handler/entity_graph_api.py b/vitrage/entity_graph/api_handler/entity_graph_api.py index 8f33b28be..3862b3e82 100644 --- a/vitrage/entity_graph/api_handler/entity_graph_api.py +++ b/vitrage/entity_graph/api_handler/entity_graph_api.py @@ -21,6 +21,10 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.graph import create_algorithm from vitrage.graph import Direction +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 import OPENSTACK_NODE LOG = log.getLogger(__name__) @@ -30,10 +34,10 @@ TOPOLOGY_QUERY = { {'==': {VProps.IS_DELETED: False}}, { 'or': [ - {'==': {VProps.TYPE: 'openstack.node'}}, - {'==': {VProps.TYPE: 'nova.zone'}}, - {'==': {VProps.TYPE: 'nova.host'}}, - {'==': {VProps.TYPE: 'nova.instance'}} + {'==': {VProps.TYPE: OPENSTACK_NODE}}, + {'==': {VProps.TYPE: NOVA_INSTANCE_PLUGIN}}, + {'==': {VProps.TYPE: NOVA_HOST_PLUGIN}}, + {'==': {VProps.TYPE: NOVA_ZONE_PLUGIN}} ] } ] diff --git a/vitrage/entity_graph/consistency/consistency_enforcer.py b/vitrage/entity_graph/consistency/consistency_enforcer.py index f8b512277..c4b53be46 100644 --- a/vitrage/entity_graph/consistency/consistency_enforcer.py +++ b/vitrage/entity_graph/consistency/consistency_enforcer.py @@ -18,10 +18,10 @@ import time from oslo_log import log from vitrage.common.constants import EntityCategory -from vitrage.common.constants import OPENSTACK_NODE from vitrage.common.constants import VertexProperties as VProps -from vitrage.common.constants import VITRAGE from vitrage.common.datetime_utils import utcnow +from vitrage.evaluator.actions.evaluator_event_transformer import VITRAGE_TYPE +from vitrage.synchronizer.plugins import OPENSTACK_NODE LOG = log.getLogger(__name__) @@ -92,7 +92,7 @@ class ConsistencyEnforcer(object): def _find_stale_entities(self): query = { 'and': [ - {'!=': {VProps.TYPE: VITRAGE}}, + {'!=': {VProps.TYPE: VITRAGE_TYPE}}, {'<': {VProps.SAMPLE_TIMESTAMP: str(utcnow() - timedelta( seconds=2 * self.conf.synchronizer.snapshots_interval))}} ] @@ -119,7 +119,7 @@ class ConsistencyEnforcer(object): query = { 'and': [ {'==': {VProps.CATEGORY: EntityCategory.ALARM}}, - {'==': {VProps.TYPE: VITRAGE}}, + {'==': {VProps.TYPE: VITRAGE_TYPE}}, {'<': {VProps.SAMPLE_TIMESTAMP: timestamp}} ] } diff --git a/vitrage/entity_graph/transformer_manager.py b/vitrage/entity_graph/transformer_manager.py index 8c2c76077..faf657d1e 100644 --- a/vitrage/entity_graph/transformer_manager.py +++ b/vitrage/entity_graph/transformer_manager.py @@ -17,11 +17,11 @@ from oslo_log import log as logging from oslo_utils import importutils from vitrage.common.constants import SynchronizerProperties as SyncProps -from vitrage.common.constants import VITRAGE from vitrage.common.exception import VitrageTransformerError from vitrage.common.utils import opt_exists from vitrage.evaluator.actions.evaluator_event_transformer import \ EvaluatorEventTransformer +from vitrage.evaluator.actions.evaluator_event_transformer import VITRAGE_TYPE LOG = logging.getLogger(__name__) ENTITIES = 'entities' @@ -45,7 +45,7 @@ class TransformerManager(object): transformers[entity] = importutils.import_object( conf[plugin].transformer, transformers) - transformers[VITRAGE] = importutils.import_object( + transformers[VITRAGE_TYPE] = importutils.import_object( "%s.%s" % (EvaluatorEventTransformer.__module__, EvaluatorEventTransformer.__name__), transformers) diff --git a/vitrage/evaluator/actions/action_executor.py b/vitrage/evaluator/actions/action_executor.py index a0738a36d..3210b4dfe 100644 --- a/vitrage/evaluator/actions/action_executor.py +++ b/vitrage/evaluator/actions/action_executor.py @@ -20,10 +20,10 @@ from oslo_utils import importutils from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.constants import VertexProperties as VProps -from vitrage.common.constants import VITRAGE from vitrage.common import datetime_utils from vitrage.evaluator.actions.base import ActionMode from vitrage.evaluator.actions.base import ActionType +from vitrage.evaluator.actions.evaluator_event_transformer import VITRAGE_TYPE 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 NOTIFY @@ -116,7 +116,7 @@ class ActionExecutor(object): def _add_default_properties(event): event[SyncProps.SYNC_MODE] = SyncMode.UPDATE - event[SyncProps.SYNC_TYPE] = VITRAGE + event[SyncProps.SYNC_TYPE] = VITRAGE_TYPE event[VProps.UPDATE_TIMESTAMP] = str(datetime_utils.utcnow()) event[VProps.SAMPLE_TIMESTAMP] = str(datetime_utils.utcnow()) diff --git a/vitrage/synchronizer/plugins/__init__.py b/vitrage/synchronizer/plugins/__init__.py index 6f2fdaf8e..1b34b2962 100644 --- a/vitrage/synchronizer/plugins/__init__.py +++ b/vitrage/synchronizer/plugins/__init__.py @@ -14,15 +14,24 @@ from oslo_config import cfg +from vitrage.synchronizer.plugins.aodh import AODH_PLUGIN +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.synchronizer.plugins.static_physical import STATIC_PHYSICAL_PLUGIN + +OPENSTACK_NODE = 'openstack.node' + # Register options for the service OPTS = [ cfg.ListOpt('plugin_type', - default=['nagios', - 'nova.host', - 'nova.instance', - 'nova.zone', - 'static_physical', - 'aodh'], + default=[NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN, + NAGIOS_PLUGIN, + STATIC_PHYSICAL_PLUGIN, + AODH_PLUGIN], help='Names of supported plugins'), ] diff --git a/vitrage/synchronizer/plugins/aodh/__init__.py b/vitrage/synchronizer/plugins/aodh/__init__.py index 517953b76..9024bcd93 100644 --- a/vitrage/synchronizer/plugins/aodh/__init__.py +++ b/vitrage/synchronizer/plugins/aodh/__init__.py @@ -14,6 +14,8 @@ from oslo_config import cfg +AODH_PLUGIN = 'aodh' + OPTS = [ cfg.StrOpt('transformer', default='vitrage.synchronizer.plugins.aodh.' diff --git a/vitrage/synchronizer/plugins/aodh/synchronizer.py b/vitrage/synchronizer/plugins/aodh/synchronizer.py index 228788fa2..a4db2a8fa 100644 --- a/vitrage/synchronizer/plugins/aodh/synchronizer.py +++ b/vitrage/synchronizer/plugins/aodh/synchronizer.py @@ -15,6 +15,7 @@ from oslo_log import log from vitrage import clients +from vitrage.synchronizer.plugins.aodh import AODH_PLUGIN from vitrage.synchronizer.plugins.aodh.properties import AodhProperties \ as AodhProps from vitrage.synchronizer.plugins.aodh.properties import AodhState @@ -22,7 +23,6 @@ from vitrage.synchronizer.plugins.base.alarm.synchronizer \ import BaseAlarmSynchronizer LOG = log.getLogger(__name__) -AODH = 'aodh' class AodhSynchronizer(BaseAlarmSynchronizer): @@ -31,7 +31,7 @@ class AodhSynchronizer(BaseAlarmSynchronizer): self.client = clients.ceilometer_client(conf) def _sync_type(self): - return AODH + return AODH_PLUGIN def _alarm_key(self, alarm): return alarm[AodhProps.NAME] diff --git a/vitrage/synchronizer/plugins/nagios/__init__.py b/vitrage/synchronizer/plugins/nagios/__init__.py index 13caef990..01dda52e9 100644 --- a/vitrage/synchronizer/plugins/nagios/__init__.py +++ b/vitrage/synchronizer/plugins/nagios/__init__.py @@ -14,6 +14,8 @@ from oslo_config import cfg +NAGIOS_PLUGIN = 'nagios' + OPTS = [ cfg.StrOpt('transformer', default='vitrage.synchronizer.plugins.nagios.' diff --git a/vitrage/synchronizer/plugins/nagios/config.py b/vitrage/synchronizer/plugins/nagios/config.py index a322cd323..0a7244928 100644 --- a/vitrage/synchronizer/plugins/nagios/config.py +++ b/vitrage/synchronizer/plugins/nagios/config.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + import re from oslo_log import log diff --git a/vitrage/synchronizer/plugins/nagios/synchronizer.py b/vitrage/synchronizer/plugins/nagios/synchronizer.py index d346c3c91..972e3c99c 100644 --- a/vitrage/synchronizer/plugins/nagios/synchronizer.py +++ b/vitrage/synchronizer/plugins/nagios/synchronizer.py @@ -23,13 +23,13 @@ from vitrage.i18n import _LW from vitrage.synchronizer.plugins.base.alarm.synchronizer \ import BaseAlarmSynchronizer from vitrage.synchronizer.plugins.nagios.config import NagiosConfig +from vitrage.synchronizer.plugins.nagios import NAGIOS_PLUGIN from vitrage.synchronizer.plugins.nagios.parser import NagiosParser from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties \ as NagiosProps from vitrage.synchronizer.plugins.nagios.properties import NagiosStatus LOG = log.getLogger(__name__) -NAGIOS = 'nagios' class NagiosSynchronizer(BaseAlarmSynchronizer): @@ -41,7 +41,7 @@ class NagiosSynchronizer(BaseAlarmSynchronizer): self.config = NagiosConfig(conf) def _sync_type(self): - return NAGIOS + return NAGIOS_PLUGIN def _alarm_key(self, alarm): return self.ServiceKey(host_name=alarm[NagiosProps.RESOURCE_NAME], diff --git a/vitrage/synchronizer/plugins/nagios/transformer.py b/vitrage/synchronizer/plugins/nagios/transformer.py index 7ab3b92a6..c28078da8 100644 --- a/vitrage/synchronizer/plugins/nagios/transformer.py +++ b/vitrage/synchronizer/plugins/nagios/transformer.py @@ -25,10 +25,11 @@ from vitrage.synchronizer.plugins.base.alarm.properties \ from vitrage.synchronizer.plugins.base.alarm.transformer \ import BaseAlarmTransformer from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.static_physical import SWITCH from vitrage.synchronizer.plugins import transformer_base as tbase LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' class NagiosTransformer(BaseAlarmTransformer): @@ -74,7 +75,7 @@ class NagiosTransformer(BaseAlarmTransformer): tbase.TIMESTAMP_FORMAT) resource_type = entity_event[NagiosProperties.RESOURCE_TYPE] - if resource_type == NOVA_HOST or resource_type == 'switch': + if resource_type == NOVA_HOST_PLUGIN or resource_type == SWITCH: return [self._create_neighbor( vitrage_id, timestamp, diff --git a/vitrage/synchronizer/plugins/nova/base.py b/vitrage/synchronizer/plugins/nova/base.py index 4c85b4a14..789a75978 100644 --- a/vitrage/synchronizer/plugins/nova/base.py +++ b/vitrage/synchronizer/plugins/nova/base.py @@ -18,11 +18,6 @@ from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase class NovaBase(SynchronizerBase): - - NOVA_INSTANCE = 'nova.instance' - NOVA_HOST = 'nova.host' - NOVA_ZONE = 'nova.zone' - def __init__(self, conf): super(NovaBase, self).__init__() self.client = clients.nova_client(conf) diff --git a/vitrage/synchronizer/plugins/nova/host/__init__.py b/vitrage/synchronizer/plugins/nova/host/__init__.py index ccf7c1a66..fae366de5 100644 --- a/vitrage/synchronizer/plugins/nova/host/__init__.py +++ b/vitrage/synchronizer/plugins/nova/host/__init__.py @@ -14,6 +14,8 @@ from oslo_config import cfg +NOVA_HOST_PLUGIN = 'nova.host' + OPTS = [ cfg.StrOpt('transformer', default='vitrage.synchronizer.plugins.nova.host.' diff --git a/vitrage/synchronizer/plugins/nova/host/synchronizer.py b/vitrage/synchronizer/plugins/nova/host/synchronizer.py index d16ae6713..96142a857 100644 --- a/vitrage/synchronizer/plugins/nova/host/synchronizer.py +++ b/vitrage/synchronizer/plugins/nova/host/synchronizer.py @@ -13,6 +13,7 @@ # under the License. from vitrage.synchronizer.plugins.nova.base import NovaBase +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN class HostSynchronizer(NovaBase): @@ -29,6 +30,6 @@ class HostSynchronizer(NovaBase): def get_all(self, sync_mode): return self.make_pickleable( self.filter_none_compute_hosts(self.client.hosts.list()), - self.NOVA_HOST, + NOVA_HOST_PLUGIN, sync_mode, 'manager') diff --git a/vitrage/synchronizer/plugins/nova/host/transformer.py b/vitrage/synchronizer/plugins/nova/host/transformer.py index 1bc037a22..7b3cd3456 100644 --- a/vitrage/synchronizer/plugins/nova/host/transformer.py +++ b/vitrage/synchronizer/plugins/nova/host/transformer.py @@ -22,19 +22,17 @@ from vitrage.common.constants import VertexProperties as VProps import vitrage.graph.utils as graph_utils from vitrage.synchronizer.plugins.base.resource.transformer import \ BaseResourceTransformer +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN from vitrage.synchronizer.plugins import transformer_base from vitrage.synchronizer.plugins.transformer_base import extract_field_value LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' -NOVA_ZONE = 'nova.zone' class HostTransformer(BaseResourceTransformer): - HOST_TYPE = NOVA_HOST - # Fields returned from Nova Availability Zone snapshot HOST_NAME = { SyncMode.SNAPSHOT: ('_info', 'host_name',), @@ -69,7 +67,7 @@ class HostTransformer(BaseResourceTransformer): entity_key, entity_id=host_name, entity_category=EntityCategory.RESOURCE, - entity_type=self.HOST_TYPE, + entity_type=NOVA_HOST_PLUGIN, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, metadata=metadata) @@ -97,7 +95,7 @@ class HostTransformer(BaseResourceTransformer): host_vertex_id, zone_name_path): - zone_transformer = self.transformers[NOVA_ZONE] + zone_transformer = self.transformers[NOVA_ZONE_PLUGIN] if zone_transformer: @@ -125,7 +123,7 @@ class HostTransformer(BaseResourceTransformer): entity_event, self.HOST_NAME[entity_event[SyncProps.SYNC_MODE]]) - key_fields = self._key_values(self.HOST_TYPE, host_name) + key_fields = self._key_values(NOVA_HOST_PLUGIN, host_name) return transformer_base.build_key(key_fields) def create_placeholder_vertex(self, **kwargs): @@ -133,13 +131,13 @@ class HostTransformer(BaseResourceTransformer): LOG.error('Cannot create placeholder vertex. Missing property ID') raise ValueError('Missing property ID') - key_fields = self._key_values(self.HOST_TYPE, kwargs[VProps.ID]) + key_fields = self._key_values(NOVA_HOST_PLUGIN, kwargs[VProps.ID]) return graph_utils.create_vertex( transformer_base.build_key(key_fields), entity_id=kwargs[VProps.ID], entity_category=EntityCategory.RESOURCE, - entity_type=self.HOST_TYPE, + entity_type=NOVA_HOST_PLUGIN, sample_timestamp=kwargs[VProps.SAMPLE_TIMESTAMP], is_placeholder=True, entity_state=kwargs[VProps.STATE] diff --git a/vitrage/synchronizer/plugins/nova/instance/__init__.py b/vitrage/synchronizer/plugins/nova/instance/__init__.py index 8538d9225..e8639857f 100644 --- a/vitrage/synchronizer/plugins/nova/instance/__init__.py +++ b/vitrage/synchronizer/plugins/nova/instance/__init__.py @@ -14,6 +14,8 @@ from oslo_config import cfg +NOVA_INSTANCE_PLUGIN = 'nova.instance' + OPTS = [ cfg.StrOpt('transformer', default='vitrage.synchronizer.plugins.nova.instance.' diff --git a/vitrage/synchronizer/plugins/nova/instance/synchronizer.py b/vitrage/synchronizer/plugins/nova/instance/synchronizer.py index b792f7fd1..784e7888d 100644 --- a/vitrage/synchronizer/plugins/nova/instance/synchronizer.py +++ b/vitrage/synchronizer/plugins/nova/instance/synchronizer.py @@ -13,6 +13,7 @@ # under the License. from vitrage.synchronizer.plugins.nova.base import NovaBase +from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN class InstanceSynchronizer(NovaBase): @@ -27,6 +28,6 @@ class InstanceSynchronizer(NovaBase): def get_all(self, sync_mode): return self.make_pickleable( self.filter_instances(self.client.servers.list()), - self.NOVA_INSTANCE, + NOVA_INSTANCE_PLUGIN, sync_mode, 'manager') diff --git a/vitrage/synchronizer/plugins/nova/instance/transformer.py b/vitrage/synchronizer/plugins/nova/instance/transformer.py index 6b7aaa399..71abb5fae 100644 --- a/vitrage/synchronizer/plugins/nova/instance/transformer.py +++ b/vitrage/synchronizer/plugins/nova/instance/transformer.py @@ -24,19 +24,17 @@ from vitrage.common.exception import VitrageTransformerError import vitrage.graph.utils as graph_utils from vitrage.synchronizer.plugins.base.resource.transformer import \ BaseResourceTransformer +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN from vitrage.synchronizer.plugins import transformer_base from vitrage.synchronizer.plugins.transformer_base import extract_field_value LOG = logging.getLogger(__name__) -NOVA_INSTANCE = 'nova.instance' -NOVA_HOST = 'nova.host' class InstanceTransformer(BaseResourceTransformer): - INSTANCE_TYPE = NOVA_INSTANCE - # Fields returned from Nova Instance snapshot INSTANCE_ID = { SyncMode.SNAPSHOT: ('id',), @@ -121,7 +119,7 @@ class InstanceTransformer(BaseResourceTransformer): entity_key, entity_id=entity_id, entity_category=EntityCategory.RESOURCE, - entity_type=self.INSTANCE_TYPE, + entity_type=NOVA_INSTANCE_PLUGIN, entity_state=state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, @@ -132,7 +130,7 @@ class InstanceTransformer(BaseResourceTransformer): sync_mode = entity_event[SyncProps.SYNC_MODE] neighbors = [] - host_transformer = self.transformers[NOVA_HOST] + host_transformer = self.transformers[NOVA_HOST_PLUGIN] if host_transformer: host_neighbor = self._create_host_neighbor( @@ -170,7 +168,7 @@ class InstanceTransformer(BaseResourceTransformer): entity_event, self.INSTANCE_ID[entity_event[SyncProps.SYNC_MODE]]) - key_fields = self._key_values(self.INSTANCE_TYPE, instance_id) + key_fields = self._key_values(NOVA_INSTANCE_PLUGIN, instance_id) return transformer_base.build_key(key_fields) @staticmethod @@ -196,12 +194,12 @@ class InstanceTransformer(BaseResourceTransformer): LOG.error('Cannot create placeholder vertex. Missing property ID') raise ValueError('Missing property ID') - key_fields = self._key_values(self.INSTANCE_TYPE, kwargs[VProps.ID]) + key_fields = self._key_values(NOVA_INSTANCE_PLUGIN, kwargs[VProps.ID]) return graph_utils.create_vertex( transformer_base.build_key(key_fields), entity_id=kwargs[VProps.ID], entity_category=EntityCategory.RESOURCE, - entity_type=self.INSTANCE_TYPE, + entity_type=NOVA_INSTANCE_PLUGIN, sample_timestamp=kwargs[VProps.SAMPLE_TIMESTAMP], is_placeholder=True) diff --git a/vitrage/synchronizer/plugins/nova/zone/__init__.py b/vitrage/synchronizer/plugins/nova/zone/__init__.py index e92c1b953..1c1532156 100644 --- a/vitrage/synchronizer/plugins/nova/zone/__init__.py +++ b/vitrage/synchronizer/plugins/nova/zone/__init__.py @@ -14,6 +14,8 @@ from oslo_config import cfg +NOVA_ZONE_PLUGIN = 'nova.zone' + OPTS = [ cfg.StrOpt('transformer', default='vitrage.synchronizer.plugins.nova.zone.' diff --git a/vitrage/synchronizer/plugins/nova/zone/synchronizer.py b/vitrage/synchronizer/plugins/nova/zone/synchronizer.py index b91cc7fad..2e553abed 100644 --- a/vitrage/synchronizer/plugins/nova/zone/synchronizer.py +++ b/vitrage/synchronizer/plugins/nova/zone/synchronizer.py @@ -13,6 +13,7 @@ # under the License. from vitrage.synchronizer.plugins.nova.base import NovaBase +from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN class ZoneSynchronizer(NovaBase): @@ -29,6 +30,6 @@ class ZoneSynchronizer(NovaBase): def get_all(self, sync_mode): return self.make_pickleable(self.filter_internal_zone( self.client.availability_zones.list()), - self.NOVA_ZONE, + NOVA_ZONE_PLUGIN, sync_mode, 'manager') diff --git a/vitrage/synchronizer/plugins/nova/zone/transformer.py b/vitrage/synchronizer/plugins/nova/zone/transformer.py index 4d5b0fee8..9700feea4 100644 --- a/vitrage/synchronizer/plugins/nova/zone/transformer.py +++ b/vitrage/synchronizer/plugins/nova/zone/transformer.py @@ -22,19 +22,17 @@ from vitrage.common.constants import VertexProperties as VProps import vitrage.graph.utils as graph_utils from vitrage.synchronizer.plugins.base.resource.transformer import \ BaseResourceTransformer +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN from vitrage.synchronizer.plugins import transformer_base from vitrage.synchronizer.plugins.transformer_base import extract_field_value LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' -NOVA_ZONE = 'nova.zone' class ZoneTransformer(BaseResourceTransformer): - ZONE_TYPE = NOVA_ZONE - STATE_AVAILABLE = 'available' STATE_UNAVAILABLE = 'unavailable' @@ -97,7 +95,7 @@ class ZoneTransformer(BaseResourceTransformer): entity_key, entity_id=zone_name, entity_category=EntityCategory.RESOURCE, - entity_type=self.ZONE_TYPE, + entity_type=NOVA_ZONE_PLUGIN, entity_state=state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, @@ -112,7 +110,7 @@ class ZoneTransformer(BaseResourceTransformer): neighbors = [self._create_node_neighbor(zone_vertex_id)] hosts = extract_field_value(entity_event, self.HOSTS[sync_mode]) - host_transformer = self.transformers[NOVA_HOST] + host_transformer = self.transformers[NOVA_HOST_PLUGIN] if host_transformer: for key in hosts: @@ -154,7 +152,7 @@ class ZoneTransformer(BaseResourceTransformer): def _create_host_neighbor(self, zone_id, host_name, host_state, sample_timestamp): - host_transformer = self.transformers['nova.host'] + host_transformer = self.transformers[NOVA_HOST_PLUGIN] properties = { VProps.ID: host_name, @@ -177,7 +175,7 @@ class ZoneTransformer(BaseResourceTransformer): entity_event, self.ZONE_NAME[entity_event[SyncProps.SYNC_MODE]]) - key_fields = self._key_values(self.ZONE_TYPE, zone_name) + key_fields = self._key_values(NOVA_ZONE_PLUGIN, zone_name) return transformer_base.build_key(key_fields) def create_placeholder_vertex(self, **kwargs): @@ -186,12 +184,12 @@ class ZoneTransformer(BaseResourceTransformer): raise ValueError('Missing property ID') key = transformer_base.build_key( - self._key_values(self.ZONE_TYPE, kwargs[VProps.ID])) + self._key_values(NOVA_ZONE_PLUGIN, kwargs[VProps.ID])) return graph_utils.create_vertex( key, entity_id=kwargs[VProps.ID], entity_category=EntityCategory.RESOURCE, - entity_type=self.ZONE_TYPE, + entity_type=NOVA_ZONE_PLUGIN, sample_timestamp=kwargs[VProps.SAMPLE_TIMESTAMP], is_placeholder=True) diff --git a/vitrage/synchronizer/plugins/static_physical/__init__.py b/vitrage/synchronizer/plugins/static_physical/__init__.py index 7bb69db6b..f9848a6b6 100644 --- a/vitrage/synchronizer/plugins/static_physical/__init__.py +++ b/vitrage/synchronizer/plugins/static_physical/__init__.py @@ -14,6 +14,9 @@ from oslo_config import cfg +STATIC_PHYSICAL_PLUGIN = 'static_physical' +SWITCH = 'switch' + OPTS = [ cfg.StrOpt('transformer', default='vitrage.synchronizer.plugins.static_physical.' @@ -34,6 +37,6 @@ OPTS = [ cfg.StrOpt('directory', default='/etc/vitrage/static_plugins', help='Static physical plugins directory'), cfg.ListOpt('entities', - default=['switch'], + default=[SWITCH], help='Static physical entity types list') ] diff --git a/vitrage/synchronizer/plugins/static_physical/synchronizer.py b/vitrage/synchronizer/plugins/static_physical/synchronizer.py index 696bbe22e..e2df0d17c 100644 --- a/vitrage/synchronizer/plugins/static_physical/synchronizer.py +++ b/vitrage/synchronizer/plugins/static_physical/synchronizer.py @@ -18,10 +18,9 @@ from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties as VProps from vitrage.common import file_utils +from vitrage.synchronizer.plugins.static_physical import STATIC_PHYSICAL_PLUGIN from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase -STATIC_PHYSICAL = 'static_physical' - class StaticPhysicalSynchronizer(SynchronizerBase): ENTITIES_SECTION = 'entities' @@ -33,12 +32,12 @@ class StaticPhysicalSynchronizer(SynchronizerBase): def get_all(self, sync_mode): return self.make_pickleable(self._get_all_entities(), - STATIC_PHYSICAL, + STATIC_PHYSICAL_PLUGIN, sync_mode) def get_changes(self, sync_mode): return self.make_pickleable(self._get_changes_entities(), - STATIC_PHYSICAL, + STATIC_PHYSICAL_PLUGIN, sync_mode) def _get_all_entities(self): diff --git a/vitrage/synchronizer/plugins/static_physical/transformer.py b/vitrage/synchronizer/plugins/static_physical/transformer.py index 521bb4fa5..0a99d16c0 100644 --- a/vitrage/synchronizer/plugins/static_physical/transformer.py +++ b/vitrage/synchronizer/plugins/static_physical/transformer.py @@ -23,17 +23,17 @@ from vitrage.common.exception import VitrageTransformerError import vitrage.graph.utils as graph_utils from vitrage.synchronizer.plugins.base.resource.transformer import \ BaseResourceTransformer +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.static_physical import SWITCH from vitrage.synchronizer.plugins import transformer_base LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' class StaticPhysicalTransformer(BaseResourceTransformer): RELATION_TYPE = 'relation_type' RELATIONSHIPS_SECTION = 'relationships' - SWITCH = 'switch' def __init__(self, transformers): self.transformers = transformers @@ -163,8 +163,8 @@ class StaticPhysicalTransformer(BaseResourceTransformer): def _register_relations_direction(self): self.relation_direction = {} - relationship = (self.SWITCH, NOVA_HOST) + relationship = (SWITCH, NOVA_HOST_PLUGIN) self.relation_direction[relationship] = True - relationship = (self.SWITCH, self.SWITCH) + relationship = (SWITCH, SWITCH) self.relation_direction[relationship] = True diff --git a/vitrage/synchronizer/plugins/transformer_base.py b/vitrage/synchronizer/plugins/transformer_base.py index 2578f0d57..95538c717 100644 --- a/vitrage/synchronizer/plugins/transformer_base.py +++ b/vitrage/synchronizer/plugins/transformer_base.py @@ -21,11 +21,11 @@ import six import vitrage.common.constants as cons from vitrage.common.constants import EventAction -from vitrage.common.constants import OPENSTACK_NODE from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.exception import VitrageTransformerError import vitrage.graph.utils as graph_utils +from vitrage.synchronizer.plugins import OPENSTACK_NODE LOG = logging.getLogger(__name__) diff --git a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py index 08db0cefd..90e7edeab 100644 --- a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py +++ b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py @@ -19,6 +19,7 @@ import unittest from datetime import timedelta from oslo_config import cfg 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 @@ -30,6 +31,10 @@ from vitrage.entity_graph.processor.processor import Processor from vitrage.evaluator.scenario_evaluator import ScenarioEvaluator from vitrage.evaluator.scenario_repository import ScenarioRepository import vitrage.graph.utils as graph_utils +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.mocks import utils @@ -154,12 +159,12 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase): # Test Assertions instance_vertices = self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: self.NOVA_INSTANCE + VProps.TYPE: NOVA_INSTANCE_PLUGIN }) is_deleted_instance_vertices = \ self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: self.NOVA_INSTANCE, + VProps.TYPE: NOVA_INSTANCE_PLUGIN, VProps.IS_DELETED: True }) self.assertEqual(self.NUM_INSTANCES - 3, len(instance_vertices)) @@ -179,7 +184,7 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase): # check number of instances in graph instance_vertices = self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: self.NOVA_INSTANCE + VProps.TYPE: NOVA_INSTANCE_PLUGIN }) self.assertEqual(self.NUM_INSTANCES, len(instance_vertices)) @@ -199,11 +204,11 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase): self.processor.entity_graph.update_vertex(instance_vertices[i]) def _set_end_messages(self): - self.initialization_status.end_messages[self.NOVA_ZONE] = True - self.initialization_status.end_messages[self.NOVA_HOST] = True - self.initialization_status.end_messages[self.NOVA_INSTANCE] = \ + self.initialization_status.end_messages[NOVA_ZONE_PLUGIN] = True + self.initialization_status.end_messages[NOVA_HOST_PLUGIN] = True + self.initialization_status.end_messages[NOVA_INSTANCE_PLUGIN] = \ True - self.initialization_status.end_messages[self.NAGIOS] = True + self.initialization_status.end_messages[NAGIOS_PLUGIN] = True self.initialization_status.status = \ self.initialization_status.RECEIVED_ALL_END_MESSAGES @@ -211,7 +216,7 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase): # find hosts and instances host_vertices = self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: self.NOVA_HOST + VProps.TYPE: NOVA_HOST_PLUGIN }) # add host alarms + deduced alarms @@ -221,7 +226,7 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase): alarm_name = '%s:%s' % ('nagios_alarm_on_host_', host_vertex[VProps.NAME]) alarms_on_hosts_list.append( - self._create_alarm(alarm_name, self.NAGIOS)) + self._create_alarm(alarm_name, NAGIOS_PLUGIN)) self.processor.entity_graph.add_vertex(alarms_on_hosts_list[index]) edge = graph_utils.create_edge( alarms_on_hosts_list[index].vertex_id, diff --git a/vitrage/tests/functional/evaluator/test_action_executor.py b/vitrage/tests/functional/evaluator/test_action_executor.py index ce8d1d949..3066b7dca 100644 --- a/vitrage/tests/functional/evaluator/test_action_executor.py +++ b/vitrage/tests/functional/evaluator/test_action_executor.py @@ -20,17 +20,19 @@ 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 -from vitrage.common.constants import VITRAGE from vitrage.entity_graph.states.normalized_resource_state import \ NormalizedResourceState from vitrage.evaluator.actions.action_executor import ActionExecutor from vitrage.evaluator.actions.base import ActionMode from vitrage.evaluator.actions.base import ActionType +from vitrage.evaluator.actions.evaluator_event_transformer import VITRAGE_TYPE from vitrage.evaluator.template import ActionSpecs from vitrage.evaluator.template_fields import TemplateFields as TFields from vitrage.service import load_plugin 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 @@ -54,7 +56,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: self.NOVA_HOST} + vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) host_vertex_before = host_vertices[0] @@ -101,21 +103,21 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: self.NOVA_HOST} + vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) host_1 = host_vertices[0] nagios_event1 = TestActionExecutor._get_nagios_event( - host_1.get(VProps.ID), self.NOVA_HOST) + host_1.get(VProps.ID), NOVA_HOST_PLUGIN) processor.process_event(nagios_event1) host_2 = host_vertices[1] nagios_event2 = TestActionExecutor._get_nagios_event( - host_2.get(VProps.ID), self.NOVA_HOST) + host_2.get(VProps.ID), NOVA_HOST_PLUGIN) processor.process_event(nagios_event2) - alarms_attrs = {VProps.TYPE: self.NAGIOS} + alarms_attrs = {VProps.TYPE: NAGIOS_PLUGIN} alarms_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=alarms_attrs) @@ -151,7 +153,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: self.NOVA_HOST} + vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) @@ -167,7 +169,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): # Raise alarm action adds new vertex with type vitrage to the graph action_spec = ActionSpecs(ActionType.RAISE_ALARM, targets, props) - alarm_vertex_attrs = {VProps.TYPE: VITRAGE} + alarm_vertex_attrs = {VProps.TYPE: VITRAGE_TYPE} before_alarms = processor.entity_graph.get_vertices( vertex_attr_filter=alarm_vertex_attrs) event_queue = queue.Queue() @@ -195,7 +197,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): self.assertEqual(alarm.properties[VProps.CATEGORY], EntityCategory.ALARM) - self.assertEqual(alarm.properties[VProps.TYPE], VITRAGE) + self.assertEqual(alarm.properties[VProps.TYPE], VITRAGE_TYPE) self.assertEqual(alarm.properties[VProps.SEVERITY], props[TFields.SEVERITY]) self.assertEqual(alarm.properties[VProps.NORMALIZED_SEVERITY], @@ -208,7 +210,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: self.NOVA_HOST} + vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) @@ -229,7 +231,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase): processor.process_event(add_vertex_event) - alarm_vertex_attrs = {VProps.TYPE: VITRAGE, + alarm_vertex_attrs = {VProps.TYPE: VITRAGE_TYPE, VProps.IS_DELETED: False} before_alarms = processor.entity_graph.get_vertices( vertex_attr_filter=alarm_vertex_attrs) diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index f16315e2b..ab6a4766b 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -15,16 +15,17 @@ from oslo_config import cfg from oslo_log import log as logging 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.mocks import utils LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' class TestScenarioEvaluator(TestEntityGraphFunctionalBase): @@ -68,7 +69,7 @@ class TestScenarioEvaluator(TestEntityGraphFunctionalBase): nagios_event = {'last_check': '2016-02-07 15:26:04', 'resource_name': target_host, - 'resource_type': self.NOVA_HOST, + 'resource_type': NOVA_HOST_PLUGIN, 'service': 'Check_MK', 'status': 'CRITICAL', 'status_info': 'ok', @@ -95,7 +96,7 @@ class TestScenarioEvaluator(TestEntityGraphFunctionalBase): @staticmethod def _get_host_from_graph(host_name, entity_graph): - vertex_attrs = {VProps.TYPE: NOVA_HOST, + vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN, VProps.NAME: host_name} host_vertices = entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) diff --git a/vitrage/tests/mocks/trace_generator.py b/vitrage/tests/mocks/trace_generator.py index 1da893497..107671b17 100644 --- a/vitrage/tests/mocks/trace_generator.py +++ b/vitrage/tests/mocks/trace_generator.py @@ -27,6 +27,7 @@ from random import randint import exrex # noinspection PyPep8Naming +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.tests.mocks.entity_model import BasicEntityModel as bem import vitrage.tests.mocks.utils as utils @@ -325,7 +326,7 @@ def _get_sync_switch_snapshot_values(spec): for host_name, switch_name in host_switch_mapping: switch_info = switches_info.get(switch_name, []) - relationship_info = {"type": "nova.host", + relationship_info = {"type": NOVA_HOST_PLUGIN, "name": host_name, "id": host_name, "relation_type": "contains" diff --git a/vitrage/tests/unit/entity_graph/base.py b/vitrage/tests/unit/entity_graph/base.py index c65dd466e..206706e3b 100644 --- a/vitrage/tests/unit/entity_graph/base.py +++ b/vitrage/tests/unit/entity_graph/base.py @@ -22,6 +22,10 @@ from vitrage.entity_graph.initialization_status import InitializationStatus from vitrage.entity_graph.processor import processor as proc import vitrage.graph.utils as graph_utils from vitrage.service import load_plugin +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 import base from vitrage.tests.mocks import mock_syncronizer as mock_sync from vitrage.tests.mocks import utils @@ -36,18 +40,13 @@ class TestEntityGraphUnitBase(base.BaseTest): PLUGINS_OPTS = [ cfg.ListOpt('plugin_type', - default=['nagios', - 'nova.host', - 'nova.instance', - 'nova.zone'], + default=[NAGIOS_PLUGIN, + NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN], help='Names of supported synchronizer plugins'), ] - NOVA_INSTANCE = 'nova.instance' - NOVA_HOST = 'nova.host' - NOVA_ZONE = 'nova.zone' - NAGIOS = 'nagios' - NUM_NODES = 1 NUM_ZONES = 2 NUM_HOSTS = 4 diff --git a/vitrage/tests/unit/entity_graph/states/test_state_manager.py b/vitrage/tests/unit/entity_graph/states/test_state_manager.py index bcd3c2182..4792aefd5 100644 --- a/vitrage/tests/unit/entity_graph/states/test_state_manager.py +++ b/vitrage/tests/unit/entity_graph/states/test_state_manager.py @@ -21,14 +21,13 @@ from vitrage.entity_graph.states.normalized_resource_state import \ from vitrage.entity_graph.states.state_manager import StateManager from vitrage.graph.utils import create_vertex from vitrage.service import load_plugin +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 import base from vitrage.tests.mocks import utils -NOVA_INSTANCE = 'nova.instance' -NOVA_HOST = 'nova.host' -NOVA_ZONE = 'nova.zone' -NAGIOS = 'nagios' - class TestStateManager(base.BaseTest): @@ -39,10 +38,10 @@ class TestStateManager(base.BaseTest): PLUGINS_OPTS = [ cfg.ListOpt('plugin_type', - default=['nagios', - 'nova.host', - 'nova.instance', - 'nova.zone'], + default=[NAGIOS_PLUGIN, + NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN], help='Names of supported synchronizer plugins'), ] @@ -100,7 +99,7 @@ class TestStateManager(base.BaseTest): # action normalized_state = \ state_manager.normalize_state(EntityCategory.RESOURCE, - NOVA_INSTANCE, + NOVA_INSTANCE_PLUGIN, 'BUILDING') # test assertions @@ -112,7 +111,7 @@ class TestStateManager(base.BaseTest): # action state_priority = \ - state_manager.state_priority(NOVA_INSTANCE, + state_manager.state_priority(NOVA_INSTANCE_PLUGIN, NormalizedResourceState.RUNNING) # test assertions @@ -125,13 +124,13 @@ class TestStateManager(base.BaseTest): new_vertex1 = create_vertex('12345', entity_state='ACTIVE', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE, + entity_type=NOVA_INSTANCE_PLUGIN, metadata=metadata1) metadata2 = {VProps.VITRAGE_STATE: 'ACTIVE'} new_vertex2 = create_vertex('23456', entity_state='SUSPENDED', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE, + entity_type=NOVA_INSTANCE_PLUGIN, metadata=metadata2) # action @@ -150,18 +149,18 @@ class TestStateManager(base.BaseTest): new_vertex1 = create_vertex('12345', entity_state='ACTIVE', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE) + entity_type=NOVA_INSTANCE_PLUGIN) metadata2 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'} new_vertex2 = create_vertex('23456', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE, + entity_type=NOVA_INSTANCE_PLUGIN, metadata=metadata2) new_vertex3 = create_vertex('34567', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE) + entity_type=NOVA_INSTANCE_PLUGIN) graph_vertex3 = create_vertex('45678', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE) + entity_type=NOVA_INSTANCE_PLUGIN) # action state_manager.aggregated_state(new_vertex1, diff --git a/vitrage/tests/unit/entity_graph/test_transformer_manager.py b/vitrage/tests/unit/entity_graph/test_transformer_manager.py index 7a9836237..11bb4d1e8 100644 --- a/vitrage/tests/unit/entity_graph/test_transformer_manager.py +++ b/vitrage/tests/unit/entity_graph/test_transformer_manager.py @@ -17,31 +17,31 @@ from oslo_log import log as logging from vitrage.entity_graph.transformer_manager import TransformerManager from vitrage.service import load_plugin +from vitrage.synchronizer.plugins.nagios import NAGIOS_PLUGIN from vitrage.synchronizer.plugins.nagios.transformer import \ NagiosTransformer +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.host.transformer import \ HostTransformer +from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN from vitrage.synchronizer.plugins.nova.instance.transformer import \ InstanceTransformer +from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN from vitrage.synchronizer.plugins.nova.zone.transformer import \ ZoneTransformer from vitrage.tests import base LOG = logging.getLogger(__name__) -NOVA_INSTANCE = 'nova.instance' -NOVA_HOST = 'nova.host' -NOVA_ZONE = 'nova.zone' -NAGIOS = 'nagios' class TransformerManagerTest(base.BaseTest): OPTS = [ cfg.ListOpt('plugin_type', - default=['nagios', - 'nova.host', - 'nova.instance', - 'nova.zone'], + default=[NAGIOS_PLUGIN, + NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + NOVA_ZONE_PLUGIN], help='Names of supported synchronizer plugins'), ] @@ -56,16 +56,16 @@ class TransformerManagerTest(base.BaseTest): def test_transformer_registration_nagios(self): self.assertIsInstance(self.manager.get_transformer - (NAGIOS), NagiosTransformer) + (NAGIOS_PLUGIN), NagiosTransformer) def test_transformer_registration_nova_host(self): self.assertIsInstance(self.manager.get_transformer - (NOVA_HOST), HostTransformer) + (NOVA_HOST_PLUGIN), HostTransformer) def test_transformer_registration_nova_instance(self): self.assertIsInstance(self.manager.get_transformer - (NOVA_INSTANCE), InstanceTransformer) + (NOVA_INSTANCE_PLUGIN), InstanceTransformer) def test_transformer_registration_nova_zone(self): self.assertIsInstance(self.manager.get_transformer - (NOVA_ZONE), ZoneTransformer) + (NOVA_ZONE_PLUGIN), ZoneTransformer) diff --git a/vitrage/tests/unit/graph/base.py b/vitrage/tests/unit/graph/base.py index de4898d0a..84ab4172d 100644 --- a/vitrage/tests/unit/graph/base.py +++ b/vitrage/tests/unit/graph/base.py @@ -18,6 +18,7 @@ test_vitrage graph Tests for `vitrage` graph driver """ + import random import time @@ -25,9 +26,12 @@ from oslo_log import log as logging from vitrage.common.constants import EdgeLabels as ELabel from vitrage.common.constants import EntityCategory -from vitrage.common.constants import OPENSTACK_NODE from vitrage.graph import create_graph from vitrage.graph import utils as graph_utils +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN +from vitrage.synchronizer.plugins import OPENSTACK_NODE +from vitrage.synchronizer.plugins.static_physical import SWITCH from vitrage.tests import base LOG = logging.getLogger(__name__) @@ -41,10 +45,7 @@ ENTITY_GRAPH_ALARMS_PER_VM = 8 RESOURCE = EntityCategory.RESOURCE ALARM = EntityCategory.ALARM -HOST = 'nova.host' -INSTANCE = 'nova.instance' TEST = 'TEST' -SWITCH = 'switch' ALARM_ON_VM = 'ALARM_ON_VM' ALARM_ON_HOST = 'ALARM_ON_HOST' TEST_ON_HOST = 'TEST_ON_HOST' @@ -55,14 +56,14 @@ v_node = graph_utils.create_vertex( entity_type=OPENSTACK_NODE, entity_category=RESOURCE) v_host = graph_utils.create_vertex( - vitrage_id=HOST + '222222222222', + vitrage_id=NOVA_HOST_PLUGIN + '222222222222', entity_id='222222222222', - entity_type=HOST, + entity_type=NOVA_HOST_PLUGIN, entity_category=RESOURCE) v_instance = graph_utils.create_vertex( - vitrage_id=INSTANCE + '333333333333', + vitrage_id=NOVA_INSTANCE_PLUGIN + '333333333333', entity_id='333333333333', - entity_type=INSTANCE, + entity_type=NOVA_INSTANCE_PLUGIN, entity_category=RESOURCE) v_alarm = graph_utils.create_vertex( vitrage_id=ALARM + '444444444444', @@ -147,8 +148,13 @@ class GraphTestBase(base.BaseTest): # Add Hosts for host_id in range(num_of_hosts_per_node): - host_to_add = add_connected_vertex(g, RESOURCE, HOST, host_id, - ELabel.CONTAINS, v_node, True) + host_to_add = add_connected_vertex(g, + RESOURCE, + NOVA_HOST_PLUGIN, + host_id, + ELabel.CONTAINS, + v_node, + True) g.add_edge(graph_utils.create_edge(host_to_add.vertex_id, v_switch.vertex_id, 'USES')) @@ -168,9 +174,13 @@ class GraphTestBase(base.BaseTest): # Add Host Vms for j in range(num_of_vms_per_host): - vm_to_add = add_connected_vertex(g, RESOURCE, INSTANCE, - self.vm_id, ELabel.CONTAINS, - host_to_add, True) + vm_to_add = add_connected_vertex(g, + RESOURCE, + NOVA_INSTANCE_PLUGIN, + self.vm_id, + ELabel.CONTAINS, + host_to_add, + True) self.vm_id += 1 self.vms.append(vm_to_add) diff --git a/vitrage/tests/unit/graph/test_graph.py b/vitrage/tests/unit/graph/test_graph.py index 7cb4eec6f..c6accb273 100644 --- a/vitrage/tests/unit/graph/test_graph.py +++ b/vitrage/tests/unit/graph/test_graph.py @@ -55,7 +55,7 @@ class GraphTest(GraphTestBase): v_from_graph_copy = graph_copy.get_vertex(v_host.vertex_id) self.assertEqual(ALARM, v_from_g[VProps.CATEGORY], 'graph vertex changed after update') - self.assertEqual(HOST, v_from_graph_copy[VProps.TYPE], + self.assertEqual(NOVA_HOST_PLUGIN, v_from_graph_copy[VProps.TYPE], 'graph copy vertex unchanged after update') def test_vertex_crud(self): @@ -100,7 +100,9 @@ class GraphTest(GraphTestBase): # check metadata another_vertex = utils.create_vertex( - vitrage_id='123', entity_id='456', entity_category=INSTANCE, + vitrage_id='123', + entity_id='456', + entity_category=NOVA_INSTANCE_PLUGIN, metadata={'some_meta': 'DATA'} ) g.add_vertex(another_vertex) @@ -228,7 +230,7 @@ class GraphTest(GraphTestBase): v4 = v_alarm v5 = utils.create_vertex( vitrage_id='kuku', - entity_category=HOST) + entity_category=NOVA_HOST_PLUGIN) g = create_graph('test_neighbors') g.add_vertex(v1) @@ -272,7 +274,7 @@ class GraphTest(GraphTestBase): v1_neighbors = g.neighbors( v_id=v1.vertex_id, - vertex_attr_filter={VProps.TYPE: HOST}) + vertex_attr_filter={VProps.TYPE: NOVA_HOST_PLUGIN}) self._assert_set_equal({v2}, v1_neighbors, 'Check V1 neighbors, vertex property filter') @@ -301,7 +303,7 @@ class GraphTest(GraphTestBase): v_id=v1.vertex_id, direction=Direction.IN, edge_attr_filter={EProps.RELATIONSHIP_TYPE: relationship_c}, - vertex_attr_filter={VProps.TYPE: HOST}) + vertex_attr_filter={VProps.TYPE: NOVA_HOST_PLUGIN}) self._assert_set_equal( {v2}, v1_neighbors, 'Check V1 neighbors, vertex/edge property filter and direction') @@ -314,13 +316,13 @@ class GraphTest(GraphTestBase): v2_neighbors = g.neighbors( v_id=v2.vertex_id, - vertex_attr_filter={VProps.CATEGORY: HOST}) + vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_PLUGIN}) self._assert_set_equal({}, v2_neighbors, 'Check v2 neighbors, vertex property filter') v2_neighbors = g.neighbors( v_id=v2.vertex_id, - vertex_attr_filter={VProps.CATEGORY: [HOST, ALARM]}) + vertex_attr_filter={VProps.CATEGORY: [NOVA_HOST_PLUGIN, ALARM]}) self._assert_set_equal({v4}, v2_neighbors, 'Check v2 neighbors, vertex property filter') @@ -331,7 +333,10 @@ class GraphTest(GraphTestBase): }, vertex_attr_filter={ VProps.CATEGORY: [RESOURCE, ALARM], - VProps.TYPE: [HOST, INSTANCE, ALARM_ON_VM, ALARM_ON_HOST] + VProps.TYPE: [NOVA_HOST_PLUGIN, + NOVA_INSTANCE_PLUGIN, + ALARM_ON_VM, + ALARM_ON_HOST] } ) self._assert_set_equal({v3, v4}, v2_neighbors, @@ -345,13 +350,13 @@ class GraphTest(GraphTestBase): v3_neighbors = g.neighbors( v_id=v3.vertex_id, - vertex_attr_filter={VProps.CATEGORY: HOST}, + vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_PLUGIN}, direction=Direction.OUT) self._assert_set_equal({}, v3_neighbors, 'Check neighbors for vertex without any') v5_neighbors = g.neighbors( v_id=v5.vertex_id, - vertex_attr_filter={VProps.CATEGORY: HOST}) + vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_PLUGIN}) self._assert_set_equal({}, v5_neighbors, 'Check neighbors for not connected vertex') diff --git a/vitrage/tests/unit/graph/test_graph_algo.py b/vitrage/tests/unit/graph/test_graph_algo.py index 16abb49ce..d7b994463 100644 --- a/vitrage/tests/unit/graph/test_graph_algo.py +++ b/vitrage/tests/unit/graph/test_graph_algo.py @@ -36,7 +36,7 @@ class GraphAlgorithmTest(GraphTestBase): query = { 'or': [ - {'==': {VProps.TYPE: HOST}}, + {'==': {VProps.TYPE: NOVA_HOST_PLUGIN}}, {'==': {VProps.TYPE: OPENSTACK_NODE}} ] } @@ -48,9 +48,9 @@ class GraphAlgorithmTest(GraphTestBase): query = { 'or': [ - {'==': {VProps.TYPE: INSTANCE}}, + {'==': {VProps.TYPE: NOVA_INSTANCE_PLUGIN}}, {'==': {VProps.CATEGORY: ALARM}}, - {'==': {VProps.TYPE: HOST}}, + {'==': {VProps.TYPE: NOVA_HOST_PLUGIN}}, {'==': {VProps.TYPE: OPENSTACK_NODE}} ] } @@ -65,7 +65,7 @@ class GraphAlgorithmTest(GraphTestBase): # Get first host ID neighboring_hosts = self.entity_graph.neighbors( - v_node.vertex_id, {VProps.TYPE: HOST}) + v_node.vertex_id, {VProps.TYPE: NOVA_HOST_PLUGIN}) first_host_id = neighboring_hosts.pop().vertex_id query = {'!=': {'NOTHING': 'IS EVERYTHING'}} @@ -83,7 +83,7 @@ class GraphAlgorithmTest(GraphTestBase): query = { 'or': [ {'==': {VProps.TYPE: SWITCH}}, - {'==': {VProps.TYPE: HOST}}, + {'==': {VProps.TYPE: NOVA_HOST_PLUGIN}}, ] } subgraph = ga.graph_query_vertices( @@ -157,9 +157,13 @@ class GraphAlgorithmTest(GraphTestBase): t_v_alarm_fail = graph_utils.create_vertex( vitrage_id='1', entity_category=ALARM, entity_type='fail') t_v_host = graph_utils.create_vertex( - vitrage_id='2', entity_category=RESOURCE, entity_type=HOST) + vitrage_id='2', + entity_category=RESOURCE, + entity_type=NOVA_HOST_PLUGIN) t_v_vm = graph_utils.create_vertex( - vitrage_id='3', entity_category=RESOURCE, entity_type=INSTANCE) + vitrage_id='3', + entity_category=RESOURCE, + entity_type=NOVA_INSTANCE_PLUGIN) t_v_vm_alarm = graph_utils.create_vertex( vitrage_id='4', entity_category=ALARM, entity_type=ALARM_ON_VM) t_v_switch = graph_utils.create_vertex( diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_alarm_transformer.py b/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_alarm_transformer.py index 4fab04c3a..7a9c1bce5 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_alarm_transformer.py +++ b/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_alarm_transformer.py @@ -11,6 +11,7 @@ # 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_log import log as logging from vitrage.common.constants import EdgeLabels @@ -23,6 +24,7 @@ from vitrage.synchronizer.plugins.base.alarm.properties \ import AlarmProperties as AlarmProps from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties from vitrage.synchronizer.plugins.nagios.transformer import NagiosTransformer +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.host.transformer import HostTransformer from vitrage.synchronizer.plugins.transformer_base import TransformerBase from vitrage.tests import base @@ -30,7 +32,6 @@ from vitrage.tests.mocks import mock_syncronizer as mock_sync LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' class NagiosTransformerTest(base.BaseTest): @@ -41,7 +42,7 @@ class NagiosTransformerTest(base.BaseTest): self.transformers = {} host_transformer = HostTransformer(self.transformers) - self.transformers[NOVA_HOST] = host_transformer + self.transformers[NOVA_HOST_PLUGIN] = host_transformer def test_extract_key(self): LOG.debug('Test get key from nova instance transformer') @@ -85,7 +86,7 @@ class NagiosTransformerTest(base.BaseTest): neighbor = neighbors[0] # Right now we are support only host as a resource - if neighbor.vertex[VProps.TYPE] == NOVA_HOST: + if neighbor.vertex[VProps.TYPE] == NOVA_HOST_PLUGIN: self._validate_host_neighbor(neighbors[0], alarm) self._validate_action(alarm, wrapper) @@ -123,7 +124,7 @@ class NagiosTransformerTest(base.BaseTest): key_fields = host_vertex.vertex_id.split(TransformerBase.KEY_SEPARATOR) self.assertEqual(EntityCategory.RESOURCE, key_fields[0]) - self.assertEqual(NOVA_HOST, key_fields[1]) + self.assertEqual(NOVA_HOST_PLUGIN, key_fields[1]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], key_fields[2]) self.assertFalse(host_vertex[VProps.IS_DELETED]) @@ -132,7 +133,7 @@ class NagiosTransformerTest(base.BaseTest): self.assertEqual(EntityCategory.RESOURCE, host_vertex[VProps.CATEGORY]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], host_vertex[VProps.ID]) - self.assertEqual(NOVA_HOST, host_vertex[VProps.TYPE]) + self.assertEqual(NOVA_HOST_PLUGIN, host_vertex[VProps.TYPE]) edge = neighbor.edge self.assertEqual(EdgeLabels.ON, edge.label) diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py b/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py index 1e88d8e35..19741624f 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py +++ b/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py @@ -11,11 +11,14 @@ # 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 oslo_log import log as logging from vitrage.synchronizer.plugins.nagios.config import NagiosConfig from vitrage.synchronizer.plugins.nagios.config import NagiosHostMapping +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN from vitrage.tests import base from vitrage.tests.mocks import utils @@ -52,19 +55,25 @@ class TestNagiosConfig(base.BaseTest): ] # the mappings match the ones in nagios_conf.yaml - MAPPING_1 = NagiosHostMapping('compute-1', 'nova.host', 'compute-1') - MAPPING_2 = NagiosHostMapping('compute-2', 'nova.host', 'host2') + MAPPING_1 = NagiosHostMapping('compute-1', NOVA_HOST_PLUGIN, 'compute-1') + MAPPING_2 = NagiosHostMapping('compute-2', NOVA_HOST_PLUGIN, 'host2') MAPPING_3 = NagiosHostMapping('compute-(.*)', - 'nova.host', + NOVA_HOST_PLUGIN, '${nagios_host}') MAPPING_4 = NagiosHostMapping('instance-(.*)', - 'nova.instance', + NOVA_INSTANCE_PLUGIN, '${nagios_host}') MAPPINGS = [MAPPING_1, MAPPING_2, MAPPING_3, MAPPING_4] - NON_EXISTING_MAPPING_1 = NagiosHostMapping('X', 'nova.host', 'compute-1') - NON_EXISTING_MAPPING_2 = NagiosHostMapping('compute-1', 'X', 'compute-1') - NON_EXISTING_MAPPING_3 = NagiosHostMapping('compute-1', 'nova.host', 'X') + NON_EXISTING_MAPPING_1 = NagiosHostMapping('X', + NOVA_HOST_PLUGIN, + 'compute-1') + NON_EXISTING_MAPPING_2 = NagiosHostMapping('compute-1', + 'X', + 'compute-1') + NON_EXISTING_MAPPING_3 = NagiosHostMapping('compute-1', + NOVA_HOST_PLUGIN, + 'X') NON_EXISTING_MAPPINGS = [NON_EXISTING_MAPPING_1, NON_EXISTING_MAPPING_2, NON_EXISTING_MAPPING_3] @@ -148,22 +157,22 @@ class TestNagiosConfig(base.BaseTest): mapped_resource = nagios_conf.get_vitrage_resource('compute-1') self.assertIsNotNone(mapped_resource, 'expected Not None') - self.assertEqual('nova.host', mapped_resource[0]) + self.assertEqual(NOVA_HOST_PLUGIN, mapped_resource[0]) self.assertEqual('compute-1', mapped_resource[1]) mapped_resource = nagios_conf.get_vitrage_resource('compute-2') self.assertIsNotNone(mapped_resource, 'expected Not None') - self.assertEqual('nova.host', mapped_resource[0]) + self.assertEqual(NOVA_HOST_PLUGIN, mapped_resource[0]) self.assertEqual('host2', mapped_resource[1]) mapped_resource = nagios_conf.get_vitrage_resource('compute-88') self.assertIsNotNone(mapped_resource, 'expected Not None') - self.assertEqual('nova.host', mapped_resource[0]) + self.assertEqual(NOVA_HOST_PLUGIN, mapped_resource[0]) self.assertEqual('compute-88', mapped_resource[1]) mapped_resource = nagios_conf.get_vitrage_resource('instance-7') self.assertIsNotNone(mapped_resource, 'expected Not None') - self.assertEqual('nova.instance', mapped_resource[0]) + self.assertEqual(NOVA_INSTANCE_PLUGIN, mapped_resource[0]) self.assertEqual('instance-7', mapped_resource[1]) @staticmethod diff --git a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py b/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py index 93df9d58a..c3de22e6b 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py +++ b/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py @@ -22,7 +22,9 @@ from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.constants import VertexProperties +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.host.transformer import HostTransformer +from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN from vitrage.synchronizer.plugins.nova.zone.transformer import ZoneTransformer from vitrage.synchronizer.plugins import transformer_base as tbase from vitrage.synchronizer.plugins.transformer_base import TransformerBase @@ -30,7 +32,6 @@ from vitrage.tests import base from vitrage.tests.mocks import mock_syncronizer as mock_sync LOG = logging.getLogger(__name__) -NOVA_ZONE = 'nova.zone' class NovaHostTransformerTest(base.BaseTest): @@ -41,7 +42,7 @@ class NovaHostTransformerTest(base.BaseTest): self.transformers = {} zone_transformer = ZoneTransformer(self.transformers) - self.transformers[NOVA_ZONE] = zone_transformer + self.transformers[NOVA_ZONE_PLUGIN] = zone_transformer def test_create_placeholder_vertex(self): LOG.debug('Nova host transformer test: Test create placeholder vertex') @@ -61,7 +62,7 @@ class NovaHostTransformerTest(base.BaseTest): # Test assertions observed_id_values = placeholder.vertex_id.split( TransformerBase.KEY_SEPARATOR) - expected_id_values = host_transformer._key_values('nova.host', + expected_id_values = host_transformer._key_values(NOVA_HOST_PLUGIN, host_name) self.assertEqual(tuple(observed_id_values), expected_id_values) @@ -69,7 +70,7 @@ class NovaHostTransformerTest(base.BaseTest): self.assertEqual(observed_time, timestamp) observed_subtype = placeholder.get(VertexProperties.TYPE) - self.assertEqual(observed_subtype, host_transformer.HOST_TYPE) + self.assertEqual(observed_subtype, NOVA_HOST_PLUGIN) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, host_name) @@ -89,12 +90,12 @@ class NovaHostTransformerTest(base.BaseTest): host_transformer = HostTransformer(self.transformers) # Test action - observed_key_fields = host_transformer._key_values('nova.host', + observed_key_fields = host_transformer._key_values(NOVA_HOST_PLUGIN, host_name) # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) - self.assertEqual(host_transformer.HOST_TYPE, observed_key_fields[1]) + self.assertEqual(NOVA_HOST_PLUGIN, observed_key_fields[1]) self.assertEqual(host_name, observed_key_fields[2]) def test_snapshot_transform(self): @@ -132,7 +133,7 @@ class NovaHostTransformerTest(base.BaseTest): ) time = event[SyncProps.SAMPLE_DATE] - zt = self.transformers[NOVA_ZONE] + zt = self.transformers[NOVA_ZONE_PLUGIN] properties = { VertexProperties.ID: zone_name, VertexProperties.SAMPLE_TIMESTAMP: time @@ -166,7 +167,7 @@ class NovaHostTransformerTest(base.BaseTest): ) self.assertEqual( - HostTransformer(self.transformers).HOST_TYPE, + NOVA_HOST_PLUGIN, vertex[VertexProperties.TYPE] ) diff --git a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py b/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py index a62bcf255..e90ad48dc 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py +++ b/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py @@ -22,7 +22,9 @@ from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.constants import VertexProperties +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.host.transformer import HostTransformer +from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN from vitrage.synchronizer.plugins.nova.instance.transformer import \ InstanceTransformer from vitrage.synchronizer.plugins import transformer_base as tbase @@ -31,7 +33,6 @@ from vitrage.tests import base from vitrage.tests.mocks import mock_syncronizer as mock_sync LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' class NovaInstanceTransformerTest(base.BaseTest): @@ -42,7 +43,7 @@ class NovaInstanceTransformerTest(base.BaseTest): self.transformers = {} host_transformer = HostTransformer(self.transformers) - self.transformers[NOVA_HOST] = host_transformer + self.transformers[NOVA_HOST_PLUGIN] = host_transformer def test_create_placeholder_vertex(self): LOG.debug('Test create placeholder vertex') @@ -62,7 +63,7 @@ class NovaInstanceTransformerTest(base.BaseTest): # Test assertions observed_id_values = placeholder.vertex_id.split( TransformerBase.KEY_SEPARATOR) - expected_id_values = transformer._key_values('nova.instance', + expected_id_values = transformer._key_values(NOVA_INSTANCE_PLUGIN, instance_id) self.assertEqual(tuple(observed_id_values), expected_id_values) @@ -70,7 +71,7 @@ class NovaInstanceTransformerTest(base.BaseTest): self.assertEqual(observed_time, timestamp) observed_type = placeholder.get(VertexProperties.TYPE) - self.assertEqual(observed_type, InstanceTransformer.INSTANCE_TYPE) + self.assertEqual(observed_type, NOVA_INSTANCE_PLUGIN) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, instance_id) @@ -175,7 +176,7 @@ class NovaInstanceTransformerTest(base.BaseTest): ) self.assertEqual( - InstanceTransformer.INSTANCE_TYPE, + NOVA_INSTANCE_PLUGIN, vertex[VertexProperties.TYPE] ) @@ -218,7 +219,7 @@ class NovaInstanceTransformerTest(base.BaseTest): host_name = tbase.extract_field_value(event, it.HOST_NAME[sync_mode]) time = event[SyncProps.SAMPLE_DATE] - ht = self.transformers[NOVA_HOST] + ht = self.transformers[NOVA_HOST_PLUGIN] properties = { VertexProperties.ID: host_name, VertexProperties.SAMPLE_TIMESTAMP: time @@ -255,7 +256,7 @@ class NovaInstanceTransformerTest(base.BaseTest): self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) self.assertEqual( - InstanceTransformer.INSTANCE_TYPE, + NOVA_INSTANCE_PLUGIN, observed_key_fields[1] ) @@ -266,7 +267,7 @@ class NovaInstanceTransformerTest(base.BaseTest): self.assertEqual(instance_id, observed_key_fields[2]) - key_values = instance_transformer._key_values('nova.instance', + key_values = instance_transformer._key_values(NOVA_INSTANCE_PLUGIN, instance_id) expected_key = tbase.build_key(key_values) @@ -281,7 +282,7 @@ class NovaInstanceTransformerTest(base.BaseTest): instance_transformer = InstanceTransformer(self.transformers) # Test action - key_fields = instance_transformer._key_values('nova.instance', + key_fields = instance_transformer._key_values(NOVA_INSTANCE_PLUGIN, instance_id) # Test assertions @@ -302,7 +303,7 @@ class NovaInstanceTransformerTest(base.BaseTest): vertex_id, host_name, time, - self.transformers[NOVA_HOST] + self.transformers[NOVA_HOST_PLUGIN] ) # Test assertions diff --git a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py b/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py index 68856c7f9..038daccd9 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py +++ b/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py @@ -18,18 +18,19 @@ from oslo_log import log as logging from vitrage.common.constants import EdgeLabels from vitrage.common.constants import EntityCategory -from vitrage.common.constants import OPENSTACK_NODE from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties +from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.host.transformer import HostTransformer +from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN from vitrage.synchronizer.plugins.nova.zone.transformer import ZoneTransformer +from vitrage.synchronizer.plugins import OPENSTACK_NODE from vitrage.synchronizer.plugins import transformer_base as tbase from vitrage.synchronizer.plugins.transformer_base import TransformerBase from vitrage.tests import base from vitrage.tests.mocks import mock_syncronizer as mock_sync LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' class NovaZoneTransformerTest(base.BaseTest): @@ -40,7 +41,7 @@ class NovaZoneTransformerTest(base.BaseTest): self.transformers = {} host_transformer = HostTransformer(self.transformers) - self.transformers[NOVA_HOST] = host_transformer + self.transformers[NOVA_HOST_PLUGIN] = host_transformer def test_create_placeholder_vertex(self): @@ -62,14 +63,14 @@ class NovaZoneTransformerTest(base.BaseTest): observed_id_values = placeholder.vertex_id.split( TransformerBase.KEY_SEPARATOR) expected_id_values = ZoneTransformer(self.transformers)._key_values( - 'nova.zone', zone_name) + NOVA_ZONE_PLUGIN, zone_name) self.assertEqual(tuple(observed_id_values), expected_id_values) observed_time = placeholder.get(VertexProperties.SAMPLE_TIMESTAMP) self.assertEqual(observed_time, timestamp) observed_subtype = placeholder.get(VertexProperties.TYPE) - self.assertEqual(observed_subtype, zone_transformer.ZONE_TYPE) + self.assertEqual(observed_subtype, NOVA_ZONE_PLUGIN) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, zone_name) @@ -88,13 +89,13 @@ class NovaZoneTransformerTest(base.BaseTest): zone_transformer = ZoneTransformer(self.transformers) # Test action - observed_key_fields = zone_transformer._key_values('nova.zone', + observed_key_fields = zone_transformer._key_values(NOVA_ZONE_PLUGIN, zone_name) # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) self.assertEqual( - ZoneTransformer(self.transformers).ZONE_TYPE, + NOVA_ZONE_PLUGIN, observed_key_fields[1] ) self.assertEqual(zone_name, observed_key_fields[2]) @@ -216,7 +217,7 @@ class NovaZoneTransformerTest(base.BaseTest): ) self.assertEqual( - zone_transform.ZONE_TYPE, + NOVA_ZONE_PLUGIN, vertex[VertexProperties.TYPE] ) diff --git a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py b/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py index 35a2461d5..0b8fb4d23 100644 --- a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py +++ b/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py @@ -22,14 +22,14 @@ from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.constants import VertexProperties as VProps from vitrage.common import file_utils +from vitrage.synchronizer.plugins.static_physical import STATIC_PHYSICAL_PLUGIN +from vitrage.synchronizer.plugins.static_physical import SWITCH from vitrage.synchronizer.plugins.static_physical import synchronizer from vitrage.tests import base from vitrage.tests.mocks import utils LOG = logging.getLogger(__name__) -SWITCH = 'switch' -STATIC_PHYSICAL = 'static_physical' class TestStaticPhysicalSynchronizer(base.BaseTest): @@ -49,7 +49,7 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): cfg.StrOpt('directory', default=utils.get_resources_dir() + '/static_plugins'), cfg.ListOpt('entities', - default=['switch']) + default=[SWITCH]) ] CHANGES_OPTS = [ @@ -73,7 +73,7 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): def setUp(self): super(TestStaticPhysicalSynchronizer, self).setUp() self.conf = cfg.ConfigOpts() - self.conf.register_opts(self.OPTS, group=STATIC_PHYSICAL) + self.conf.register_opts(self.OPTS, group=STATIC_PHYSICAL_PLUGIN) self.static_physical_synchronizer = \ synchronizer.StaticPhysicalSynchronizer(self.conf) @@ -103,9 +103,10 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): entities = self.static_physical_synchronizer.get_all(SyncMode.UPDATE) self.assertEqual(5, len(entities)) - conf = cfg.ConfigOpts() - conf.register_opts(self.CHANGES_OPTS, group=STATIC_PHYSICAL) - self.static_physical_synchronizer.cfg = conf + self.conf = cfg.ConfigOpts() + self.conf.register_opts(self.CHANGES_OPTS, + group=STATIC_PHYSICAL_PLUGIN) + self.static_physical_synchronizer.cfg = self.conf # Action changes = self.static_physical_synchronizer.get_changes( diff --git a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py b/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py index 3e7241443..dce5e0d3c 100644 --- a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py +++ b/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py @@ -20,7 +20,9 @@ from vitrage.common.constants import EdgeLabels 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.nova.host import NOVA_HOST_PLUGIN from vitrage.synchronizer.plugins.nova.host.transformer import HostTransformer +from vitrage.synchronizer.plugins.static_physical import STATIC_PHYSICAL_PLUGIN from vitrage.synchronizer.plugins.static_physical.transformer \ import StaticPhysicalTransformer from vitrage.synchronizer.plugins.transformer_base import TransformerBase @@ -28,8 +30,6 @@ from vitrage.tests import base from vitrage.tests.mocks import mock_syncronizer as mock_sync LOG = logging.getLogger(__name__) -NOVA_HOST = 'nova.host' -STATIC_PHYSICAL = 'static_physical' class TestStaticPhysicalTransformer(base.BaseTest): @@ -41,8 +41,8 @@ class TestStaticPhysicalTransformer(base.BaseTest): self.transformers = {} host_transformer = HostTransformer(self.transformers) static_transformer = StaticPhysicalTransformer(self.transformers) - self.transformers[NOVA_HOST] = host_transformer - self.transformers[STATIC_PHYSICAL] = static_transformer + self.transformers[NOVA_HOST_PLUGIN] = host_transformer + self.transformers[STATIC_PHYSICAL_PLUGIN] = static_transformer def test_create_placeholder_vertex(self): @@ -50,7 +50,7 @@ class TestStaticPhysicalTransformer(base.BaseTest): 'vertex') # Test setup - switch_type = STATIC_PHYSICAL + switch_type = STATIC_PHYSICAL_PLUGIN switch_name = 'switch-1' timestamp = datetime.datetime.utcnow() static_transformer = StaticPhysicalTransformer(self.transformers) @@ -91,7 +91,7 @@ class TestStaticPhysicalTransformer(base.BaseTest): LOG.debug('Static Physical transformer test: get key values') # Test setup - switch_type = STATIC_PHYSICAL + switch_type = STATIC_PHYSICAL_PLUGIN switch_name = 'switch-1' static_transformer = StaticPhysicalTransformer(self.transformers) @@ -101,7 +101,7 @@ class TestStaticPhysicalTransformer(base.BaseTest): # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) - self.assertEqual(STATIC_PHYSICAL, observed_key_fields[1]) + self.assertEqual(STATIC_PHYSICAL_PLUGIN, observed_key_fields[1]) self.assertEqual(switch_name, observed_key_fields[2]) def test_snapshot_transform(self):