diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 7911e7985..d39c9c278 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -100,14 +100,14 @@ function cleanup_vitrage { fi } -function disable_vitrage_plugin { +function disable_vitrage_datasource { - local enabled_plugins=",${VITRAGE_DEFAULT_PLUGINS}," - local plugin - for plugin in $@; do - enabled_plugins=${enabled_plugins//,$plugin,/,} + local enabled_datasources=",${VITRAGE_DEFAULT_DATASOURCES}," + local datasource + for datasource in $@; do + enabled_datasources=${enabled_datasources//,$datasource,/,} done - VITRAGE_DEFAULT_PLUGINS=$(_cleanup_service_list "$enabled_plugins") + VITRAGE_DEFAULT_DATSOURCES=$(_cleanup_service_list "$enabled_datasources") } @@ -134,29 +134,29 @@ function configure_vitrage { iniset $VITRAGE_CONF service_credentials region_name $REGION_NAME iniset $VITRAGE_CONF service_credentials auth_url $KEYSTONE_SERVICE_URI - # add default plugins - iniset $VITRAGE_CONF plugins plugin_type $VITRAGE_DEFAULT_PLUGINS + # add default datasources + iniset $VITRAGE_CONF datasources types $VITRAGE_DEFAULT_DATASOURCES - # remove neutron vitrage plugin if neutron plugin not installed + # remove neutron vitrage datasource if neutron datasource not installed if ! is_service_enabled neutron; then - disable_vitrage_plugin neutron.network neutron.port + disable_vitrage_datasource neutron.network neutron.port fi - # remove aodh vitrage plugin if aodh plugin not installed + # remove aodh vitrage datasource if aodh datasource not installed if ! is_service_enabled aodh; then - disable_vitrage_plugin aodh + disable_vitrage_datasource aodh fi # copy the mock sample files cp $VITRAGE_DIR/etc/vitrage/*.sample.json $VITRAGE_CONF_DIR # create some folders - mkdir -p $VITRAGE_CONF_DIR/states_plugins - mkdir -p $VITRAGE_CONF_DIR/static_plugins + mkdir -p $VITRAGE_CONF_DIR/datasources_states + mkdir -p $VITRAGE_CONF_DIR/static_datasources mkdir -p $VITRAGE_CONF_DIR/templates - # copy plugins - cp $VITRAGE_DIR/etc/vitrage/states_plugins/*.yaml $VITRAGE_CONF_DIR/states_plugins + # copy datasources + cp $VITRAGE_DIR/etc/vitrage/datasources_states/*.yaml $VITRAGE_CONF_DIR/datasources_states configure_auth_token_middleware $VITRAGE_CONF vitrage $VITRAGE_AUTH_CACHE_DIR diff --git a/devstack/settings b/devstack/settings index 7135b88f0..9f44adabe 100644 --- a/devstack/settings +++ b/devstack/settings @@ -20,8 +20,7 @@ VITRAGE_SERVICE_PROTOCOL=http VITRAGE_SERVICE_HOST=$SERVICE_HOST VITRAGE_SERVICE_PORT=${VITRAGE_SERVICE_PORT:-8999} VITRAGE_USE_MOD_WSGI=${VITRAGE_USE_MOD_WSGI:-${ENABLE_HTTPD_MOD_WSGI_SERVICES}} -VITRAGE_DEFAULT_PLUGINS=${VITRAGE_DEFAULT_PLUGINS:-nova.host,nova.instance, -nova.zone,nagios,static_physical,aodh,cinder.volume,neutron.network,neutron.port} +VITRAGE_DEFAULT_DATASOURCES=${VITRAGE_DEFAULT_DATASOURCES:-nova.host,nova.instance,nova.zone,nagios,static_physical,aodh,cinder.volume,neutron.network,neutron.port} # Tell Tempest this project is present diff --git a/etc/vitrage/vitrage-config-generator.conf b/etc/vitrage/vitrage-config-generator.conf index a30a987a8..8ab6fd51d 100644 --- a/etc/vitrage/vitrage-config-generator.conf +++ b/etc/vitrage/vitrage-config-generator.conf @@ -2,7 +2,7 @@ output_file = etc/vitrage/vitrage.conf wrap_width = 79 namespace = vitrage -namespace = plugins +namespace = datasources namespace = oslo.db namespace = oslo.log namespace = oslo.middleware diff --git a/etc/vitrage/vitrage.conf.sample b/etc/vitrage/vitrage.conf.sample index f8228bf8f..8939ed71a 100644 --- a/etc/vitrage/vitrage.conf.sample +++ b/etc/vitrage/vitrage.conf.sample @@ -112,16 +112,16 @@ [aodh] # -# From plugins +# From datasources # # Aodh plugin transformer class path (string value) -#transformer = vitrage.synchronizer.plugins.aodh.transformer.AodhTransformer +#transformer = vitrage.datasources.aodh.transformer.AodhTransformer # Aodh plugin synchronizer class path (string value) -#synchronizer = vitrage.synchronizer.plugins.aodh.synchronizer.AodhSynchronizer +#synchronizer = vitrage.datasources.aodh.driver.AodhDriver -# interval between checking changes in aodh plugin (integer value) +# interval between checking changes in aodh datasource (integer value) # Minimum value: 30 #changes_interval = 30 @@ -165,12 +165,12 @@ #min_time_to_delete = 60 # interval between consistency initialization checks for finding if all end -# messages from plugins were received (in seconds) (integer value) +# messages from data sources were received (in seconds) (integer value) # Minimum value: 1 #initialization_interval = 3 # maximum retries for consistency initialization for finding if all end -# messages from plugins were received (in seconds) (integer value) +# messages from data sources were received (in seconds) (integer value) # Minimum value: 1 #initialization_max_retries = 30 @@ -237,8 +237,8 @@ # From vitrage # -# A path for the configuration files of the plugins states (string value) -#states_plugins_dir = /etc/vitrage/states_plugins +# A path for the configuration files of the data sources states (string value) +#states_plugins_dir = /etc/vitrage/datasources_states [evaluator] @@ -392,16 +392,16 @@ [nagios] # -# From plugins +# From datasources # # Nagios plugin transformer class path (string value) -#transformer = vitrage.synchronizer.plugins.nagios.transformer.NagiosTransformer +#transformer = vitrage.datasources.nagios.transformer.NagiosTransformer -# Nagios plugin synchronizer class path (string value) -#synchronizer = vitrage.synchronizer.plugins.nagios.synchronizer.NagiosSynchronizer +# Nagios plugin driver class path (string value) +#synchronizer = vitrage.datasources.nagios.driver.NagiosDriver -# interval between checking changes in nagios plugin (integer value) +# interval between checking changes in nagios datasource (integer value) # Minimum value: 30 #changes_interval = 30 @@ -421,40 +421,40 @@ [nova.host] # -# From plugins +# From datasources # # Nova host transformer class path (string value) -#transformer = vitrage.synchronizer.plugins.nova.host.transformer.HostTransformer +#transformer = vitrage.datasources.nova.host.transformer.HostTransformer -# Nova host synchronizer class path (string value) -#synchronizer = vitrage.synchronizer.plugins.nova.host.synchronizer.HostSynchronizer +# Nova host driver class path (string value) +#synchronizer = vitrage.datasources.nova.host.driver.HostDriver [nova.instance] # -# From plugins +# From datasources # # Nova instance transformer class path (string value) -#transformer = vitrage.synchronizer.plugins.nova.instance.transformer.InstanceTransformer +#transformer = vitrage.datasources.nova.instance.transformer.InstanceTransformer -# Nova instance synchronizer class path (string value) -#synchronizer = vitrage.synchronizer.plugins.nova.instance.synchronizer.InstanceSynchronizer +# Nova instance driver class path (string value) +#synchronizer = vitrage.datasources.nova.instance.driver.InstanceDriver [nova.zone] # -# From plugins +# From datasources # # Nova zone transformer class path (string value) -#transformer = vitrage.synchronizer.plugins.nova.zone.transformer.ZoneTransformer +#transformer = vitrage.datasources.nova.zone.transformer.ZoneTransformer -# Nova zone synchronizer class path (string value) -#synchronizer = vitrage.synchronizer.plugins.nova.zone.synchronizer.ZoneSynchronizer +# Nova zone driver class path (string value) +#synchronizer = vitrage.datasources.nova.zone.driver.ZoneDriver [oslo_middleware] diff --git a/vitrage/api/controllers/rest.py b/vitrage/api/controllers/rest.py index fea939094..c1eca381f 100644 --- a/vitrage/api/controllers/rest.py +++ b/vitrage/api/controllers/rest.py @@ -20,7 +20,7 @@ import pecan as pecan from pecan import abort from pecan import rest -from vitrage.synchronizer.plugins import OPENSTACK_NODE +from vitrage.datasources import OPENSTACK_NODE LOG = log.getLogger(__name__) diff --git a/vitrage/cmd/graph.py b/vitrage/cmd/graph.py index 4241f3de1..c834caecc 100644 --- a/vitrage/cmd/graph.py +++ b/vitrage/cmd/graph.py @@ -19,6 +19,8 @@ import sys from oslo_service import service as os_service from vitrage.common.constants import EntityCategory +from vitrage.datasources import launcher as datasource_launcher +from vitrage.datasources 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 @@ -27,8 +29,6 @@ from vitrage.entity_graph import service as entity_graph_svc 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(): @@ -42,9 +42,9 @@ def main(): conf, event_queue, evaluator, e_graph, initialization_status = init() launcher = os_service.ServiceLauncher(conf) - synchronizers = synchronizers_launcher.Launcher( + synchronizers = datasource_launcher.Launcher( conf, - synchronizers_launcher.create_send_to_queue_callback(event_queue)) + datasource_launcher.create_send_to_queue_callback(event_queue)) launcher.launch_service(entity_graph_svc.VitrageGraphService( conf, event_queue, evaluator, e_graph, initialization_status)) diff --git a/vitrage/datasources/__init__.py b/vitrage/datasources/__init__.py new file mode 100644 index 000000000..503e400ec --- /dev/null +++ b/vitrage/datasources/__init__.py @@ -0,0 +1,48 @@ +# 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.datasources.aodh import AODH_DATASOURCE +from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.neutron.network import NEUTRON_NETWORK_DATASOURCE +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE + +OPENSTACK_NODE = 'openstack.node' + +# Register options for the service +OPTS = [ + + cfg.ListOpt('types', + default=[NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + NAGIOS_DATASOURCE, + STATIC_PHYSICAL_DATASOURCE, + AODH_DATASOURCE, + CINDER_VOLUME_DATASOURCE, + NEUTRON_NETWORK_DATASOURCE], + help='Names of supported data sources'), + cfg.ListOpt('path', + default=['vitrage.datasources'], + help='base path for data sources'), + cfg.IntOpt('snapshots_interval', + default=600, + min=10, + help='interval between full snapshots') +] diff --git a/vitrage/synchronizer/plugins/base/alarm/synchronizer.py b/vitrage/datasources/alarm_driver_base.py similarity index 92% rename from vitrage/synchronizer/plugins/base/alarm/synchronizer.py rename to vitrage/datasources/alarm_driver_base.py index f399d7aa0..4258187ef 100644 --- a/vitrage/synchronizer/plugins/base/alarm/synchronizer.py +++ b/vitrage/datasources/alarm_driver_base.py @@ -13,14 +13,15 @@ # under the License. from oslo_log import log -from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase + +from vitrage.datasources.driver_base import DriverBase LOG = log.getLogger(__name__) -class BaseAlarmSynchronizer(SynchronizerBase): +class AlarmDriverBase(DriverBase): def __init__(self): - super(SynchronizerBase, self).__init__() + super(DriverBase, self).__init__() self.cache = dict() def _sync_type(self): @@ -83,14 +84,14 @@ class BaseAlarmSynchronizer(SynchronizerBase): self._enrich_alarms(alarms) return self._filter_and_cache_alarms( alarms, - BaseAlarmSynchronizer._filter_get_all) + AlarmDriverBase._filter_get_all) def _get_changed_alarms(self): alarms = self._get_alarms() self._enrich_alarms(alarms) return self._filter_and_cache_alarms( alarms, - BaseAlarmSynchronizer._filter_get_changes) + AlarmDriverBase._filter_get_changes) def _filter_and_cache_alarms(self, alarms, filter_): alarms_to_update = [] diff --git a/vitrage/synchronizer/plugins/base/alarm/properties.py b/vitrage/datasources/alarm_properties.py similarity index 100% rename from vitrage/synchronizer/plugins/base/alarm/properties.py rename to vitrage/datasources/alarm_properties.py diff --git a/vitrage/synchronizer/plugins/base/alarm/transformer.py b/vitrage/datasources/alarm_transformer_base.py similarity index 93% rename from vitrage/synchronizer/plugins/base/alarm/transformer.py rename to vitrage/datasources/alarm_transformer_base.py index 24f1017d8..2e1fe2b15 100644 --- a/vitrage/synchronizer/plugins/base/alarm/transformer.py +++ b/vitrage/datasources/alarm_transformer_base.py @@ -19,12 +19,12 @@ from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.exception import VitrageTransformerError -from vitrage.synchronizer.plugins import transformer_base as tbase +from vitrage.datasources import transformer_base as tbase LOG = logging.getLogger(__name__) -class BaseAlarmTransformer(tbase.TransformerBase): +class AlarmTransformerBase(tbase.TransformerBase): def __init__(self, transformers): self.transformers = transformers diff --git a/vitrage/synchronizer/plugins/aodh/__init__.py b/vitrage/datasources/aodh/__init__.py similarity index 67% rename from vitrage/synchronizer/plugins/aodh/__init__.py rename to vitrage/datasources/aodh/__init__.py index 9024bcd93..c5029ceb1 100644 --- a/vitrage/synchronizer/plugins/aodh/__init__.py +++ b/vitrage/datasources/aodh/__init__.py @@ -14,22 +14,21 @@ from oslo_config import cfg -AODH_PLUGIN = 'aodh' +AODH_DATASOURCE = 'aodh' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.aodh.' + default='vitrage.datasources.aodh.' 'transformer.AodhTransformer', - help='Aodh plugin transformer class path', + help='Aodh transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.aodh.synchronizer' - '.AodhSynchronizer', - help='Aodh plugin synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.aodh.driver.AodhDriver', + help='Aodh driver class path', required=True), cfg.IntOpt('changes_interval', default=30, min=30, - help='interval between checking changes in aodh plugin', + help='interval between checking changes in aodh data source', required=True), ] diff --git a/vitrage/synchronizer/plugins/aodh/synchronizer.py b/vitrage/datasources/aodh/driver.py similarity index 77% rename from vitrage/synchronizer/plugins/aodh/synchronizer.py rename to vitrage/datasources/aodh/driver.py index a4db2a8fa..e5de21fc6 100644 --- a/vitrage/synchronizer/plugins/aodh/synchronizer.py +++ b/vitrage/datasources/aodh/driver.py @@ -15,23 +15,21 @@ 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 -from vitrage.synchronizer.plugins.base.alarm.synchronizer \ - import BaseAlarmSynchronizer +from vitrage.datasources.alarm_driver_base import AlarmDriverBase +from vitrage.datasources.aodh import AODH_DATASOURCE +from vitrage.datasources.aodh.properties import AodhProperties as AodhProps +from vitrage.datasources.aodh.properties import AodhState LOG = log.getLogger(__name__) -class AodhSynchronizer(BaseAlarmSynchronizer): +class AodhDriver(AlarmDriverBase): def __init__(self, conf): - super(AodhSynchronizer, self).__init__() + super(AodhDriver, self).__init__() self.client = clients.ceilometer_client(conf) def _sync_type(self): - return AODH_PLUGIN + return AODH_DATASOURCE def _alarm_key(self, alarm): return alarm[AodhProps.NAME] @@ -60,19 +58,19 @@ class AodhSynchronizer(BaseAlarmSynchronizer): @staticmethod def _convert_event_alarm(alarm): - converted_alarm = AodhSynchronizer._convert_base_alarm(alarm) + converted_alarm = AodhDriver._convert_base_alarm(alarm) event_type, resource_id = \ - AodhSynchronizer._parse_event_rule(alarm.event_rule) + AodhDriver._parse_event_rule(alarm.event_rule) converted_alarm[AodhProps.EVENT_TYPE] = event_type converted_alarm[AodhProps.RESOURCE_ID] = resource_id return converted_alarm @staticmethod def _convert_threshold_alarm(alarm): - converted_alarm = AodhSynchronizer._convert_base_alarm(alarm) + converted_alarm = AodhDriver._convert_base_alarm(alarm) converted_alarm[AodhProps.STATE_TIMESTAMP] = alarm.state_timestamp converted_alarm[AodhProps.RESOURCE_ID] = \ - AodhSynchronizer._parse_threshold_rule(alarm.threshold_rule) + AodhDriver._parse_threshold_rule(alarm.threshold_rule) return converted_alarm @staticmethod @@ -96,12 +94,12 @@ class AodhSynchronizer(BaseAlarmSynchronizer): def _parse_event_rule(rule): event_type = rule[AodhProps.EVENT_TYPE] resource_id = \ - AodhSynchronizer._parse_resource_id(rule[AodhProps.QUERY]) + AodhDriver._parse_resource_id(rule[AodhProps.QUERY]) return event_type, resource_id @staticmethod def _parse_threshold_rule(rule): - return AodhSynchronizer._parse_resource_id(rule[AodhProps.QUERY]) + return AodhDriver._parse_resource_id(rule[AodhProps.QUERY]) @staticmethod def _parse_resource_id(query_fields): @@ -116,8 +114,8 @@ class AodhSynchronizer(BaseAlarmSynchronizer): def _convert_alarm(alarm): alarm_type = alarm.type if alarm_type == AodhProps.EVENT: - return AodhSynchronizer._convert_event_alarm(alarm) + return AodhDriver._convert_event_alarm(alarm) elif alarm_type == AodhProps.THRESHOLD: - return AodhSynchronizer._convert_threshold_alarm(alarm) + return AodhDriver._convert_threshold_alarm(alarm) else: LOG.info('Unsupported Aodh alarm of type %s' % alarm_type) diff --git a/vitrage/synchronizer/plugins/aodh/properties.py b/vitrage/datasources/aodh/properties.py similarity index 100% rename from vitrage/synchronizer/plugins/aodh/properties.py rename to vitrage/datasources/aodh/properties.py diff --git a/vitrage/synchronizer/plugins/aodh/transformer.py b/vitrage/datasources/aodh/transformer.py similarity index 90% rename from vitrage/synchronizer/plugins/aodh/transformer.py rename to vitrage/datasources/aodh/transformer.py index 33eb7b36c..e71d65846 100644 --- a/vitrage/synchronizer/plugins/aodh/transformer.py +++ b/vitrage/datasources/aodh/transformer.py @@ -18,20 +18,17 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties as VProps from vitrage.common import datetime_utils +from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps +from vitrage.datasources.alarm_transformer_base import AlarmTransformerBase +from vitrage.datasources.aodh.properties import AodhProperties as AodhProps +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import Neighbor import vitrage.graph.utils as graph_utils -from vitrage.synchronizer.plugins.aodh.properties import AodhProperties \ - as AodhProps -from vitrage.synchronizer.plugins.base.alarm.properties \ - import AlarmProperties as AlarmProps -from vitrage.synchronizer.plugins.base.alarm.transformer \ - import BaseAlarmTransformer -from vitrage.synchronizer.plugins import transformer_base as tbase -from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) -class AodhTransformer(BaseAlarmTransformer): +class AodhTransformer(AlarmTransformerBase): STATUS_OK = 'ok' diff --git a/vitrage/synchronizer/plugins/cinder/__init__.py b/vitrage/datasources/cinder/__init__.py similarity index 100% rename from vitrage/synchronizer/plugins/cinder/__init__.py rename to vitrage/datasources/cinder/__init__.py diff --git a/vitrage/synchronizer/plugins/cinder/volume/__init__.py b/vitrage/datasources/cinder/volume/__init__.py similarity index 70% rename from vitrage/synchronizer/plugins/cinder/volume/__init__.py rename to vitrage/datasources/cinder/volume/__init__.py index e3ab2f8af..c0a14fde7 100644 --- a/vitrage/synchronizer/plugins/cinder/volume/__init__.py +++ b/vitrage/datasources/cinder/volume/__init__.py @@ -14,18 +14,18 @@ from oslo_config import cfg -CINDER_VOLUME_PLUGIN = 'cinder.volume' +CINDER_VOLUME_DATASOURCE = 'cinder.volume' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.cinder.volume.' - 'transformer.CinderVolumeTransformer', + default='vitrage.datasources.cinder.volume.transformer.' + 'CinderVolumeTransformer', help='Nova host transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.cinder.volume.' - 'synchronizer.CinderVolumeSynchronizer', - help='Nova host synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.cinder.volume.driver.' + 'CinderVolumeDriver', + help='Nova host driver class path', required=True), cfg.StrOpt('notification_topic', default='vitrage_notifications', diff --git a/vitrage/synchronizer/plugins/cinder/volume/synchronizer.py b/vitrage/datasources/cinder/volume/driver.py similarity index 71% rename from vitrage/synchronizer/plugins/cinder/volume/synchronizer.py rename to vitrage/datasources/cinder/volume/driver.py index dafd13887..3ca2f7c81 100644 --- a/vitrage/synchronizer/plugins/cinder/volume/synchronizer.py +++ b/vitrage/datasources/cinder/volume/driver.py @@ -17,16 +17,16 @@ from oslo_log import log as logging from vitrage import clients from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode -from vitrage.synchronizer.plugins.cinder.volume import CINDER_VOLUME_PLUGIN -from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase +from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE +from vitrage.datasources.driver_base import DriverBase LOG = logging.getLogger(__name__) -class CinderVolumeSynchronizer(SynchronizerBase): +class CinderVolumeDriver(DriverBase): def __init__(self, conf): - super(CinderVolumeSynchronizer, self).__init__() + super(CinderVolumeDriver, self).__init__() self.client = clients.cinder_client(conf) self.conf = conf @@ -37,16 +37,16 @@ class CinderVolumeSynchronizer(SynchronizerBase): def get_all(self, sync_mode): return self.make_pickleable( self.extract_events(self.client.volumes.list()), - CINDER_VOLUME_PLUGIN, + CINDER_VOLUME_DATASOURCE, sync_mode) @staticmethod def enrich_event(event, event_type): event[SyncProps.EVENT_TYPE] = event_type - return CinderVolumeSynchronizer.make_pickleable([event], - CINDER_VOLUME_PLUGIN, - SyncMode.UPDATE)[0] + return CinderVolumeDriver.make_pickleable([event], + CINDER_VOLUME_DATASOURCE, + SyncMode.UPDATE)[0] @staticmethod def get_event_types(conf): @@ -54,4 +54,4 @@ class CinderVolumeSynchronizer(SynchronizerBase): @staticmethod def get_topic(conf): - return conf[CINDER_VOLUME_PLUGIN].notification_topic + return conf[CINDER_VOLUME_DATASOURCE].notification_topic diff --git a/vitrage/synchronizer/plugins/cinder/volume/transformer.py b/vitrage/datasources/cinder/volume/transformer.py similarity index 87% rename from vitrage/synchronizer/plugins/cinder/volume/transformer.py rename to vitrage/datasources/cinder/volume/transformer.py index bece1df73..106f6ad6b 100644 --- a/vitrage/synchronizer/plugins/cinder/volume/transformer.py +++ b/vitrage/datasources/cinder/volume/transformer.py @@ -19,21 +19,21 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.resource_transformer_base import \ + ResourceTransformerBase +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import build_key +from vitrage.datasources.transformer_base import extract_field_value +from vitrage.datasources.transformer_base import Neighbor import vitrage.graph.utils as graph_utils -from vitrage.synchronizer.plugins.base.resource.transformer import \ - BaseResourceTransformer -from vitrage.synchronizer.plugins.cinder.volume import CINDER_VOLUME_PLUGIN -from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN -from vitrage.synchronizer.plugins import transformer_base as tbase -from vitrage.synchronizer.plugins.transformer_base import build_key -from vitrage.synchronizer.plugins.transformer_base import extract_field_value -from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) -class CinderVolumeTransformer(BaseResourceTransformer): +class CinderVolumeTransformer(ResourceTransformerBase): # Event types which need to refer them differently UPDATE_EVENT_TYPES = { @@ -85,7 +85,7 @@ class CinderVolumeTransformer(BaseResourceTransformer): entity_key, entity_id=volume_id, entity_category=EntityCategory.RESOURCE, - entity_type=CINDER_VOLUME_PLUGIN, + entity_type=CINDER_VOLUME_DATASOURCE, entity_state=volume_state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, @@ -109,14 +109,14 @@ class CinderVolumeTransformer(BaseResourceTransformer): id_field_path = 'volume_id' if is_update_event else 'id' volume_id = extract_field_value(entity_event, id_field_path) - key_fields = self._key_values(CINDER_VOLUME_PLUGIN, volume_id) + key_fields = self._key_values(CINDER_VOLUME_DATASOURCE, volume_id) return build_key(key_fields) def _create_instance_neighbors(self, entity_event, attachments_property, instance_id_property): - transformer = self.transformers[NOVA_INSTANCE_PLUGIN] + transformer = self.transformers[NOVA_INSTANCE_DATASOURCE] if transformer: return [self._create_instance_neighbor(entity_event, @@ -140,7 +140,7 @@ class CinderVolumeTransformer(BaseResourceTransformer): properties = { VProps.ID: instance_id, - VProps.TYPE: NOVA_INSTANCE_PLUGIN, + VProps.TYPE: NOVA_INSTANCE_DATASOURCE, VProps.SAMPLE_TIMESTAMP: sample_timestamp } instance_vertex = \ diff --git a/vitrage/synchronizer/plugins/synchronizer_base.py b/vitrage/datasources/driver_base.py similarity index 99% rename from vitrage/synchronizer/plugins/synchronizer_base.py rename to vitrage/datasources/driver_base.py index 3b25fe192..aa3995e1c 100644 --- a/vitrage/synchronizer/plugins/synchronizer_base.py +++ b/vitrage/datasources/driver_base.py @@ -26,7 +26,7 @@ LOG = log.getLogger(__name__) @six.add_metaclass(abc.ABCMeta) -class SynchronizerBase(object): +class DriverBase(object): def __init__(self): pass diff --git a/vitrage/synchronizer/launcher.py b/vitrage/datasources/launcher.py similarity index 77% rename from vitrage/synchronizer/launcher.py rename to vitrage/datasources/launcher.py index e210b06fe..d10ed1003 100644 --- a/vitrage/synchronizer/launcher.py +++ b/vitrage/datasources/launcher.py @@ -18,7 +18,7 @@ import itertools from oslo_log import log from oslo_service import service as os_service from oslo_utils import importutils as utils -from vitrage.synchronizer.plugins.listener_service import ListenerService +from vitrage.datasources.listener_service import ListenerService from services import ChangesService from services import SnapshotsService @@ -39,7 +39,7 @@ class Launcher(object): def __init__(self, conf, callback): self.conf = conf self.callback = callback - self.snapshot_plugins = self._register_snapshot_plugins() + self.snapshot_datasources = self._register_snapshot_datasources() self.services = self._register_services() def launch(self): @@ -47,25 +47,25 @@ class Launcher(object): for service in self.services: launcher.launch_service(service, 1) - def _register_snapshot_plugins(self): - return {plugin: utils.import_object(self.conf[plugin].synchronizer, + def _register_snapshot_datasources(self): + return {plugin: utils.import_object(self.conf[plugin].driver, self.conf) - for plugin in self.conf.plugins.plugin_type} + for plugin in self.conf.datasources.types} def _register_services(self): return itertools.chain( (ChangesService(self.conf, - [self.snapshot_plugins[plugin]], + [self.snapshot_datasources[plugin]], self.conf[plugin].changes_interval, self.callback) - for plugin in self.conf.plugins.plugin_type + for plugin in self.conf.datasources.types if opt_exists(self.conf[plugin], CHANGES_INTERVAL)), (SnapshotsService(self.conf, - self.snapshot_plugins, + self.snapshot_datasources, self.callback),), (ListenerService(self.conf, - self.snapshot_plugins, + self.snapshot_datasources, self.callback),),) diff --git a/vitrage/synchronizer/plugins/listener_service.py b/vitrage/datasources/listener_service.py similarity index 73% rename from vitrage/synchronizer/plugins/listener_service.py rename to vitrage/datasources/listener_service.py index 46b36736d..a1c2a5997 100644 --- a/vitrage/synchronizer/plugins/listener_service.py +++ b/vitrage/datasources/listener_service.py @@ -26,34 +26,34 @@ LOG = log.getLogger(__name__) class ListenerService(os_service.Service): - def __init__(self, conf, synchronizers, callback): + def __init__(self, conf, drivers, callback): super(ListenerService, self).__init__() - # Get the topics of the synchronizers and callbacks - topics = self._get_topics_set(synchronizers, conf) + # Get the topics of the drivers and callbacks + topics = self._get_topics_set(drivers, conf) self.enrich_callbacks_by_events = \ - self._create_callbacks_by_events_dict(synchronizers, conf) - self.skipped_event_types = self._get_skipped_event_types(synchronizers) + self._create_callbacks_by_events_dict(drivers, conf) + self.skipped_event_types = self._get_skipped_event_types(drivers) self.listener = self._get_topics_listener(conf, topics, callback) def start(self): - LOG.info("Vitrage Synchronizer Listener Service - Starting...") + LOG.info("Vitrage data source Listener Service - Starting...") super(ListenerService, self).start() self.listener.start() - LOG.info("Vitrage Synchronizer Listener Service - Started!") + LOG.info("Vitrage data source Listener Service - Started!") def stop(self, graceful=False): - LOG.info("Vitrage Synchronizer Listener Service - Stopping...") + LOG.info("Vitrage data source Listener Service - Stopping...") super(ListenerService, self).stop(graceful) - LOG.info("Vitrage Synchronizer Listener Service - Stopped!") + LOG.info("Vitrage data source Listener Service - Stopped!") @staticmethod - def _get_topics_set(synchronizers, conf): - topics = {sync.get_topic(conf) for sync in synchronizers.values()} + def _get_topics_set(drivers, conf): + topics = {driver.get_topic(conf) for driver in drivers.values()} if None in topics: topics.remove(None) @@ -61,12 +61,12 @@ class ListenerService(os_service.Service): return topics @staticmethod - def _create_callbacks_by_events_dict(synchronizers, conf): + def _create_callbacks_by_events_dict(drivers, conf): ret = defaultdict(list) - for sync in synchronizers.values(): - for event in sync.get_event_types(conf): - ret[event].append(sync.enrich_event) + for driver in drivers.values(): + for event in driver.get_event_types(conf): + ret[event].append(driver.enrich_event) return ret @@ -84,10 +84,11 @@ class ListenerService(os_service.Service): self.skipped_event_types)]) @staticmethod - def _get_skipped_event_types(synchronizers): + def _get_skipped_event_types(drivers): + skipped_events = [] - for synchronizer in synchronizers.values(): - skipped_events += synchronizer.get_skipped_event_types() + for driver in drivers.values(): + skipped_events += driver.get_skipped_event_types() return set(skipped_events) @@ -104,8 +105,7 @@ class NotificationsEndpoint(object): def info(self, ctxt, publisher_id, event_type, payload, metadata): # TODO(Alexey): improve skipped implementation because we need to skip - # event depending on the synchronizer and not for all - # synchronizers + # event depending on the drivers and not for all drivers if event_type in self.skipped_event_types: LOG.info('EVENT SKIPPED: ' + str(event_type)) return diff --git a/vitrage/synchronizer/plugins/nagios/__init__.py b/vitrage/datasources/nagios/__init__.py similarity index 74% rename from vitrage/synchronizer/plugins/nagios/__init__.py rename to vitrage/datasources/nagios/__init__.py index 01dda52e9..064fb6a16 100644 --- a/vitrage/synchronizer/plugins/nagios/__init__.py +++ b/vitrage/datasources/nagios/__init__.py @@ -14,23 +14,22 @@ from oslo_config import cfg -NAGIOS_PLUGIN = 'nagios' +NAGIOS_DATASOURCE = 'nagios' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.nagios.' - 'transformer.NagiosTransformer', - help='Nagios plugin transformer class path', + default='vitrage.datasources.nagios.transformer.' + 'NagiosTransformer', + help='Nagios transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.nagios.synchronizer' - '.NagiosSynchronizer', - help='Nagios plugin synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.nagios.driver.NagiosDriver', + help='Nagios driver class path', required=True), cfg.IntOpt('changes_interval', default=30, min=30, - help='interval between checking changes in nagios plugin', + help='interval between checking changes in nagios data source', required=True), cfg.StrOpt('user', default='nagiosadmin', help='Nagios user name'), diff --git a/vitrage/synchronizer/plugins/nagios/config.py b/vitrage/datasources/nagios/config.py similarity index 100% rename from vitrage/synchronizer/plugins/nagios/config.py rename to vitrage/datasources/nagios/config.py diff --git a/vitrage/synchronizer/plugins/nagios/synchronizer.py b/vitrage/datasources/nagios/driver.py similarity index 85% rename from vitrage/synchronizer/plugins/nagios/synchronizer.py rename to vitrage/datasources/nagios/driver.py index 8513ad706..af7088e8f 100644 --- a/vitrage/synchronizer/plugins/nagios/synchronizer.py +++ b/vitrage/datasources/nagios/driver.py @@ -18,32 +18,31 @@ from oslo_log import log import requests from vitrage.common.constants import SynchronizerProperties as SyncProps +from vitrage.datasources.alarm_driver_base import AlarmDriverBase +from vitrage.datasources.nagios.config import NagiosConfig +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nagios.parser import NagiosParser +from vitrage.datasources.nagios.properties import NagiosProperties\ + as NagiosProps +from vitrage.datasources.nagios.properties import NagiosStatus # noinspection PyProtectedMember from vitrage.i18n import _LE # noinspection PyProtectedMember 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__) -class NagiosSynchronizer(BaseAlarmSynchronizer): +class NagiosDriver(AlarmDriverBase): ServiceKey = namedtuple('ServiceKey', ['host_name', 'service']) def __init__(self, conf): - super(NagiosSynchronizer, self).__init__() + super(NagiosDriver, self).__init__() self.conf = conf self.config = NagiosConfig(conf) def _sync_type(self): - return NAGIOS_PLUGIN + return NAGIOS_DATASOURCE def _alarm_key(self, alarm): return self.ServiceKey(host_name=alarm[NagiosProps.RESOURCE_NAME], diff --git a/vitrage/synchronizer/plugins/nagios/parser.py b/vitrage/datasources/nagios/parser.py similarity index 98% rename from vitrage/synchronizer/plugins/nagios/parser.py rename to vitrage/datasources/nagios/parser.py index e616739bd..d666b9dd1 100644 --- a/vitrage/synchronizer/plugins/nagios/parser.py +++ b/vitrage/datasources/nagios/parser.py @@ -14,8 +14,9 @@ from lxml import etree from oslo_log import log + from six.moves import StringIO -from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties +from vitrage.datasources.nagios.properties import NagiosProperties LOG = log.getLogger(__name__) diff --git a/vitrage/synchronizer/plugins/nagios/properties.py b/vitrage/datasources/nagios/properties.py similarity index 100% rename from vitrage/synchronizer/plugins/nagios/properties.py rename to vitrage/datasources/nagios/properties.py diff --git a/vitrage/synchronizer/plugins/nagios/transformer.py b/vitrage/datasources/nagios/transformer.py similarity index 86% rename from vitrage/synchronizer/plugins/nagios/transformer.py rename to vitrage/datasources/nagios/transformer.py index 4a6da6196..8c7cf6e78 100644 --- a/vitrage/synchronizer/plugins/nagios/transformer.py +++ b/vitrage/datasources/nagios/transformer.py @@ -19,22 +19,20 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties as VProps from vitrage.common import datetime_utils +from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps +from vitrage.datasources.alarm_transformer_base import AlarmTransformerBase +from vitrage.datasources.nagios.properties import NagiosProperties +from vitrage.datasources.nagios.properties import NagiosStatus +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.static_physical import SWITCH +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import Neighbor import vitrage.graph.utils as graph_utils -from vitrage.synchronizer.plugins.base.alarm.properties \ - import AlarmProperties as AlarmProps -from vitrage.synchronizer.plugins.base.alarm.transformer \ - import BaseAlarmTransformer -from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties -from vitrage.synchronizer.plugins.nagios.properties import NagiosStatus -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 -from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) -class NagiosTransformer(BaseAlarmTransformer): +class NagiosTransformer(AlarmTransformerBase): STATUS_OK = 'OK' @@ -87,7 +85,7 @@ class NagiosTransformer(BaseAlarmTransformer): tbase.TIMESTAMP_FORMAT) resource_type = entity_event[NagiosProperties.RESOURCE_TYPE] - if resource_type == NOVA_HOST_PLUGIN or resource_type == SWITCH: + if resource_type == NOVA_HOST_DATASOURCE or resource_type == SWITCH: return [self._create_neighbor( vitrage_id, timestamp, diff --git a/vitrage/synchronizer/plugins/neutron/__init__.py b/vitrage/datasources/neutron/__init__.py similarity index 100% rename from vitrage/synchronizer/plugins/neutron/__init__.py rename to vitrage/datasources/neutron/__init__.py diff --git a/vitrage/synchronizer/plugins/neutron/base.py b/vitrage/datasources/neutron/base.py similarity index 87% rename from vitrage/synchronizer/plugins/neutron/base.py rename to vitrage/datasources/neutron/base.py index a2ccf0cb2..248e4f92e 100644 --- a/vitrage/synchronizer/plugins/neutron/base.py +++ b/vitrage/datasources/neutron/base.py @@ -14,10 +14,10 @@ from vitrage import clients -from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase +from vitrage.datasources.driver_base import DriverBase -class NeutronBase(SynchronizerBase): +class NeutronBase(DriverBase): def __init__(self, conf): super(NeutronBase, self).__init__() self.client = clients.neutron_client(conf) diff --git a/vitrage/synchronizer/plugins/neutron/network/__init__.py b/vitrage/datasources/neutron/network/__init__.py similarity index 66% rename from vitrage/synchronizer/plugins/neutron/network/__init__.py rename to vitrage/datasources/neutron/network/__init__.py index 0982d8cc5..b7f86ce07 100644 --- a/vitrage/synchronizer/plugins/neutron/network/__init__.py +++ b/vitrage/datasources/neutron/network/__init__.py @@ -14,17 +14,17 @@ from oslo_config import cfg -NEUTRON_NETWORK_PLUGIN = 'neutron.network' +NEUTRON_NETWORK_DATASOURCE = 'neutron.network' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.neutron.network.' - 'transformer.NetworkTransformer', + default='vitrage.datasources.neutron.network.transformer.' + 'NetworkTransformer', help='Neutron network transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.neutron.network.' - 'synchronizer.NetworkSynchronizer', - help='Neutron network synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.neutron.network.driver.' + 'NetworkDriver', + help='Neutron network driver class path', required=True), ] diff --git a/vitrage/synchronizer/plugins/neutron/network/synchronizer.py b/vitrage/datasources/neutron/network/driver.py similarity index 81% rename from vitrage/synchronizer/plugins/neutron/network/synchronizer.py rename to vitrage/datasources/neutron/network/driver.py index c7d39792e..0f20035b3 100644 --- a/vitrage/synchronizer/plugins/neutron/network/synchronizer.py +++ b/vitrage/datasources/neutron/network/driver.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -from vitrage.synchronizer.plugins.neutron.base import NeutronBase -from vitrage.synchronizer.plugins.neutron.network import NEUTRON_NETWORK_PLUGIN +from vitrage.datasources.neutron.base import NeutronBase +from vitrage.datasources.neutron.network import NEUTRON_NETWORK_DATASOURCE -class NetworkSynchronizer(NeutronBase): +class NetworkDriver(NeutronBase): @staticmethod def get_skipped_event_types(): @@ -37,5 +37,5 @@ class NetworkSynchronizer(NeutronBase): def get_all(self, sync_mode): return self.make_pickleable( self.client.list_networks()['networks'], - NEUTRON_NETWORK_PLUGIN, + NEUTRON_NETWORK_DATASOURCE, sync_mode) diff --git a/vitrage/synchronizer/plugins/neutron/network/transformer.py b/vitrage/datasources/neutron/network/transformer.py similarity index 84% rename from vitrage/synchronizer/plugins/neutron/network/transformer.py rename to vitrage/datasources/neutron/network/transformer.py index ed2b9e803..857641857 100644 --- a/vitrage/synchronizer/plugins/neutron/network/transformer.py +++ b/vitrage/datasources/neutron/network/transformer.py @@ -15,16 +15,15 @@ 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.base.resource.transformer import \ - BaseResourceTransformer -from vitrage.synchronizer.plugins.neutron.network import NEUTRON_NETWORK_PLUGIN -from vitrage.synchronizer.plugins import transformer_base as tbase -from vitrage.synchronizer.plugins.transformer_base import extract_field_value - +from vitrage.datasources.neutron.network import NEUTRON_NETWORK_DATASOURCE +from vitrage.datasources.resource_transformer_base import \ + ResourceTransformerBase +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import extract_field_value import vitrage.graph.utils as graph_utils -class NetworkTransformer(BaseResourceTransformer): +class NetworkTransformer(ResourceTransformerBase): UPDATE_EVENT_TYPES = {} @@ -34,7 +33,7 @@ class NetworkTransformer(BaseResourceTransformer): def _create_entity_key(self, entity_event): network_id = 'network_id' if tbase.is_update_event(entity_event) \ else 'id' - key_fields = self._key_values(NEUTRON_NETWORK_PLUGIN, + key_fields = self._key_values(NEUTRON_NETWORK_DATASOURCE, extract_field_value(entity_event, network_id)) return tbase.build_key(key_fields) @@ -64,7 +63,7 @@ class NetworkTransformer(BaseResourceTransformer): self._create_entity_key(entity_event), entity_id=entity_id, entity_category=EntityCategory.RESOURCE, - entity_type=NEUTRON_NETWORK_PLUGIN, + entity_type=NEUTRON_NETWORK_DATASOURCE, entity_state=state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, diff --git a/vitrage/synchronizer/plugins/neutron/port/__init__.py b/vitrage/datasources/neutron/port/__init__.py similarity index 71% rename from vitrage/synchronizer/plugins/neutron/port/__init__.py rename to vitrage/datasources/neutron/port/__init__.py index 0d67681c4..d18158c8c 100644 --- a/vitrage/synchronizer/plugins/neutron/port/__init__.py +++ b/vitrage/datasources/neutron/port/__init__.py @@ -14,17 +14,16 @@ from oslo_config import cfg -NEUTRON_PORT_PLUGIN = 'neutron.port' +NEUTRON_PORT_DATASOURCE = 'neutron.port' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.neutron.port.' + default='vitrage.datasources.neutron.port.' 'transformer.PortTransformer', help='Neutron port transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.neutron.port.' - 'synchronizer.PortSynchronizer', - help='Neutron port synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.neutron.port.driver.PortDriver', + help='Neutron port driver class path', required=True), ] diff --git a/vitrage/synchronizer/plugins/neutron/port/synchronizer.py b/vitrage/datasources/neutron/port/driver.py similarity index 82% rename from vitrage/synchronizer/plugins/neutron/port/synchronizer.py rename to vitrage/datasources/neutron/port/driver.py index 76483683e..3208000b4 100644 --- a/vitrage/synchronizer/plugins/neutron/port/synchronizer.py +++ b/vitrage/datasources/neutron/port/driver.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -from vitrage.synchronizer.plugins.neutron.base import NeutronBase -from vitrage.synchronizer.plugins.neutron.port import NEUTRON_PORT_PLUGIN +from vitrage.datasources.neutron.base import NeutronBase +from vitrage.datasources.neutron.port import NEUTRON_PORT_DATASOURCE -class PortSynchronizer(NeutronBase): +class PortDriver(NeutronBase): @staticmethod def get_skipped_event_types(): @@ -37,5 +37,5 @@ class PortSynchronizer(NeutronBase): def get_all(self, sync_mode): return self.make_pickleable( self.client.list_ports()['ports'], - NEUTRON_PORT_PLUGIN, + NEUTRON_PORT_DATASOURCE, sync_mode) diff --git a/vitrage/synchronizer/plugins/neutron/port/transformer.py b/vitrage/datasources/neutron/port/transformer.py similarity index 87% rename from vitrage/synchronizer/plugins/neutron/port/transformer.py rename to vitrage/datasources/neutron/port/transformer.py index 9bc891f8d..e3c83bf97 100644 --- a/vitrage/synchronizer/plugins/neutron/port/transformer.py +++ b/vitrage/datasources/neutron/port/transformer.py @@ -11,6 +11,8 @@ # 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.datasources.resource_transformer_base import \ + ResourceTransformerBase from oslo_log import log as logging @@ -18,28 +20,26 @@ 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.base.resource.transformer import \ - BaseResourceTransformer -from vitrage.synchronizer.plugins.neutron.network import NEUTRON_NETWORK_PLUGIN -from vitrage.synchronizer.plugins.neutron.port import NEUTRON_PORT_PLUGIN -from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN -from vitrage.synchronizer.plugins import transformer_base as tbase -from vitrage.synchronizer.plugins.transformer_base import extract_field_value -from vitrage.synchronizer.plugins.transformer_base import Neighbor +from vitrage.datasources.neutron.network import NEUTRON_NETWORK_DATASOURCE +from vitrage.datasources.neutron.port import NEUTRON_PORT_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import extract_field_value +from vitrage.datasources.transformer_base import Neighbor import vitrage.graph.utils as graph_utils LOG = logging.getLogger(__name__) -class PortTransformer(BaseResourceTransformer): +class PortTransformer(ResourceTransformerBase): def __init__(self, transformers): super(PortTransformer, self).__init__(transformers) def _create_entity_key(self, entity_event): port_id = 'port_id' if tbase.is_update_event(entity_event) \ else 'id' - key_fields = self._key_values(NEUTRON_PORT_PLUGIN, + key_fields = self._key_values(NEUTRON_PORT_DATASOURCE, extract_field_value(entity_event, port_id)) return tbase.build_key(key_fields) @@ -70,7 +70,7 @@ class PortTransformer(BaseResourceTransformer): self._create_entity_key(entity_event), entity_id=entity_id, entity_category=EntityCategory.RESOURCE, - entity_type=NEUTRON_PORT_PLUGIN, + entity_type=NEUTRON_PORT_DATASOURCE, entity_state=state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, @@ -122,7 +122,7 @@ class PortTransformer(BaseResourceTransformer): properties = { VProps.ID: instance_id, - VProps.TYPE: NOVA_INSTANCE_PLUGIN, + VProps.TYPE: NOVA_INSTANCE_DATASOURCE, VProps.SAMPLE_TIMESTAMP: sample_timestamp } instance_vertex = self.create_placeholder_vertex(**properties) @@ -143,7 +143,7 @@ class PortTransformer(BaseResourceTransformer): properties = { VProps.ID: net_id, - VProps.TYPE: NEUTRON_NETWORK_PLUGIN, + VProps.TYPE: NEUTRON_NETWORK_DATASOURCE, VProps.SAMPLE_TIMESTAMP: sample_timestamp } diff --git a/vitrage/datasources/nova/__init__.py b/vitrage/datasources/nova/__init__.py new file mode 100644 index 000000000..6a20380a1 --- /dev/null +++ b/vitrage/datasources/nova/__init__.py @@ -0,0 +1 @@ +__author__ = 'stack' diff --git a/vitrage/synchronizer/plugins/nova/host/__init__.py b/vitrage/datasources/nova/host/__init__.py similarity index 72% rename from vitrage/synchronizer/plugins/nova/host/__init__.py rename to vitrage/datasources/nova/host/__init__.py index fae366de5..fb498ab00 100644 --- a/vitrage/synchronizer/plugins/nova/host/__init__.py +++ b/vitrage/datasources/nova/host/__init__.py @@ -14,17 +14,16 @@ from oslo_config import cfg -NOVA_HOST_PLUGIN = 'nova.host' +NOVA_HOST_DATASOURCE = 'nova.host' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.nova.host.' + default='vitrage.datasources.nova.host.' 'transformer.HostTransformer', help='Nova host transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.nova.host.synchronizer' - '.HostSynchronizer', - help='Nova host synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.nova.host.driver.HostDriver', + help='Nova host driver class path', required=True), ] diff --git a/vitrage/synchronizer/plugins/nova/host/synchronizer.py b/vitrage/datasources/nova/host/driver.py similarity index 84% rename from vitrage/synchronizer/plugins/nova/host/synchronizer.py rename to vitrage/datasources/nova/host/driver.py index 96142a857..b74f92dfe 100644 --- a/vitrage/synchronizer/plugins/nova/host/synchronizer.py +++ b/vitrage/datasources/nova/host/driver.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -from vitrage.synchronizer.plugins.nova.base import NovaBase -from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.nova_driver_base import NovaDriverBase -class HostSynchronizer(NovaBase): +class HostDriver(NovaDriverBase): @staticmethod def filter_none_compute_hosts(entities): @@ -30,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()), - NOVA_HOST_PLUGIN, + NOVA_HOST_DATASOURCE, sync_mode, 'manager') diff --git a/vitrage/synchronizer/plugins/nova/host/transformer.py b/vitrage/datasources/nova/host/transformer.py similarity index 83% rename from vitrage/synchronizer/plugins/nova/host/transformer.py rename to vitrage/datasources/nova/host/transformer.py index 741aca012..6c30e0ecc 100644 --- a/vitrage/synchronizer/plugins/nova/host/transformer.py +++ b/vitrage/datasources/nova/host/transformer.py @@ -18,20 +18,20 @@ 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.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources.resource_transformer_base import \ + ResourceTransformerBase +from vitrage.datasources import transformer_base +from vitrage.datasources.transformer_base import extract_field_value +from vitrage.datasources.transformer_base import Neighbor 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 -from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) -class HostTransformer(BaseResourceTransformer): +class HostTransformer(ResourceTransformerBase): def __init__(self, transformers): super(HostTransformer, self).__init__(transformers) @@ -57,7 +57,7 @@ class HostTransformer(BaseResourceTransformer): entity_key, entity_id=host_name, entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_HOST_PLUGIN, + entity_type=NOVA_HOST_DATASOURCE, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, metadata=metadata) @@ -84,7 +84,7 @@ class HostTransformer(BaseResourceTransformer): host_vertex_id, zone_name_path): - zone_transformer = self.transformers[NOVA_ZONE_PLUGIN] + zone_transformer = self.transformers[NOVA_ZONE_DATASOURCE] if zone_transformer: @@ -92,7 +92,7 @@ class HostTransformer(BaseResourceTransformer): properties = { VProps.ID: zone_name, - VProps.TYPE: NOVA_ZONE_PLUGIN, + VProps.TYPE: NOVA_ZONE_DATASOURCE, VProps.SAMPLE_TIMESTAMP: sample_timestamp } zone_neighbor = zone_transformer.create_placeholder_vertex( @@ -112,5 +112,5 @@ class HostTransformer(BaseResourceTransformer): host_name = extract_field_value(entity_event, '_info', 'host_name') - key_fields = self._key_values(NOVA_HOST_PLUGIN, host_name) + key_fields = self._key_values(NOVA_HOST_DATASOURCE, host_name) return transformer_base.build_key(key_fields) diff --git a/vitrage/synchronizer/plugins/nova/instance/__init__.py b/vitrage/datasources/nova/instance/__init__.py similarity index 70% rename from vitrage/synchronizer/plugins/nova/instance/__init__.py rename to vitrage/datasources/nova/instance/__init__.py index ce200d02c..dfaa517c5 100644 --- a/vitrage/synchronizer/plugins/nova/instance/__init__.py +++ b/vitrage/datasources/nova/instance/__init__.py @@ -14,18 +14,18 @@ from oslo_config import cfg -NOVA_INSTANCE_PLUGIN = 'nova.instance' +NOVA_INSTANCE_DATASOURCE = 'nova.instance' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.nova.instance.' - 'transformer.InstanceTransformer', + default='vitrage.datasources.nova.instance.transformer.' + 'InstanceTransformer', help='Nova instance transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.nova.instance.' - 'synchronizer.InstanceSynchronizer', - help='Nova instance synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.nova.instance.driver.' + 'InstanceDriver', + help='Nova instance driver class path', required=True), cfg.StrOpt('notification_topic', default='vitrage_notifications', diff --git a/vitrage/synchronizer/plugins/nova/instance/synchronizer.py b/vitrage/datasources/nova/instance/driver.py similarity index 75% rename from vitrage/synchronizer/plugins/nova/instance/synchronizer.py rename to vitrage/datasources/nova/instance/driver.py index 4b686b182..b18f41fca 100644 --- a/vitrage/synchronizer/plugins/nova/instance/synchronizer.py +++ b/vitrage/datasources/nova/instance/driver.py @@ -16,13 +16,13 @@ from oslo_log import log as logging from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode -from vitrage.synchronizer.plugins.nova.base import NovaBase -from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.nova_driver_base import NovaDriverBase LOG = logging.getLogger(__name__) -class InstanceSynchronizer(NovaBase): +class InstanceDriver(NovaDriverBase): @staticmethod def extract_events(instances): @@ -31,7 +31,7 @@ class InstanceSynchronizer(NovaBase): def get_all(self, sync_mode): return self.make_pickleable( self.extract_events(self.client.servers.list()), - NOVA_INSTANCE_PLUGIN, + NOVA_INSTANCE_DATASOURCE, sync_mode, 'manager') @@ -39,9 +39,9 @@ class InstanceSynchronizer(NovaBase): def enrich_event(event, event_type): event[SyncProps.EVENT_TYPE] = event_type - return InstanceSynchronizer.make_pickleable([event], - NOVA_INSTANCE_PLUGIN, - SyncMode.UPDATE)[0] + return InstanceDriver.make_pickleable([event], + NOVA_INSTANCE_DATASOURCE, + SyncMode.UPDATE)[0] @staticmethod def get_event_types(conf): @@ -53,4 +53,4 @@ class InstanceSynchronizer(NovaBase): @staticmethod def get_topic(conf): - return conf[NOVA_INSTANCE_PLUGIN].notification_topic + return conf[NOVA_INSTANCE_DATASOURCE].notification_topic diff --git a/vitrage/synchronizer/plugins/nova/instance/transformer.py b/vitrage/datasources/nova/instance/transformer.py similarity index 85% rename from vitrage/synchronizer/plugins/nova/instance/transformer.py rename to vitrage/datasources/nova/instance/transformer.py index 5ae17cce4..e030c3e49 100644 --- a/vitrage/synchronizer/plugins/nova/instance/transformer.py +++ b/vitrage/datasources/nova/instance/transformer.py @@ -19,19 +19,20 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.resource_transformer_base import \ + ResourceTransformerBase +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import extract_field_value +from vitrage.datasources.transformer_base import Neighbor 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 as tbase -from vitrage.synchronizer.plugins.transformer_base import extract_field_value -from vitrage.synchronizer.plugins.transformer_base import Neighbor + LOG = logging.getLogger(__name__) -class InstanceTransformer(BaseResourceTransformer): +class InstanceTransformer(ResourceTransformerBase): # Event types which need to refer them differently UPDATE_EVENT_TYPES = { @@ -78,7 +79,7 @@ class InstanceTransformer(BaseResourceTransformer): self._create_entity_key(entity_event), entity_id=entity_id, entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN, + entity_type=NOVA_INSTANCE_DATASOURCE, entity_state=state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, @@ -87,7 +88,7 @@ class InstanceTransformer(BaseResourceTransformer): def _create_neighbors(self, entity_event): neighbors = [] - host_transformer = self.transformers[NOVA_HOST_PLUGIN] + host_transformer = self.transformers[NOVA_HOST_DATASOURCE] host_name = 'host' if tbase.is_update_event(entity_event) \ else 'OS-EXT-SRV-ATTR:host' @@ -107,7 +108,7 @@ class InstanceTransformer(BaseResourceTransformer): def _create_entity_key(self, event): instance_id = 'instance_id' if tbase.is_update_event(event) else 'id' - key_fields = self._key_values(NOVA_INSTANCE_PLUGIN, + key_fields = self._key_values(NOVA_INSTANCE_DATASOURCE, extract_field_value(event, instance_id)) return tbase.build_key(key_fields) @@ -119,7 +120,7 @@ class InstanceTransformer(BaseResourceTransformer): host_transformer): properties = { VProps.ID: host_name, - VProps.TYPE: NOVA_HOST_PLUGIN, + VProps.TYPE: NOVA_HOST_DATASOURCE, VProps.SAMPLE_TIMESTAMP: sample_timestamp } host_vertex = host_transformer.create_placeholder_vertex(**properties) diff --git a/vitrage/synchronizer/plugins/nova/base.py b/vitrage/datasources/nova/nova_driver_base.py similarity index 83% rename from vitrage/synchronizer/plugins/nova/base.py rename to vitrage/datasources/nova/nova_driver_base.py index 789a75978..e1f80ff0a 100644 --- a/vitrage/synchronizer/plugins/nova/base.py +++ b/vitrage/datasources/nova/nova_driver_base.py @@ -14,12 +14,12 @@ from vitrage import clients -from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase +from vitrage.datasources.driver_base import DriverBase -class NovaBase(SynchronizerBase): +class NovaDriverBase(DriverBase): def __init__(self, conf): - super(NovaBase, self).__init__() + super(NovaDriverBase, self).__init__() self.client = clients.nova_client(conf) self.conf = conf diff --git a/vitrage/synchronizer/plugins/nova/zone/__init__.py b/vitrage/datasources/nova/zone/__init__.py similarity index 73% rename from vitrage/synchronizer/plugins/nova/zone/__init__.py rename to vitrage/datasources/nova/zone/__init__.py index 1c1532156..7fa01b05c 100644 --- a/vitrage/synchronizer/plugins/nova/zone/__init__.py +++ b/vitrage/datasources/nova/zone/__init__.py @@ -14,17 +14,17 @@ from oslo_config import cfg -NOVA_ZONE_PLUGIN = 'nova.zone' +NOVA_ZONE_DATASOURCE = 'nova.zone' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.nova.zone.' - 'transformer.ZoneTransformer', + default='vitrage.datasources.nova.zone.transformer.' + 'ZoneTransformer', help='Nova zone transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.nova.zone.synchronizer' - '.ZoneSynchronizer', + cfg.StrOpt('driver', + default='vitrage.datasources.nova.zone.driver' + '.ZoneDriver', help='Nova zone synchronizer class path', required=True), ] diff --git a/vitrage/synchronizer/plugins/nova/zone/synchronizer.py b/vitrage/datasources/nova/zone/driver.py similarity index 84% rename from vitrage/synchronizer/plugins/nova/zone/synchronizer.py rename to vitrage/datasources/nova/zone/driver.py index 2e553abed..30eea9475 100644 --- a/vitrage/synchronizer/plugins/nova/zone/synchronizer.py +++ b/vitrage/datasources/nova/zone/driver.py @@ -10,13 +10,13 @@ # 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.synchronizer.plugins.nova.base import NovaBase -from vitrage.synchronizer.plugins.nova.zone import NOVA_ZONE_PLUGIN +from vitrage.datasources.nova.nova_driver_base import NovaDriverBase +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE -class ZoneSynchronizer(NovaBase): +class ZoneDriver(NovaDriverBase): @staticmethod def filter_internal_zone(zones): @@ -30,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()), - NOVA_ZONE_PLUGIN, + NOVA_ZONE_DATASOURCE, sync_mode, 'manager') diff --git a/vitrage/synchronizer/plugins/nova/zone/transformer.py b/vitrage/datasources/nova/zone/transformer.py similarity index 87% rename from vitrage/synchronizer/plugins/nova/zone/transformer.py rename to vitrage/datasources/nova/zone/transformer.py index bb222f02c..00bf9806d 100644 --- a/vitrage/synchronizer/plugins/nova/zone/transformer.py +++ b/vitrage/datasources/nova/zone/transformer.py @@ -18,19 +18,19 @@ 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.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources.resource_transformer_base import \ + ResourceTransformerBase +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import extract_field_value 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 as tbase -from vitrage.synchronizer.plugins.transformer_base import extract_field_value LOG = logging.getLogger(__name__) -class ZoneTransformer(BaseResourceTransformer): +class ZoneTransformer(ResourceTransformerBase): STATE_AVAILABLE = 'available' STATE_UNAVAILABLE = 'unavailable' @@ -67,7 +67,7 @@ class ZoneTransformer(BaseResourceTransformer): entity_key, entity_id=zone_name, entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_ZONE_PLUGIN, + entity_type=NOVA_ZONE_DATASOURCE, entity_state=state, sample_timestamp=sample_timestamp, update_timestamp=update_timestamp, @@ -78,7 +78,7 @@ class ZoneTransformer(BaseResourceTransformer): zone_vertex_id = self._create_entity_key(entity_event) neighbors = [self._create_node_neighbor(zone_vertex_id)] hosts = extract_field_value(entity_event, 'hosts') - host_transformer = self.transformers[NOVA_HOST_PLUGIN] + host_transformer = self.transformers[NOVA_HOST_DATASOURCE] if host_transformer: for hostname, host_data in hosts.items(): @@ -120,12 +120,12 @@ class ZoneTransformer(BaseResourceTransformer): def _create_host_neighbor(self, zone_id, host_name, host_state, sample_timestamp): - host_transformer = self.transformers[NOVA_HOST_PLUGIN] + host_transformer = self.transformers[NOVA_HOST_DATASOURCE] properties = { VProps.ID: host_name, VProps.SAMPLE_TIMESTAMP: sample_timestamp, - VProps.TYPE: NOVA_HOST_PLUGIN + VProps.TYPE: NOVA_HOST_DATASOURCE } host_neighbor = \ host_transformer.create_placeholder_vertex(**properties) @@ -143,5 +143,5 @@ class ZoneTransformer(BaseResourceTransformer): zone_name = extract_field_value(entity_event, 'zoneName') - key_fields = self._key_values(NOVA_ZONE_PLUGIN, zone_name) + key_fields = self._key_values(NOVA_ZONE_DATASOURCE, zone_name) return tbase.build_key(key_fields) diff --git a/vitrage/synchronizer/plugins/base/resource/transformer.py b/vitrage/datasources/resource_transformer_base.py similarity index 88% rename from vitrage/synchronizer/plugins/base/resource/transformer.py rename to vitrage/datasources/resource_transformer_base.py index 5075e2c50..a99b4f82d 100644 --- a/vitrage/synchronizer/plugins/base/resource/transformer.py +++ b/vitrage/datasources/resource_transformer_base.py @@ -16,15 +16,14 @@ from oslo_log import log as logging from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources import transformer_base as tbase import vitrage.graph.utils as graph_utils -from vitrage.synchronizer.plugins import transformer_base as tbase -from vitrage.synchronizer.plugins import transformer_base LOG = logging.getLogger(__name__) -class BaseResourceTransformer(tbase.TransformerBase): +class ResourceTransformerBase(tbase.TransformerBase): def __init__(self, transformers): self.transformers = transformers @@ -44,7 +43,7 @@ class BaseResourceTransformer(tbase.TransformerBase): key_fields = self._key_values(kwargs[VProps.TYPE], kwargs[VProps.ID]) return graph_utils.create_vertex( - transformer_base.build_key(key_fields), + tbase.build_key(key_fields), entity_id=kwargs[VProps.ID], entity_category=EntityCategory.RESOURCE, entity_type=kwargs[VProps.TYPE], diff --git a/vitrage/synchronizer/services.py b/vitrage/datasources/services.py similarity index 70% rename from vitrage/synchronizer/services.py rename to vitrage/datasources/services.py index 1004eefda..917083c7e 100644 --- a/vitrage/synchronizer/services.py +++ b/vitrage/datasources/services.py @@ -22,42 +22,42 @@ LOG = log.getLogger(__name__) class SynchronizerService(os_service.Service): - def __init__(self, conf, registered_plugins, callback_function): + def __init__(self, conf, registered_datasources, callback_function): super(SynchronizerService, self).__init__() self.conf = conf - self.registered_plugins = registered_plugins + self.registered_datasources = registered_datasources self.callback_function = callback_function class SnapshotsService(SynchronizerService): - def __init__(self, conf, registered_plugins, callback_function): + def __init__(self, conf, registered_datasources, callback_function): super(SnapshotsService, self).__init__(conf, - registered_plugins, + registered_datasources, callback_function) self.first_time = True def start(self): - LOG.info("Vitrage Synchronizer Snapshot Service - Starting...") + LOG.info("Vitrage datasources Snapshot Service - Starting...") super(SnapshotsService, self).start() - interval = self.conf.synchronizer.snapshots_interval + interval = self.conf.datasources.snapshots_interval self.tg.add_timer(interval, self._get_all) - LOG.info("Vitrage Synchronizer Snapshot Service - Started!") + LOG.info("Vitrage datasources Snapshot Service - Started!") def stop(self, graceful=False): - LOG.info("Vitrage Synchronizer Snapshot Service - Stopping...") + LOG.info("Vitrage datasources Snapshot Service - Stopping...") super(SnapshotsService, self).stop() - LOG.info("Vitrage Synchronizer Snapshot Service - Stopped!") + LOG.info("Vitrage datasources Snapshot Service - Stopped!") def _get_all(self): sync_mode = SyncMode.INIT_SNAPSHOT \ if self.first_time else SyncMode.SNAPSHOT LOG.debug("start get all with sync mode %s" % sync_mode) - for plugin in self.registered_plugins.values(): + for plugin in self.registered_datasources.values(): entities_dictionaries = plugin.get_all(sync_mode) for entity in entities_dictionaries: self.callback_function(entity) @@ -68,17 +68,17 @@ class SnapshotsService(SynchronizerService): class ChangesService(SynchronizerService): def __init__(self, conf, - registered_plugins, + registered_datasources, changes_interval, callback_function): super(ChangesService, self).__init__(conf, - registered_plugins, + registered_datasources, callback_function) self.changes_interval = changes_interval def start(self): LOG.info("Vitrage Synchronizer Changes Service For: %s - Starting...", - self.registered_plugins[0].__class__.__name__) + self.registered_datasources[0].__class__.__name__) super(ChangesService, self).start() self.tg.add_timer(interval=self.changes_interval, @@ -86,22 +86,22 @@ class ChangesService(SynchronizerService): initial_delay=self.changes_interval) LOG.info("Vitrage Synchronizer Changes Service For: %s - Started!", - self.registered_plugins[0].__class__.__name__) + self.registered_datasources[0].__class__.__name__) def stop(self, graceful=False): LOG.info("Vitrage Synchronizer Changes Service For: %s - Stopping...", - self.registered_plugins[0].__class__.__name__) + self.registered_datasources[0].__class__.__name__) super(ChangesService, self).stop() LOG.info("Vitrage Synchronizer Changes Service For: %s - Stopped!", - self.registered_plugins[0].__class__.__name__) + self.registered_datasources[0].__class__.__name__) def _get_changes(self): LOG.debug("start get changes") - for plugin in self.registered_plugins: - for entity in plugin.get_changes(SyncMode.UPDATE): + for datasource in self.registered_datasources: + for entity in datasource.get_changes(SyncMode.UPDATE): self.callback_function(entity) LOG.debug("end get changes") diff --git a/vitrage/synchronizer/plugins/static_physical/__init__.py b/vitrage/datasources/static_physical/__init__.py similarity index 65% rename from vitrage/synchronizer/plugins/static_physical/__init__.py rename to vitrage/datasources/static_physical/__init__.py index f9848a6b6..05afb1567 100644 --- a/vitrage/synchronizer/plugins/static_physical/__init__.py +++ b/vitrage/datasources/static_physical/__init__.py @@ -14,28 +14,28 @@ from oslo_config import cfg -STATIC_PHYSICAL_PLUGIN = 'static_physical' +STATIC_PHYSICAL_DATASOURCE = 'static_physical' SWITCH = 'switch' OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.static_physical.' - 'transformer.StaticPhysicalTransformer', + default='vitrage.datasources.static_physical.transformer.' + 'StaticPhysicalTransformer', help='Static physical transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.static_physical' - '.synchronizer.StaticPhysicalSynchronizer', - help='Static physical synchronizer class path', + cfg.StrOpt('driver', + default='vitrage.datasources.static_physical.driver.' + 'StaticPhysicalDriver', + help='Static physical driver class path', required=True), cfg.IntOpt('changes_interval', default=30, min=30, help='interval between checking changes in the configuration ' - 'files of the physical topology plugin', + 'files of the physical topology data sources', required=True), - cfg.StrOpt('directory', default='/etc/vitrage/static_plugins', - help='Static physical plugins directory'), + cfg.StrOpt('directory', default='/etc/vitrage/static_datasources', + help='Static physical data sources directory'), cfg.ListOpt('entities', default=[SWITCH], help='Static physical entity types list') diff --git a/vitrage/synchronizer/plugins/static_physical/synchronizer.py b/vitrage/datasources/static_physical/driver.py similarity index 92% rename from vitrage/synchronizer/plugins/static_physical/synchronizer.py rename to vitrage/datasources/static_physical/driver.py index 4f5906130..99ea47d2b 100644 --- a/vitrage/synchronizer/plugins/static_physical/synchronizer.py +++ b/vitrage/datasources/static_physical/driver.py @@ -19,26 +19,26 @@ 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 +from vitrage.datasources.driver_base import DriverBase +from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE -class StaticPhysicalSynchronizer(SynchronizerBase): +class StaticPhysicalDriver(DriverBase): ENTITIES_SECTION = 'entities' def __init__(self, conf): - super(StaticPhysicalSynchronizer, self).__init__() + super(StaticPhysicalDriver, self).__init__() self.cfg = conf self.cache = {} def get_all(self, sync_mode): return self.make_pickleable(self._get_all_entities(), - STATIC_PHYSICAL_PLUGIN, + STATIC_PHYSICAL_DATASOURCE, sync_mode) def get_changes(self, sync_mode): return self.make_pickleable(self._get_changes_entities(), - STATIC_PHYSICAL_PLUGIN, + STATIC_PHYSICAL_DATASOURCE, sync_mode) def _get_all_entities(self): diff --git a/vitrage/synchronizer/plugins/static_physical/transformer.py b/vitrage/datasources/static_physical/transformer.py similarity index 91% rename from vitrage/synchronizer/plugins/static_physical/transformer.py rename to vitrage/datasources/static_physical/transformer.py index 9f64ae18d..bc42ca801 100644 --- a/vitrage/synchronizer/plugins/static_physical/transformer.py +++ b/vitrage/datasources/static_physical/transformer.py @@ -17,18 +17,18 @@ from oslo_log import log as logging from vitrage.common.constants import EntityCategory from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.resource_transformer_base import \ + ResourceTransformerBase +from vitrage.datasources.static_physical import SWITCH +from vitrage.datasources import transformer_base +from vitrage.datasources.transformer_base import Neighbor 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 -from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) -class StaticPhysicalTransformer(BaseResourceTransformer): +class StaticPhysicalTransformer(ResourceTransformerBase): RELATION_TYPE = 'relation_type' RELATIONSHIPS_SECTION = 'relationships' @@ -129,7 +129,7 @@ class StaticPhysicalTransformer(BaseResourceTransformer): def _register_relations_direction(self): self.relation_direction = {} - relationship = (SWITCH, NOVA_HOST_PLUGIN) + relationship = (SWITCH, NOVA_HOST_DATASOURCE) self.relation_direction[relationship] = True relationship = (SWITCH, SWITCH) diff --git a/vitrage/synchronizer/plugins/transformer_base.py b/vitrage/datasources/transformer_base.py similarity index 93% rename from vitrage/synchronizer/plugins/transformer_base.py rename to vitrage/datasources/transformer_base.py index e5e10b98f..081710bf1 100644 --- a/vitrage/synchronizer/plugins/transformer_base.py +++ b/vitrage/datasources/transformer_base.py @@ -25,8 +25,8 @@ from vitrage.common.constants import EventAction from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.exception import VitrageTransformerError +from vitrage.datasources import OPENSTACK_NODE import vitrage.graph.utils as graph_utils -from vitrage.synchronizer.plugins import OPENSTACK_NODE LOG = logging.getLogger(__name__) @@ -97,13 +97,13 @@ class TransformerBase(object): def transform(self, entity_event): """Transform an entity event into entity wrapper. - Entity event is received from synchronizer it need to be + Entity event is received from driver and it need to be transformed into entity wrapper. The wrapper contains: 1. Entity Vertex - The vertex itself with all fields 2. Neighbor list - neighbor placeholder vertex and an edge 3. Action type - CREATE/UPDATE/DELETE - :param entity_event: a general event from the synchronizer + :param entity_event: a general event from the driver :return: entity wrapper :rtype:EntityWrapper """ @@ -139,9 +139,9 @@ class TransformerBase(object): """Extracts entity neighbors received from a given entity event. Extracting entity neighbors from a given event provided - by synchronizer + by driver - :param entity_event: an event provided by synchronizer + :param entity_event: an event provided by driver :return: neighbors - a list of neighbors where each item in the list is a tuple of (vertex, edge) :rtype: list @@ -154,7 +154,7 @@ class TransformerBase(object): By given an entity event, return a entity key which consisting key fields - :param entity_event: event that returns from the synchronizer + :param entity_event: event that returns from the driver :return: key """ pass @@ -164,7 +164,7 @@ class TransformerBase(object): """Creates placeholder vertex. Placeholder vertex contains only mandatory fields of this entity. - This way other plugins can create placeholder vertices of those + This way other datasources can create placeholder vertices of those entities :param kwargs: the properties for the placeholder vertex @@ -179,7 +179,7 @@ class TransformerBase(object): Decides what action (from constants.EventAction) the processor need to perform according to the data received from the event. - :param entity_event: event that returns from the synchronizer + :param entity_event: event that returns from the driver :return: the action that the processor needs to perform :rtype: str """ diff --git a/vitrage/entity_graph/__init__.py b/vitrage/entity_graph/__init__.py index 2b8bc78de..6ea689c47 100644 --- a/vitrage/entity_graph/__init__.py +++ b/vitrage/entity_graph/__init__.py @@ -17,8 +17,9 @@ from oslo_config import cfg OPTS = [ - cfg.StrOpt('states_plugins_dir', - default='/etc/vitrage/states_plugins', - help='A path for the configuration files of the plugins states' + cfg.StrOpt('datasources_states_dir', + default='/etc/vitrage/datasources_states', + help='A path for the configuration files of the data sources' + ' states' ), ] diff --git a/vitrage/entity_graph/api_handler/entity_graph_api.py b/vitrage/entity_graph/api_handler/entity_graph_api.py index 11522d213..8408a9647 100644 --- a/vitrage/entity_graph/api_handler/entity_graph_api.py +++ b/vitrage/entity_graph/api_handler/entity_graph_api.py @@ -19,12 +19,12 @@ from vitrage.common.constants import EdgeLabels from vitrage.common.constants import EdgeProperties as EProps from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources import OPENSTACK_NODE 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__) @@ -37,9 +37,9 @@ TREE_TOPOLOGY_QUERY = { { 'or': [ {'==': {VProps.TYPE: OPENSTACK_NODE}}, - {'==': {VProps.TYPE: NOVA_INSTANCE_PLUGIN}}, - {'==': {VProps.TYPE: NOVA_HOST_PLUGIN}}, - {'==': {VProps.TYPE: NOVA_ZONE_PLUGIN}} + {'==': {VProps.TYPE: NOVA_INSTANCE_DATASOURCE}}, + {'==': {VProps.TYPE: NOVA_HOST_DATASOURCE}}, + {'==': {VProps.TYPE: NOVA_ZONE_DATASOURCE}} ] } ] diff --git a/vitrage/entity_graph/consistency/__init__.py b/vitrage/entity_graph/consistency/__init__.py index 06d1d6ce4..d278d48f3 100644 --- a/vitrage/entity_graph/consistency/__init__.py +++ b/vitrage/entity_graph/consistency/__init__.py @@ -24,12 +24,12 @@ OPTS = [ default=3, min=1, help='interval between consistency initialization checks for ' - 'finding if all end messages from plugins were ' + 'finding if all end messages from datasources were ' 'received (in seconds)'), cfg.IntOpt('initialization_max_retries', default=30, min=1, help='maximum retries for consistency initialization ' - 'for finding if all end messages from plugins were ' + 'for finding if all end messages from datasources were ' 'received (in seconds)'), ] diff --git a/vitrage/entity_graph/consistency/consistency_enforcer.py b/vitrage/entity_graph/consistency/consistency_enforcer.py index c4b53be46..9ef5328d1 100644 --- a/vitrage/entity_graph/consistency/consistency_enforcer.py +++ b/vitrage/entity_graph/consistency/consistency_enforcer.py @@ -20,8 +20,8 @@ from oslo_log import log from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.common.datetime_utils import utcnow +from vitrage.datasources import OPENSTACK_NODE from vitrage.evaluator.actions.evaluator_event_transformer import VITRAGE_TYPE -from vitrage.synchronizer.plugins import OPENSTACK_NODE LOG = log.getLogger(__name__) @@ -94,7 +94,7 @@ class ConsistencyEnforcer(object): 'and': [ {'!=': {VProps.TYPE: VITRAGE_TYPE}}, {'<': {VProps.SAMPLE_TIMESTAMP: str(utcnow() - timedelta( - seconds=2 * self.conf.synchronizer.snapshots_interval))}} + seconds=2 * self.conf.datasources.snapshots_interval))}} ] } diff --git a/vitrage/entity_graph/consistency/service.py b/vitrage/entity_graph/consistency/service.py index 6372daea8..a306f897b 100644 --- a/vitrage/entity_graph/consistency/service.py +++ b/vitrage/entity_graph/consistency/service.py @@ -47,10 +47,10 @@ class VitrageGraphConsistencyService(os_service.Service): self.evaluator, self.entity_graph, self.initialization_status) - self.tg.add_timer(self.conf.synchronizer.snapshots_interval, + self.tg.add_timer(self.conf.datasources.snapshots_interval, consistency_enf.periodic_process, initial_delay=60 + - self.conf.synchronizer.snapshots_interval) + self.conf.datasources.snapshots_interval) initializing_process_thread = \ threading.Thread(target=consistency_enf.initializing_process) diff --git a/vitrage/entity_graph/processor/processor.py b/vitrage/entity_graph/processor/processor.py index 8d759715a..83e354aa8 100644 --- a/vitrage/entity_graph/processor/processor.py +++ b/vitrage/entity_graph/processor/processor.py @@ -17,12 +17,12 @@ from oslo_log import log from vitrage.common.constants import EventAction from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.transformer_base import TransformerBase from vitrage.entity_graph.processor import base as processor from vitrage.entity_graph.processor import entity_graph from vitrage.entity_graph.states.state_manager import StateManager from vitrage.entity_graph.transformer_manager import TransformerManager from vitrage.graph import Direction -from vitrage.synchronizer.plugins.transformer_base import TransformerBase LOG = log.getLogger(__name__) @@ -156,7 +156,7 @@ class Processor(processor.ProcessorBase): self.initialization_status.end_messages[vertex[VProps.TYPE]] = True if len(self.initialization_status.end_messages) == \ - len(self.conf.plugins.plugin_type): + len(self.conf.datasources.types): self.initialization_status.status = \ self.initialization_status.RECEIVED_ALL_END_MESSAGES diff --git a/vitrage/entity_graph/states/state_manager.py b/vitrage/entity_graph/states/state_manager.py index 4e8f7601e..4516740ee 100644 --- a/vitrage/entity_graph/states/state_manager.py +++ b/vitrage/entity_graph/states/state_manager.py @@ -35,40 +35,45 @@ class StateManager(object): def __init__(self, conf): self.conf = conf self.category_normalizator = self._init_category_normalizator() - self.states_plugins = self._load_state_configurations() + self.datasources_state_confs = self._load_state_configurations() - def normalize_state(self, category, plugin_name, state): + def normalize_state(self, category, datasource_name, state): upper_state = state if not state else state.upper() important_states = \ self.category_normalizator[category].important_states() - if plugin_name in self.states_plugins: - return self.states_plugins[plugin_name][self.STATES][upper_state] \ - if upper_state in \ - self.states_plugins[plugin_name][self.STATES] else \ - self.states_plugins[plugin_name][important_states.unknown] + if datasource_name in self.datasources_state_confs: + + states_conf = self.datasources_state_confs[datasource_name] + + return states_conf[self.STATES][upper_state] \ + if upper_state in states_conf[self.STATES] \ + else states_conf[important_states.unknown] else: return important_states.undefined - def state_priority(self, plugin_name, normalized_state): + def state_priority(self, datasource_name, normalized_state): # no need to check if normalized_state exists, cause it exists for sure upper_state = normalized_state if not normalized_state else \ normalized_state.upper() - if plugin_name in self.states_plugins: - return \ - self.states_plugins[plugin_name][self.PRIORITIES][upper_state] + if datasource_name in self.datasources_state_confs: + states_conf = self.datasources_state_confs[datasource_name] + return states_conf[self.PRIORITIES][upper_state] else: # default UNDEFINED priority return 0 def aggregated_state(self, new_vertex, graph_vertex, is_normalized=False): - plugin_name = new_vertex[VProps.TYPE] if VProps.TYPE in \ - new_vertex.properties else graph_vertex[VProps.TYPE] - category = new_vertex[VProps.CATEGORY] if VProps.CATEGORY in \ - new_vertex.properties else graph_vertex[VProps.CATEGORY] + datasource_name = new_vertex[VProps.TYPE] if \ + VProps.TYPE in new_vertex.properties else \ + graph_vertex[VProps.TYPE] - if plugin_name in self.states_plugins: + category = new_vertex[VProps.CATEGORY] if \ + VProps.CATEGORY in new_vertex.properties else \ + graph_vertex[VProps.CATEGORY] + + if datasource_name in self.datasources_state_confs: state_properties = \ self.category_normalizator[category].state_properties() normalized_state, state_priority = \ @@ -76,7 +81,7 @@ class StateManager(object): graph_vertex, state_properties[0], category, - plugin_name, + datasource_name, is_normalized) state_properties.pop(0) @@ -86,7 +91,7 @@ class StateManager(object): graph_vertex, property_, category, - plugin_name, + datasource_name, is_normalized) if tmp_state_priority > state_priority: normalized_state = tmp_normalized_state @@ -106,33 +111,33 @@ class StateManager(object): } def _load_state_configurations(self): - states_plugins = {} - erroneous_plugins = [] + ok_datasources = {} + erroneous_datasources = [] files = file_utils.load_files( - self.conf.entity_graph.states_plugins_dir, '.yaml') + self.conf.entity_graph.datasources_states_dir, '.yaml') for file_name in files: try: - full_path = self.conf.entity_graph.states_plugins_dir + '/' \ - + file_name + full_path = self.conf.entity_graph.datasources_states_dir \ + + '/' + file_name states, priorities = \ self._retrieve_states_and_priorities_from_file(full_path) - states_plugins[os.path.splitext(file_name)[0]] = { + ok_datasources[os.path.splitext(file_name)[0]] = { self.STATES: states, self.PRIORITIES: priorities } except Exception as e: LOG.exception("Exception: %s", e) - plugin = os.path.splitext(file_name)[0] - LOG.error('erroneous plugins is %s', - erroneous_plugins.append(plugin)) + datasource = os.path.splitext(file_name)[0] + LOG.error('erroneous data sources is %s', + erroneous_datasources.append(datasource)) - self._is_all_plugins_states_exists( - [key for key in states_plugins.keys()], - erroneous_plugins) + self._check_state_confs_exists( + [key for key in ok_datasources.keys()], + erroneous_datasources) - return states_plugins + return ok_datasources def _retrieve_states_and_priorities_from_file(self, full_path): states = {} @@ -154,7 +159,7 @@ class StateManager(object): priorities[normalized_state_name] = \ int(normalized_state['priority']) - self.check_validity(category, states, priorities, full_path) + self.check_validity(category, priorities, full_path) return states, priorities @@ -164,7 +169,7 @@ class StateManager(object): states[None] = state priorities[NormalizedResourceState.UNDEFINED] = priority - def check_validity(self, category, states, priorities, full_path): + def check_validity(self, category, priorities, full_path): important_states = \ self.category_normalizator[category].important_states() if important_states.unknown not in priorities: @@ -187,7 +192,7 @@ class StateManager(object): graph_vertex, property_, category, - plugin_name, + datasource_name, is_normalized=False): state = self._get_updated_property(new_vertex, graph_vertex, @@ -196,9 +201,10 @@ class StateManager(object): upper_state1 = state if not state else state.upper() normalized_state = upper_state1 if is_normalized else \ - self.normalize_state(category, plugin_name, upper_state1) + self.normalize_state(category, datasource_name, upper_state1) - state_priority = self.state_priority(plugin_name, normalized_state) + state_priority = self.state_priority(datasource_name, + normalized_state) return normalized_state, state_priority @@ -207,13 +213,17 @@ class StateManager(object): return [attr for attr in dir(class_instance) if not callable(attr) and not attr.startswith("__")] - def _is_all_plugins_states_exists(self, states_plugins, error_plugins): - plugin_types = self.conf.plugins.plugin_type - all_state_loaded_plugins = states_plugins + error_plugins + def _check_state_confs_exists(self, + ok_datasources, + error_datasources): - for plugin_type in plugin_types: - if plugin_type not in all_state_loaded_plugins: - LOG.error("No state configuration file for: %s", plugin_type) + datasource_types = self.conf.datasources.types + datasources_with_state_conf = ok_datasources + error_datasources + + for datasource_type in datasource_types: + if datasource_type not in datasources_with_state_conf: + LOG.error("No state configuration file for: %s", + datasource_type) @staticmethod def _get_updated_property(new_vertex, graph_vertex, prop): diff --git a/vitrage/entity_graph/transformer_manager.py b/vitrage/entity_graph/transformer_manager.py index 2997a7467..fd48956a9 100644 --- a/vitrage/entity_graph/transformer_manager.py +++ b/vitrage/entity_graph/transformer_manager.py @@ -36,14 +36,14 @@ class TransformerManager(object): def register_transformer_classes(conf): transformers = {} - for plugin in conf.plugins.plugin_type: - transformers[plugin] = importutils.import_object( - conf[plugin].transformer, + for datasource_type in conf.datasources.types: + transformers[datasource_type] = importutils.import_object( + conf[datasource_type].transformer, transformers) - if opt_exists(conf[plugin], ENTITIES): - for entity in conf[plugin].entities: + if opt_exists(conf[datasource_type], ENTITIES): + for entity in conf[datasource_type].entities: transformers[entity] = importutils.import_object( - conf[plugin].transformer, transformers) + conf[datasource_type].transformer, transformers) transformers[VITRAGE_TYPE] = importutils.import_object( "%s.%s" % (EvaluatorEventTransformer.__module__, diff --git a/vitrage/evaluator/actions/evaluator_event_transformer.py b/vitrage/evaluator/actions/evaluator_event_transformer.py index 7e6561f5e..9df9467fe 100644 --- a/vitrage/evaluator/actions/evaluator_event_transformer.py +++ b/vitrage/evaluator/actions/evaluator_event_transformer.py @@ -20,6 +20,8 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import EventAction from vitrage.common.constants import VertexProperties as VProps from vitrage.common.exception import VitrageTransformerError +from vitrage.datasources import transformer_base +from vitrage.datasources.transformer_base import Neighbor 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 REMOVE_EDGE @@ -29,8 +31,6 @@ from vitrage.evaluator.actions.recipes.base import EVALUATOR_EVENT_TYPE from vitrage.evaluator.template_fields import TemplateFields as TFields import vitrage.graph.utils as graph_utils from vitrage.graph import Vertex -from vitrage.synchronizer.plugins import transformer_base -from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) diff --git a/vitrage/evaluator/actions/recipes/raise_alarm.py b/vitrage/evaluator/actions/recipes/raise_alarm.py index e89a97972..5f771dc93 100644 --- a/vitrage/evaluator/actions/recipes/raise_alarm.py +++ b/vitrage/evaluator/actions/recipes/raise_alarm.py @@ -14,14 +14,13 @@ from vitrage.common.constants import NotifierEventTypes from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps from vitrage.evaluator.actions.recipes.action_steps import ADD_VERTEX from vitrage.evaluator.actions.recipes.action_steps import NOTIFY from vitrage.evaluator.actions.recipes.action_steps import REMOVE_VERTEX from vitrage.evaluator.actions.recipes import base from vitrage.evaluator.actions.recipes.base import ActionStepWrapper from vitrage.evaluator.template_fields import TemplateFields as TFields -from vitrage.synchronizer.plugins.base.alarm.properties \ - import AlarmProperties as AlarmProps class RaiseAlarm(base.Recipe): diff --git a/vitrage/opts.py b/vitrage/opts.py index 2cbc58b86..c2c2849fb 100644 --- a/vitrage/opts.py +++ b/vitrage/opts.py @@ -19,36 +19,31 @@ from oslo_utils import importutils import vitrage.api import vitrage.clients +import vitrage.datasources import vitrage.entity_graph.consistency import vitrage.evaluator import vitrage.keystone_client import vitrage.rpc -import vitrage.synchronizer -import vitrage.synchronizer.plugins -PLUGINS_MODULE_PATH = 'vitrage.synchronizer.plugins.' -PLUGINS_FS_PATH = os.path.join('vitrage', 'synchronizer', 'plugins') -SYNCHRONIZER_FILE = 'synchronizer.py' -TRANSFORMER_FILE = 'transformer.py' +DATASOURCES_MODULE_PATH = 'vitrage.datasources.' +DATASOURCE_FS_PATH = os.path.join('vitrage', 'datasources') +DRIVER_FILE = 'driver.py' +TRANSFORMER_FILE = 'alarm_transformer_base.py' def list_opts(): return [ ('api', vitrage.api.OPTS), - ('synchronizer', vitrage.synchronizer.OPTS), + ('datasources', vitrage.datasources.OPTS), ('evaluator', vitrage.evaluator.OPTS), - ('plugins', vitrage.synchronizer.plugins.OPTS), ('consistency', vitrage.entity_graph.consistency.OPTS), ('entity_graph', vitrage.entity_graph.OPTS), ('service_credentials', vitrage.keystone_client.OPTS), - ('DEFAULT', - itertools.chain( - vitrage.clients.OPTS, - vitrage.rpc.OPTS)) + ('DEFAULT', itertools.chain(vitrage.clients.OPTS, vitrage.rpc.OPTS)) ] -def plugins_opts(): +def datasources_opts(): top = os.getcwd() plugin_names = _normalize_path_to_plugin_name( _filter_folders_containing_transformer( @@ -56,14 +51,14 @@ def plugins_opts(): return [(plugin_name, plugin_module.OPTS) for plugin_name in plugin_names for plugin_module in - [importutils.import_module(PLUGINS_MODULE_PATH + plugin_name)] + [importutils.import_module(DATASOURCES_MODULE_PATH + plugin_name)] if 'OPTS' in plugin_module.__dict__] def _get_folders_containing_synchronizer(top=os.getcwd()): return [os.path.dirname(os.path.join(root, name)) for root, dirs, files in os.walk(top, topdown=False) - for name in files if name == SYNCHRONIZER_FILE] + for name in files if name == DRIVER_FILE] def _filter_folders_containing_transformer(folders): @@ -73,5 +68,5 @@ def _filter_folders_containing_transformer(folders): def _normalize_path_to_plugin_name(path_list, top=os.getcwd()): - return [os.path.relpath(path, os.path.join(top, PLUGINS_FS_PATH)) + return [os.path.relpath(path, os.path.join(top, DATASOURCE_FS_PATH)) .replace(os.sep, '.') for path in path_list] diff --git a/vitrage/service.py b/vitrage/service.py index 95ae21035..2d62fc61f 100644 --- a/vitrage/service.py +++ b/vitrage/service.py @@ -38,8 +38,8 @@ def prepare_service(args=None, conf=None, config_files=None): conf(args, project='vitrage', validate_default_values=True, default_config_files=config_files) - for plugin_name in conf.plugins.plugin_type: - load_plugin(conf, plugin_name, conf.plugins.plugin_path) + for datasource in conf.datasources.types: + load_datasource(conf, datasource, conf.datasources.path) keystone_client.register_keystoneauth_opts(conf) @@ -51,7 +51,7 @@ def prepare_service(args=None, conf=None, config_files=None): return conf -def load_plugin(conf, name, paths): +def load_datasource(conf, name, paths): for path in paths: try: opt = importutils.import_module("%s.%s" % (path, name)).OPTS diff --git a/vitrage/synchronizer/__init__.py b/vitrage/synchronizer/__init__.py deleted file mode 100644 index 31fbea826..000000000 --- a/vitrage/synchronizer/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2016 - Alcatel-Lucent -# -# 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 - -OPTS = [ - cfg.IntOpt('snapshots_interval', - default=600, - min=10, - help='interval between full snapshots'), -] diff --git a/vitrage/synchronizer/plugins/__init__.py b/vitrage/synchronizer/plugins/__init__.py deleted file mode 100644 index 376b71229..000000000 --- a/vitrage/synchronizer/plugins/__init__.py +++ /dev/null @@ -1,46 +0,0 @@ -# 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.synchronizer.plugins.aodh import AODH_PLUGIN -from vitrage.synchronizer.plugins.cinder.volume import CINDER_VOLUME_PLUGIN -from vitrage.synchronizer.plugins.nagios import NAGIOS_PLUGIN -from vitrage.synchronizer.plugins.neutron.network import NEUTRON_NETWORK_PLUGIN -from vitrage.synchronizer.plugins.neutron.port import NEUTRON_PORT_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=[NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN, - NAGIOS_PLUGIN, - STATIC_PHYSICAL_PLUGIN, - AODH_PLUGIN, - CINDER_VOLUME_PLUGIN, - NEUTRON_NETWORK_PLUGIN, - NEUTRON_PORT_PLUGIN], - help='Names of supported plugins'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], - help='base path for plugins') -] diff --git a/vitrage/synchronizer/test_client.py.template b/vitrage/synchronizer/test_client.py.template deleted file mode 100644 index aa55a65d9..000000000 --- a/vitrage/synchronizer/test_client.py.template +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2015 - Alcatel-Lucent -# -# 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. - -import multiprocessing - -from vitrage.synchronizer.synchronizer import Synchronizer - - -class TestClient(object): - def queue_callback_function(self, output): - for entity in output: - self.queue.put(entity) - - def print_queue(self): - while True: - entity = self.queue.get() - print(entity) - - def __init__(self): - self.queue = multiprocessing.Queue() - self.synchronizer = Synchronizer(self.queue) - self.worker = multiprocessing.Process(target=self.print_queue) - - def get_all(self): - self.synchronizer.get_all() - - -if __name__ == '__main__': - client = TestClient() - client.get_all() - client.worker.start() - client.worker.join() diff --git a/vitrage/tests/functional/base.py b/vitrage/tests/functional/base.py index 354f8aab3..c99705ce7 100644 --- a/vitrage/tests/functional/base.py +++ b/vitrage/tests/functional/base.py @@ -16,7 +16,7 @@ from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.entity_graph.initialization_status import InitializationStatus from vitrage.entity_graph.processor import processor as proc -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase @@ -34,19 +34,19 @@ class TestFunctionalBase(TestEntityGraphUnitBase): return processor def _create_mock_events(self): - gen_list = mock_sync.simple_zone_generators( + gen_list = mock_driver.simple_zone_generators( self.NUM_ZONES, self.NUM_HOSTS, snapshot_events=self.NUM_ZONES, snap_vals={SyncProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT}) - gen_list += mock_sync.simple_host_generators( + gen_list += mock_driver.simple_host_generators( self.NUM_ZONES, self.NUM_HOSTS, self.NUM_HOSTS, snap_vals={SyncProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT}) - gen_list += mock_sync.simple_instance_generators( + gen_list += mock_driver.simple_instance_generators( self.NUM_HOSTS, self.NUM_INSTANCES, self.NUM_INSTANCES, snap_vals={SyncProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT}) - return mock_sync.generate_sequential_events_list(gen_list) + return mock_driver.generate_sequential_events_list(gen_list) diff --git a/vitrage/synchronizer/plugins/base/__init__.py b/vitrage/tests/functional/datasources/__init__.py similarity index 100% rename from vitrage/synchronizer/plugins/base/__init__.py rename to vitrage/tests/functional/datasources/__init__.py diff --git a/vitrage/synchronizer/plugins/base/alarm/__init__.py b/vitrage/tests/functional/datasources/aodh/__init__.py similarity index 100% rename from vitrage/synchronizer/plugins/base/alarm/__init__.py rename to vitrage/tests/functional/datasources/aodh/__init__.py diff --git a/vitrage/tests/functional/data_sources/aodh/test_aodh.py b/vitrage/tests/functional/datasources/aodh/test_aodh.py similarity index 100% rename from vitrage/tests/functional/data_sources/aodh/test_aodh.py rename to vitrage/tests/functional/datasources/aodh/test_aodh.py diff --git a/vitrage/tests/functional/data_sources/base.py b/vitrage/tests/functional/datasources/base.py similarity index 100% rename from vitrage/tests/functional/data_sources/base.py rename to vitrage/tests/functional/datasources/base.py diff --git a/vitrage/synchronizer/plugins/base/resource/__init__.py b/vitrage/tests/functional/datasources/cinder/__init__.py similarity index 100% rename from vitrage/synchronizer/plugins/base/resource/__init__.py rename to vitrage/tests/functional/datasources/cinder/__init__.py diff --git a/vitrage/tests/functional/data_sources/cinder/test_cinder_volume.py b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py similarity index 64% rename from vitrage/tests/functional/data_sources/cinder/test_cinder_volume.py rename to vitrage/tests/functional/datasources/cinder/test_cinder_volume.py index 2e17ba8f0..faa692c97 100644 --- a/vitrage/tests/functional/data_sources/cinder/test_cinder_volume.py +++ b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py @@ -16,29 +16,28 @@ 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 +from vitrage.datasources import CINDER_VOLUME_DATASOURCE +from vitrage.datasources import NAGIOS_DATASOURCE +from vitrage.datasources import NOVA_HOST_DATASOURCE +from vitrage.datasources import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources import NOVA_ZONE_DATASOURCE +from vitrage.tests.functional.datasources.base import TestDataSourcesBase +from vitrage.tests.mocks import mock_driver class TestCinderVolume(TestDataSourcesBase): - PLUGINS_OPTS = [ - cfg.ListOpt('plugin_type', - default=[NAGIOS_PLUGIN, - NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN, - CINDER_VOLUME_PLUGIN], + DATASOURCES_OPTS = [ + cfg.ListOpt('types', + default=[NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + CINDER_VOLUME_DATASOURCE], help='Names of supported driver data sources'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], + cfg.ListOpt('path', + default=['vitrage.datasources'], help='base path for data sources') ] @@ -47,8 +46,8 @@ class TestCinderVolume(TestDataSourcesBase): 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) def test_cinder_volume_validity(self): # Setup @@ -56,15 +55,15 @@ class TestCinderVolume(TestDataSourcesBase): self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) - spec_list = mock_sync.simple_volume_generators( + spec_list = mock_driver.simple_volume_generators( volume_num=1, instance_num=1, snapshot_events=1) - static_events = mock_sync.generate_random_events_list(spec_list) + static_events = mock_driver.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) + NOVA_INSTANCE_DATASOURCE) # Action processor.process_event(cinder_volume_event) @@ -76,7 +75,7 @@ class TestCinderVolume(TestDataSourcesBase): cinder_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: CINDER_VOLUME_PLUGIN + VProps.TYPE: CINDER_VOLUME_DATASOURCE }) self.assertEqual(1, len(cinder_vertices)) @@ -84,5 +83,5 @@ class TestCinderVolume(TestDataSourcesBase): cinder_vertices[0].vertex_id) self.assertEqual(1, len(cinder_neighbors)) - self.assertEqual(NOVA_INSTANCE_PLUGIN, + self.assertEqual(NOVA_INSTANCE_DATASOURCE, cinder_neighbors[0][VProps.TYPE]) diff --git a/vitrage/synchronizer/plugins/nova/__init__.py b/vitrage/tests/functional/datasources/nagios/__init__.py similarity index 100% rename from vitrage/synchronizer/plugins/nova/__init__.py rename to vitrage/tests/functional/datasources/nagios/__init__.py diff --git a/vitrage/tests/functional/data_sources/nagios/test_nagios.py b/vitrage/tests/functional/datasources/nagios/test_nagios.py similarity index 66% rename from vitrage/tests/functional/data_sources/nagios/test_nagios.py rename to vitrage/tests/functional/datasources/nagios/test_nagios.py index c71af3d51..b517b82e0 100644 --- a/vitrage/tests/functional/data_sources/nagios/test_nagios.py +++ b/vitrage/tests/functional/datasources/nagios/test_nagios.py @@ -16,28 +16,28 @@ 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 \ +from vitrage.datasources import NAGIOS_DATASOURCE +from vitrage.datasources import NOVA_HOST_DATASOURCE +from vitrage.datasources import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources import NOVA_ZONE_DATASOURCE +from vitrage.tests.functional.datasources.base import \ TestDataSourcesBase -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver class TestNagios(TestDataSourcesBase): - PLUGINS_OPTS = [ - cfg.ListOpt('plugin_type', - default=[NAGIOS_PLUGIN, - NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN, - NAGIOS_PLUGIN], + DATASOURCES_OPTS = [ + cfg.ListOpt('types', + default=[NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + NAGIOS_DATASOURCE], help='Names of supported driver data sources'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], + cfg.ListOpt('path', + default=['vitrage.datasources'], help='base path for data sources') ] @@ -46,8 +46,8 @@ class TestNagios(TestDataSourcesBase): 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) def test_nagios_validity(self): # Setup @@ -55,14 +55,14 @@ class TestNagios(TestDataSourcesBase): self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) - spec_list = mock_sync.simple_nagios_alarm_generators( + spec_list = mock_driver.simple_nagios_alarm_generators( host_num=1, events_num=1) - static_events = mock_sync.generate_random_events_list(spec_list) + static_events = mock_driver.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) + NOVA_HOST_DATASOURCE) nagios_event['status'] = 'critical' # Action @@ -75,7 +75,7 @@ class TestNagios(TestDataSourcesBase): nagios_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.CATEGORY: EntityCategory.ALARM, - VProps.TYPE: NAGIOS_PLUGIN + VProps.TYPE: NAGIOS_DATASOURCE }) self.assertEqual(1, len(nagios_vertices)) @@ -83,5 +83,5 @@ class TestNagios(TestDataSourcesBase): nagios_vertices[0].vertex_id) self.assertEqual(1, len(nagios_neighbors)) - self.assertEqual(NOVA_HOST_PLUGIN, + self.assertEqual(NOVA_HOST_DATASOURCE, nagios_neighbors[0][VProps.TYPE]) diff --git a/vitrage/tests/functional/data_sources/__init__.py b/vitrage/tests/functional/datasources/neutron/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/__init__.py rename to vitrage/tests/functional/datasources/neutron/__init__.py diff --git a/vitrage/tests/functional/data_sources/neutron/test_neutron_network.py b/vitrage/tests/functional/datasources/neutron/test_neutron_network.py similarity index 100% rename from vitrage/tests/functional/data_sources/neutron/test_neutron_network.py rename to vitrage/tests/functional/datasources/neutron/test_neutron_network.py diff --git a/vitrage/tests/functional/data_sources/neutron/test_neutron_port.py b/vitrage/tests/functional/datasources/neutron/test_neutron_port.py similarity index 100% rename from vitrage/tests/functional/data_sources/neutron/test_neutron_port.py rename to vitrage/tests/functional/datasources/neutron/test_neutron_port.py diff --git a/vitrage/tests/functional/data_sources/aodh/__init__.py b/vitrage/tests/functional/datasources/nova/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/aodh/__init__.py rename to vitrage/tests/functional/datasources/nova/__init__.py diff --git a/vitrage/tests/functional/data_sources/nova/test_nova_plugins.py b/vitrage/tests/functional/datasources/nova/test_nova_datasources.py similarity index 82% rename from vitrage/tests/functional/data_sources/nova/test_nova_plugins.py rename to vitrage/tests/functional/datasources/nova/test_nova_datasources.py index 2d5d88da7..a916652e4 100644 --- a/vitrage/tests/functional/data_sources/nova/test_nova_plugins.py +++ b/vitrage/tests/functional/datasources/nova/test_nova_datasources.py @@ -14,21 +14,21 @@ from oslo_config import cfg -from vitrage.tests.functional.data_sources.base import \ +from vitrage.tests.functional.datasources.base import \ TestDataSourcesBase -class TestNovaPlugins(TestDataSourcesBase): +class TestNovaDatasources(TestDataSourcesBase): @classmethod def setUpClass(cls): - super(TestNovaPlugins, cls).setUpClass() + super(TestNovaDatasources, 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) - def test_nova_plugins(self): + def test_nova_datasources(self): processor = self._create_processor_with_graph(self.conf) self.assertEqual(self._num_total_expected_vertices(), diff --git a/vitrage/tests/functional/data_sources/cinder/__init__.py b/vitrage/tests/functional/datasources/static_physical/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/cinder/__init__.py rename to vitrage/tests/functional/datasources/static_physical/__init__.py diff --git a/vitrage/tests/functional/data_sources/static_physical/test_static_physical.py b/vitrage/tests/functional/datasources/static_physical/test_static_physical.py similarity index 64% rename from vitrage/tests/functional/data_sources/static_physical/test_static_physical.py rename to vitrage/tests/functional/datasources/static_physical/test_static_physical.py index e70b4f018..f351877d1 100644 --- a/vitrage/tests/functional/data_sources/static_physical/test_static_physical.py +++ b/vitrage/tests/functional/datasources/static_physical/test_static_physical.py @@ -17,30 +17,30 @@ 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 \ +from vitrage.datasources import NAGIOS_DATASOURCE +from vitrage.datasources import NOVA_HOST_DATASOURCE +from vitrage.datasources import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources import NOVA_ZONE_DATASOURCE +from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE +from vitrage.datasources.static_physical import SWITCH +from vitrage.tests.functional.datasources.base import \ TestDataSourcesBase -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver class TestStaticPhysical(TestDataSourcesBase): - PLUGINS_OPTS = [ - cfg.ListOpt('plugin_type', - default=[NAGIOS_PLUGIN, - NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN, - STATIC_PHYSICAL_PLUGIN], + DATASOURCES_OPTS = [ + cfg.ListOpt('types', + default=[NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + STATIC_PHYSICAL_DATASOURCE], help='Names of supported driver data sources'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], + cfg.ListOpt('path', + default=['vitrage.datasources'], help='base path for data sources') ] @@ -49,27 +49,27 @@ class TestStaticPhysical(TestDataSourcesBase): 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(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] + transformers = processor.transformer_manager.transformers + transformers[SWITCH] = transformers[STATIC_PHYSICAL_DATASOURCE] self.assertEqual(self._num_total_expected_vertices(), len(processor.entity_graph)) - spec_list = mock_sync.simple_switch_generators( + spec_list = mock_driver.simple_switch_generators( switch_num=1, host_num=1, snapshot_events=1) - static_events = mock_sync.generate_random_events_list(spec_list) + static_events = mock_driver.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) + NOVA_HOST_DATASOURCE) # Action processor.process_event(static_physical_event) @@ -89,5 +89,5 @@ class TestStaticPhysical(TestDataSourcesBase): static_physical_vertices[0].vertex_id) self.assertEqual(1, len(static_physical_neighbors)) - self.assertEqual(NOVA_HOST_PLUGIN, + self.assertEqual(NOVA_HOST_DATASOURCE, 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 d2e572a21..8ae610c8c 100644 --- a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py +++ b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py @@ -24,6 +24,10 @@ from vitrage.common.constants import EdgeLabels from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.common.datetime_utils import utcnow +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE from vitrage.entity_graph.consistency.consistency_enforcer \ import ConsistencyEnforcer from vitrage.entity_graph.initialization_status import InitializationStatus @@ -32,12 +36,7 @@ from vitrage.evaluator.actions.evaluator_event_transformer import VITRAGE_TYPE 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.base import \ - TestFunctionalBase +from vitrage.tests.functional.base import TestFunctionalBase from vitrage.tests.mocks import utils @@ -54,12 +53,6 @@ class TestConsistencyFunctional(TestFunctionalBase): default=10), ] - SYNCHRONIZER_OPTS = [ - cfg.IntOpt('snapshots_interval', - default=1, - min=1), - ] - EVALUATOR_OPTS = [ cfg.StrOpt('templates_dir', default=utils.get_resources_dir() + @@ -79,9 +72,8 @@ class TestConsistencyFunctional(TestFunctionalBase): cls.conf.register_opts(cls.CONSISTENCY_OPTS, group='consistency') cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') cls.conf.register_opts(cls.EVALUATOR_OPTS, group='evaluator') - cls.conf.register_opts(cls.SYNCHRONIZER_OPTS, group='synchronizer') - cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') - cls.load_plugins(cls.conf) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) cls.processor = Processor(cls.conf, cls.initialization_status) cls.event_queue = queue.Queue() @@ -150,7 +142,7 @@ class TestConsistencyFunctional(TestFunctionalBase): def test_periodic_process(self): # Setup - consistency_interval = self.conf.synchronizer.snapshots_interval + consistency_interval = self.conf.datasources.snapshots_interval self._periodic_process_setup_stage(consistency_interval) # Action @@ -160,18 +152,18 @@ class TestConsistencyFunctional(TestFunctionalBase): # Test Assertions instance_vertices = self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: NOVA_INSTANCE_PLUGIN + VProps.TYPE: NOVA_INSTANCE_DATASOURCE }) - is_deleted_instance_vertices = \ + deleted_instance_vertices = \ self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: NOVA_INSTANCE_PLUGIN, + VProps.TYPE: NOVA_INSTANCE_DATASOURCE, VProps.IS_DELETED: True }) self.assertEqual(self.NUM_INSTANCES - 3, len(instance_vertices)) self.assertEqual(self._num_total_expected_vertices() - 3, len(self.processor.entity_graph.get_vertices())) - self.assertEqual(6, len(is_deleted_instance_vertices)) + self.assertEqual(6, len(deleted_instance_vertices)) def _periodic_process_setup_stage(self, consistency_interval): self._create_processor_with_graph(self.conf, processor=self.processor) @@ -185,7 +177,7 @@ class TestConsistencyFunctional(TestFunctionalBase): # check number of instances in graph instance_vertices = self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: NOVA_INSTANCE_PLUGIN + VProps.TYPE: NOVA_INSTANCE_DATASOURCE }) self.assertEqual(self.NUM_INSTANCES, len(instance_vertices)) @@ -205,11 +197,11 @@ class TestConsistencyFunctional(TestFunctionalBase): self.processor.entity_graph.update_vertex(instance_vertices[i]) def _set_end_messages(self): - 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] = \ + self.initialization_status.end_messages[NOVA_ZONE_DATASOURCE] = True + self.initialization_status.end_messages[NOVA_HOST_DATASOURCE] = True + self.initialization_status.end_messages[NOVA_INSTANCE_DATASOURCE] = \ True - self.initialization_status.end_messages[NAGIOS_PLUGIN] = True + self.initialization_status.end_messages[NAGIOS_DATASOURCE] = True self.initialization_status.status = \ self.initialization_status.RECEIVED_ALL_END_MESSAGES @@ -217,7 +209,7 @@ class TestConsistencyFunctional(TestFunctionalBase): # find hosts and instances host_vertices = self.processor.entity_graph.get_vertices({ VProps.CATEGORY: EntityCategory.RESOURCE, - VProps.TYPE: NOVA_HOST_PLUGIN + VProps.TYPE: NOVA_HOST_DATASOURCE }) # add host alarms + deduced alarms @@ -227,7 +219,7 @@ class TestConsistencyFunctional(TestFunctionalBase): alarm_name = '%s:%s' % ('nagios_alarm_on_host_', host_vertex[VProps.NAME]) alarms_on_hosts_list.append( - self._create_alarm(alarm_name, NAGIOS_PLUGIN)) + self._create_alarm(alarm_name, NAGIOS_DATASOURCE)) 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/entity_graph/processor/test_processor.py b/vitrage/tests/functional/entity_graph/processor/test_processor.py index 6ea638853..37aafff19 100644 --- a/vitrage/tests/functional/entity_graph/processor/test_processor.py +++ b/vitrage/tests/functional/entity_graph/processor/test_processor.py @@ -30,8 +30,8 @@ class TestProcessorFunctional(TestFunctionalBase): super(TestProcessorFunctional, 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) def test_create_entity_graph(self): processor = self._create_processor_with_graph(self.conf) 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 293846445..b383f8788 100644 --- a/vitrage/tests/functional/entity_graph/states/test_state_manager.py +++ b/vitrage/tests/functional/entity_graph/states/test_state_manager.py @@ -17,14 +17,12 @@ from oslo_config import cfg from vitrage.common.constants import EventAction from vitrage.common.constants import SyncMode from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.nova.instance.transformer import InstanceTransformer from vitrage.entity_graph.initialization_status import InitializationStatus from vitrage.entity_graph.processor import processor as proc from vitrage.entity_graph.states.normalized_resource_state import \ NormalizedResourceState -from vitrage.synchronizer.plugins.nova.instance.transformer import \ - InstanceTransformer -from vitrage.tests.functional.base import \ - TestFunctionalBase +from vitrage.tests.functional.base import TestFunctionalBase class TestStateManagerFunctional(TestFunctionalBase): @@ -35,8 +33,8 @@ class TestStateManagerFunctional(TestFunctionalBase): super(TestStateManagerFunctional, 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) def test_state_on_update(self): # setup diff --git a/vitrage/tests/functional/evaluator/test_action_executor.py b/vitrage/tests/functional/evaluator/test_action_executor.py index dcabc9e6b..13aa70ad1 100644 --- a/vitrage/tests/functional/evaluator/test_action_executor.py +++ b/vitrage/tests/functional/evaluator/test_action_executor.py @@ -20,6 +20,9 @@ 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.datasources.alarm_properties import AlarmProperties as AlarmProps +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE from vitrage.entity_graph.states.normalized_resource_state import \ NormalizedResourceState from vitrage.evaluator.actions.action_executor import ActionExecutor @@ -28,13 +31,8 @@ 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.base import \ - TestFunctionalBase +from vitrage.service import load_datasource +from vitrage.tests.functional.base import TestFunctionalBase LOG = logging.getLogger(__name__) @@ -46,16 +44,19 @@ class TestActionExecutor(TestFunctionalBase): def setUpClass(cls): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') - for plugin_name in cls.conf.plugins.plugin_type: - load_plugin(cls.conf, plugin_name, cls.conf.plugins.plugin_path) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + + for datasource_name in cls.conf.datasources.types: + load_datasource(cls.conf, + datasource_name, + cls.conf.datasources.path) def test_execute_update_vertex(self): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} + vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) host_vertex_before = host_vertices[0] @@ -102,21 +103,21 @@ class TestActionExecutor(TestFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} + vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE} 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), NOVA_HOST_PLUGIN) + host_1.get(VProps.ID), NOVA_HOST_DATASOURCE) processor.process_event(nagios_event1) host_2 = host_vertices[1] nagios_event2 = TestActionExecutor._get_nagios_event( - host_2.get(VProps.ID), NOVA_HOST_PLUGIN) + host_2.get(VProps.ID), NOVA_HOST_DATASOURCE) processor.process_event(nagios_event2) - alarms_attrs = {VProps.TYPE: NAGIOS_PLUGIN} + alarms_attrs = {VProps.TYPE: NAGIOS_DATASOURCE} alarms_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=alarms_attrs) @@ -152,7 +153,7 @@ class TestActionExecutor(TestFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} + vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) @@ -209,7 +210,7 @@ class TestActionExecutor(TestFunctionalBase): # Test Setup processor = self._create_processor_with_graph(self.conf) - vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN} + vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index 748565625..dfc0bfa75 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -17,9 +17,9 @@ from oslo_log import log as logging from six.moves import queue from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE 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.base import \ TestFunctionalBase from vitrage.tests.mocks import utils @@ -45,8 +45,8 @@ class TestScenarioEvaluator(TestFunctionalBase): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') cls.conf.register_opts(cls.EVALUATOR_OPTS, group='evaluator') - cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') - TestScenarioEvaluator.load_plugins(cls.conf) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + TestScenarioEvaluator.load_datasources(cls.conf) cls.scenario_repository = ScenarioRepository(cls.conf) def test_deduced_state(self): @@ -67,7 +67,7 @@ class TestScenarioEvaluator(TestFunctionalBase): nagios_event = {'last_check': '2016-02-07 15:26:04', 'resource_name': target_host, - 'resource_type': NOVA_HOST_PLUGIN, + 'resource_type': NOVA_HOST_DATASOURCE, 'service': 'Check_MK', 'status': 'CRITICAL', 'status_info': 'ok', @@ -94,7 +94,7 @@ class TestScenarioEvaluator(TestFunctionalBase): @staticmethod def _get_host_from_graph(host_name, entity_graph): - vertex_attrs = {VProps.TYPE: NOVA_HOST_PLUGIN, + vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE, VProps.NAME: host_name} host_vertices = entity_graph.get_vertices( vertex_attr_filter=vertex_attrs) diff --git a/vitrage/tests/mocks/mock_syncronizer.py b/vitrage/tests/mocks/mock_driver.py similarity index 90% rename from vitrage/tests/mocks/mock_syncronizer.py rename to vitrage/tests/mocks/mock_driver.py index 7afce7b20..c2bd32b1b 100644 --- a/vitrage/tests/mocks/mock_syncronizer.py +++ b/vitrage/tests/mocks/mock_driver.py @@ -13,15 +13,15 @@ # under the License. -"""Methods for generating synchronizer events +"""Methods for generating driver events For each type of entity, need to supply configuration files that specify (a -regex of) what can be returned, which will be used to generate sync events +regex of) what can be returned, which will be used to generate driver events usage example: test_entity_spec_list = [ - {mg.DYNAMIC_INFO_FKEY: 'sync_inst_snapshot_dynamic.json', - mg.STATIC_INFO_FKEY: 'sync_inst_snapshot_static.json', + {mg.DYNAMIC_INFO_FKEY: 'driver_inst_snapshot_dynamic.json', + mg.STATIC_INFO_FKEY: 'driver_inst_snapshot_static.json', mg.MAPPING_KEY: [('vm1', 'host1'), ('vm2', 'host1'), ('vm3','host2')], mg.NAME_KEY: 'Instance (vm) generator', NUM_EVENTS_KEY: 10 @@ -47,7 +47,7 @@ def generate_random_events_list(generator_spec_list): :param generator_spec_list: list of generators :type generator_spec_list: list - :return list of synchronizer events + :return list of driver events :rtype list """ @@ -69,7 +69,7 @@ def generate_sequential_events_list(generator_spec_list): :param generator_spec_list: list of generators :type generator_spec_list: list - :return list of synchronizer events + :return list of driver events :rtype list """ @@ -106,8 +106,8 @@ def simple_instance_generators(host_num, vm_num, test_entity_spec_list = [] if snapshot_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_INST_SNAPSHOT_D, - tg.STATIC_INFO_FKEY: tg.SYNC_INST_SNAPSHOT_S, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_INST_SNAPSHOT_D, + tg.STATIC_INFO_FKEY: tg.DRIVER_INST_SNAPSHOT_S, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: mapping, tg.NAME_KEY: 'Instance (vm) snapshot generator', @@ -116,7 +116,7 @@ def simple_instance_generators(host_num, vm_num, ) if update_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_INST_UPDATE_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_INST_UPDATE_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: update_vals, tg.MAPPING_KEY: mapping, @@ -148,7 +148,7 @@ def simple_host_generators(zone_num, host_num, snapshot_events=0, test_entity_spec_list = [] if snapshot_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_HOST_SNAPSHOT_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_HOST_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: mapping, @@ -180,7 +180,7 @@ def simple_zone_generators(zone_num, host_num, snapshot_events=0, test_entity_spec_list = [] if snapshot_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_ZONE_SNAPSHOT_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_ZONE_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: mapping, @@ -214,7 +214,7 @@ def simple_volume_generators(volume_num, instance_num, test_entity_spec_list = [] if snapshot_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_VOLUME_SNAPSHOT_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_VOLUME_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: mapping, @@ -224,7 +224,7 @@ def simple_volume_generators(volume_num, instance_num, ) if update_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_VOLUME_UPDATE_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_VOLUME_UPDATE_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: update_vals, tg.MAPPING_KEY: mapping, @@ -259,7 +259,7 @@ def simple_switch_generators(switch_num, host_num, test_entity_spec_list = [] if snapshot_events: test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_SWITCH_SNAPSHOT_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_SWITCH_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: mapping, @@ -271,7 +271,7 @@ def simple_switch_generators(switch_num, host_num, update_vals = {} if not update_vals else update_vals update_vals['sync_mode'] = 'update' test_entity_spec_list.append( - {tg.DYNAMIC_INFO_FKEY: tg.SYNC_SWITCH_SNAPSHOT_D, + {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_SWITCH_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: update_vals, tg.MAPPING_KEY: mapping, @@ -300,7 +300,7 @@ def simple_nagios_alarm_generators(host_num, test_entity_spec_list = [] if events_num: test_entity_spec_list.append({ - tg.DYNAMIC_INFO_FKEY: tg.SYNC_NAGIOS_SNAPSHOT_D, + tg.DYNAMIC_INFO_FKEY: tg.DRIVER_NAGIOS_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: hosts, @@ -308,8 +308,8 @@ def simple_nagios_alarm_generators(host_num, tg.NUM_EVENTS: max(events_num - len(hosts), 0) }) test_entity_spec_list.append({ - tg.DYNAMIC_INFO_FKEY: tg.SYNC_NAGIOS_SNAPSHOT_D, - tg.STATIC_INFO_FKEY: tg.SYNC_NAGIOS_SNAPSHOT_S, + tg.DYNAMIC_INFO_FKEY: tg.DRIVER_NAGIOS_SNAPSHOT_D, + tg.STATIC_INFO_FKEY: tg.DRIVER_NAGIOS_SNAPSHOT_S, tg.EXTERNAL_INFO_KEY: snap_vals, tg.MAPPING_KEY: hosts, tg.NAME_KEY: 'Nagios alarm generator (alarm off)', diff --git a/vitrage/tests/mocks/trace_generator.py b/vitrage/tests/mocks/trace_generator.py index 608667b23..15b6c3dee 100644 --- a/vitrage/tests/mocks/trace_generator.py +++ b/vitrage/tests/mocks/trace_generator.py @@ -27,7 +27,7 @@ from random import randint import exrex # noinspection PyPep8Naming -from vitrage.synchronizer.plugins.nova.host import NOVA_HOST_PLUGIN +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE from vitrage.tests.mocks.entity_model import BasicEntityModel as Bem import vitrage.tests.mocks.utils as utils @@ -42,17 +42,18 @@ GENERATOR = 'generator' # specification files for input types -# Mock synchronizer specs -SYNC_INST_SNAPSHOT_D = 'sync_inst_snapshot_dynamic.json' -SYNC_INST_SNAPSHOT_S = 'sync_inst_snapshot_static.json' -SYNC_INST_UPDATE_D = 'sync_inst_update_dynamic.json' -SYNC_HOST_SNAPSHOT_D = 'sync_host_snapshot_dynamic.json' -SYNC_ZONE_SNAPSHOT_D = 'sync_zone_snapshot_dynamic.json' -SYNC_VOLUME_SNAPSHOT_D = 'sync_volume_snapshot_dynamic.json' -SYNC_VOLUME_UPDATE_D = 'sync_volume_update_dynamic.json' -SYNC_SWITCH_SNAPSHOT_D = 'sync_switch_snapshot_dynamic.json' -SYNC_NAGIOS_SNAPSHOT_D = 'sync_nagios_snapshot_dynamic.json' -SYNC_NAGIOS_SNAPSHOT_S = 'sync_nagios_snapshot_static.json' +# Mock driver specs +DRIVER_HOST_SNAPSHOT_D = 'driver_host_snapshot_dynamic.json' +DRIVER_INST_SNAPSHOT_D = 'driver_inst_snapshot_dynamic.json' +DRIVER_INST_SNAPSHOT_S = 'driver_inst_snapshot_static.json' +DRIVER_INST_UPDATE_D = 'driver_inst_update_dynamic.json' +DRIVER_NAGIOS_SNAPSHOT_D = 'driver_nagios_snapshot_dynamic.json' +DRIVER_NAGIOS_SNAPSHOT_S = 'driver_nagios_snapshot_static.json' +DRIVER_SWITCH_SNAPSHOT_D = 'driver_switch_snapshot_dynamic.json' +DRIVER_VOLUME_UPDATE_D = 'driver_volume_update_dynamic.json' +DRIVER_VOLUME_SNAPSHOT_D = 'driver_volume_snapshot_dynamic.json' +DRIVER_ZONE_SNAPSHOT_D = 'driver_zone_snapshot_dynamic.json' + # Mock transformer Specs (i.e., what the transformer outputs) TRANS_INST_SNAPSHOT_D = 'transformer_inst_snapshot_dynamic.json' @@ -96,14 +97,14 @@ class EventTraceGenerator(object): """ static_info_parsers = \ - {SYNC_INST_SNAPSHOT_D: _get_sync_vm_snapshot_values, - SYNC_INST_UPDATE_D: _get_sync_vm_update_values, - SYNC_HOST_SNAPSHOT_D: _get_sync_host_snapshot_values, - SYNC_ZONE_SNAPSHOT_D: _get_sync_zone_snapshot_values, - SYNC_VOLUME_SNAPSHOT_D: _get_sync_volume_snapshot_values, - SYNC_VOLUME_UPDATE_D: _get_sync_volume_update_values, - SYNC_SWITCH_SNAPSHOT_D: _get_sync_switch_snapshot_values, - SYNC_NAGIOS_SNAPSHOT_D: _get_sync_nagios_alarm_values, + {DRIVER_INST_SNAPSHOT_D: _get_vm_snapshot_driver_values, + DRIVER_INST_UPDATE_D: _get_vm_update_driver_values, + DRIVER_HOST_SNAPSHOT_D: _get_host_snapshot_driver_values, + DRIVER_ZONE_SNAPSHOT_D: _get_zone_snapshot_driver_values, + DRIVER_VOLUME_SNAPSHOT_D: _get_volume_snapshot_driver_values, + DRIVER_VOLUME_UPDATE_D: _get_volume_update_driver_values, + DRIVER_SWITCH_SNAPSHOT_D: _get_switch_snapshot_driver_values, + DRIVER_NAGIOS_SNAPSHOT_D: _get_nagios_alarm_driver_values, TRANS_INST_SNAPSHOT_D: _get_trans_vm_snapshot_values, TRANS_HOST_SNAPSHOT_D: _get_trans_host_snapshot_values, @@ -163,12 +164,12 @@ def generate_round_robin_data_stream(models, event_num=100): return data_stream -def _get_sync_vm_snapshot_values(spec): - """Generates the static synchronizer values for each vm. +def _get_vm_snapshot_driver_values(spec): + """Generates the static driver values for each vm. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each vm. + :return: list of static driver values for each vm. :rtype: list """ @@ -193,12 +194,12 @@ def _get_sync_vm_snapshot_values(spec): return static_values -def _get_sync_host_snapshot_values(spec): - """Generates the static synchronizer values for each host. +def _get_host_snapshot_driver_values(spec): + """Generates the static driver values for each host. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each host. + :return: list of static driver values for each host. :rtype: list """ @@ -219,12 +220,12 @@ def _get_sync_host_snapshot_values(spec): return static_values -def _get_sync_zone_snapshot_values(spec): - """Generates the static synchronizer values for each zone. +def _get_zone_snapshot_driver_values(spec): + """Generates the static driver values for each zone. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each host. + :return: list of static driver values for each host. :rtype: list """ @@ -261,12 +262,12 @@ def _get_sync_zone_snapshot_values(spec): return static_values -def _get_sync_volume_snapshot_values(spec): - """Generates the static synchronizer values for each volume. +def _get_volume_snapshot_driver_values(spec): + """Generates the static driver values for each volume. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each volume. + :return: list of static driver values for each volume. :rtype: list """ @@ -286,12 +287,12 @@ def _get_sync_volume_snapshot_values(spec): return static_values -def _get_sync_volume_update_values(spec): - """Generates the static synchronizer values for each volume. +def _get_volume_update_driver_values(spec): + """Generates the static driver values for each volume. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each volume. + :return: list of static driver values for each volume. :rtype: list """ @@ -336,12 +337,12 @@ def _get_trans_vm_snapshot_values(spec): return static_values -def _get_sync_vm_update_values(spec): - """Generates the static synchronizer values for each vm, for updates. +def _get_vm_update_driver_values(spec): + """Generates the static driver values for each vm, for updates. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each vm updates. + :return: list of static driver values for each vm updates. :rtype: list """ @@ -360,12 +361,12 @@ def _get_sync_vm_update_values(spec): return static_values -def _get_sync_switch_snapshot_values(spec): - """Generates the static synchronizer values for each zone. +def _get_switch_snapshot_driver_values(spec): + """Generates the static driver values for each zone. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each zone. + :return: list of static driver values for each zone. :rtype: list """ @@ -380,7 +381,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_PLUGIN, + relationship_info = {"type": NOVA_HOST_DATASOURCE, "name": host_name, "id": host_name, "relation_type": "contains" @@ -400,7 +401,7 @@ def _get_sync_switch_snapshot_values(spec): return static_values -def _get_sync_nagios_alarm_values(spec): +def _get_nagios_alarm_driver_values(spec): hosts = spec[MAPPING_KEY] static_info_re = None if spec[STATIC_INFO_FKEY] is not None: @@ -416,11 +417,11 @@ def _get_sync_nagios_alarm_values(spec): def _get_trans_host_snapshot_values(spec): - """Generates the static synchronizer values for each host. + """Generates the static driver values for each host. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each host. + :return: list of static driver values for each host. :rtype: list """ @@ -441,11 +442,11 @@ def _get_trans_host_snapshot_values(spec): def _get_trans_zone_snapshot_values(spec): - """Generates the static synchronizer values for each zone. + """Generates the static driver values for each zone. :param spec: specification of event generation. :type spec: dict - :return: list of static synchronizer values for each zone. + :return: list of static driver values for each zone. :rtype: list """ diff --git a/vitrage/tests/resources/states_plugins/erroneous_states_plugins/nagios.yaml b/vitrage/tests/resources/datasources_states/erroneous_states/nagios.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/erroneous_states_plugins/nagios.yaml rename to vitrage/tests/resources/datasources_states/erroneous_states/nagios.yaml diff --git a/vitrage/tests/resources/states_plugins/erroneous_states_plugins/nova.host.yaml b/vitrage/tests/resources/datasources_states/erroneous_states/nova.host.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/erroneous_states_plugins/nova.host.yaml rename to vitrage/tests/resources/datasources_states/erroneous_states/nova.host.yaml diff --git a/vitrage/tests/resources/states_plugins/erroneous_states_plugins/nova.instance.yaml b/vitrage/tests/resources/datasources_states/erroneous_states/nova.instance.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/erroneous_states_plugins/nova.instance.yaml rename to vitrage/tests/resources/datasources_states/erroneous_states/nova.instance.yaml diff --git a/vitrage/tests/resources/states_plugins/nagios.yaml b/vitrage/tests/resources/datasources_states/nagios.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/nagios.yaml rename to vitrage/tests/resources/datasources_states/nagios.yaml diff --git a/vitrage/tests/resources/states_plugins/nova.host.yaml b/vitrage/tests/resources/datasources_states/nova.host.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/nova.host.yaml rename to vitrage/tests/resources/datasources_states/nova.host.yaml diff --git a/vitrage/tests/resources/states_plugins/nova.instance.yaml b/vitrage/tests/resources/datasources_states/nova.instance.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/nova.instance.yaml rename to vitrage/tests/resources/datasources_states/nova.instance.yaml diff --git a/vitrage/tests/resources/states_plugins/nova.zone.yaml b/vitrage/tests/resources/datasources_states/nova.zone.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/nova.zone.yaml rename to vitrage/tests/resources/datasources_states/nova.zone.yaml diff --git a/vitrage/tests/resources/states_plugins/vitrage.yaml b/vitrage/tests/resources/datasources_states/vitrage.yaml similarity index 100% rename from vitrage/tests/resources/states_plugins/vitrage.yaml rename to vitrage/tests/resources/datasources_states/vitrage.yaml diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_host_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_host_snapshot_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_host_snapshot_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_host_snapshot_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_inst_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_inst_snapshot_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_inst_snapshot_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_inst_snapshot_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_inst_snapshot_static.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_inst_snapshot_static.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_inst_snapshot_static.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_inst_snapshot_static.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_inst_update_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_inst_update_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_inst_update_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_inst_update_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_nagios_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_nagios_snapshot_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_nagios_snapshot_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_nagios_snapshot_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_nagios_snapshot_static.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_nagios_snapshot_static.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_nagios_snapshot_static.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_nagios_snapshot_static.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_switch_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_switch_snapshot_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_switch_snapshot_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_switch_snapshot_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_volume_snapshot_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_snapshot_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_volume_snapshot_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_update_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_volume_update_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_volume_update_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_volume_update_dynamic.json diff --git a/vitrage/tests/resources/mock_configurations/synchronizer/sync_zone_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/synchronizer/driver_zone_snapshot_dynamic.json similarity index 100% rename from vitrage/tests/resources/mock_configurations/synchronizer/sync_zone_snapshot_dynamic.json rename to vitrage/tests/resources/mock_configurations/synchronizer/driver_zone_snapshot_dynamic.json diff --git a/vitrage/tests/resources/static_plugins/changes_plugins/switch_to_host_plugin.yaml b/vitrage/tests/resources/static_datasources/changes_datasources/switch_to_host_plugin.yaml similarity index 96% rename from vitrage/tests/resources/static_plugins/changes_plugins/switch_to_host_plugin.yaml rename to vitrage/tests/resources/static_datasources/changes_datasources/switch_to_host_plugin.yaml index 603c6f316..0ad50e908 100644 --- a/vitrage/tests/resources/static_plugins/changes_plugins/switch_to_host_plugin.yaml +++ b/vitrage/tests/resources/static_datasources/changes_datasources/switch_to_host_plugin.yaml @@ -38,4 +38,4 @@ entities: - type: nova.host name: host-3 id: 3 - relation_type: attached \ No newline at end of file + relation_type: attached diff --git a/vitrage/tests/resources/static_plugins/changes_plugins/switch_to_switch_plugin.yaml b/vitrage/tests/resources/static_datasources/changes_datasources/switch_to_switch_plugin.yaml similarity index 91% rename from vitrage/tests/resources/static_plugins/changes_plugins/switch_to_switch_plugin.yaml rename to vitrage/tests/resources/static_datasources/changes_datasources/switch_to_switch_plugin.yaml index d484b29b7..d53a7ec46 100644 --- a/vitrage/tests/resources/static_plugins/changes_plugins/switch_to_switch_plugin.yaml +++ b/vitrage/tests/resources/static_datasources/changes_datasources/switch_to_switch_plugin.yaml @@ -16,4 +16,4 @@ entities: - type: switch name: switch-3 id: 34567 - relation_type: backup \ No newline at end of file + relation_type: backup diff --git a/vitrage/tests/resources/static_plugins/switch_to_host_plugin.yaml b/vitrage/tests/resources/static_datasources/switch_to_host_plugin.yaml similarity index 96% rename from vitrage/tests/resources/static_plugins/switch_to_host_plugin.yaml rename to vitrage/tests/resources/static_datasources/switch_to_host_plugin.yaml index 716629868..b8295bc07 100644 --- a/vitrage/tests/resources/static_plugins/switch_to_host_plugin.yaml +++ b/vitrage/tests/resources/static_datasources/switch_to_host_plugin.yaml @@ -37,4 +37,4 @@ entities: - type: nova.host name: host-4 id: 4 - relation_type: attached \ No newline at end of file + relation_type: attached diff --git a/vitrage/tests/resources/static_plugins/switch_to_switch_plugin.yaml b/vitrage/tests/resources/static_datasources/switch_to_switch_plugin.yaml similarity index 91% rename from vitrage/tests/resources/static_plugins/switch_to_switch_plugin.yaml rename to vitrage/tests/resources/static_datasources/switch_to_switch_plugin.yaml index d484b29b7..d53a7ec46 100644 --- a/vitrage/tests/resources/static_plugins/switch_to_switch_plugin.yaml +++ b/vitrage/tests/resources/static_datasources/switch_to_switch_plugin.yaml @@ -16,4 +16,4 @@ entities: - type: switch name: switch-3 id: 34567 - relation_type: backup \ No newline at end of file + relation_type: backup diff --git a/vitrage/tests/functional/data_sources/nagios/__init__.py b/vitrage/tests/unit/datasources/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/nagios/__init__.py rename to vitrage/tests/unit/datasources/__init__.py diff --git a/vitrage/tests/functional/data_sources/neutron/__init__.py b/vitrage/tests/unit/datasources/cinder/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/neutron/__init__.py rename to vitrage/tests/unit/datasources/cinder/__init__.py diff --git a/vitrage/tests/unit/synchronizer/plugins/cinder/test_cinder_volume_transformer.py b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py similarity index 87% rename from vitrage/tests/unit/synchronizer/plugins/cinder/test_cinder_volume_transformer.py rename to vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py index b1f22a91a..9b4b749b4 100644 --- a/vitrage/tests/unit/synchronizer/plugins/cinder/test_cinder_volume_transformer.py +++ b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py @@ -20,16 +20,15 @@ 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.cinder.volume import CINDER_VOLUME_PLUGIN -from vitrage.synchronizer.plugins.cinder.volume.transformer \ +from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE +from vitrage.datasources.cinder.volume.transformer \ import CinderVolumeTransformer -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 -from vitrage.synchronizer.plugins.transformer_base import TransformerBase +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.instance.transformer import InstanceTransformer +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync LOG = logging.getLogger(__name__) @@ -40,9 +39,9 @@ class TestCinderVolumeTransformer(base.BaseTest): @classmethod def setUpClass(cls): cls.transformers = {} - cls.transformers[CINDER_VOLUME_PLUGIN] = \ + cls.transformers[CINDER_VOLUME_DATASOURCE] = \ CinderVolumeTransformer(cls.transformers) - cls.transformers[NOVA_INSTANCE_PLUGIN] = \ + cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers) def test_create_placeholder_vertex(self): @@ -54,7 +53,7 @@ class TestCinderVolumeTransformer(base.BaseTest): timestamp = datetime.datetime.utcnow() properties = { VProps.ID: volume_id, - VProps.TYPE: CINDER_VOLUME_PLUGIN, + VProps.TYPE: CINDER_VOLUME_DATASOURCE, VProps.SAMPLE_TIMESTAMP: timestamp } transformer = CinderVolumeTransformer(self.transformers) @@ -65,7 +64,7 @@ class TestCinderVolumeTransformer(base.BaseTest): # Test assertions observed_id_values = placeholder.vertex_id.split( TransformerBase.KEY_SEPARATOR) - expected_id_values = transformer._key_values(CINDER_VOLUME_PLUGIN, + expected_id_values = transformer._key_values(CINDER_VOLUME_DATASOURCE, volume_id) self.assertEqual(tuple(observed_id_values), expected_id_values) @@ -73,7 +72,7 @@ class TestCinderVolumeTransformer(base.BaseTest): self.assertEqual(observed_time, timestamp) observed_type = placeholder.get(VProps.TYPE) - self.assertEqual(observed_type, CINDER_VOLUME_PLUGIN) + self.assertEqual(observed_type, CINDER_VOLUME_DATASOURCE) observed_entity_id = placeholder.get(VProps.ID) self.assertEqual(observed_entity_id, volume_id) @@ -88,7 +87,7 @@ class TestCinderVolumeTransformer(base.BaseTest): LOG.debug('Cinder Volume transformer test: get key values') # Test setup - volume_type = CINDER_VOLUME_PLUGIN + volume_type = CINDER_VOLUME_DATASOURCE volume_id = '12345' transformer = CinderVolumeTransformer(self.transformers) @@ -98,7 +97,7 @@ class TestCinderVolumeTransformer(base.BaseTest): # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) - self.assertEqual(CINDER_VOLUME_PLUGIN, observed_key_fields[1]) + self.assertEqual(CINDER_VOLUME_DATASOURCE, observed_key_fields[1]) self.assertEqual(volume_id, observed_key_fields[2]) def test_snapshot_transform(self): @@ -113,7 +112,8 @@ class TestCinderVolumeTransformer(base.BaseTest): for event in static_events: # Test action - wrapper = self.transformers[CINDER_VOLUME_PLUGIN].transform(event) + wrapper = self.transformers[CINDER_VOLUME_DATASOURCE].transform( + event) # Test assertions vertex = wrapper.vertex @@ -135,7 +135,8 @@ class TestCinderVolumeTransformer(base.BaseTest): for event in static_events: # Test action - wrapper = self.transformers[CINDER_VOLUME_PLUGIN].transform(event) + wrapper = self.transformers[CINDER_VOLUME_DATASOURCE].transform( + event) # Test assertions vertex = wrapper.vertex @@ -196,7 +197,7 @@ class TestCinderVolumeTransformer(base.BaseTest): # validate neighbor vertex self.assertEqual(EntityCategory.RESOURCE, instance_neighbor.vertex[VProps.CATEGORY]) - self.assertEqual(NOVA_INSTANCE_PLUGIN, + self.assertEqual(NOVA_INSTANCE_DATASOURCE, instance_neighbor.vertex[VProps.TYPE]) self.assertEqual(instance_id, instance_neighbor.vertex[VProps.ID]) self.assertTrue(instance_neighbor.vertex[VProps.IS_PLACEHOLDER]) diff --git a/vitrage/tests/functional/data_sources/nova/__init__.py b/vitrage/tests/unit/datasources/nagios/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/nova/__init__.py rename to vitrage/tests/unit/datasources/nagios/__init__.py diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/mock_synchronizer.py b/vitrage/tests/unit/datasources/nagios/mock_driver.py similarity index 71% rename from vitrage/tests/unit/synchronizer/plugins/nagios/mock_synchronizer.py rename to vitrage/tests/unit/datasources/nagios/mock_driver.py index f75121690..a62d976d5 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/mock_synchronizer.py +++ b/vitrage/tests/unit/datasources/nagios/mock_driver.py @@ -12,19 +12,19 @@ # License for the specific language governing permissions and limitations # under the License. -from vitrage.synchronizer.plugins.nagios.synchronizer import NagiosSynchronizer -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.datasources.nagios.driver import NagiosDriver +from vitrage.tests.mocks import mock_driver -class MockNagiosSynchronizer(NagiosSynchronizer): - """A nagios synchronizer for tests. +class MockNagiosDriver(NagiosDriver): + """A nagios driver for tests. Instead of calling Nagios URL to get the data, it returns the data it is asked to """ def __init__(self, conf): - super(MockNagiosSynchronizer, self).__init__(conf) + super(MockNagiosDriver, self).__init__(conf) self.service_datas = None def set_service_datas(self, service_datas): @@ -33,11 +33,11 @@ class MockNagiosSynchronizer(NagiosSynchronizer): def _get_alarms(self): alarms = [] for service_data in self.service_datas: - generators = mock_sync.simple_nagios_alarm_generators( + generators = mock_driver.simple_nagios_alarm_generators( host_num=1, events_num=1, snap_vals=service_data) alarms.append( - mock_sync.generate_sequential_events_list(generators)[0]) + mock_driver.generate_sequential_events_list(generators)[0]) return alarms diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/nagios_base_test.py b/vitrage/tests/unit/datasources/nagios/nagios_base_test.py similarity index 95% rename from vitrage/tests/unit/synchronizer/plugins/nagios/nagios_base_test.py rename to vitrage/tests/unit/datasources/nagios/nagios_base_test.py index cdbe1f404..e20dd3763 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/nagios_base_test.py +++ b/vitrage/tests/unit/datasources/nagios/nagios_base_test.py @@ -11,7 +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 vitrage.synchronizer.plugins.nagios.properties import NagiosProperties \ +from vitrage.datasources.nagios.properties import NagiosProperties \ as NagiosProps from vitrage.tests import base diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py b/vitrage/tests/unit/datasources/nagios/test_nagios_config.py similarity index 84% rename from vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py rename to vitrage/tests/unit/datasources/nagios/test_nagios_config.py index 19741624f..1f6802991 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_config.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_config.py @@ -15,10 +15,10 @@ 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.datasources.nagios.config import NagiosConfig +from vitrage.datasources.nagios.config import NagiosHostMapping +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE from vitrage.tests import base from vitrage.tests.mocks import utils @@ -29,13 +29,12 @@ class TestNagiosConfig(base.BaseTest): OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.nagios.' - 'transformer.NagiosTransformer', - help='Nagios plugin transformer class path', + default='vitrage.datasources.nagios.transformer.' + 'NagiosTransformer', + help='Nagios data source transformer class path', required=True), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.nagios.synchronizer' - '.NagiosSynchronizer', + cfg.StrOpt('driver', + default='vitrage.datasources.nagios.driver.NagiosDriver', help='Nagios plugin synchronizer class path', required=True), cfg.IntOpt('changes_interval', @@ -55,24 +54,26 @@ class TestNagiosConfig(base.BaseTest): ] # the mappings match the ones in nagios_conf.yaml - MAPPING_1 = NagiosHostMapping('compute-1', NOVA_HOST_PLUGIN, 'compute-1') - MAPPING_2 = NagiosHostMapping('compute-2', NOVA_HOST_PLUGIN, 'host2') + MAPPING_1 = NagiosHostMapping('compute-1', + NOVA_HOST_DATASOURCE, + 'compute-1') + MAPPING_2 = NagiosHostMapping('compute-2', NOVA_HOST_DATASOURCE, 'host2') MAPPING_3 = NagiosHostMapping('compute-(.*)', - NOVA_HOST_PLUGIN, + NOVA_HOST_DATASOURCE, '${nagios_host}') MAPPING_4 = NagiosHostMapping('instance-(.*)', - NOVA_INSTANCE_PLUGIN, + NOVA_INSTANCE_DATASOURCE, '${nagios_host}') MAPPINGS = [MAPPING_1, MAPPING_2, MAPPING_3, MAPPING_4] NON_EXISTING_MAPPING_1 = NagiosHostMapping('X', - NOVA_HOST_PLUGIN, + NOVA_HOST_DATASOURCE, 'compute-1') NON_EXISTING_MAPPING_2 = NagiosHostMapping('compute-1', 'X', 'compute-1') NON_EXISTING_MAPPING_3 = NagiosHostMapping('compute-1', - NOVA_HOST_PLUGIN, + NOVA_HOST_DATASOURCE, 'X') NON_EXISTING_MAPPINGS = [NON_EXISTING_MAPPING_1, NON_EXISTING_MAPPING_2, @@ -157,22 +158,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_PLUGIN, mapped_resource[0]) + self.assertEqual(NOVA_HOST_DATASOURCE, 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_PLUGIN, mapped_resource[0]) + self.assertEqual(NOVA_HOST_DATASOURCE, 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_PLUGIN, mapped_resource[0]) + self.assertEqual(NOVA_HOST_DATASOURCE, 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_PLUGIN, mapped_resource[0]) + self.assertEqual(NOVA_INSTANCE_DATASOURCE, mapped_resource[0]) self.assertEqual('instance-7', mapped_resource[1]) @staticmethod diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_synchronizer.py b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py similarity index 76% rename from vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_synchronizer.py rename to vitrage/tests/unit/datasources/nagios/test_nagios_driver.py index f6b1ca5ed..2d813397a 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_synchronizer.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py @@ -15,19 +15,18 @@ from oslo_config import cfg from oslo_log import log as logging -from vitrage.synchronizer.plugins.nagios.properties import ( - NagiosProperties as NagiosProps) +from vitrage.datasources.nagios.properties import NagiosProperties as \ + NagiosProps from vitrage.tests.mocks import utils -from vitrage.tests.unit.synchronizer.plugins.nagios.mock_synchronizer import ( - MockNagiosSynchronizer) -from vitrage.tests.unit.synchronizer.plugins.nagios.nagios_base_test import ( - NagiosBaseTest) +from vitrage.tests.unit.datasources.nagios.mock_driver import MockNagiosDriver +from vitrage.tests.unit.datasources.nagios.nagios_base_test import \ + NagiosBaseTest LOG = logging.getLogger(__name__) # noinspection PyProtectedMember -class NagiosSynchronizerTest(NagiosBaseTest): +class NagiosDriverTest(NagiosBaseTest): OPTS = [ cfg.StrOpt('config_file', @@ -51,7 +50,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): """ # Setup - nagios_synchronizer = MockNagiosSynchronizer(self.conf) + nagios_driver = MockNagiosDriver(self.conf) # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -64,11 +63,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions # Services with status OK should not be returned @@ -86,11 +85,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -108,11 +107,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -131,11 +130,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions # The services of service_data1/2 should be returned although their @@ -146,7 +145,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self._assert_contains(service_data2, services) # Action - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions # Calling get_services again should not return anything, since all @@ -162,7 +161,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): """ # Setup - nagios_synchronizer = MockNagiosSynchronizer(self.conf) + nagios_driver = MockNagiosDriver(self.conf) # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -175,11 +174,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions # Services with status OK should not be returned @@ -197,11 +196,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -219,11 +218,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -242,11 +241,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -264,11 +263,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -277,7 +276,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self._assert_contains(service_data2, services) # Action - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'services is None') @@ -287,7 +286,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): """Check get_changes and get_all functionalities """ # Setup - nagios_synchronizer = MockNagiosSynchronizer(self.conf) + nagios_driver = MockNagiosDriver(self.conf) # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -300,11 +299,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -312,7 +311,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self._assert_contains(service_data1, services) # Action - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions # Calling get_changes for the second time should return nothing @@ -320,7 +319,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self.assertEqual(0, len(services)) # Action - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -328,7 +327,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self._assert_contains(service_data1, services) # Action - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions # Calling get_all for the second time should return the same results @@ -347,11 +346,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'OK'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -360,7 +359,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self._assert_contains(service_data2, services) # Action - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions # Calling get_changes after get_all should return nothing @@ -368,7 +367,7 @@ class NagiosSynchronizerTest(NagiosBaseTest): self.assertEqual(0, len(services)) # Action - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions # Calling get_all for the second time should return the same results @@ -388,11 +387,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'CRITICAL'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -411,11 +410,11 @@ class NagiosSynchronizerTest(NagiosBaseTest): NagiosProps.SERVICE: 'Uptime', NagiosProps.STATUS: 'CRITICAL'} - nagios_synchronizer.set_service_datas([service_data1, - service_data2, - service_data3]) + nagios_driver.set_service_datas([service_data1, + service_data2, + service_data3]) - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') @@ -423,14 +422,14 @@ class NagiosSynchronizerTest(NagiosBaseTest): self._assert_contains(service_data1, services) # Action - services = nagios_synchronizer._get_changed_alarms() + services = nagios_driver._get_changed_alarms() # Test assertions self.assertIsNotNone(services, 'services is None') self.assertEqual(0, len(services)) # Action - services = nagios_synchronizer._get_all_alarms() + services = nagios_driver._get_all_alarms() # Test assertions # Calling get_all for the second time should return the same results diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_parser.py b/vitrage/tests/unit/datasources/nagios/test_nagios_parser.py similarity index 93% rename from vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_parser.py rename to vitrage/tests/unit/datasources/nagios/test_nagios_parser.py index 536af9060..128919de1 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_parser.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_parser.py @@ -13,10 +13,10 @@ # under the License. from oslo_log import log as logging -from vitrage.synchronizer.plugins.nagios.parser import NagiosParser -from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties +from vitrage.datasources.nagios.parser import NagiosParser +from vitrage.datasources.nagios.properties import NagiosProperties from vitrage.tests.mocks import utils -from vitrage.tests.unit.synchronizer.plugins.nagios.nagios_base_test \ +from vitrage.tests.unit.datasources.nagios.nagios_base_test \ import NagiosBaseTest LOG = logging.getLogger(__name__) diff --git a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_transformer.py b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py similarity index 86% rename from vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_transformer.py rename to vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py index 0b79b4b97..9349d88eb 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/test_nagios_transformer.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py @@ -20,16 +20,15 @@ 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 as VProps -from vitrage.synchronizer.plugins.base.alarm.properties \ - import AlarmProperties as AlarmProps -from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties -from vitrage.synchronizer.plugins.nagios.properties import NagiosStatus -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.datasources.alarm_properties import AlarmProperties as AlarmProps +from vitrage.datasources.nagios.properties import NagiosProperties +from vitrage.datasources.nagios.properties import NagiosStatus +from vitrage.datasources.nagios.transformer import NagiosTransformer +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync LOG = logging.getLogger(__name__) @@ -43,7 +42,7 @@ class NagiosTransformerTest(base.BaseTest): def setUpClass(cls): cls.transformers = {} host_transformer = HostTransformer(cls.transformers) - cls.transformers[NOVA_HOST_PLUGIN] = host_transformer + cls.transformers[NOVA_HOST_DATASOURCE] = host_transformer def test_extract_key(self): LOG.debug('Test get key from nova instance transformer') @@ -87,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_PLUGIN: + if neighbor.vertex[VProps.TYPE] == NOVA_HOST_DATASOURCE: self._validate_host_neighbor(neighbors[0], alarm) self._validate_action(alarm, wrapper) @@ -132,7 +131,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_PLUGIN, key_fields[1]) + self.assertEqual(NOVA_HOST_DATASOURCE, key_fields[1]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], key_fields[2]) self.assertFalse(host_vertex[VProps.IS_DELETED]) @@ -141,7 +140,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_PLUGIN, host_vertex[VProps.TYPE]) + self.assertEqual(NOVA_HOST_DATASOURCE, host_vertex[VProps.TYPE]) edge = neighbor.edge self.assertEqual(EdgeLabels.ON, edge.label) diff --git a/vitrage/tests/functional/data_sources/static_physical/__init__.py b/vitrage/tests/unit/datasources/nova/__init__.py similarity index 100% rename from vitrage/tests/functional/data_sources/static_physical/__init__.py rename to vitrage/tests/unit/datasources/nova/__init__.py diff --git a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py similarity index 83% rename from vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py rename to vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py index a26194dcb..757fd4c0c 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_host_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py @@ -22,14 +22,14 @@ 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 +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources.nova.zone.transformer import ZoneTransformer +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync LOG = logging.getLogger(__name__) @@ -41,8 +41,10 @@ class NovaHostTransformerTest(base.BaseTest): @classmethod def setUpClass(cls): cls.transformers = {} - cls.transformers[NOVA_ZONE_PLUGIN] = ZoneTransformer(cls.transformers) - cls.transformers[NOVA_HOST_PLUGIN] = HostTransformer(cls.transformers) + cls.transformers[NOVA_ZONE_DATASOURCE] = ZoneTransformer( + cls.transformers) + cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( + cls.transformers) def test_create_placeholder_vertex(self): LOG.debug('Nova host transformer test: Test create placeholder vertex') @@ -55,7 +57,7 @@ class NovaHostTransformerTest(base.BaseTest): # Test action properties = { VertexProperties.ID: host_name, - VertexProperties.TYPE: NOVA_HOST_PLUGIN, + VertexProperties.TYPE: NOVA_HOST_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: timestamp } placeholder = host_transformer.create_placeholder_vertex(**properties) @@ -63,15 +65,16 @@ 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_PLUGIN, - host_name) + expected_id_values = host_transformer._key_values( + NOVA_HOST_DATASOURCE, + host_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, NOVA_HOST_PLUGIN) + self.assertEqual(observed_subtype, NOVA_HOST_DATASOURCE) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, host_name) @@ -91,12 +94,13 @@ class NovaHostTransformerTest(base.BaseTest): host_transformer = HostTransformer(self.transformers) # Test action - observed_key_fields = host_transformer._key_values(NOVA_HOST_PLUGIN, - host_name) + observed_key_fields = host_transformer._key_values( + NOVA_HOST_DATASOURCE, + host_name) # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) - self.assertEqual(NOVA_HOST_PLUGIN, observed_key_fields[1]) + self.assertEqual(NOVA_HOST_DATASOURCE, observed_key_fields[1]) self.assertEqual(host_name, observed_key_fields[2]) def test_snapshot_transform(self): @@ -111,7 +115,7 @@ class NovaHostTransformerTest(base.BaseTest): for event in host_events: # Test action - wrapper = self.transformers[NOVA_HOST_PLUGIN].transform(event) + wrapper = self.transformers[NOVA_HOST_DATASOURCE].transform(event) # Test assertions self._validate_vertex_props(wrapper.vertex, event) @@ -130,10 +134,10 @@ class NovaHostTransformerTest(base.BaseTest): zone_name = tbase.extract_field_value(event, 'zone') time = event[SyncProps.SAMPLE_DATE] - zt = self.transformers[NOVA_ZONE_PLUGIN] + zt = self.transformers[NOVA_ZONE_DATASOURCE] properties = { VertexProperties.ID: zone_name, - VertexProperties.TYPE: NOVA_ZONE_PLUGIN, + VertexProperties.TYPE: NOVA_ZONE_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: time } expected_neighbor = zt.create_placeholder_vertex(**properties) @@ -161,7 +165,7 @@ class NovaHostTransformerTest(base.BaseTest): ) self.assertEqual( - NOVA_HOST_PLUGIN, + NOVA_HOST_DATASOURCE, vertex[VertexProperties.TYPE] ) diff --git a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformers.py similarity index 87% rename from vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py rename to vitrage/tests/unit/datasources/nova/test_nova_instance_transformers.py index ed0aa45e6..f5213d5e2 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_instance_transformers.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformers.py @@ -22,15 +22,14 @@ 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 -from vitrage.synchronizer.plugins.transformer_base import TransformerBase +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.instance.transformer import InstanceTransformer +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync LOG = logging.getLogger(__name__) @@ -42,8 +41,9 @@ class NovaInstanceTransformerTest(base.BaseTest): @classmethod def setUpClass(cls): cls.transformers = {} - cls.transformers[NOVA_HOST_PLUGIN] = HostTransformer(cls.transformers) - cls.transformers[NOVA_INSTANCE_PLUGIN] = \ + cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( + cls.transformers) + cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers) def test_create_placeholder_vertex(self): @@ -54,7 +54,7 @@ class NovaInstanceTransformerTest(base.BaseTest): timestamp = datetime.datetime.utcnow() properties = { VertexProperties.ID: instance_id, - VertexProperties.TYPE: NOVA_INSTANCE_PLUGIN, + VertexProperties.TYPE: NOVA_INSTANCE_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: timestamp } transformer = InstanceTransformer(self.transformers) @@ -65,7 +65,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_PLUGIN, + expected_id_values = transformer._key_values(NOVA_INSTANCE_DATASOURCE, instance_id) self.assertEqual(tuple(observed_id_values), expected_id_values) @@ -73,7 +73,7 @@ class NovaInstanceTransformerTest(base.BaseTest): self.assertEqual(observed_time, timestamp) observed_type = placeholder.get(VertexProperties.TYPE) - self.assertEqual(observed_type, NOVA_INSTANCE_PLUGIN) + self.assertEqual(observed_type, NOVA_INSTANCE_DATASOURCE) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, instance_id) @@ -97,7 +97,8 @@ class NovaInstanceTransformerTest(base.BaseTest): for event in instance_events: # Test action - wrapper = self.transformers[NOVA_INSTANCE_PLUGIN].transform(event) + wrapper = self.transformers[NOVA_INSTANCE_DATASOURCE].transform( + event) # Test assertions self._validate_vertex_props(wrapper.vertex, event) @@ -126,7 +127,8 @@ class NovaInstanceTransformerTest(base.BaseTest): for event in instance_events: # Test action - wrapper = self.transformers[NOVA_INSTANCE_PLUGIN].transform(event) + wrapper = self.transformers[NOVA_INSTANCE_DATASOURCE].transform( + event) # Test assertions self._validate_vertex_props(wrapper.vertex, event) @@ -161,7 +163,8 @@ class NovaInstanceTransformerTest(base.BaseTest): EntityCategory.RESOURCE, vertex[VertexProperties.CATEGORY] ) - self.assertEqual(NOVA_INSTANCE_PLUGIN, vertex[VertexProperties.TYPE]) + self.assertEqual(NOVA_INSTANCE_DATASOURCE, + vertex[VertexProperties.TYPE]) expected_project = extract_value(event, 'tenant_id') observed_project = vertex[VertexProperties.PROJECT_ID] @@ -196,10 +199,10 @@ class NovaInstanceTransformerTest(base.BaseTest): host_name = tbase.extract_field_value(event, name) time = event[SyncProps.SAMPLE_DATE] - ht = self.transformers[NOVA_HOST_PLUGIN] + ht = self.transformers[NOVA_HOST_DATASOURCE] properties = { VertexProperties.ID: host_name, - VertexProperties.TYPE: NOVA_HOST_PLUGIN, + VertexProperties.TYPE: NOVA_HOST_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: time } expected_neighbor = ht.create_placeholder_vertex(**properties) @@ -234,7 +237,7 @@ class NovaInstanceTransformerTest(base.BaseTest): self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) self.assertEqual( - NOVA_INSTANCE_PLUGIN, + NOVA_INSTANCE_DATASOURCE, observed_key_fields[1] ) @@ -242,8 +245,9 @@ class NovaInstanceTransformerTest(base.BaseTest): self.assertEqual(instance_id, observed_key_fields[2]) - key_values = instance_transformer._key_values(NOVA_INSTANCE_PLUGIN, - instance_id) + key_values = instance_transformer._key_values( + NOVA_INSTANCE_DATASOURCE, + instance_id) expected_key = tbase.build_key(key_values) self.assertEqual(expected_key, observed_key) @@ -257,8 +261,9 @@ class NovaInstanceTransformerTest(base.BaseTest): instance_transformer = InstanceTransformer(self.transformers) # Test action - key_fields = instance_transformer._key_values(NOVA_INSTANCE_PLUGIN, - instance_id) + key_fields = instance_transformer._key_values( + NOVA_INSTANCE_DATASOURCE, + instance_id) # Test assertions observed_key = tbase.build_key(key_fields) @@ -278,7 +283,7 @@ class NovaInstanceTransformerTest(base.BaseTest): vertex_id, host_name, time, - self.transformers[NOVA_HOST_PLUGIN] + self.transformers[NOVA_HOST_DATASOURCE] ) # Test assertions diff --git a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py similarity index 85% rename from vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py rename to vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py index a9b0230ab..bcd02acc3 100644 --- a/vitrage/tests/unit/synchronizer/plugins/nova/test_nova_zone_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py @@ -20,15 +20,15 @@ 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 -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.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources.nova.zone.transformer import ZoneTransformer +from vitrage.datasources import OPENSTACK_NODE +from vitrage.datasources import transformer_base as tbase +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync LOG = logging.getLogger(__name__) @@ -40,8 +40,10 @@ class NovaZoneTransformerTest(base.BaseTest): @classmethod def setUpClass(cls): cls.transformers = {} - cls.transformers[NOVA_HOST_PLUGIN] = HostTransformer(cls.transformers) - cls.transformers[NOVA_ZONE_PLUGIN] = ZoneTransformer(cls.transformers) + cls.transformers[NOVA_HOST_DATASOURCE] = \ + HostTransformer(cls.transformers) + cls.transformers[NOVA_ZONE_DATASOURCE] = \ + ZoneTransformer(cls.transformers) def test_create_placeholder_vertex(self): @@ -55,7 +57,7 @@ class NovaZoneTransformerTest(base.BaseTest): # Test action properties = { VertexProperties.ID: zone_name, - VertexProperties.TYPE: NOVA_ZONE_PLUGIN, + VertexProperties.TYPE: NOVA_ZONE_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: timestamp } placeholder = zone_transformer.create_placeholder_vertex(**properties) @@ -64,14 +66,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_PLUGIN, zone_name) + NOVA_ZONE_DATASOURCE, 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, NOVA_ZONE_PLUGIN) + self.assertEqual(observed_subtype, NOVA_ZONE_DATASOURCE) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, zone_name) @@ -90,13 +92,14 @@ class NovaZoneTransformerTest(base.BaseTest): zone_transformer = ZoneTransformer(self.transformers) # Test action - observed_key_fields = zone_transformer._key_values(NOVA_ZONE_PLUGIN, - zone_name) + observed_key_fields = zone_transformer._key_values( + NOVA_ZONE_DATASOURCE, + zone_name) # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) self.assertEqual( - NOVA_ZONE_PLUGIN, + NOVA_ZONE_DATASOURCE, observed_key_fields[1] ) self.assertEqual(zone_name, observed_key_fields[2]) @@ -115,7 +118,7 @@ class NovaZoneTransformerTest(base.BaseTest): for event in zone_events: # Test action - wrapper = self.transformers[NOVA_ZONE_PLUGIN].transform(event) + wrapper = self.transformers[NOVA_ZONE_DATASOURCE].transform(event) # Test assertions vertex = wrapper.vertex @@ -209,15 +212,11 @@ class NovaZoneTransformerTest(base.BaseTest): observed_id = vertex[VertexProperties.ID] self.assertEqual(expected_id, observed_id) - self.assertEqual( - EntityCategory.RESOURCE, - vertex[VertexProperties.CATEGORY] - ) + self.assertEqual(EntityCategory.RESOURCE, + vertex[VertexProperties.CATEGORY]) - self.assertEqual( - NOVA_ZONE_PLUGIN, - vertex[VertexProperties.TYPE] - ) + self.assertEqual(NOVA_ZONE_DATASOURCE, + vertex[VertexProperties.TYPE]) expected_timestamp = event[SyncProps.SAMPLE_DATE] observed_timestamp = vertex[VertexProperties.SAMPLE_TIMESTAMP] diff --git a/vitrage/tests/unit/synchronizer/__init__.py b/vitrage/tests/unit/datasources/static_physical/__init__.py similarity index 100% rename from vitrage/tests/unit/synchronizer/__init__.py rename to vitrage/tests/unit/datasources/static_physical/__init__.py diff --git a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py b/vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py similarity index 68% rename from vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py rename to vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py index 91033242c..7f60366df 100644 --- a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_synchronizer.py +++ b/vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py @@ -22,9 +22,9 @@ 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.datasources.static_physical import driver +from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE +from vitrage.datasources.static_physical import SWITCH from vitrage.tests import base from vitrage.tests.mocks import utils @@ -32,33 +32,33 @@ from vitrage.tests.mocks import utils LOG = logging.getLogger(__name__) -class TestStaticPhysicalSynchronizer(base.BaseTest): +class TestStaticPhysicalDriver(base.BaseTest): OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.static_physical.' - 'transformer.StaticPhysicalTransformer'), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.static_physical' - '.synchronizer.StaticPhysicalTransformer'), + default='vitrage.datasources.static_physical.transformer.' + 'StaticPhysicalTransformer'), + cfg.StrOpt('driver', + default='vitrage.datasources.static_physical.driver.' + 'StaticPhysicalDriver'), cfg.IntOpt('changes_interval', default=30, min=30, help='interval between checking changes in the ' 'configuration files of the physical topology plugin'), cfg.StrOpt('directory', - default=utils.get_resources_dir() + '/static_plugins'), + default=utils.get_resources_dir() + '/static_datasources'), cfg.ListOpt('entities', default=[SWITCH]) ] CHANGES_OPTS = [ cfg.StrOpt('transformer', - default='vitrage.synchronizer.plugins.static_physical.' - 'transformer.StaticPhysicalTransformer'), - cfg.StrOpt('synchronizer', - default='vitrage.synchronizer.plugins.static_physical' - '.synchronizer.StaticPhysicalTransformer'), + default='vitrage.datasources.static_physical.transformer.' + 'StaticPhysicalTransformer'), + cfg.StrOpt('driver', + default='vitrage.datasources.static_physical.driver.' + 'StaticPhysicalDriver'), cfg.IntOpt('changes_interval', default=30, min=30, @@ -66,20 +66,19 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): 'configuration files of the physical topology plugin'), cfg.StrOpt('directory', default=utils.get_resources_dir() + - '/static_plugins/changes_plugins'), + '/static_datasources/changes_datasources'), ] # noinspection PyAttributeOutsideInit,PyPep8Naming @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=STATIC_PHYSICAL_PLUGIN) - cls.static_physical_synchronizer = \ - synchronizer.StaticPhysicalSynchronizer(cls.conf) + cls.conf.register_opts(cls.OPTS, group=STATIC_PHYSICAL_DATASOURCE) + cls.static_physical_driver = driver.StaticPhysicalDriver(cls.conf) - def test_static_plugins_loader(self): + def test_static_datasources_loader(self): # Setup - total_static_plugins = \ + total_static_datasources = \ os.listdir(self.conf.static_physical.directory) # Action @@ -87,13 +86,13 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): self.conf.static_physical.directory) # Test assertions - # -1 is because there are 2 files and a folder in static_plugins_dir - self.assertEqual(len(total_static_plugins) - 1, len(static_configs)) + # -1 is because there are 2 files and a folder in static_datasource_dir + self.assertEqual(len(total_static_datasources) - 1, + len(static_configs)) def test_get_all(self): # Action - static_entities = self.static_physical_synchronizer.get_all( - SyncMode.UPDATE) + static_entities = self.static_physical_driver.get_all(SyncMode.UPDATE) # Test assertions self.assertEqual(5, len(static_entities)) @@ -101,16 +100,16 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): # noinspection PyAttributeOutsideInit def test_get_changes(self): # Setup - entities = self.static_physical_synchronizer.get_all(SyncMode.UPDATE) + entities = self.static_physical_driver.get_all(SyncMode.UPDATE) self.assertEqual(5, len(entities)) self.conf = cfg.ConfigOpts() self.conf.register_opts(self.CHANGES_OPTS, - group=STATIC_PHYSICAL_PLUGIN) - self.static_physical_synchronizer.cfg = self.conf + group=STATIC_PHYSICAL_DATASOURCE) + self.static_physical_driver.cfg = self.conf # Action - changes = self.static_physical_synchronizer.get_changes( + changes = self.static_physical_driver.get_changes( EventAction.UPDATE_ENTITY) # Test Assertions @@ -138,7 +137,7 @@ class TestStaticPhysicalSynchronizer(base.BaseTest): self.assertEqual(4, len(changes)) # Action - changes = self.static_physical_synchronizer.get_changes( + changes = self.static_physical_driver.get_changes( EventAction.UPDATE_ENTITY) # Test Assertions diff --git a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py b/vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py similarity index 89% rename from vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py rename to vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py index 188f5f73e..5fb913aa9 100644 --- a/vitrage/tests/unit/synchronizer/plugins/static_physical/test_static_physical_transformer.py +++ b/vitrage/tests/unit/datasources/static_physical/test_static_physical_transformer.py @@ -20,14 +20,14 @@ 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 \ +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE +from vitrage.datasources.static_physical.transformer \ import StaticPhysicalTransformer -from vitrage.synchronizer.plugins.transformer_base import TransformerBase +from vitrage.datasources.transformer_base import TransformerBase from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync LOG = logging.getLogger(__name__) @@ -38,9 +38,10 @@ class TestStaticPhysicalTransformer(base.BaseTest): @classmethod def setUpClass(cls): cls.transformers = {} - cls.transformers[NOVA_HOST_PLUGIN] = HostTransformer(cls.transformers) - cls.transformers[STATIC_PHYSICAL_PLUGIN] = StaticPhysicalTransformer( + cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( cls.transformers) + cls.transformers[STATIC_PHYSICAL_DATASOURCE] = \ + StaticPhysicalTransformer(cls.transformers) def test_create_placeholder_vertex(self): @@ -48,7 +49,7 @@ class TestStaticPhysicalTransformer(base.BaseTest): 'vertex') # Test setup - switch_type = STATIC_PHYSICAL_PLUGIN + switch_type = STATIC_PHYSICAL_DATASOURCE switch_name = 'switch-1' timestamp = datetime.datetime.utcnow() static_transformer = StaticPhysicalTransformer(self.transformers) @@ -89,7 +90,7 @@ class TestStaticPhysicalTransformer(base.BaseTest): LOG.debug('Static Physical transformer test: get key values') # Test setup - switch_type = STATIC_PHYSICAL_PLUGIN + switch_type = STATIC_PHYSICAL_DATASOURCE switch_name = 'switch-1' static_transformer = StaticPhysicalTransformer(self.transformers) @@ -99,7 +100,7 @@ class TestStaticPhysicalTransformer(base.BaseTest): # Test assertions self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) - self.assertEqual(STATIC_PHYSICAL_PLUGIN, observed_key_fields[1]) + self.assertEqual(STATIC_PHYSICAL_DATASOURCE, observed_key_fields[1]) self.assertEqual(switch_name, observed_key_fields[2]) def test_snapshot_transform(self): diff --git a/vitrage/tests/unit/entity_graph/base.py b/vitrage/tests/unit/entity_graph/base.py index 9373e7632..41b7a7e24 100644 --- a/vitrage/tests/unit/entity_graph/base.py +++ b/vitrage/tests/unit/entity_graph/base.py @@ -18,37 +18,41 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import SynchronizerProperties as SyncProps from vitrage.common.constants import SyncMode from vitrage.common.datetime_utils import utcnow +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE 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.service import load_datasource from vitrage.tests import base -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync from vitrage.tests.mocks import utils class TestEntityGraphUnitBase(base.BaseTest): PROCESSOR_OPTS = [ - cfg.StrOpt('states_plugins_dir', - default=utils.get_resources_dir() + '/states_plugins'), + cfg.StrOpt('datasources_states_dir', + default=utils.get_resources_dir() + '/datasources_states'), ] - PLUGINS_OPTS = [ - cfg.ListOpt('plugin_type', - default=[NAGIOS_PLUGIN, - NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN], - help='Names of supported synchronizer plugins'), + DATASOURCES_OPTS = [ + cfg.ListOpt('types', + default=[NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE], + help='Names of supported data sources'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], - help='base path for plugins') + cfg.ListOpt('path', + default=['vitrage.datasources'], + help='base path for data sources'), + + cfg.IntOpt('snapshots_interval', + default=1, + min=1) ] NUM_NODES = 1 @@ -57,9 +61,9 @@ class TestEntityGraphUnitBase(base.BaseTest): NUM_INSTANCES = 16 @staticmethod - def load_plugins(conf): - for plugin_name in conf.plugins.plugin_type: - load_plugin(conf, plugin_name, conf.plugins.plugin_path) + def load_datasources(conf): + for datasource in conf.datasources.types: + load_datasource(conf, datasource, conf.datasources.path) def _create_processor_with_graph(self, conf, processor=None): events = self._create_mock_events() diff --git a/vitrage/tests/unit/entity_graph/processor/base.py b/vitrage/tests/unit/entity_graph/processor/base.py index 500e65ba4..a203d608e 100644 --- a/vitrage/tests/unit/entity_graph/processor/base.py +++ b/vitrage/tests/unit/entity_graph/processor/base.py @@ -27,8 +27,8 @@ class TestBaseProcessor(TestEntityGraphUnitBase): def setUpClass(cls): super(TestBaseProcessor, cls).setUpClass() cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') - cls.load_plugins(cls.conf) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) cls.transform = transformer_manager.TransformerManager(cls.conf) @staticmethod diff --git a/vitrage/tests/unit/entity_graph/processor/test_processor.py b/vitrage/tests/unit/entity_graph/processor/test_processor.py index 8b3bd238a..d755ca3c0 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_processor.py +++ b/vitrage/tests/unit/entity_graph/processor/test_processor.py @@ -21,12 +21,12 @@ 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.datetime_utils import utcnow +from vitrage.datasources.transformer_base import Neighbor from vitrage.entity_graph.initialization_status import InitializationStatus from vitrage.entity_graph.processor import processor as proc from vitrage.entity_graph.states.normalized_resource_state import \ NormalizedResourceState import vitrage.graph.utils as graph_utils -from vitrage.synchronizer.plugins.transformer_base import Neighbor from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase @@ -46,8 +46,8 @@ class TestProcessor(TestEntityGraphUnitBase): super(TestProcessor, 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) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls.load_datasources(cls.conf) # TODO(Alexey): un skip this test when instance transformer update is ready @unittest.skip('Not ready yet') 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 bddeb573d..f53e860f0 100644 --- a/vitrage/tests/unit/entity_graph/states/test_state_manager.py +++ b/vitrage/tests/unit/entity_graph/states/test_state_manager.py @@ -16,15 +16,15 @@ from oslo_config import cfg from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE from vitrage.entity_graph.states.normalized_resource_state import \ NormalizedResourceState 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.service import load_datasource from vitrage.tests import base from vitrage.tests.mocks import utils @@ -32,27 +32,27 @@ from vitrage.tests.mocks import utils class TestStateManager(base.BaseTest): ENTITY_GRAPH_OPTS = [ - cfg.StrOpt('states_plugins_dir', - default=utils.get_resources_dir() + '/states_plugins'), + cfg.StrOpt('datasources_states_dir', + default=utils.get_resources_dir() + '/datasources_states'), ] - PLUGINS_OPTS = [ - cfg.ListOpt('plugin_type', - default=[NAGIOS_PLUGIN, - NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN], - help='Names of supported synchronizer plugins'), + DATASOURCES_OPTS = [ + cfg.ListOpt('types', + default=[NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE], + help='Names of supported data sources'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], - help='base path for plugins') + cfg.ListOpt('path', + default=['vitrage.datasources'], + help='base path for datasources') ] @staticmethod - def _load_plugins(conf): - for plugin_name in conf.plugins.plugin_type: - load_plugin(conf, plugin_name, conf.plugins.plugin_path) + def _load_datasources(conf): + for datasource_name in conf.datasources.types: + load_datasource(conf, datasource_name, conf.datasources.path) # noinspection PyAttributeOutsideInit,PyPep8Naming @classmethod @@ -60,40 +60,42 @@ class TestStateManager(base.BaseTest): super(TestStateManager, cls).setUpClass() cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.ENTITY_GRAPH_OPTS, group='entity_graph') - cls.conf.register_opts(cls.PLUGINS_OPTS, group='plugins') - cls._load_plugins(cls.conf) + cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') + cls._load_datasources(cls.conf) - def test_load_state_plugins_without_errors(self): + def test_load_datasource_state_without_errors(self): # action state_manager = StateManager(self.conf) # test assertions - # Total plugins plus the evaluator which is not definable - total_plugins = len(self.conf.plugins.plugin_type) + 1 - self.assertEqual(total_plugins, len(state_manager.states_plugins)) + # Total datasources plus the evaluator which is not definable + total_datasources = len(self.conf.datasources.types) + 1 + self.assertEqual(total_datasources, + len(state_manager.datasources_state_confs)) - def test_load_state_plugins_with_errors(self): + def test_load_datasources_state_with_errors(self): # setup entity_graph_opts = [ - cfg.StrOpt('states_plugins_dir', + cfg.StrOpt('datasources_states_dir', default=utils.get_resources_dir() + - '/states_plugins/erroneous_states_plugins'), + '/datasources_states/erroneous_states'), ] conf = cfg.ConfigOpts() conf.register_opts(entity_graph_opts, group='entity_graph') - conf.register_opts(self.PLUGINS_OPTS, group='plugins') - self._load_plugins(conf) + conf.register_opts(self.DATASOURCES_OPTS, group='datasources') + self._load_datasources(conf) # action state_manager = StateManager(conf) # test assertions - missing_states_plugins = 1 - erroneous_states_plugins = 2 - num_valid_plugins = len(state_manager.states_plugins) + \ - missing_states_plugins + erroneous_states_plugins - self.assertEqual(len(conf.plugins.plugin_type), num_valid_plugins) + missing_states = 1 + erroneous_states = 2 + num_valid_datasources = len(state_manager.datasources_state_confs) + \ + missing_states + erroneous_states + self.assertEqual(len(conf.datasources.types), + num_valid_datasources) def test_normalize_state(self): # setup @@ -102,7 +104,7 @@ class TestStateManager(base.BaseTest): # action normalized_state = \ state_manager.normalize_state(EntityCategory.RESOURCE, - NOVA_INSTANCE_PLUGIN, + NOVA_INSTANCE_DATASOURCE, 'BUILDING') # test assertions @@ -114,7 +116,7 @@ class TestStateManager(base.BaseTest): # action state_priority = \ - state_manager.state_priority(NOVA_INSTANCE_PLUGIN, + state_manager.state_priority(NOVA_INSTANCE_DATASOURCE, NormalizedResourceState.RUNNING) # test assertions @@ -127,13 +129,13 @@ class TestStateManager(base.BaseTest): new_vertex1 = create_vertex('12345', entity_state='ACTIVE', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN, + entity_type=NOVA_INSTANCE_DATASOURCE, metadata=metadata1) metadata2 = {VProps.VITRAGE_STATE: 'ACTIVE'} new_vertex2 = create_vertex('23456', entity_state='SUSPENDED', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN, + entity_type=NOVA_INSTANCE_DATASOURCE, metadata=metadata2) # action @@ -152,18 +154,18 @@ class TestStateManager(base.BaseTest): new_vertex1 = create_vertex('12345', entity_state='ACTIVE', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN) + entity_type=NOVA_INSTANCE_DATASOURCE) metadata2 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'} new_vertex2 = create_vertex('23456', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN, + entity_type=NOVA_INSTANCE_DATASOURCE, metadata=metadata2) new_vertex3 = create_vertex('34567', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN) + entity_type=NOVA_INSTANCE_DATASOURCE) graph_vertex3 = create_vertex('45678', entity_category=EntityCategory.RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN) + entity_type=NOVA_INSTANCE_DATASOURCE) # 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 4e6c8bcc0..5dbb1f717 100644 --- a/vitrage/tests/unit/entity_graph/test_transformer_manager.py +++ b/vitrage/tests/unit/entity_graph/test_transformer_manager.py @@ -15,20 +15,16 @@ from oslo_config import cfg from oslo_log import log as logging +from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nagios.transformer import NagiosTransformer +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.host.transformer import HostTransformer +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources.nova.instance.transformer import InstanceTransformer +from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.datasources.nova.zone.transformer import ZoneTransformer 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.service import load_datasource from vitrage.tests import base LOG = logging.getLogger(__name__) @@ -37,41 +33,41 @@ LOG = logging.getLogger(__name__) class TransformerManagerTest(base.BaseTest): OPTS = [ - cfg.ListOpt('plugin_type', - default=[NAGIOS_PLUGIN, - NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, - NOVA_ZONE_PLUGIN], - help='Names of supported synchronizer plugins'), + cfg.ListOpt('types', + default=[NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE], + help='Names of supported data sources'), - cfg.ListOpt('plugin_path', - default=['vitrage.synchronizer.plugins'], - help='base path for plugins') + cfg.ListOpt('path', + default=['vitrage.datasources'], + help='base path for data sources') ] # noinspection PyPep8Naming @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='plugins') + cls.conf.register_opts(cls.OPTS, group='datasources') - for plugin_name in cls.conf.plugins.plugin_type: - load_plugin(cls.conf, plugin_name, cls.conf.plugins.plugin_path) + for datasource in cls.conf.datasources.types: + load_datasource(cls.conf, datasource, cls.conf.datasources.path) cls.manager = TransformerManager(cls.conf) def test_transformer_registration_nagios(self): self.assertIsInstance(self.manager.get_transformer - (NAGIOS_PLUGIN), NagiosTransformer) + (NAGIOS_DATASOURCE), NagiosTransformer) def test_transformer_registration_nova_host(self): self.assertIsInstance(self.manager.get_transformer - (NOVA_HOST_PLUGIN), HostTransformer) + (NOVA_HOST_DATASOURCE), HostTransformer) def test_transformer_registration_nova_instance(self): self.assertIsInstance(self.manager.get_transformer - (NOVA_INSTANCE_PLUGIN), InstanceTransformer) + (NOVA_INSTANCE_DATASOURCE), InstanceTransformer) def test_transformer_registration_nova_zone(self): self.assertIsInstance(self.manager.get_transformer - (NOVA_ZONE_PLUGIN), ZoneTransformer) + (NOVA_ZONE_DATASOURCE), ZoneTransformer) diff --git a/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py b/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py index f5b0fc4e6..42b1f94b5 100644 --- a/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py +++ b/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py @@ -14,6 +14,7 @@ from oslo_log import log as logging from vitrage.common.constants import NotifierEventTypes +from vitrage.datasources.alarm_properties import AlarmProperties from vitrage.evaluator.actions.base import ActionType from vitrage.evaluator.actions.recipes.action_steps import ADD_VERTEX from vitrage.evaluator.actions.recipes.action_steps import NOTIFY @@ -21,7 +22,6 @@ from vitrage.evaluator.actions.recipes.action_steps import REMOVE_VERTEX from vitrage.evaluator.actions.recipes.raise_alarm import RaiseAlarm from vitrage.evaluator.template import ActionSpecs from vitrage.evaluator.template_fields import TemplateFields as TFields -from vitrage.synchronizer.plugins.base.alarm.properties import AlarmProperties from vitrage.tests import base diff --git a/vitrage/tests/unit/graph/base.py b/vitrage/tests/unit/graph/base.py index 1d97ffc2f..8d5862c35 100644 --- a/vitrage/tests/unit/graph/base.py +++ b/vitrage/tests/unit/graph/base.py @@ -26,12 +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.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE +from vitrage.datasources import OPENSTACK_NODE +from vitrage.datasources.static_physical import SWITCH 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__) @@ -56,14 +56,14 @@ v_node = graph_utils.create_vertex( entity_type=OPENSTACK_NODE, entity_category=RESOURCE) v_host = graph_utils.create_vertex( - vitrage_id=NOVA_HOST_PLUGIN + '222222222222', + vitrage_id=NOVA_HOST_DATASOURCE + '222222222222', entity_id='222222222222', - entity_type=NOVA_HOST_PLUGIN, + entity_type=NOVA_HOST_DATASOURCE, entity_category=RESOURCE) v_instance = graph_utils.create_vertex( - vitrage_id=NOVA_INSTANCE_PLUGIN + '333333333333', + vitrage_id=NOVA_INSTANCE_DATASOURCE + '333333333333', entity_id='333333333333', - entity_type=NOVA_INSTANCE_PLUGIN, + entity_type=NOVA_INSTANCE_DATASOURCE, entity_category=RESOURCE) v_alarm = graph_utils.create_vertex( vitrage_id=ALARM + '444444444444', @@ -150,7 +150,7 @@ class GraphTestBase(base.BaseTest): for host_id in range(num_of_hosts_per_node): host_to_add = add_connected_vertex(g, RESOURCE, - NOVA_HOST_PLUGIN, + NOVA_HOST_DATASOURCE, host_id, ELabel.CONTAINS, v_node, @@ -176,7 +176,7 @@ class GraphTestBase(base.BaseTest): for j in range(num_of_vms_per_host): vm_to_add = add_connected_vertex(g, RESOURCE, - NOVA_INSTANCE_PLUGIN, + NOVA_INSTANCE_DATASOURCE, self.vm_id, ELabel.CONTAINS, host_to_add, diff --git a/vitrage/tests/unit/graph/test_graph.py b/vitrage/tests/unit/graph/test_graph.py index e2a757b20..aa60a03d6 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(NOVA_HOST_PLUGIN, v_from_graph_copy[VProps.TYPE], + self.assertEqual(NOVA_HOST_DATASOURCE, v_from_graph_copy[VProps.TYPE], 'graph copy vertex unchanged after update') def test_vertex_crud(self): @@ -102,7 +102,7 @@ class GraphTest(GraphTestBase): another_vertex = utils.create_vertex( vitrage_id='123', entity_id='456', - entity_category=NOVA_INSTANCE_PLUGIN, + entity_category=NOVA_INSTANCE_DATASOURCE, metadata={'some_meta': 'DATA'} ) g.add_vertex(another_vertex) @@ -230,7 +230,7 @@ class GraphTest(GraphTestBase): v4 = v_alarm v5 = utils.create_vertex( vitrage_id='kuku', - entity_category=NOVA_HOST_PLUGIN) + entity_category=NOVA_HOST_DATASOURCE) g = create_graph('test_neighbors') g.add_vertex(v1) @@ -274,7 +274,7 @@ class GraphTest(GraphTestBase): v1_neighbors = g.neighbors( v_id=v1.vertex_id, - vertex_attr_filter={VProps.TYPE: NOVA_HOST_PLUGIN}) + vertex_attr_filter={VProps.TYPE: NOVA_HOST_DATASOURCE}) self._assert_set_equal({v2}, v1_neighbors, 'Check V1 neighbors, vertex property filter') @@ -303,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: NOVA_HOST_PLUGIN}) + vertex_attr_filter={VProps.TYPE: NOVA_HOST_DATASOURCE}) self._assert_set_equal( {v2}, v1_neighbors, 'Check V1 neighbors, vertex/edge property filter and direction') @@ -316,13 +316,14 @@ class GraphTest(GraphTestBase): v2_neighbors = g.neighbors( v_id=v2.vertex_id, - vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_PLUGIN}) + vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_DATASOURCE}) 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: [NOVA_HOST_PLUGIN, ALARM]}) + vertex_attr_filter={VProps.CATEGORY: [NOVA_HOST_DATASOURCE, + ALARM]}) self._assert_set_equal({v4}, v2_neighbors, 'Check v2 neighbors, vertex property filter') @@ -333,8 +334,8 @@ class GraphTest(GraphTestBase): }, vertex_attr_filter={ VProps.CATEGORY: [RESOURCE, ALARM], - VProps.TYPE: [NOVA_HOST_PLUGIN, - NOVA_INSTANCE_PLUGIN, + VProps.TYPE: [NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, ALARM_ON_VM, ALARM_ON_HOST] } @@ -350,13 +351,13 @@ class GraphTest(GraphTestBase): v3_neighbors = g.neighbors( v_id=v3.vertex_id, - vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_PLUGIN}, + vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_DATASOURCE}, 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: NOVA_HOST_PLUGIN}) + vertex_attr_filter={VProps.CATEGORY: NOVA_HOST_DATASOURCE}) 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 dfa969837..442cfec7b 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: NOVA_HOST_PLUGIN}}, + {'==': {VProps.TYPE: NOVA_HOST_DATASOURCE}}, {'==': {VProps.TYPE: OPENSTACK_NODE}} ] } @@ -48,9 +48,9 @@ class GraphAlgorithmTest(GraphTestBase): query = { 'or': [ - {'==': {VProps.TYPE: NOVA_INSTANCE_PLUGIN}}, + {'==': {VProps.TYPE: NOVA_INSTANCE_DATASOURCE}}, {'==': {VProps.CATEGORY: ALARM}}, - {'==': {VProps.TYPE: NOVA_HOST_PLUGIN}}, + {'==': {VProps.TYPE: NOVA_HOST_DATASOURCE}}, {'==': {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: NOVA_HOST_PLUGIN}) + v_node.vertex_id, {VProps.TYPE: NOVA_HOST_DATASOURCE}) 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: NOVA_HOST_PLUGIN}}, + {'==': {VProps.TYPE: NOVA_HOST_DATASOURCE}}, ] } subgraph = ga.graph_query_vertices( @@ -159,11 +159,11 @@ class GraphAlgorithmTest(GraphTestBase): t_v_host = graph_utils.create_vertex( vitrage_id='2', entity_category=RESOURCE, - entity_type=NOVA_HOST_PLUGIN) + entity_type=NOVA_HOST_DATASOURCE) t_v_vm = graph_utils.create_vertex( vitrage_id='3', entity_category=RESOURCE, - entity_type=NOVA_INSTANCE_PLUGIN) + entity_type=NOVA_INSTANCE_DATASOURCE) 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/__init__.py b/vitrage/tests/unit/synchronizer/plugins/__init__.py deleted file mode 100644 index dd32b852f..000000000 --- a/vitrage/tests/unit/synchronizer/plugins/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# 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/unit/synchronizer/plugins/cinder/__init__.py b/vitrage/tests/unit/synchronizer/plugins/cinder/__init__.py deleted file mode 100644 index dd32b852f..000000000 --- a/vitrage/tests/unit/synchronizer/plugins/cinder/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# 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/unit/synchronizer/plugins/nagios/__init__.py b/vitrage/tests/unit/synchronizer/plugins/nagios/__init__.py deleted file mode 100644 index dd32b852f..000000000 --- a/vitrage/tests/unit/synchronizer/plugins/nagios/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# 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/unit/synchronizer/plugins/nova/__init__.py b/vitrage/tests/unit/synchronizer/plugins/nova/__init__.py deleted file mode 100644 index dd32b852f..000000000 --- a/vitrage/tests/unit/synchronizer/plugins/nova/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# 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/unit/synchronizer/plugins/static_physical/__init__.py b/vitrage/tests/unit/synchronizer/plugins/static_physical/__init__.py deleted file mode 100644 index dd32b852f..000000000 --- a/vitrage/tests/unit/synchronizer/plugins/static_physical/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# 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_tempest_tests/tests/base_mock.py b/vitrage_tempest_tests/tests/base_mock.py index fb28a71ae..91ca56d54 100644 --- a/vitrage_tempest_tests/tests/base_mock.py +++ b/vitrage_tempest_tests/tests/base_mock.py @@ -19,7 +19,7 @@ from oslo_config import cfg from vitrage.entity_graph.initialization_status import InitializationStatus from vitrage.entity_graph.processor import processor as proc -from vitrage.tests.mocks import mock_syncronizer as mock_sync +from vitrage.tests.mocks import mock_driver as mock_sync from vitrage.tests.mocks import utils @@ -27,8 +27,8 @@ class BaseMock(testtools.TestCase): """Base test class for Vitrage API tests.""" PROCESSOR_OPTS = [ - cfg.StrOpt('states_plugins_dir', - default=utils.get_resources_dir() + '/states_plugins'), + cfg.StrOpt('states_datasources_dir', + default=utils.get_resources_dir() + '/datasources_states'), ] def create_processor_with_graph(self):