From 66c608cb561896d9cab99e4b52393d0351b289d9 Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Wed, 15 May 2019 19:42:00 +0300 Subject: [PATCH] Refactor vitrage to use global CONF instead of local one Remove usage of local config object in Vitrage services and tests. Instead, it's been replaced with the global CONF object. The structure of the code becomes more like in other OpenStack projects. Also, this change provides an opportunity to introduce migrations and tests for them. Story: 2004059 Task: 27065 Change-Id: I37544a350adf8ca38a6fc4ff5d0fd96e38a3f922 --- tools/datasource-scaffold/sample/driver.py | 3 +- .../datasource-scaffold/sample/transformer.py | 4 +- .../{{cookiecutter.name}}/driver.py | 3 +- .../{{cookiecutter.name}}/transformer.py | 4 +- tools/load_generator/load_generator.py | 15 +-- vitrage/api/app.py | 47 +++++----- vitrage/api/app.wsgi | 6 +- vitrage/api/hooks.py | 26 +++--- vitrage/api_handler/apis/base.py | 3 +- vitrage/api_handler/apis/event.py | 5 +- vitrage/api_handler/apis/operational.py | 3 +- vitrage/api_handler/apis/resource.py | 3 - vitrage/api_handler/apis/topology.py | 3 - vitrage/api_handler/apis/webhook.py | 3 +- vitrage/cli/api.py | 6 +- vitrage/cli/graph.py | 14 +-- vitrage/cli/machine_learning.py | 6 +- vitrage/cli/notifier.py | 6 +- vitrage/cli/persistor.py | 9 +- vitrage/cli/snmp_parsing.py | 7 +- vitrage/cli/storage.py | 12 ++- vitrage/{service.py => common/config.py} | 47 +++++----- vitrage/coordination/coordination.py | 7 +- vitrage/coordination/service.py | 6 +- vitrage/datasources/alarm_transformer_base.py | 3 - vitrage/datasources/aodh/driver.py | 5 +- vitrage/datasources/aodh/transformer.py | 3 - vitrage/datasources/ceilometer/driver.py | 5 +- vitrage/datasources/ceilometer/transformer.py | 3 - vitrage/datasources/cinder/volume/driver.py | 5 +- .../datasources/cinder/volume/transformer.py | 3 - vitrage/datasources/collectd/driver.py | 11 ++- vitrage/datasources/collectd/transformer.py | 3 - .../datasources/consistency/transformer.py | 4 +- vitrage/datasources/doctor/driver.py | 3 +- vitrage/datasources/doctor/transformer.py | 3 - vitrage/datasources/driver_base.py | 3 - vitrage/datasources/heat/stack/driver.py | 15 +-- vitrage/datasources/heat/stack/transformer.py | 3 - vitrage/datasources/kapacitor/config.py | 6 +- vitrage/datasources/kapacitor/driver.py | 5 +- vitrage/datasources/kapacitor/transformer.py | 3 - vitrage/datasources/kubernetes/driver.py | 13 +-- vitrage/datasources/kubernetes/transformer.py | 7 +- vitrage/datasources/monasca/driver.py | 5 +- vitrage/datasources/nagios/config.py | 6 +- vitrage/datasources/nagios/driver.py | 13 +-- vitrage/datasources/nagios/transformer.py | 3 - vitrage/datasources/neutron/base.py | 5 +- .../neutron/network/transformer.py | 3 - .../datasources/neutron/port/transformer.py | 3 - vitrage/datasources/nova/host/transformer.py | 3 - vitrage/datasources/nova/instance/driver.py | 5 +- .../datasources/nova/instance/transformer.py | 8 +- vitrage/datasources/nova/nova_driver_base.py | 5 +- vitrage/datasources/nova/zone/transformer.py | 3 - vitrage/datasources/prometheus/driver.py | 17 ++-- vitrage/datasources/prometheus/transformer.py | 3 - .../datasources/resource_transformer_base.py | 4 +- vitrage/datasources/static/driver.py | 7 +- vitrage/datasources/static/transformer.py | 3 - vitrage/datasources/transformer_base.py | 11 ++- vitrage/datasources/trove/cluster/driver.py | 4 +- vitrage/datasources/trove/instance/driver.py | 4 +- .../datasources/trove/trove_driver_base.py | 5 +- vitrage/datasources/utils.py | 26 +++--- vitrage/datasources/zabbix/driver.py | 23 ++--- vitrage/datasources/zabbix/transformer.py | 3 - vitrage/entity_graph/__init__.py | 6 +- .../consistency/consistency_enforcer.py | 14 +-- vitrage/entity_graph/driver_exec.py | 24 ++--- vitrage/entity_graph/graph_init.py | 28 +++--- vitrage/entity_graph/graph_persistency.py | 3 +- .../mappings/datasource_info_mapper.py | 13 +-- vitrage/entity_graph/processor/notifier.py | 25 ++--- vitrage/entity_graph/processor/processor.py | 7 +- .../processor/transformer_manager.py | 26 +++--- vitrage/entity_graph/scheduler.py | 17 ++-- vitrage/entity_graph/workers.py | 55 +++++------ vitrage/evaluator/actions/action_executor.py | 4 +- .../actions/evaluator_event_transformer.py | 4 +- vitrage/evaluator/actions/notifier.py | 11 ++- vitrage/evaluator/scenario_evaluator.py | 18 ++-- vitrage/evaluator/scenario_repository.py | 4 +- vitrage/keystone_client.py | 21 +++-- vitrage/machine_learning/plugins/base.py | 3 - .../jaccard_correlation/alarm_processor.py | 12 ++- .../correlation_manager.py | 12 ++- vitrage/machine_learning/service.py | 26 +++--- vitrage/messaging.py | 17 ++-- .../notifier/plugins/aodh/aodh_notifier.py | 6 +- vitrage/notifier/plugins/base.py | 3 - .../plugins/mistral/mistral_notifier.py | 7 +- .../notifier/plugins/nova/nova_notifier.py | 6 +- vitrage/notifier/plugins/snmp/base.py | 3 - .../notifier/plugins/snmp/snmp_notifier.py | 8 +- vitrage/notifier/plugins/snmp/snmp_sender.py | 11 ++- vitrage/notifier/plugins/webhook/webhook.py | 10 +- .../notifier/plugins/zaqar/zaqar_notifier.py | 12 ++- vitrage/notifier/service.py | 29 +++--- vitrage/opts.py | 7 +- vitrage/os_clients.py | 66 ++++++------- vitrage/persistency/service.py | 18 ++-- vitrage/snmp_parsing/service.py | 13 +-- vitrage/storage/__init__.py | 13 +-- vitrage/storage/base.py | 2 +- vitrage/storage/impl_sqlalchemy.py | 7 +- vitrage/tests/base.py | 33 ++++++- vitrage/tests/functional/api/__init__.py | 15 +-- .../tests/functional/api/v1/test_keycloak.py | 2 +- .../tests/functional/api/v1/test_service.py | 11 ++- .../tests/functional/api_handler/test_apis.py | 74 +++++++-------- .../functional/api_handler/test_templates.py | 13 +-- vitrage/tests/functional/base.py | 4 +- .../functional/datasources/aodh/test_aodh.py | 20 ++-- .../datasources/ceilometer/test_ceilometer.py | 19 ++-- .../datasources/cinder/test_cinder_volume.py | 20 ++-- .../datasources/collectd/test_collectd.py | 20 ++-- .../datasources/heat/test_heat_stack.py | 20 ++-- .../listener_service/test_listener_service.py | 5 - .../datasources/nagios/test_nagios.py | 20 ++-- .../datasources/nova/test_nova_datasources.py | 15 +-- .../datasources/trove/test_trove_instance.py | 15 ++- .../consistency/test_consistency.py | 41 ++++----- .../graph_persistor/test_graph_persistor.py | 22 ++--- .../entity_graph/processor/test_processor.py | 15 +-- .../states/test_datasource_info_mapper.py | 15 +-- .../evaluator/test_action_executor.py | 30 +++--- .../evaluator/test_scenario_evaluator.py | 26 +++--- .../tests/functional/test_configuration.py | 29 +++--- .../mocks/mock_graph_datasource/driver.py | 8 +- .../mock_graph_datasource/transformer.py | 4 +- .../unit/datasources/aodh/mock_driver.py | 3 - .../unit/datasources/aodh/test_aodh_driver.py | 10 +- .../datasources/aodh/test_aodh_transformer.py | 4 +- .../datasources/ceilometer/mock_driver.py | 3 - .../ceilometer/test_ceilometer_driver.py | 4 +- .../ceilometer/test_ceilometer_transformer.py | 4 +- .../cinder/test_cinder_volume_transformer.py | 4 +- .../collectd/test_collectd_driver.py | 2 +- .../collectd/test_collectd_transformer.py | 19 ++-- .../test_consistency_transformer.py | 2 +- .../datasources/doctor/test_doctor_driver.py | 2 +- .../doctor/test_doctor_transformer.py | 19 ++-- .../heat/test_heat_stack_transformer.py | 6 +- .../kapacitor/test_kapacitor_configuration.py | 11 +-- .../kapacitor/test_kapacitor_driver.py | 11 +-- .../kapacitor/test_kapacitor_transformer.py | 8 +- .../kubernetes/test_kubernetes_transformer.py | 4 +- .../unit/datasources/nagios/mock_driver.py | 4 +- .../datasources/nagios/test_nagios_config.py | 13 +-- .../datasources/nagios/test_nagios_driver.py | 17 ++-- .../nagios/test_nagios_transformer.py | 8 +- .../nova/base_nova_instance_transformer.py | 4 +- ...stance_transformer_legacy_notifications.py | 8 +- ...nce_transformer_versioned_notifications.py | 5 - .../nova/test_nova_host_transformer.py | 4 +- .../nova/test_nova_instance_driver.py | 21 ++--- .../nova/test_nova_zone_transformer.py | 4 +- .../prometheus/test_prometheus_driver.py | 22 ++--- .../prometheus/test_prometheus_transformer.py | 22 ++--- .../datasources/static/test_static_driver.py | 6 +- .../static/test_static_transformer.py | 4 +- .../test_datasource_update_method.py | 39 ++++---- .../trove/test_trove_cluster_transformer.py | 2 +- .../trove/test_trove_instance_transformer.py | 2 +- .../unit/datasources/zabbix/mock_driver.py | 4 +- .../zabbix/test_zabbix_configuration.py | 11 +-- .../datasources/zabbix/test_zabbix_driver.py | 19 ++-- .../zabbix/test_zabbix_transformer.py | 8 +- vitrage/tests/unit/entity_graph/base.py | 25 +++-- .../tests/unit/entity_graph/processor/base.py | 14 +-- .../processor/test_entity_graph.py | 5 +- .../entity_graph/processor/test_processor.py | 14 +-- .../states/test_datasource_info_mapper.py | 92 ++++++++----------- .../entity_graph/test_processor_service.py | 2 +- .../entity_graph/test_transformer_manager.py | 35 +++---- .../test_template_loading_v3.py | 9 +- .../test_template_validator_v3.py | 11 +-- .../evaluator/test_equivalence_repository.py | 5 +- .../evaluator/test_scenario_repository.py | 91 ++++++------------ .../test_jaccard_correlation.py | 42 +++------ .../test_snmp_sender_with_severity_map.py | 40 +++----- .../test_snmp_sender_without_severity_map.py | 40 +++----- .../unit/snmp_parsing/test_snmp_parsing.py | 31 ++----- 185 files changed, 1065 insertions(+), 1327 deletions(-) rename vitrage/{service.py => common/config.py} (64%) diff --git a/tools/datasource-scaffold/sample/driver.py b/tools/datasource-scaffold/sample/driver.py index 91f6f24a4..e0a828930 100644 --- a/tools/datasource-scaffold/sample/driver.py +++ b/tools/datasource-scaffold/sample/driver.py @@ -22,9 +22,8 @@ LOG = log.getLogger(__name__) class SampleDriver(DriverBase): - def __init__(self, conf): + def __init__(self): super(SampleDriver, self).__init__() - self.cfg = conf @staticmethod def get_event_types(): diff --git a/tools/datasource-scaffold/sample/transformer.py b/tools/datasource-scaffold/sample/transformer.py index 5a4eb76ec..d3ea5d12c 100644 --- a/tools/datasource-scaffold/sample/transformer.py +++ b/tools/datasource-scaffold/sample/transformer.py @@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__) class SampleTransformer(ResourceTransformerBase): - def __init__(self, transformers, conf): - super(SampleTransformer, self).__init__(transformers, conf) + def __init__(self, transformers): + super(SampleTransformer, self).__init__(transformers) def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/tools/datasource-scaffold/{{cookiecutter.name}}/driver.py b/tools/datasource-scaffold/{{cookiecutter.name}}/driver.py index 699a5e8f6..ae5e2e6d4 100644 --- a/tools/datasource-scaffold/{{cookiecutter.name}}/driver.py +++ b/tools/datasource-scaffold/{{cookiecutter.name}}/driver.py @@ -22,9 +22,8 @@ LOG = log.getLogger(__name__) class {{cookiecutter.name|capitalize}}Driver(DriverBase): - def __init__(self, conf): + def __init__(self): super({{cookiecutter.name|capitalize}}Driver, self).__init__() - self.cfg = conf @staticmethod def get_event_types(): diff --git a/tools/datasource-scaffold/{{cookiecutter.name}}/transformer.py b/tools/datasource-scaffold/{{cookiecutter.name}}/transformer.py index 0e9cc7751..19c1793cb 100644 --- a/tools/datasource-scaffold/{{cookiecutter.name}}/transformer.py +++ b/tools/datasource-scaffold/{{cookiecutter.name}}/transformer.py @@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__) class {{cookiecutter.name|capitalize}}Transformer(ResourceTransformerBase): - def __init__(self, transformers, conf): - super({{cookiecutter.name|capitalize}}Transformer, self).__init__(transformers, conf) + def __init__(self, transformers: + super({{cookiecutter.name|capitalize}}Transformer, self).__init__(transformers) def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/tools/load_generator/load_generator.py b/tools/load_generator/load_generator.py index 01aee4d77..8c8de6484 100644 --- a/tools/load_generator/load_generator.py +++ b/tools/load_generator/load_generator.py @@ -17,14 +17,17 @@ import sys import cotyledon from futurist import periodics from futurist import ThreadPoolExecutor + +from oslo_config import cfg from oslo_log import log import oslo_messaging from tools.load_generator.notification_info import * # noqa +from vitrage.common import config from vitrage.messaging import get_transport -from vitrage import service +CONF = cfg.CONF LOG = log.getLogger(__name__) EXISTING_COMPUTES_NUM = 64 @@ -62,12 +65,12 @@ to avoid Vitrage consistency deleting the created resources. class StressNotificationsService(cotyledon.Service): - def __init__(self, worker_id, conf): + def __init__(self, worker_id): super(StressNotificationsService, self).__init__(worker_id) self.oslo_notifier = None - topics = conf.datasources.notification_topics + topics = CONF.datasources.notification_topics self.oslo_notifier = oslo_messaging.Notifier( - get_transport(conf), + get_transport(), driver='messagingv2', publisher_id='vitrage.stress', topics=topics) @@ -141,9 +144,9 @@ def create_vm(instance_num, compute_num): def main(): - conf = service.prepare_service() + config.parse_config(sys.argv) sm = cotyledon.ServiceManager() - sm.add(StressNotificationsService, args=(conf,)) + sm.add(StressNotificationsService) sm.run() diff --git a/vitrage/api/app.py b/vitrage/api/app.py index c61e5744a..7bedcd423 100644 --- a/vitrage/api/app.py +++ b/vitrage/api/app.py @@ -27,6 +27,8 @@ from werkzeug import serving from vitrage.api import hooks +CONF = cfg.CONF + LOG = log.getLogger(__name__) # NOTE(sileht): pastedeploy uses ConfigParser to handle @@ -40,13 +42,13 @@ APPCONFIGS = {} def setup_app(root, conf=None): - app_hooks = [hooks.ConfigHook(conf), + app_hooks = [hooks.ConfigHook(), hooks.TranslationHook(), hooks.GCHook(), - hooks.RPCHook(conf), + hooks.RPCHook(), hooks.ContextHook(), - hooks.DBHook(conf), - hooks.CoordinatorHook(conf)] + hooks.DBHook(), + hooks.CoordinatorHook()] app = pecan.make_app( root, @@ -57,53 +59,52 @@ def setup_app(root, conf=None): return app -def load_app(conf): +def load_app(): global APPCONFIGS - # Build the WSGI app - cfg_path = conf.api.paste_config + cfg_path = CONF.api.paste_config if not os.path.isabs(cfg_path): - cfg_path = conf.find_file(cfg_path) + cfg_path = CONF.find_file(cfg_path) if cfg_path is None or not os.path.exists(cfg_path): - raise cfg.ConfigFilesNotFoundError([conf.api.paste_config]) + raise cfg.ConfigFilesNotFoundError([CONF.api.paste_config]) - config = dict(conf=conf) + config = dict(conf=CONF) configkey = uuidutils.generate_uuid() APPCONFIGS[configkey] = config LOG.info('Full WSGI config used: %s', cfg_path) - appname = "vitrage+" + conf.api.auth_mode + appname = "vitrage+" + CONF.api.auth_mode return deploy.loadapp("config:" + cfg_path, name=appname, global_conf={'configkey': configkey}) -def build_server(conf): +def build_server(): uwsgi = spawn.find_executable("uwsgi") if not uwsgi: LOG.warning('uwsgi not installed, starting a TEST server') - build_simple_server(conf) + build_simple_server() else: - build_uwsgi_server(conf, uwsgi) + build_uwsgi_server(uwsgi) def wsgi_file(): return path.join(path.dirname(__file__), 'app.wsgi') -def build_uwsgi_server(conf, uwsgi): +def build_uwsgi_server(uwsgi): args = [ "--if-not-plugin", "python", "--plugin", "python", "--endif", - "--http-socket", "%s:%d" % (conf.api.host, conf.api.port), + "--http-socket", "%s:%d" % (CONF.api.host, CONF.api.port), "--master", "--enable-threads", "--thunder-lock", "--hook-master-start", "unix_signal:15 gracefully_kill_them_all", "--die-on-term", - "--processes", str(math.floor(conf.api.workers * 1.5)), - "--threads", str(conf.api.workers), + "--processes", str(math.floor(CONF.api.workers * 1.5)), + "--threads", str(CONF.api.workers), "--lazy-apps", "--chdir", "/", "--buffer-size", "65535", @@ -119,14 +120,14 @@ def build_uwsgi_server(conf, uwsgi): return os.execl(uwsgi, uwsgi, *args) -def build_simple_server(conf): - app = load_app(conf) +def build_simple_server(): + app = load_app() # Create the WSGI server and start it - host, port = conf.api.host, conf.api.port + host, port = CONF.api.host, CONF.api.port LOG.info('Starting server in PID %s', os.getpid()) LOG.info('Configuration:') - conf.log_opt_values(LOG, log.INFO) + CONF.log_opt_values(LOG, log.INFO) if host == '0.0.0.0': LOG.info( @@ -139,7 +140,7 @@ def build_simple_server(conf): LOG.info('"DANGER! For testing only, do not use in production"') serving.run_simple(host, port, - app, processes=conf.api.workers) + app, processes=CONF.api.workers) def app_factory(global_config, **local_conf): diff --git a/vitrage/api/app.wsgi b/vitrage/api/app.wsgi index b5b2e59ec..f278bc559 100644 --- a/vitrage/api/app.wsgi +++ b/vitrage/api/app.wsgi @@ -14,8 +14,8 @@ See http://pecan.readthedocs.org/en/latest/deployment.html for details. """ from vitrage.api import app -from vitrage import service +from vitrage.common import config # Initialize the oslo configuration library and logging -conf = service.prepare_service() -application = app.load_app(conf) +config.parse_config([]) +application = app.load_app() diff --git a/vitrage/api/hooks.py b/vitrage/api/hooks.py index 755f9f139..146bccfaf 100644 --- a/vitrage/api/hooks.py +++ b/vitrage/api/hooks.py @@ -12,6 +12,7 @@ import gc import oslo_messaging +from oslo_config import cfg from oslo_context import context from oslo_policy import policy from pecan import hooks @@ -22,31 +23,32 @@ from vitrage import messaging from vitrage import rpc as vitrage_rpc from vitrage import storage +CONF = cfg.CONF + class ConfigHook(hooks.PecanHook): """Attach the configuration and policy enforcer object to the request. """ - def __init__(self, conf): - self.conf = conf - self.enforcer = policy.Enforcer(conf) + def __init__(self): + self.enforcer = policy.Enforcer(CONF) self._register_rules() def _register_rules(self): self.enforcer.register_defaults(policies.list_rules()) def before(self, state): - state.request.cfg = self.conf + state.request.cfg = CONF state.request.enforcer = self.enforcer class RPCHook(hooks.PecanHook): """Create and attach an rpc to the request. """ - def __init__(self, conf): - transport = messaging.get_rpc_transport(conf) - target = oslo_messaging.Target(topic=conf.rpc_topic) + def __init__(self): + transport = messaging.get_rpc_transport() + target = oslo_messaging.Target(topic=CONF.rpc_topic) self.client = vitrage_rpc.get_client(transport, target) - self.check_backend = conf.api.check_backend + self.check_backend = CONF.api.check_backend def on_route(self, state): state.request.client = self.client @@ -87,8 +89,8 @@ class ContextHook(hooks.PecanHook): class DBHook(hooks.PecanHook): - def __init__(self, conf): - self.storage = storage.get_connection_from_config(conf) + def __init__(self): + self.storage = storage.get_connection_from_config() def before(self, state): state.request.storage = self.storage @@ -102,8 +104,8 @@ class GCHook(hooks.PecanHook): class CoordinatorHook(hooks.PecanHook): - def __init__(self, conf): - self.coordinator = coordination.Coordinator(conf) + def __init__(self): + self.coordinator = coordination.Coordinator() self.coordinator.start() self.coordinator.join_group() diff --git a/vitrage/api_handler/apis/base.py b/vitrage/api_handler/apis/base.py index 848576645..1d61c9dcc 100644 --- a/vitrage/api_handler/apis/base.py +++ b/vitrage/api_handler/apis/base.py @@ -76,9 +76,8 @@ RESOURCES_ALL_QUERY = { class EntityGraphApisBase(object): - def __init__(self, entity_graph, conf, api_lock, db=None): + def __init__(self, entity_graph, api_lock, db=None): self.entity_graph = entity_graph - self.conf = conf self.db = db self.api_lock = api_lock diff --git a/vitrage/api_handler/apis/event.py b/vitrage/api_handler/apis/event.py index b27b4651a..a9d941aff 100644 --- a/vitrage/api_handler/apis/event.py +++ b/vitrage/api_handler/apis/event.py @@ -32,8 +32,7 @@ LOG = log.getLogger(__name__) info={}, hide_args=False, trace_private=False) class EventApis(object): - def __init__(self, conf): - self.conf = conf + def __init__(self): self._init_oslo_notifier() def post(self, ctx, event_time, event_type, details): @@ -65,7 +64,7 @@ class EventApis(object): self.publisher = 'api_%s' % socket.gethostname() self.oslo_notifier = oslo_messaging.Notifier( - get_transport(self.conf), + get_transport(), driver='messagingv2', publisher_id=self.publisher, topics=['vitrage_notifications']) diff --git a/vitrage/api_handler/apis/operational.py b/vitrage/api_handler/apis/operational.py index 74677c97d..75c3d0cb3 100644 --- a/vitrage/api_handler/apis/operational.py +++ b/vitrage/api_handler/apis/operational.py @@ -19,8 +19,7 @@ LOG = log.getLogger(__name__) class OperationalApis(object): - def __init__(self, conf, graph): - self.conf = conf + def __init__(self, graph): self.graph = graph def is_alive(self, ctx): diff --git a/vitrage/api_handler/apis/resource.py b/vitrage/api_handler/apis/resource.py index 8caf16d6f..091aea310 100644 --- a/vitrage/api_handler/apis/resource.py +++ b/vitrage/api_handler/apis/resource.py @@ -31,9 +31,6 @@ LOG = log.getLogger(__name__) info={}, hide_args=False, trace_private=False) class ResourceApis(base.EntityGraphApisBase): - def __init__(self, entity_graph, conf, api_lock): - super(ResourceApis, self).__init__(entity_graph, conf, api_lock) - @timed_method(log_results=True) @base.lock_graph def get_resources(self, ctx, resource_type=None, all_tenants=False, diff --git a/vitrage/api_handler/apis/topology.py b/vitrage/api_handler/apis/topology.py index d7cca7e1f..67e24c839 100644 --- a/vitrage/api_handler/apis/topology.py +++ b/vitrage/api_handler/apis/topology.py @@ -34,9 +34,6 @@ LOG = log.getLogger(__name__) info={}, hide_args=False, trace_private=False) class TopologyApis(base.EntityGraphApisBase): - def __init__(self, entity_graph, conf, api_lock): - super(TopologyApis, self).__init__(entity_graph, conf, api_lock) - @timed_method(log_results=True) @base.lock_graph def get_topology(self, ctx, graph_type, depth, query, root, all_tenants): diff --git a/vitrage/api_handler/apis/webhook.py b/vitrage/api_handler/apis/webhook.py index 504400ad8..2cbdd614d 100644 --- a/vitrage/api_handler/apis/webhook.py +++ b/vitrage/api_handler/apis/webhook.py @@ -34,8 +34,7 @@ Result = namedtuple("Result", ["is_valid", "message"]) class WebhookApis(object): DELETED_ROWS_SUCCESS = 1 - def __init__(self, conf, db): - self.conf = conf + def __init__(self, db): self.db_conn = db def delete_webhook(self, ctx, id): diff --git a/vitrage/cli/api.py b/vitrage/cli/api.py index 6a2d63fe3..0aa2a0038 100644 --- a/vitrage/cli/api.py +++ b/vitrage/cli/api.py @@ -16,13 +16,13 @@ import sys from vitrage.api import app from vitrage.cli import VITRAGE_TITLE -from vitrage import service +from vitrage.common import config def main(): print(VITRAGE_TITLE) - conf = service.prepare_service() - app.build_server(conf) + config.parse_config(sys.argv) + app.build_server() if __name__ == "__main__": diff --git a/vitrage/cli/graph.py b/vitrage/cli/graph.py index 72e5d388a..eba40f2e5 100644 --- a/vitrage/cli/graph.py +++ b/vitrage/cli/graph.py @@ -16,10 +16,10 @@ from oslo_log import log import sys from vitrage.cli import VITRAGE_TITLE +from vitrage.common import config from vitrage.common.utils import spawn from vitrage.entity_graph.graph_init import VitrageGraphInit from vitrage.entity_graph.workers import GraphWorkersManager -from vitrage import service LOG = log.getLogger(__name__) @@ -27,19 +27,19 @@ LOG = log.getLogger(__name__) def main(): """Main method of vitrage-graph""" - conf = service.prepare_service() LOG.info(VITRAGE_TITLE) - - workers = GraphWorkersManager(conf) - spawn(init, conf, workers) + config.parse_config(sys.argv) + workers = GraphWorkersManager() + spawn(init, workers) workers.run() -def init(conf, workers): +def init(workers): # Because fork duplicates the process memory. # We should only create master process resources after workers are forked. workers.wait_for_worker_start() - VitrageGraphInit(conf, workers).run() + VitrageGraphInit(workers).run() + if __name__ == "__main__": sys.exit(main()) diff --git a/vitrage/cli/machine_learning.py b/vitrage/cli/machine_learning.py index 128708f72..d7e187153 100644 --- a/vitrage/cli/machine_learning.py +++ b/vitrage/cli/machine_learning.py @@ -16,15 +16,15 @@ import cotyledon import sys from vitrage.cli import VITRAGE_TITLE +from vitrage.common import config from vitrage.machine_learning.service import MachineLearningService -from vitrage import service def main(): print(VITRAGE_TITLE) - conf = service.prepare_service() + config.parse_config(sys.argv) sm = cotyledon.ServiceManager() - sm.add(MachineLearningService, args=(conf,)) + sm.add(MachineLearningService) sm.run() diff --git a/vitrage/cli/notifier.py b/vitrage/cli/notifier.py index 488ec8e05..0b3dd09b8 100644 --- a/vitrage/cli/notifier.py +++ b/vitrage/cli/notifier.py @@ -15,15 +15,15 @@ import cotyledon import sys from vitrage.cli import VITRAGE_TITLE +from vitrage.common import config from vitrage.notifier.service import VitrageNotifierService -from vitrage import service def main(): print(VITRAGE_TITLE) - conf = service.prepare_service() + config.parse_config(sys.argv) sm = cotyledon.ServiceManager() - sm.add(VitrageNotifierService, args=(conf,)) + sm.add(VitrageNotifierService) sm.run() diff --git a/vitrage/cli/persistor.py b/vitrage/cli/persistor.py index 192908231..f9261be87 100644 --- a/vitrage/cli/persistor.py +++ b/vitrage/cli/persistor.py @@ -16,9 +16,10 @@ import sys import cotyledon from oslo_log import log + from vitrage.cli import VITRAGE_TITLE +from vitrage.common import config from vitrage.persistency.service import PersistorService -from vitrage import service from vitrage import storage LOG = log.getLogger(__name__) @@ -26,10 +27,10 @@ LOG = log.getLogger(__name__) def main(): print(VITRAGE_TITLE) - conf = service.prepare_service() - db_connection = storage.get_connection_from_config(conf) + config.parse_config(sys.argv) + db_connection = storage.get_connection_from_config() sm = cotyledon.ServiceManager() - sm.add(PersistorService, args=(conf, db_connection)) + sm.add(PersistorService, args=(db_connection,)) sm.run() diff --git a/vitrage/cli/snmp_parsing.py b/vitrage/cli/snmp_parsing.py index 39be1e2b1..4bffcbd66 100644 --- a/vitrage/cli/snmp_parsing.py +++ b/vitrage/cli/snmp_parsing.py @@ -15,16 +15,17 @@ import sys import cotyledon + from vitrage.cli import VITRAGE_TITLE -from vitrage import service +from vitrage.common import config from vitrage.snmp_parsing.service import SnmpParsingService def main(): print(VITRAGE_TITLE) - conf = service.prepare_service() + config.parse_config(sys.argv) sm = cotyledon.ServiceManager() - sm.add(SnmpParsingService, args=(conf,)) + sm.add(SnmpParsingService) sm.run() diff --git a/vitrage/cli/storage.py b/vitrage/cli/storage.py index d6edab2bc..bd2833edc 100644 --- a/vitrage/cli/storage.py +++ b/vitrage/cli/storage.py @@ -12,21 +12,23 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + from vitrage.cli import VITRAGE_TITLE -from vitrage import service +from vitrage.common import config from vitrage import storage def dbsync(): print(VITRAGE_TITLE) - conf = service.prepare_service() - storage.get_connection_from_config(conf).upgrade() + config.parse_config(sys.argv) + storage.get_connection_from_config().upgrade() def purge_data(): print(VITRAGE_TITLE) - conf = service.prepare_service() - db = storage.get_connection_from_config(conf) + config.parse_config(sys.argv) + db = storage.get_connection_from_config() db.active_actions.delete() db.events.delete() db.graph_snapshots.delete() diff --git a/vitrage/service.py b/vitrage/common/config.py similarity index 64% rename from vitrage/service.py rename to vitrage/common/config.py index f91dcf90b..6c1ed46d1 100644 --- a/vitrage/service.py +++ b/vitrage/common/config.py @@ -1,4 +1,4 @@ -# 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 @@ -10,7 +10,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - from oslo_config import cfg from oslo_db import options as db_options from oslo_log import log @@ -20,47 +19,43 @@ from osprofiler import opts as osprofiler_opts from vitrage import keystone_client from vitrage import messaging from vitrage import opts -from vitrage.opts import register_opts +CONF = cfg.CONF LOG = log.getLogger(__name__) -def prepare_service(args=None, conf=None, config_files=None): +def parse_config(args, default_config_files=None): set_defaults() - if conf is None: - conf = cfg.ConfigOpts() - log.register_options(conf) - policy_opts.set_defaults(conf) - osprofiler_opts.set_defaults(conf) - db_options.set_defaults(conf) + log.register_options(CONF) + policy_opts.set_defaults(CONF) + osprofiler_opts.set_defaults(CONF) + db_options.set_defaults(CONF) for group, options in opts.list_opts(): - conf.register_opts(list(options), + CONF.register_opts(list(options), group=None if group == 'DEFAULT' else group) - conf(args, project='vitrage', validate_default_values=True, - default_config_files=config_files) + CONF(args[1:], project='vitrage', validate_default_values=True, + default_config_files=default_config_files) - if conf.profiler.enabled: + if CONF.profiler.enabled: osprofiler_initializer.init_from_conf( - conf=conf, + conf=CONF, context=None, - project="vitrage", - service="api", - host=conf.api.host) + project='vitrage', + service='api', + host=CONF.api.host + ) - for datasource in conf.datasources.types: - register_opts(conf, datasource, conf.datasources.path) + for datasource in CONF.datasources.types: + opts.register_opts(datasource, CONF.datasources.path) - keystone_client.register_keystoneauth_opts(conf) - - log.setup(conf, 'vitrage') - conf.log_opt_values(LOG, log.DEBUG) + keystone_client.register_keystoneauth_opts() + log.setup(CONF, 'vitrage') + CONF.log_opt_values(LOG, log.DEBUG) messaging.setup() - return conf - def set_defaults(): from oslo_middleware import cors diff --git a/vitrage/coordination/coordination.py b/vitrage/coordination/coordination.py index a1fb4d5fa..ff33fdd4c 100644 --- a/vitrage/coordination/coordination.py +++ b/vitrage/coordination/coordination.py @@ -20,16 +20,17 @@ import six import tenacity import tooz.coordination +from oslo_config import cfg from oslo_log import log from oslo_utils import timeutils +CONF = cfg.CONF LOG = log.getLogger(__name__) class Coordinator(object): - def __init__(self, conf, my_id=None): - self.conf = conf - self.backend_url = self.conf.coordination.backend_url + def __init__(self, my_id=None): + self.backend_url = CONF.coordination.backend_url self.my_id = my_id or ' '.join(psutil.Process(os.getpid()).cmdline()) self.coordinator = None if self.backend_url: diff --git a/vitrage/coordination/service.py b/vitrage/coordination/service.py index f84e221a9..607ee8136 100644 --- a/vitrage/coordination/service.py +++ b/vitrage/coordination/service.py @@ -19,10 +19,10 @@ from vitrage.coordination.coordination import Coordinator class Service(cotyledon.Service): - def __init__(self, worker_id, conf): + def __init__(self, worker_id): super(Service, self).__init__(worker_id) - self.coordinator = Coordinator(conf, '%s worker(%s)' % (self.name, - worker_id)) + self.coordinator = Coordinator('%s worker(%s)' % (self.name, + worker_id)) def run(self): self.coordinator.start() diff --git a/vitrage/datasources/alarm_transformer_base.py b/vitrage/datasources/alarm_transformer_base.py index e477f70e1..fa55eae8b 100644 --- a/vitrage/datasources/alarm_transformer_base.py +++ b/vitrage/datasources/alarm_transformer_base.py @@ -22,9 +22,6 @@ from vitrage.datasources import transformer_base as tbase class AlarmTransformerBase(tbase.TransformerBase): - def __init__(self, transformers, conf): - super(AlarmTransformerBase, self).__init__(transformers, conf) - def _ok_status(self, entity_event): pass diff --git a/vitrage/datasources/aodh/driver.py b/vitrage/datasources/aodh/driver.py index 49bed926d..063fe2f02 100644 --- a/vitrage/datasources/aodh/driver.py +++ b/vitrage/datasources/aodh/driver.py @@ -32,10 +32,9 @@ LOG = log.getLogger(__name__) class AodhDriver(AlarmDriverBase): - def __init__(self, conf): + def __init__(self): super(AodhDriver, self).__init__() self._client = None - self.conf = conf self._init_aodh_event_actions() self._init_convert_aodh_alarm_rule_actions() self._init_alarm_type_to_rule() @@ -86,7 +85,7 @@ class AodhDriver(AlarmDriverBase): @property def client(self): if not self._client: - self._client = os_clients.aodh_client(self.conf) + self._client = os_clients.aodh_client() return self._client def _vitrage_type(self): diff --git a/vitrage/datasources/aodh/transformer.py b/vitrage/datasources/aodh/transformer.py index b4051c73d..f032e106a 100644 --- a/vitrage/datasources/aodh/transformer.py +++ b/vitrage/datasources/aodh/transformer.py @@ -38,9 +38,6 @@ class AodhTransformer(AlarmTransformerBase): AodhEventType.DELETION: GraphAction.DELETE_ENTITY, } - def __init__(self, transformers, conf): - super(AodhTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): if _is_vitrage_alarm(entity_event): return self._create_merge_alarm_vertex(entity_event) diff --git a/vitrage/datasources/ceilometer/driver.py b/vitrage/datasources/ceilometer/driver.py index 7ea0d7f77..0ae5d3668 100644 --- a/vitrage/datasources/ceilometer/driver.py +++ b/vitrage/datasources/ceilometer/driver.py @@ -32,17 +32,16 @@ LOG = log.getLogger(__name__) class CeilometerDriver(AlarmDriverBase): - def __init__(self, conf): + def __init__(self): super(CeilometerDriver, self).__init__() self._client = None - self.conf = conf self._init_aodh_event_actions() self._cache_all_alarms() @property def client(self): if not self._client: - self._client = os_clients.ceilometer_client(self.conf) + self._client = os_clients.ceilometer_client() return self._client def _vitrage_type(self): diff --git a/vitrage/datasources/ceilometer/transformer.py b/vitrage/datasources/ceilometer/transformer.py index 50da04b90..d73316006 100644 --- a/vitrage/datasources/ceilometer/transformer.py +++ b/vitrage/datasources/ceilometer/transformer.py @@ -41,9 +41,6 @@ class CeilometerTransformer(AlarmTransformerBase): CeilEventType.DELETION: GraphAction.DELETE_ENTITY, } - def __init__(self, transformers, conf): - super(CeilometerTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): if _is_vitrage_alarm(entity_event): return self._create_merge_alarm_vertex(entity_event) diff --git a/vitrage/datasources/cinder/volume/driver.py b/vitrage/datasources/cinder/volume/driver.py index bffa21697..399f6a2c2 100644 --- a/vitrage/datasources/cinder/volume/driver.py +++ b/vitrage/datasources/cinder/volume/driver.py @@ -21,15 +21,14 @@ from vitrage import os_clients class CinderVolumeDriver(DriverBase): - def __init__(self, conf): + def __init__(self): super(CinderVolumeDriver, self).__init__() self._client = None - self.conf = conf @property def client(self): if not self._client: - self._client = os_clients.cinder_client(self.conf) + self._client = os_clients.cinder_client() return self._client @staticmethod diff --git a/vitrage/datasources/cinder/volume/transformer.py b/vitrage/datasources/cinder/volume/transformer.py index ad555c713..39022c061 100644 --- a/vitrage/datasources/cinder/volume/transformer.py +++ b/vitrage/datasources/cinder/volume/transformer.py @@ -39,9 +39,6 @@ class CinderVolumeTransformer(ResourceTransformerBase): 'volume.attach.end': GraphAction.UPDATE_RELATIONSHIP } - def __init__(self, transformers, conf): - super(CinderVolumeTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): volume_name = extract_field_value(entity_event, diff --git a/vitrage/datasources/collectd/driver.py b/vitrage/datasources/collectd/driver.py index 6b5267a02..32bb4120a 100644 --- a/vitrage/datasources/collectd/driver.py +++ b/vitrage/datasources/collectd/driver.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import DatasourceAction @@ -24,17 +25,17 @@ from vitrage.datasources.collectd.properties\ import CollectdProperties as CProps from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) class CollectdDriver(AlarmDriverBase): conf_map = None - def __init__(self, conf): + def __init__(self): super(CollectdDriver, self).__init__() - self.conf = conf if not CollectdDriver.conf_map: - mapper = CollectdDriver._configuration_mapping(conf) + mapper = CollectdDriver._configuration_mapping() if mapper: CollectdDriver.conf_map = CollectdMapper(mapper) @@ -59,9 +60,9 @@ class CollectdDriver(AlarmDriverBase): and alarm[CProps.RESOURCE_NAME] is not None @staticmethod - def _configuration_mapping(conf): + def _configuration_mapping(): try: - collectd_config_file = conf.collectd[DSOpts.CONFIG_FILE] + collectd_config_file = CONF.collectd[DSOpts.CONFIG_FILE] collectd_config = file_utils.load_yaml_file(collectd_config_file) collectd_config_elements = collectd_config[COLLECTD_DATASOURCE] diff --git a/vitrage/datasources/collectd/transformer.py b/vitrage/datasources/collectd/transformer.py index 549d86723..78e2d9c4f 100644 --- a/vitrage/datasources/collectd/transformer.py +++ b/vitrage/datasources/collectd/transformer.py @@ -28,9 +28,6 @@ from vitrage.utils.datetime import format_unix_timestamp class CollectdTransformer(AlarmTransformerBase): - def __init__(self, transformers, conf): - super(CollectdTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): # The Collectd datasource does not support snapshot mode return None diff --git a/vitrage/datasources/consistency/transformer.py b/vitrage/datasources/consistency/transformer.py index 517529999..cd8a065bf 100644 --- a/vitrage/datasources/consistency/transformer.py +++ b/vitrage/datasources/consistency/transformer.py @@ -29,8 +29,8 @@ class ConsistencyTransformer(ResourceTransformerBase): GraphAction.REMOVE_DELETED_ENTITY: GraphAction.REMOVE_DELETED_ENTITY } - def __init__(self, transformers, conf): - super(ConsistencyTransformer, self).__init__(transformers, conf) + def __init__(self, transformers): + super(ConsistencyTransformer, self).__init__(transformers) def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/vitrage/datasources/doctor/driver.py b/vitrage/datasources/doctor/driver.py index efa7613ee..2f5a273ad 100644 --- a/vitrage/datasources/doctor/driver.py +++ b/vitrage/datasources/doctor/driver.py @@ -32,9 +32,8 @@ LOG = log.getLogger(__name__) class DoctorDriver(AlarmDriverBase): AlarmKey = namedtuple('AlarmKey', ['alarm_name', 'hostname']) - def __init__(self, conf): + def __init__(self): super(DoctorDriver, self).__init__() - self.conf = conf self._client = None def _vitrage_type(self): diff --git a/vitrage/datasources/doctor/transformer.py b/vitrage/datasources/doctor/transformer.py index e0f6dd4f2..de9f6b7ed 100644 --- a/vitrage/datasources/doctor/transformer.py +++ b/vitrage/datasources/doctor/transformer.py @@ -35,9 +35,6 @@ LOG = logging.getLogger(__name__) class DoctorTransformer(AlarmTransformerBase): - def __init__(self, transformers, conf): - super(DoctorTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): # The Doctor monitor does not support snapshot mode return None diff --git a/vitrage/datasources/driver_base.py b/vitrage/datasources/driver_base.py index 50f009ee2..401554849 100644 --- a/vitrage/datasources/driver_base.py +++ b/vitrage/datasources/driver_base.py @@ -29,9 +29,6 @@ class DriverBase(object): _datasource_name = None - def __init__(self): - pass - @abc.abstractmethod def get_all(self, datasource_action): pass diff --git a/vitrage/datasources/heat/stack/driver.py b/vitrage/datasources/heat/stack/driver.py index 84b036a6f..e6f0585bf 100644 --- a/vitrage/datasources/heat/stack/driver.py +++ b/vitrage/datasources/heat/stack/driver.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg + from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import GraphAction @@ -27,6 +29,8 @@ from vitrage.datasources.nova.instance.driver import InstanceDriver from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE from vitrage import os_clients +CONF = cfg.CONF + class HeatStackDriver(DriverBase): @@ -44,21 +48,20 @@ class HeatStackDriver(DriverBase): 'OS::Neutron::Port': PortDriver } - def __init__(self, conf): + def __init__(self): super(HeatStackDriver, self).__init__() self._client = None - self._conf = conf self._filter_resource_types() @property def client(self): if not self._client: - self._client = os_clients.heat_client(self._conf) + self._client = os_clients.heat_client() return self._client @staticmethod - def get_topic(conf): - return conf[HEAT_STACK_DATASOURCE].notification_topic + def get_topic(): + return CONF[HEAT_STACK_DATASOURCE].notification_topic @staticmethod def get_event_types(): @@ -93,7 +96,7 @@ class HeatStackDriver(DriverBase): return self.client.stacks.get(_id).to_dict()['parent'] def _filter_resource_types(self): - types = self._conf.datasources.types + types = CONF.datasources.types self.RESOURCE_TYPE = {key: value for key, value in self.RESOURCE_TYPE.items() if value in types} diff --git a/vitrage/datasources/heat/stack/transformer.py b/vitrage/datasources/heat/stack/transformer.py index ce6bcd2fc..c09642bcc 100644 --- a/vitrage/datasources/heat/stack/transformer.py +++ b/vitrage/datasources/heat/stack/transformer.py @@ -46,9 +46,6 @@ class HeatStackTransformer(ResourceTransformerBase): 'orchestration.stack.delete.end': GraphAction.DELETE_ENTITY, } - def __init__(self, transformers, conf): - super(HeatStackTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): stack_name = extract_field_value(entity_event, StackProps.STACK_NAME) diff --git a/vitrage/datasources/kapacitor/config.py b/vitrage/datasources/kapacitor/config.py index f7e8dd9a0..c655e71ee 100644 --- a/vitrage/datasources/kapacitor/config.py +++ b/vitrage/datasources/kapacitor/config.py @@ -14,11 +14,13 @@ import re +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) KAPACITOR_HOST = 'kapacitor_host' KAPACITOR = 'kapacitor' @@ -30,9 +32,9 @@ VITRAGE_RESOURCE = 'vitrage_resource' class KapacitorConfig(object): - def __init__(self, conf): + def __init__(self): try: - kapacitor_config_file = conf.kapacitor[DSOpts.CONFIG_FILE] + kapacitor_config_file = CONF.kapacitor[DSOpts.CONFIG_FILE] kapacitor_config = file_utils.load_yaml_file(kapacitor_config_file) kapacitor = kapacitor_config[KAPACITOR] diff --git a/vitrage/datasources/kapacitor/driver.py b/vitrage/datasources/kapacitor/driver.py index ce5d98c49..8bb7a1151 100644 --- a/vitrage/datasources/kapacitor/driver.py +++ b/vitrage/datasources/kapacitor/driver.py @@ -32,12 +32,11 @@ class KapacitorDriver(AlarmDriverBase): ServiceKey = namedtuple('ServiceKey', ['hostname', 'alarmid']) conf_map = None - def __init__(self, conf): + def __init__(self): super(KapacitorDriver, self).__init__() - self.cfg = conf if not KapacitorDriver.conf_map: - self.conf_map = KapacitorConfig(conf) + self.conf_map = KapacitorConfig() self._client = None @staticmethod diff --git a/vitrage/datasources/kapacitor/transformer.py b/vitrage/datasources/kapacitor/transformer.py index 4428ae265..78906546a 100644 --- a/vitrage/datasources/kapacitor/transformer.py +++ b/vitrage/datasources/kapacitor/transformer.py @@ -34,9 +34,6 @@ LOG = logging.getLogger(__name__) class KapacitorTransformer(AlarmTransformerBase): - def __init__(self, transformers, conf): - super(KapacitorTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/vitrage/datasources/kubernetes/driver.py b/vitrage/datasources/kubernetes/driver.py index 5fcb888cd..d4955f29d 100644 --- a/vitrage/datasources/kubernetes/driver.py +++ b/vitrage/datasources/kubernetes/driver.py @@ -14,36 +14,37 @@ from kubernetes import client from kubernetes import config +from oslo_log import cfg from oslo_log import log from vitrage.datasources.driver_base import DriverBase from vitrage.datasources.kubernetes.properties import KUBERNETES_DATASOURCE from vitrage.datasources.kubernetes.properties import KubernetesProperties\ as kubProp +CONF = cfg.CONF LOG = log.getLogger(__name__) class KubernetesDriver(DriverBase): - def __init__(self, conf): + def __init__(self): super(KubernetesDriver, self).__init__() self._client = None - self.conf = conf @property def client(self): if not self._client: - self._client = self._k8s_client(self.conf) + self._client = self._k8s_client() return self._client @staticmethod - def _k8s_client(conf): + def _k8s_client(): try: - if not conf.kubernetes.config_file: + if not CONF.kubernetes.config_file: LOG.warning('kubernetes config file is not defined') return - kubeconf = conf.kubernetes.config_file + kubeconf = CONF.kubernetes.config_file config.load_kube_config(config_file=kubeconf) k8s_client = client.CoreV1Api() if k8s_client is None: diff --git a/vitrage/datasources/kubernetes/transformer.py b/vitrage/datasources/kubernetes/transformer.py index 1dd2a3630..268960395 100644 --- a/vitrage/datasources/kubernetes/transformer.py +++ b/vitrage/datasources/kubernetes/transformer.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log as logging from vitrage.common.constants import DatasourceProperties as DSProps @@ -32,13 +33,11 @@ from vitrage.datasources.kubernetes.properties import \ KubernetesProperties as kubProp from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = logging.getLogger(__name__) class KubernetesTransformer(ResourceTransformerBase): - def __init__(self, transformers, conf): - super(KubernetesTransformer, self).__init__(transformers, conf) - self.conf = conf def _create_vertex(self, entity_event): metadata = { @@ -84,7 +83,7 @@ class KubernetesTransformer(ResourceTransformerBase): return KUBERNETES_DATASOURCE def _get_cluster_name(self): - kubeconf = file_utils.load_yaml_file(self.conf.kubernetes.config_file) + kubeconf = file_utils.load_yaml_file(CONF.kubernetes.config_file) if not kubeconf: return None contexts = kubeconf['contexts'] diff --git a/vitrage/datasources/monasca/driver.py b/vitrage/datasources/monasca/driver.py index 420213a0c..65ae2a25c 100644 --- a/vitrage/datasources/monasca/driver.py +++ b/vitrage/datasources/monasca/driver.py @@ -28,15 +28,14 @@ LOG = log.getLogger(__name__) class MonascaDriver(AlarmDriverBase): - def __init__(self, conf): + def __init__(self): super(MonascaDriver, self).__init__() - self.conf = conf self.__client = None @property def client(self): if not self.__client: - self.__client = os_clients.monasca_client(self.conf) + self.__client = os_clients.monasca_client() return self.__client def _vitrage_type(self): diff --git a/vitrage/datasources/nagios/config.py b/vitrage/datasources/nagios/config.py index f54a5ee55..17d5194c3 100644 --- a/vitrage/datasources/nagios/config.py +++ b/vitrage/datasources/nagios/config.py @@ -14,11 +14,13 @@ import re +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) NAGIOS_HOST = 'nagios_host' NAGIOS = 'nagios' @@ -28,9 +30,9 @@ NAME = 'name' class NagiosConfig(object): - def __init__(self, conf): + def __init__(self): try: - nagios_config_file = conf.nagios[DSOpts.CONFIG_FILE] + nagios_config_file = CONF.nagios[DSOpts.CONFIG_FILE] nagios_config = file_utils.load_yaml_file(nagios_config_file) nagios = nagios_config[NAGIOS] # nagios root in the yaml file diff --git a/vitrage/datasources/nagios/driver.py b/vitrage/datasources/nagios/driver.py index 53d71a070..921ccc677 100644 --- a/vitrage/datasources/nagios/driver.py +++ b/vitrage/datasources/nagios/driver.py @@ -14,6 +14,7 @@ from collections import namedtuple +from oslo_config import cfg from oslo_log import log import requests @@ -26,16 +27,16 @@ from vitrage.datasources.nagios.properties import NagiosProperties\ as NagiosProps from vitrage.datasources.nagios.properties import NagiosTestStatus +CONF = cfg.CONF LOG = log.getLogger(__name__) class NagiosDriver(AlarmDriverBase): ServiceKey = namedtuple('ServiceKey', ['hostname', 'service']) - def __init__(self, conf): + def __init__(self): super(NagiosDriver, self).__init__() - self.conf = conf - self.config = NagiosConfig(conf) + self.config = NagiosConfig() def _vitrage_type(self): return NAGIOS_DATASOURCE @@ -45,9 +46,9 @@ class NagiosDriver(AlarmDriverBase): service=alarm[NagiosProps.SERVICE]) def _get_alarms(self): - nagios_user = self.conf.nagios.user - nagios_password = self.conf.nagios.password - nagios_url = self.conf.nagios.url + nagios_user = CONF.nagios.user + nagios_password = CONF.nagios.password + nagios_url = CONF.nagios.url if not nagios_user: return [] diff --git a/vitrage/datasources/nagios/transformer.py b/vitrage/datasources/nagios/transformer.py index 3650cda52..b5a4f2a7e 100644 --- a/vitrage/datasources/nagios/transformer.py +++ b/vitrage/datasources/nagios/transformer.py @@ -27,9 +27,6 @@ from vitrage.utils import datetime as datetime_utils class NagiosTransformer(AlarmTransformerBase): - def __init__(self, transformers, conf): - super(NagiosTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/vitrage/datasources/neutron/base.py b/vitrage/datasources/neutron/base.py index 6655fdb64..44cd7a874 100644 --- a/vitrage/datasources/neutron/base.py +++ b/vitrage/datasources/neutron/base.py @@ -18,13 +18,12 @@ from vitrage import os_clients class NeutronBase(DriverBase): - def __init__(self, conf): + def __init__(self): super(NeutronBase, self).__init__() self._client = None - self.conf = conf @property def client(self): if not self._client: - self._client = os_clients.neutron_client(self.conf) + self._client = os_clients.neutron_client() return self._client diff --git a/vitrage/datasources/neutron/network/transformer.py b/vitrage/datasources/neutron/network/transformer.py index ca40ab74c..613589b17 100644 --- a/vitrage/datasources/neutron/network/transformer.py +++ b/vitrage/datasources/neutron/network/transformer.py @@ -40,9 +40,6 @@ class NetworkTransformer(ResourceTransformerBase): 'network.delete.end': GraphAction.DELETE_ENTITY, } - def __init__(self, transformers, conf): - super(NetworkTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): name = entity_event[NetworkProps.NAME] diff --git a/vitrage/datasources/neutron/port/transformer.py b/vitrage/datasources/neutron/port/transformer.py index edb5bd4ab..8e8ca2f37 100644 --- a/vitrage/datasources/neutron/port/transformer.py +++ b/vitrage/datasources/neutron/port/transformer.py @@ -51,9 +51,6 @@ class PortTransformer(ResourceTransformerBase): 'port.delete.end': GraphAction.DELETE_ENTITY, } - def __init__(self, transformers, conf): - super(PortTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): name = entity_event[PortProps.NAME]\ diff --git a/vitrage/datasources/nova/host/transformer.py b/vitrage/datasources/nova/host/transformer.py index af2e8f3cc..ad09b0a1a 100644 --- a/vitrage/datasources/nova/host/transformer.py +++ b/vitrage/datasources/nova/host/transformer.py @@ -33,9 +33,6 @@ LOG = logging.getLogger(__name__) class HostTransformer(ResourceTransformerBase): - def __init__(self, transformers, conf): - super(HostTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event, entity_event.get(HostProps.HOST)) diff --git a/vitrage/datasources/nova/instance/driver.py b/vitrage/datasources/nova/instance/driver.py index cf9c5897b..bca42e426 100644 --- a/vitrage/datasources/nova/instance/driver.py +++ b/vitrage/datasources/nova/instance/driver.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import GraphAction @@ -19,6 +20,8 @@ from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE from vitrage.datasources.nova.nova_driver_base import NovaDriverBase +CONF = cfg.CONF + # versioned notifications VERSIONED_NOTIFICATIONS = { 'instance.create.end', @@ -114,7 +117,7 @@ class InstanceDriver(NovaDriverBase): *self.properties_to_filter_out()) def enrich_event(self, event, event_type): - use_versioned = self.conf.use_nova_versioned_notifications + use_versioned = CONF.use_nova_versioned_notifications # Send to the processor only events of the matching types. Nova may # send both versioned and legacy notifications, and we don't want to diff --git a/vitrage/datasources/nova/instance/transformer.py b/vitrage/datasources/nova/instance/transformer.py index 38216f5fb..d3a032723 100644 --- a/vitrage/datasources/nova/instance/transformer.py +++ b/vitrage/datasources/nova/instance/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 oslo_config import cfg from oslo_log import log as logging from vitrage.common.constants import DatasourceProperties as DSProps @@ -32,6 +34,7 @@ from vitrage.datasources import transformer_base as tbase from vitrage.datasources.transformer_base import extract_field_value import vitrage.graph.utils as graph_utils +CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -47,9 +50,6 @@ class InstanceTransformer(ResourceTransformerBase): 'instance.delete.end': GraphAction.DELETE_ENTITY, } - def __init__(self, transformers, conf): - super(InstanceTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): LOG.debug('got snapshot') return self._create_vertex(entity_event) @@ -134,7 +134,7 @@ class InstanceTransformer(ResourceTransformerBase): """Return an object that extracts the field values from the event""" if tbase.is_update_event(event): return self.versioned_notifications_extractor if \ - self.conf.use_nova_versioned_notifications is True else \ + CONF.use_nova_versioned_notifications is True else \ self.legacy_notifications_extractor else: return self.snapshot_extractor diff --git a/vitrage/datasources/nova/nova_driver_base.py b/vitrage/datasources/nova/nova_driver_base.py index 804231d2b..9c2045e40 100644 --- a/vitrage/datasources/nova/nova_driver_base.py +++ b/vitrage/datasources/nova/nova_driver_base.py @@ -18,13 +18,12 @@ from vitrage import os_clients class NovaDriverBase(DriverBase): - def __init__(self, conf): + def __init__(self): super(NovaDriverBase, self).__init__() self._client = None - self.conf = conf @property def client(self): if not self._client: - self._client = os_clients.nova_client(self.conf) + self._client = os_clients.nova_client() return self._client diff --git a/vitrage/datasources/nova/zone/transformer.py b/vitrage/datasources/nova/zone/transformer.py index 25fb4e7c2..97ccfbd20 100644 --- a/vitrage/datasources/nova/zone/transformer.py +++ b/vitrage/datasources/nova/zone/transformer.py @@ -38,9 +38,6 @@ class ZoneTransformer(ResourceTransformerBase): STATE_AVAILABLE = 'available' STATE_UNAVAILABLE = 'unavailable' - def __init__(self, transformers, conf): - super(ZoneTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): zone_name = extract_field_value(entity_event, ZoneProps.ZONE_NAME) diff --git a/vitrage/datasources/prometheus/driver.py b/vitrage/datasources/prometheus/driver.py index 3106fc500..184e118f1 100644 --- a/vitrage/datasources/prometheus/driver.py +++ b/vitrage/datasources/prometheus/driver.py @@ -16,6 +16,7 @@ import socket from collections import namedtuple from ipaddress import ip_address +from oslo_config import cfg from oslo_log import log import requests import six @@ -46,6 +47,7 @@ from vitrage.datasources.prometheus.properties \ from vitrage import os_clients from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) PROMETHEUS_EVENT_TYPE = 'prometheus.alarm' @@ -132,17 +134,16 @@ class PrometheusDriver(AlarmDriverBase): PCFProps.RESOURCE]) conf_map = {} - def __init__(self, conf): + def __init__(self): super(PrometheusDriver, self).__init__() - self.conf = conf self._client = None self._nova_client = None - self.conf_map = self._configuration_mapping(conf) + self.conf_map = self._configuration_mapping() @property def nova_client(self): if not self._nova_client: - self._nova_client = os_clients.nova_client(self.conf) + self._nova_client = os_clients.nova_client() return self._nova_client def _vitrage_type(self): @@ -167,8 +168,8 @@ class PrometheusDriver(AlarmDriverBase): old_alarm.get(PAlertProps.STATUS) def _get_all_alarms(self): - alertmanager_url = self.conf.prometheus.alertmanager_url - receiver = self.conf.prometheus.receiver + alertmanager_url = CONF.prometheus.alertmanager_url + receiver = CONF.prometheus.receiver if not alertmanager_url: LOG.warning('Alertmanager url is not defined') return [] @@ -209,8 +210,8 @@ class PrometheusDriver(AlarmDriverBase): return [] @staticmethod - def _configuration_mapping(conf): - prometheus_config_file = conf.prometheus[DSOpts.CONFIG_FILE] + def _configuration_mapping(): + prometheus_config_file = CONF.prometheus[DSOpts.CONFIG_FILE] try: prometheus_config = \ file_utils.load_yaml_file(prometheus_config_file) diff --git a/vitrage/datasources/prometheus/transformer.py b/vitrage/datasources/prometheus/transformer.py index b85fb9cf7..3fcac0a51 100644 --- a/vitrage/datasources/prometheus/transformer.py +++ b/vitrage/datasources/prometheus/transformer.py @@ -38,9 +38,6 @@ LOG = logging.getLogger(__name__) class PrometheusTransformer(AlarmTransformerBase): - def __init__(self, transformers, conf): - super(PrometheusTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/vitrage/datasources/resource_transformer_base.py b/vitrage/datasources/resource_transformer_base.py index 229e21777..322ceb47c 100644 --- a/vitrage/datasources/resource_transformer_base.py +++ b/vitrage/datasources/resource_transformer_base.py @@ -16,6 +16,4 @@ from vitrage.datasources import transformer_base as tbase class ResourceTransformerBase(tbase.TransformerBase): - - def __init__(self, transformers, conf): - super(ResourceTransformerBase, self).__init__(transformers, conf) + pass diff --git a/vitrage/datasources/static/driver.py b/vitrage/datasources/static/driver.py index 24df94efe..4455088b8 100644 --- a/vitrage/datasources/static/driver.py +++ b/vitrage/datasources/static/driver.py @@ -16,6 +16,7 @@ from itertools import chain from jsonschema import validate from six.moves import reduce +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import DatasourceProperties as DSProps @@ -26,6 +27,7 @@ from vitrage.datasources.static import STATIC_SCHEMA from vitrage.datasources.static import StaticFields from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) @@ -35,9 +37,8 @@ class StaticDriver(DriverBase): StaticFields.TYPE, StaticFields.ID} - def __init__(self, conf): + def __init__(self): super(StaticDriver, self).__init__() - self.cfg = conf self.entities_cache = [] @staticmethod @@ -77,7 +78,7 @@ class StaticDriver(DriverBase): return self.entities_cache def _get_all_entities(self): - files = file_utils.list_files(self.cfg.static.directory, '.yaml', True) + files = file_utils.list_files(CONF.static.directory, '.yaml', True) return list(reduce(chain, [self._get_entities_from_file(path) for path in files], [])) diff --git a/vitrage/datasources/static/transformer.py b/vitrage/datasources/static/transformer.py index 6523cfa2b..a4d0d41ec 100644 --- a/vitrage/datasources/static/transformer.py +++ b/vitrage/datasources/static/transformer.py @@ -29,9 +29,6 @@ LOG = logging.getLogger(__name__) class StaticTransformer(ResourceTransformerBase): - def __init__(self, transformers, conf): - super(StaticTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/vitrage/datasources/transformer_base.py b/vitrage/datasources/transformer_base.py index 2ca393275..0fce02b0b 100644 --- a/vitrage/datasources/transformer_base.py +++ b/vitrage/datasources/transformer_base.py @@ -17,6 +17,7 @@ import abc from collections import namedtuple import six +from oslo_config import cfg from oslo_log import log as logging from oslo_utils import uuidutils @@ -35,6 +36,7 @@ import vitrage.graph.utils as graph_utils from vitrage.utils import datetime as datetime_utils from vitrage.utils import opt_exists +CONF = cfg.CONF LOG = logging.getLogger(__name__) EntityWrapper = \ @@ -109,8 +111,7 @@ class TransformerBase(object): key_to_uuid_cache = {} - def __init__(self, transformers, conf): - self.conf = conf + def __init__(self, transformers): self.transformers = transformers def transform(self, entity_event): @@ -138,11 +139,11 @@ class TransformerBase(object): def _create_entity_vertex(self, entity_event): if is_update_event(entity_event) and \ - opt_exists(self.conf, self.get_vitrage_type()) and \ - opt_exists(self.conf[self.get_vitrage_type()], + opt_exists(CONF, self.get_vitrage_type()) and \ + opt_exists(CONF[self.get_vitrage_type()], DSOpts.UPDATE_METHOD): update_method = \ - self.conf[self.get_vitrage_type()].update_method.lower() + CONF[self.get_vitrage_type()].update_method.lower() if update_method == UpdateMethod.PUSH: vertex = self._create_update_entity_vertex(entity_event) return self.update_uuid_in_vertex(vertex) diff --git a/vitrage/datasources/trove/cluster/driver.py b/vitrage/datasources/trove/cluster/driver.py index 5835b8424..849e629bc 100644 --- a/vitrage/datasources/trove/cluster/driver.py +++ b/vitrage/datasources/trove/cluster/driver.py @@ -27,8 +27,8 @@ LOG = log.getLogger(__name__) class TroveClusterDriver(TroveDriverBase): - def __init__(self, conf): - super(TroveClusterDriver, self).__init__(conf) + def __init__(self): + super(TroveClusterDriver, self).__init__() self._cached_entities = [] def _get_vitrage_type(self): diff --git a/vitrage/datasources/trove/instance/driver.py b/vitrage/datasources/trove/instance/driver.py index a1e66cbe5..19226c6d3 100644 --- a/vitrage/datasources/trove/instance/driver.py +++ b/vitrage/datasources/trove/instance/driver.py @@ -26,8 +26,8 @@ LOG = log.getLogger(__name__) class TroveInstanceDriver(TroveDriverBase): - def __init__(self, conf): - super(TroveInstanceDriver, self).__init__(conf) + def __init__(self): + super(TroveInstanceDriver, self).__init__() self._cached_entities = [] def _get_vitrage_type(self): diff --git a/vitrage/datasources/trove/trove_driver_base.py b/vitrage/datasources/trove/trove_driver_base.py index 34a8f5996..a5bb16c72 100644 --- a/vitrage/datasources/trove/trove_driver_base.py +++ b/vitrage/datasources/trove/trove_driver_base.py @@ -23,16 +23,15 @@ from vitrage import os_clients class TroveDriverBase(DriverBase): - def __init__(self, conf): + def __init__(self): super(TroveDriverBase, self).__init__() - self.conf = conf self.__client = None self.__cached_entities = [] @property def client(self): if not self.__client: - self.__client = os_clients.trove_client(self.conf) + self.__client = os_clients.trove_client() return self.__client def get_all(self, datasource_action): diff --git a/vitrage/datasources/utils.py b/vitrage/datasources/utils.py index 49ff6b977..847215fa5 100644 --- a/vitrage/datasources/utils.py +++ b/vitrage/datasources/utils.py @@ -11,34 +11,38 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from oslo_config import cfg from oslo_utils import importutils as utils from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import UpdateMethod from vitrage.utils import opt_exists +CONF = cfg.CONF + drivers = {} # noinspection PyProtectedMember -def get_drivers_by_name(conf, driver_names): +def get_drivers_by_name(driver_names): for d_name in driver_names: if not drivers.get(d_name): - drivers[d_name] = utils.import_object(conf[d_name].driver, conf) + drivers[d_name] = utils.import_object(CONF[d_name].driver) drivers[d_name].__class__._datasource_name = d_name return [drivers[d_name] for d_name in driver_names] -def get_pull_drivers_names(conf): - return [name for name in conf.datasources.types - if conf[name].update_method.lower() == UpdateMethod.PULL - and opt_exists(conf[name], DSOpts.CHANGES_INTERVAL)] +def get_pull_drivers_names(): + return [name for name in CONF.datasources.types + if CONF[name].update_method.lower() == UpdateMethod.PULL + and opt_exists(CONF[name], DSOpts.CHANGES_INTERVAL)] -def get_push_drivers_names(conf): - return [name for name in conf.datasources.types - if conf[name].update_method.lower() == UpdateMethod.PUSH] +def get_push_drivers_names(): + return [name for name in CONF.datasources.types + if CONF[name].update_method.lower() == UpdateMethod.PUSH] -def get_driver_class(conf, driver_name): - return utils.import_class(conf[driver_name].driver) +def get_driver_class(driver_name): + return utils.import_class(CONF[driver_name].driver) diff --git a/vitrage/datasources/zabbix/driver.py b/vitrage/datasources/zabbix/driver.py index 0d448759e..0e5dec055 100644 --- a/vitrage/datasources/zabbix/driver.py +++ b/vitrage/datasources/zabbix/driver.py @@ -14,6 +14,7 @@ from collections import namedtuple +from oslo_config import cfg from oslo_log import log from oslo_utils import importutils as utils @@ -29,6 +30,7 @@ from vitrage.datasources.zabbix.properties import ZabbixTriggerValue \ from vitrage.datasources.zabbix import ZABBIX_DATASOURCE from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) @@ -36,30 +38,29 @@ class ZabbixDriver(AlarmDriverBase): ServiceKey = namedtuple('ServiceKey', ['hostname', 'triggerid']) conf_map = None - def __init__(self, conf): + def __init__(self): super(ZabbixDriver, self).__init__() - self.conf = conf if not ZabbixDriver.conf_map: ZabbixDriver.conf_map =\ - ZabbixDriver._configuration_mapping(conf) + ZabbixDriver._configuration_mapping() self._client = None def zabbix_client_login(self): - if not self.conf.zabbix.user: + if not CONF.zabbix.user: LOG.warning('Zabbix user is not defined') - if not self.conf.zabbix.password: + if not CONF.zabbix.password: LOG.warning('Zabbix password is not defined') - if not self.conf.zabbix.url: + if not CONF.zabbix.url: LOG.warning('Zabbix url is not defined') try: if not self._client: self._client = utils.import_object( 'pyzabbix.ZabbixAPI', - self.conf.zabbix.url) + CONF.zabbix.url) self._client.login( - self.conf.zabbix.user, - self.conf.zabbix.password) + CONF.zabbix.user, + CONF.zabbix.password) except Exception: LOG.exception('pyzabbix.ZabbixAPI error occurred.') self._client = None @@ -154,9 +155,9 @@ class ZabbixDriver(AlarmDriverBase): return alarm[ZProps.VALUE] @staticmethod - def _configuration_mapping(conf): + def _configuration_mapping(): try: - zabbix_config_file = conf.zabbix[DSOpts.CONFIG_FILE] + zabbix_config_file = CONF.zabbix[DSOpts.CONFIG_FILE] zabbix_config = file_utils.load_yaml_file(zabbix_config_file) zabbix_config_elements = zabbix_config[ZABBIX_DATASOURCE] diff --git a/vitrage/datasources/zabbix/transformer.py b/vitrage/datasources/zabbix/transformer.py index 8b8860d44..92f93339f 100644 --- a/vitrage/datasources/zabbix/transformer.py +++ b/vitrage/datasources/zabbix/transformer.py @@ -32,9 +32,6 @@ from vitrage.utils.datetime import format_unix_timestamp class ZabbixTransformer(AlarmTransformerBase): - def __init__(self, transformers, conf): - super(ZabbixTransformer, self).__init__(transformers, conf) - def _create_snapshot_entity_vertex(self, entity_event): return self._create_vertex(entity_event) diff --git a/vitrage/entity_graph/__init__.py b/vitrage/entity_graph/__init__.py index d5ef919f7..9f65b62f6 100644 --- a/vitrage/entity_graph/__init__.py +++ b/vitrage/entity_graph/__init__.py @@ -17,6 +17,8 @@ from oslo_config import cfg from stevedore import driver +CONF = cfg.CONF + OPTS = [ cfg.StrOpt('datasources_values_dir', default='/etc/vitrage/datasources_values', @@ -35,10 +37,10 @@ OPTS = [ EVALUATOR_TOPIC = 'vitrage.evaluator' -def get_graph_driver(conf): +def get_graph_driver(): try: mgr = driver.DriverManager('vitrage.entity_graph', - conf.entity_graph.graph_driver, + CONF.entity_graph.graph_driver, invoke_on_load=True) return mgr.driver except ImportError: diff --git a/vitrage/entity_graph/consistency/consistency_enforcer.py b/vitrage/entity_graph/consistency/consistency_enforcer.py index 5da41c007..6266e651c 100644 --- a/vitrage/entity_graph/consistency/consistency_enforcer.py +++ b/vitrage/entity_graph/consistency/consistency_enforcer.py @@ -14,6 +14,7 @@ from datetime import timedelta +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import DatasourceAction @@ -30,18 +31,17 @@ from vitrage.evaluator.actions.evaluator_event_transformer \ from vitrage.messaging import VitrageNotifier from vitrage.utils.datetime import utcnow +CONF = cfg.CONF LOG = log.getLogger(__name__) class ConsistencyEnforcer(object): def __init__(self, - conf, entity_graph, actions_callback=None): - self.conf = conf self.actions_callback = actions_callback or VitrageNotifier( - conf, 'vitrage_consistency', [EVALUATOR_TOPIC]).notify + 'vitrage_consistency', [EVALUATOR_TOPIC]).notify self.graph = entity_graph self._init_datasources_to_mark_deleted() @@ -73,7 +73,7 @@ class ConsistencyEnforcer(object): def _find_outdated_entities_to_mark_as_deleted(self): vitrage_sample_tstmp = str(utcnow() - timedelta( - seconds=2 * self.conf.datasources.snapshots_interval)) + seconds=2 * CONF.datasources.snapshots_interval)) query = { 'and': [ {'!=': {VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE}}, @@ -87,7 +87,7 @@ class ConsistencyEnforcer(object): def _find_old_deleted_entities(self): vitrage_sample_tstmp = str(utcnow() - timedelta( - seconds=self.conf.consistency.min_time_to_delete)) + seconds=CONF.consistency.min_time_to_delete)) query = { 'and': [ {'==': {VProps.VITRAGE_IS_DELETED: True}}, @@ -140,8 +140,8 @@ class ConsistencyEnforcer(object): def _init_datasources_to_mark_deleted(self): self.datasources_to_mark_deleted = [] - for driver_name in self.conf.datasources.types: - driver_class = utils.get_driver_class(self.conf, driver_name) + for driver_name in CONF.datasources.types: + driver_class = utils.get_driver_class(driver_name) if driver_class.should_delete_outdated_entities(): self.datasources_to_mark_deleted.append(driver_name) diff --git a/vitrage/entity_graph/driver_exec.py b/vitrage/entity_graph/driver_exec.py index b26e03a64..024ca3fa1 100644 --- a/vitrage/entity_graph/driver_exec.py +++ b/vitrage/entity_graph/driver_exec.py @@ -15,6 +15,7 @@ from collections import defaultdict import threading import time +from oslo_config import cfg from oslo_log import log import oslo_messaging @@ -22,18 +23,18 @@ from vitrage.common.constants import DatasourceAction from vitrage.datasources import utils from vitrage import messaging +CONF = cfg.CONF LOG = log.getLogger(__name__) class DriverExec(object): - def __init__(self, conf, process_output_func, persist): - self.conf = conf + def __init__(self, process_output_func, persist): self.process_output_func = process_output_func self.persist = persist def snapshot_get_all(self, action=DatasourceAction.INIT_SNAPSHOT): - driver_names = self.conf.datasources.types + driver_names = CONF.datasources.types LOG.info('get_all starting for %s', driver_names) t1 = time.time() events_count = 0 @@ -46,7 +47,7 @@ class DriverExec(object): def get_all(self, driver_name, action): try: LOCK_BY_DRIVER.acquire(driver_name) - driver = utils.get_drivers_by_name(self.conf, [driver_name])[0] + driver = utils.get_drivers_by_name([driver_name])[0] LOG.info("run driver get_all: %s", driver_name) events = driver.get_all(action) count = self.process_output_func(events) @@ -65,7 +66,7 @@ class DriverExec(object): driver_name) return 0 try: - driver = utils.get_drivers_by_name(self.conf, [driver_name])[0] + driver = utils.get_drivers_by_name([driver_name])[0] LOG.info("run driver get_changes: %s", driver_name) events = driver.get_changes(DatasourceAction.UPDATE) count = self.process_output_func(events) @@ -81,23 +82,22 @@ class DriverExec(object): class DriversNotificationEndpoint(object): - def __init__(self, conf, processor_func): - self._conf = conf + def __init__(self, processor_func): self._processor_func = processor_func self._enrich_event_methods = defaultdict(list) def init(self): - driver_names = utils.get_push_drivers_names(self._conf) - push_drivers = utils.get_drivers_by_name(self._conf, driver_names) + driver_names = utils.get_push_drivers_names() + push_drivers = utils.get_drivers_by_name(driver_names) for driver in push_drivers: for event in driver.get_event_types(): self._enrich_event_methods[event].append(driver.enrich_event) return self def get_listener(self): - topics = self._conf.datasources.notification_topics - exchange = self._conf.datasources.notification_exchange - transport = messaging.get_transport(self._conf) + topics = CONF.datasources.notification_topics + exchange = CONF.datasources.notification_exchange + transport = messaging.get_transport() targets = [oslo_messaging.Target(exchange=exchange, topic=topic) for topic in topics] diff --git a/vitrage/entity_graph/graph_init.py b/vitrage/entity_graph/graph_init.py index 095f3fd70..9e64b764d 100644 --- a/vitrage/entity_graph/graph_init.py +++ b/vitrage/entity_graph/graph_init.py @@ -14,6 +14,7 @@ import threading import time +from oslo_config import cfg from oslo_log import log import oslo_messaging @@ -33,24 +34,23 @@ from vitrage.graph.driver.networkx_graph import NXGraph from vitrage import messaging from vitrage import storage +CONF = cfg.CONF LOG = log.getLogger(__name__) class VitrageGraphInit(object): - def __init__(self, conf, workers): - self.conf = conf - self.graph = get_graph_driver(conf)('Entity Graph') - self.db = db_connection = storage.get_connection_from_config(conf) + def __init__(self, workers): + self.graph = get_graph_driver()('Entity Graph') + self.db = db_connection = storage.get_connection_from_config() self.workers = workers - self.events_coordination = EventsCoordination(conf, self.process_event) - self.persist = GraphPersistency(conf, db_connection, self.graph) + self.events_coordination = EventsCoordination(self.process_event) + self.persist = GraphPersistency(db_connection, self.graph) self.driver_exec = driver_exec.DriverExec( - self.conf, self.events_coordination.handle_multiple_low_priority, self.persist) - self.scheduler = Scheduler(conf, self.graph, self.driver_exec, + self.scheduler = Scheduler(self.graph, self.driver_exec, self.persist) - self.processor = Processor(conf, self.graph) + self.processor = Processor(self.graph) def run(self): LOG.info('Init Started') @@ -114,7 +114,7 @@ class VitrageGraphInit(object): def _add_graph_subscriptions(self): self.graph.subscribe(self.workers.submit_graph_update) - vitrage_notifier = GraphNotifier(self.conf) + vitrage_notifier = GraphNotifier() if vitrage_notifier.enabled: self.graph.subscribe(vitrage_notifier.notify_when_applicable) LOG.info('Subscribed vitrage notifier to graph changes') @@ -122,14 +122,13 @@ class VitrageGraphInit(object): finalization=True) def subscribe_presist_notifier(self): - self.graph.subscribe(PersistNotifier(self.conf).notify_when_applicable) + self.graph.subscribe(PersistNotifier().notify_when_applicable) PRIORITY_DELAY = 0.05 class EventsCoordination(object): - def __init__(self, conf, do_work_func): - self._conf = conf + def __init__(self, do_work_func): self._lock = threading.Lock() self._high_event_finish_time = 0 @@ -146,7 +145,6 @@ class EventsCoordination(object): def start(self): self._low_pri_listener = driver_exec.DriversNotificationEndpoint( - self._conf, self.handle_multiple_low_priority).init().get_listener() self._high_pri_listener = self._init_listener( EVALUATOR_TOPIC, @@ -191,7 +189,7 @@ class EventsCoordination(object): if not topic: return return messaging.get_notification_listener( - transport=messaging.get_transport(self._conf), + transport=messaging.get_transport(), targets=[oslo_messaging.Target(topic=topic)], endpoints=[PushNotificationsEndpoint(callback)]) diff --git a/vitrage/entity_graph/graph_persistency.py b/vitrage/entity_graph/graph_persistency.py index e3725d4ae..c45586f98 100644 --- a/vitrage/entity_graph/graph_persistency.py +++ b/vitrage/entity_graph/graph_persistency.py @@ -24,8 +24,7 @@ LOG = log.getLogger(__name__) class GraphPersistency(object): - def __init__(self, conf, db, graph): - self.conf = conf + def __init__(self, db, graph): self.db = db self.graph = graph self.events_buffer = [] diff --git a/vitrage/entity_graph/mappings/datasource_info_mapper.py b/vitrage/entity_graph/mappings/datasource_info_mapper.py index 533a4cab3..2e8cb897f 100644 --- a/vitrage/entity_graph/mappings/datasource_info_mapper.py +++ b/vitrage/entity_graph/mappings/datasource_info_mapper.py @@ -14,6 +14,7 @@ import os +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import EntityCategory @@ -23,6 +24,7 @@ from vitrage.entity_graph.mappings.resource_handler import \ ResourceHandler from vitrage.utils import file as file_utils +CONF = cfg.CONF LOG = log.getLogger(__name__) @@ -34,8 +36,7 @@ class DatasourceInfoMapper(object): PRIORITY_VALUES = 'priority_values' UNDEFINED_DATASOURCE = 'undefined datasource' - def __init__(self, conf): - self.conf = conf + def __init__(self): self.category_normalizer = self._init_category_normalizer() self.datasources_value_confs = self._load_value_configurations() @@ -62,7 +63,7 @@ class DatasourceInfoMapper(object): graph_vertex[VProps.VITRAGE_CATEGORY] if vitrage_type in self.datasources_value_confs or \ - vitrage_type not in self.conf.datasources.types: + vitrage_type not in CONF.datasources.types: value_properties = \ self.category_normalizer[vitrage_category].value_properties() vitrage_operational_value, vitrage_aggregated_value, value_priority = \ @@ -115,11 +116,11 @@ class DatasourceInfoMapper(object): erroneous_datasources_conf = [] files = file_utils.list_files( - self.conf.entity_graph.datasources_values_dir, '.yaml') + CONF.entity_graph.datasources_values_dir, '.yaml') for file_name in files: try: - full_path = self.conf.entity_graph.datasources_values_dir \ + full_path = CONF.entity_graph.datasources_values_dir \ + '/' + file_name operational_values, priority_values = \ self._retrieve_values_and_priorities_from_file(full_path) @@ -227,7 +228,7 @@ class DatasourceInfoMapper(object): ok_datasources, error_datasources): - datasource_types = self.conf.datasources.types + datasource_types = CONF.datasources.types datasources_with_state_conf = ok_datasources + error_datasources for datasource_type in datasource_types: diff --git a/vitrage/entity_graph/processor/notifier.py b/vitrage/entity_graph/processor/notifier.py index 7ba59950c..5ee6b2591 100644 --- a/vitrage/entity_graph/processor/notifier.py +++ b/vitrage/entity_graph/processor/notifier.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log import oslo_messaging @@ -24,19 +25,21 @@ from vitrage.graph.driver.networkx_graph import edge_copy from vitrage.graph.driver.networkx_graph import vertex_copy from vitrage.messaging import get_transport +CONF = cfg.CONF + LOG = log.getLogger(__name__) class GraphNotifier(object): """Allows writing to message bus""" - def __init__(self, conf): + def __init__(self): self.oslo_notifier = None - topics = self._get_topics(conf) + topics = self._get_topics() if not topics: LOG.info('Graph Notifier is disabled') return self.oslo_notifier = oslo_messaging.Notifier( - get_transport(conf), + get_transport(), driver='messagingv2', publisher_id='vitrage.graph', topics=topics) @@ -45,12 +48,12 @@ class GraphNotifier(object): def enabled(self): return self.oslo_notifier is not None - def _get_topics(self, conf): + def _get_topics(self): topics = [] try: - notifier_topic = conf.entity_graph.notifier_topic - notifier_plugins = conf.notifiers + notifier_topic = CONF.entity_graph.notifier_topic + notifier_plugins = CONF.notifiers if notifier_topic and notifier_plugins: topics.append(notifier_topic) except Exception: @@ -58,8 +61,8 @@ class GraphNotifier(object): try: machine_learning_topic = \ - conf.machine_learning.machine_learning_topic - machine_learning_plugins = conf.machine_learning.plugins + CONF.machine_learning.machine_learning_topic + machine_learning_plugins = CONF.machine_learning.plugins if machine_learning_topic and machine_learning_plugins: topics.append(machine_learning_topic) except Exception: @@ -117,11 +120,11 @@ class GraphNotifier(object): class PersistNotifier(object): """Allows writing to message bus""" - def __init__(self, conf): + def __init__(self): self.oslo_notifier = None - topics = [conf.persistency.persistor_topic] + topics = [CONF.persistency.persistor_topic] self.oslo_notifier = oslo_messaging.Notifier( - get_transport(conf), + get_transport(), driver='messagingv2', publisher_id='vitrage.graph', topics=topics) diff --git a/vitrage/entity_graph/processor/processor.py b/vitrage/entity_graph/processor/processor.py index 01a19e59f..3733944de 100644 --- a/vitrage/entity_graph/processor/processor.py +++ b/vitrage/entity_graph/processor/processor.py @@ -31,11 +31,10 @@ LOG = log.getLogger(__name__) class Processor(processor.ProcessorBase): - def __init__(self, conf, e_graph=None): + def __init__(self, e_graph=None): super(Processor, self).__init__() - self.conf = conf - self.transformer_manager = TransformerManager(self.conf) - self.info_mapper = DatasourceInfoMapper(self.conf) + self.transformer_manager = TransformerManager() + self.info_mapper = DatasourceInfoMapper() self._initialize_events_actions() self.entity_graph = e_graph diff --git a/vitrage/entity_graph/processor/transformer_manager.py b/vitrage/entity_graph/processor/transformer_manager.py index 0db831078..defdde426 100644 --- a/vitrage/entity_graph/processor/transformer_manager.py +++ b/vitrage/entity_graph/processor/transformer_manager.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils @@ -26,29 +27,30 @@ from vitrage.evaluator.actions.evaluator_event_transformer \ import VITRAGE_DATASOURCE from vitrage.utils import opt_exists +CONF = cfg.CONF LOG = logging.getLogger(__name__) ENTITIES = 'entities' class TransformerManager(object): - def __init__(self, conf): - self.transformers = self.register_transformer_classes(conf) + def __init__(self): + self.transformers = self.register_transformer_classes() @staticmethod - def register_transformer_classes(conf): + def register_transformer_classes(): transformers = {} - for datasource_type in conf.datasources.types: + for datasource_type in CONF.datasources.types: try: transformers[datasource_type] = importutils.import_object( - conf[datasource_type].transformer, - transformers, conf) - if opt_exists(conf[datasource_type], ENTITIES): - for entity in conf[datasource_type].entities: + CONF[datasource_type].transformer, + transformers) + if opt_exists(CONF[datasource_type], ENTITIES): + for entity in CONF[datasource_type].entities: transformers[entity] = importutils.import_object( - conf[datasource_type].transformer, - transformers, conf) + CONF[datasource_type].transformer, + transformers) except Exception: LOG.exception('Failed to register transformer %s.', @@ -56,11 +58,11 @@ class TransformerManager(object): transformers[VITRAGE_DATASOURCE] = importutils.import_object( "%s.%s" % (EvaluatorEventTransformer.__module__, - EvaluatorEventTransformer.__name__), transformers, conf) + EvaluatorEventTransformer.__name__), transformers) transformers[CONSISTENCY_DATASOURCE] = importutils.import_object( "%s.%s" % (ConsistencyTransformer.__module__, - ConsistencyTransformer.__name__), transformers, conf) + ConsistencyTransformer.__name__), transformers) return transformers diff --git a/vitrage/entity_graph/scheduler.py b/vitrage/entity_graph/scheduler.py index 734412a9d..e8e699eba 100644 --- a/vitrage/entity_graph/scheduler.py +++ b/vitrage/entity_graph/scheduler.py @@ -14,6 +14,7 @@ from concurrent.futures import ThreadPoolExecutor from futurist import periodics +from oslo_config import cfg from oslo_log import log from vitrage.datasources import utils @@ -23,22 +24,22 @@ from vitrage.common.utils import spawn from vitrage.entity_graph.consistency.consistency_enforcer import\ ConsistencyEnforcer +CONF = cfg.CONF LOG = log.getLogger(__name__) class Scheduler(object): - def __init__(self, conf, graph, driver_exec, persist): + def __init__(self, graph, driver_exec, persist): super(Scheduler, self).__init__() - self.conf = conf self.graph = graph self.driver_exec = driver_exec self.persist = persist - self.consistency = ConsistencyEnforcer(conf, graph) + self.consistency = ConsistencyEnforcer(graph) self.periodic = None def start_periodic_tasks(self, immediate_get_all): - thread_num = len(utils.get_pull_drivers_names(self.conf)) + thread_num = len(utils.get_pull_drivers_names()) thread_num += 2 # for consistency and get_all self.periodic = periodics.PeriodicWorker.create( [], executor_factory=lambda: ThreadPoolExecutor( @@ -49,7 +50,7 @@ class Scheduler(object): spawn(self.periodic.start) def _add_consistency_timer(self): - spacing = self.conf.datasources.snapshots_interval + spacing = CONF.datasources.snapshots_interval @periodics.periodic(spacing=spacing) def consistency_periodic(): @@ -62,7 +63,7 @@ class Scheduler(object): LOG.info("added consistency_periodic (spacing=%s)", spacing) def _add_datasource_timers(self, run_immediately): - spacing = self.conf.datasources.snapshots_interval + spacing = CONF.datasources.snapshots_interval @periodics.periodic(spacing=spacing, run_immediately=run_immediately) def get_all_periodic(): @@ -71,9 +72,9 @@ class Scheduler(object): self.periodic.add(get_all_periodic) LOG.info("added get_all_periodic (spacing=%s)", spacing) - driver_names = utils.get_pull_drivers_names(self.conf) + driver_names = utils.get_pull_drivers_names() for d_name in driver_names: - spacing = self.conf[d_name].changes_interval + spacing = CONF[d_name].changes_interval @periodics.periodic(spacing=spacing) def get_changes_periodic(driver_name=d_name): diff --git a/vitrage/entity_graph/workers.py b/vitrage/entity_graph/workers.py index 4c77bb04a..412e3eab7 100644 --- a/vitrage/entity_graph/workers.py +++ b/vitrage/entity_graph/workers.py @@ -18,6 +18,7 @@ import cotyledon import multiprocessing import multiprocessing.queues import os +from oslo_config import cfg from oslo_log import log import oslo_messaging from oslo_utils import uuidutils @@ -45,6 +46,7 @@ from vitrage import messaging from vitrage import rpc as vitrage_rpc from vitrage import storage +CONF = cfg.CONF LOG = None # Supported message types @@ -67,9 +69,8 @@ class GraphWorkersManager(cotyledon.ServiceManager): - the queues used to communicate with these workers - methods interface to submit tasks to workers """ - def __init__(self, conf): + def __init__(self): super(GraphWorkersManager, self).__init__() - self._conf = conf self._db = None self._evaluator_queues = [] self._template_queues = [] @@ -93,10 +94,10 @@ class GraphWorkersManager(cotyledon.ServiceManager): """ if self._evaluator_queues: raise VitrageError('add_evaluator_workers called more than once') - workers = self._conf.evaluator.workers + workers = CONF.evaluator.workers queues = [multiprocessing.JoinableQueue() for i in range(workers)] self.add(EvaluatorWorker, - args=(self._conf, queues, workers), + args=(queues, workers), workers=workers) self._evaluator_queues = queues self._all_queues.extend(queues) @@ -111,9 +112,9 @@ class GraphWorkersManager(cotyledon.ServiceManager): """ if self._api_queues: raise VitrageError('add_api_workers called more than once') - workers = self._conf.api.workers + workers = CONF.api.workers queues = [multiprocessing.Queue() for i in range(workers)] - self.add(ApiWorker, args=(self._conf, queues), workers=workers) + self.add(ApiWorker, args=(queues,), workers=workers) self._api_queues = queues self._all_queues.extend(queues) @@ -177,7 +178,7 @@ class GraphWorkersManager(cotyledon.ServiceManager): template_action = event.get(TEMPLATE_ACTION) if not self._db: - self._db = storage.get_connection_from_config(self._conf) + self._db = storage.get_connection_from_config() if template_action == ADD: templates = self._db.templates.query(status=TStatus.LOADING) @@ -219,10 +220,8 @@ class GraphWorkersManager(cotyledon.ServiceManager): class GraphCloneWorkerBase(coord.Service): def __init__(self, worker_id, - conf, task_queues): - super(GraphCloneWorkerBase, self).__init__(worker_id, conf) - self._conf = conf + super(GraphCloneWorkerBase, self).__init__(worker_id) self._task_queue = task_queues[worker_id] self._entity_graph = NXGraph() @@ -285,7 +284,7 @@ class GraphCloneWorkerBase(coord.Service): self._entity_graph.remove_edge(before) def _read_db_graph(self): - db = storage.get_connection_from_config(self._conf) + db = storage.get_connection_from_config() graph_snapshot = db.graph_snapshots.query() NXGraph.read_gpickle(graph_snapshot.graph_snapshot, self._entity_graph) GraphPersistency.do_replay_events(db, self._entity_graph, @@ -296,25 +295,22 @@ class GraphCloneWorkerBase(coord.Service): class EvaluatorWorker(GraphCloneWorkerBase): def __init__(self, worker_id, - conf, task_queues, workers_num): super(EvaluatorWorker, self).__init__( - worker_id, conf, task_queues) + worker_id, task_queues) self._workers_num = workers_num self._evaluator = None name = 'EvaluatorWorker' def _init_instance(self): - scenario_repo = ScenarioRepository(self._conf, self.worker_id, + scenario_repo = ScenarioRepository(self.worker_id, self._workers_num) actions_callback = messaging.VitrageNotifier( - conf=self._conf, publisher_id='vitrage_evaluator', topics=[EVALUATOR_TOPIC]).notify self._evaluator = ScenarioEvaluator( - self._conf, self._entity_graph, scenario_repo, actions_callback, @@ -338,7 +334,7 @@ class EvaluatorWorker(GraphCloneWorkerBase): def _reload_templates(self): LOG.info("reloading evaluator scenarios") - scenario_repo = ScenarioRepository(self._conf, self.worker_id, + scenario_repo = ScenarioRepository(self.worker_id, self._workers_num) self._evaluator.scenario_repo = scenario_repo self._evaluator.scenario_repo.log_enabled_scenarios() @@ -347,7 +343,7 @@ class EvaluatorWorker(GraphCloneWorkerBase): # Here, we create a temporary ScenarioRepo to execute the needed # templates. Once _reload_templates is called, it will create a # non temporary ScenarioRepo, to replace this one - scenario_repo = ScenarioRepository(self._conf) + scenario_repo = ScenarioRepository() for s in scenario_repo._all_scenarios: s.enabled = False for template_name in template_names: @@ -363,24 +359,23 @@ class ApiWorker(GraphCloneWorkerBase): name = 'ApiWorker' def _init_instance(self): - conf = self._conf - notifier = messaging.VitrageNotifier(conf, "vitrage.api", + notifier = messaging.VitrageNotifier("vitrage.api", [EVALUATOR_TOPIC]) - db = storage.get_connection_from_config(conf) - transport = messaging.get_rpc_transport(conf) - target = oslo_messaging.Target(topic=conf.rpc_topic, + db = storage.get_connection_from_config() + transport = messaging.get_rpc_transport() + target = oslo_messaging.Target(topic=CONF.rpc_topic, server=uuidutils.generate_uuid()) self.api_lock = threading.RLock() endpoints = [ - TopologyApis(self._entity_graph, conf, self.api_lock), - AlarmApis(self._entity_graph, conf, self.api_lock, db), - RcaApis(self._entity_graph, conf, self.api_lock, db), - ResourceApis(self._entity_graph, conf, self.api_lock), + TopologyApis(self._entity_graph, self.api_lock), + AlarmApis(self._entity_graph, self.api_lock, db), + RcaApis(self._entity_graph, self.api_lock, db), + ResourceApis(self._entity_graph, self.api_lock), TemplateApis(notifier, db), - EventApis(conf), - WebhookApis(conf, db), - OperationalApis(conf, self._entity_graph), + EventApis(), + WebhookApis(db), + OperationalApis(self._entity_graph), ] server = vitrage_rpc.get_server(target, endpoints, transport) diff --git a/vitrage/evaluator/actions/action_executor.py b/vitrage/evaluator/actions/action_executor.py index b2d7dba4e..ff714c5a2 100644 --- a/vitrage/evaluator/actions/action_executor.py +++ b/vitrage/evaluator/actions/action_executor.py @@ -51,10 +51,10 @@ SOURCE = 'source' class ActionExecutor(object): - def __init__(self, conf, actions_callback): + def __init__(self, actions_callback): self.actions_callback = actions_callback - self.notifier = EvaluatorNotifier(conf) + self.notifier = EvaluatorNotifier() self.action_recipes = ActionExecutor._register_action_recipes() self.action_step_defs = { diff --git a/vitrage/evaluator/actions/evaluator_event_transformer.py b/vitrage/evaluator/actions/evaluator_event_transformer.py index d13928afd..8299b937c 100644 --- a/vitrage/evaluator/actions/evaluator_event_transformer.py +++ b/vitrage/evaluator/actions/evaluator_event_transformer.py @@ -42,8 +42,8 @@ VITRAGE_DATASOURCE = 'vitrage' class EvaluatorEventTransformer(transformer_base.TransformerBase): - def __init__(self, transformers, conf): - super(EvaluatorEventTransformer, self).__init__(transformers, conf) + def __init__(self, transformers): + super(EvaluatorEventTransformer, self).__init__(transformers) self.actions = self._init_actions() def _create_snapshot_entity_vertex(self, entity_event): diff --git a/vitrage/evaluator/actions/notifier.py b/vitrage/evaluator/actions/notifier.py index 3eb3e2c45..7bd3b563c 100644 --- a/vitrage/evaluator/actions/notifier.py +++ b/vitrage/evaluator/actions/notifier.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 oslo_config import cfg from oslo_log import log import oslo_messaging @@ -18,15 +20,16 @@ from vitrage.common.constants import NotifierEventTypes from vitrage.messaging import get_transport +CONF = cfg.CONF LOG = log.getLogger(__name__) class EvaluatorNotifier(object): """Allows writing to message bus""" - def __init__(self, conf): + def __init__(self, ): self.oslo_notifiers = {} try: - notifier_plugins = conf.notifiers + notifier_plugins = CONF.notifiers LOG.debug('notifier_plugins: %s', notifier_plugins) @@ -35,13 +38,13 @@ class EvaluatorNotifier(object): return topic_prefix = \ - conf.evaluator_actions.evaluator_notification_topic_prefix + CONF.evaluator_actions.evaluator_notification_topic_prefix for notifier in notifier_plugins: LOG.debug('Adding evaluator notifier %s', notifier) self.oslo_notifiers[notifier] = oslo_messaging.Notifier( - get_transport(conf), + get_transport(), driver='messagingv2', publisher_id='vitrage.evaluator', topics=[topic_prefix + '.' + notifier]) diff --git a/vitrage/evaluator/scenario_evaluator.py b/vitrage/evaluator/scenario_evaluator.py index 31c43a658..eee52d530 100644 --- a/vitrage/evaluator/scenario_evaluator.py +++ b/vitrage/evaluator/scenario_evaluator.py @@ -18,6 +18,7 @@ import copy import re import time +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import EdgeProperties as EProps @@ -42,6 +43,7 @@ from vitrage import storage from vitrage.storage.sqlalchemy import models from vitrage.utils.datetime import utcnow +CONF = cfg.CONF LOG = log.getLogger(__name__) # Entry containing action info. @@ -60,16 +62,14 @@ SOURCE = 'source' class ScenarioEvaluator(object): def __init__(self, - conf, e_graph, scenario_repo, actions_callback, enabled=False): - self._conf = conf self._entity_graph = e_graph - self._db = storage.get_connection_from_config(self._conf) + self._db = storage.get_connection_from_config() self._scenario_repo = scenario_repo - self._action_executor = ActionExecutor(self._conf, actions_callback) + self._action_executor = ActionExecutor(actions_callback) self._entity_graph.subscribe(self.process_event) self.enabled = enabled self.connected_component_cache = defaultdict(dict) @@ -314,7 +314,7 @@ class ScenarioEvaluator(object): if not actions: return [] - active_actions = ActiveActionsTracker(self._conf, self._db, actions) + active_actions = ActiveActionsTracker(self._db, actions) for action_info in actions: if action_info.mode == ActionMode.DO: active_actions.calc_do_action(action_info) @@ -483,13 +483,13 @@ class ActiveActionsTracker(object): """ action_tools = None - def __init__(self, conf, db, actions): + def __init__(self, db, actions): self.db = db self.data = defaultdict(set) self.actions_to_create = {} self.actions_to_remove = set() self.actions_to_perform = [] # use a list to keep the insertion order - self._init_action_tools(conf) + self._init_action_tools() # Query DB for all actions with same properties actions_keys = set([self._get_key(action) for action in actions]) @@ -499,10 +499,10 @@ class ActiveActionsTracker(object): db_row.extra_info, db_row.action_type)].add(db_row) @classmethod - def _init_action_tools(cls, conf): + def _init_action_tools(cls): if cls.action_tools: return - info_mapper = DatasourceInfoMapper(conf) + info_mapper = DatasourceInfoMapper() alarms_score = info_mapper.get_datasource_priorities('vitrage') all_scores = info_mapper.get_datasource_priorities() cls.action_tools = { diff --git a/vitrage/evaluator/scenario_repository.py b/vitrage/evaluator/scenario_repository.py index 3da490ec7..6de2afef9 100644 --- a/vitrage/evaluator/scenario_repository.py +++ b/vitrage/evaluator/scenario_repository.py @@ -35,7 +35,7 @@ DEF_TEMPLATES_DIR_OPT = 'def_templates_dir' class ScenarioRepository(object): - def __init__(self, conf, worker_index=None, workers_num=None): + def __init__(self, worker_index=None, workers_num=None): """Create an instance of ScenarioRepository :param conf: @@ -45,7 +45,7 @@ class ScenarioRepository(object): self._templates = {} self._def_templates = {} self._all_scenarios = [] - self._db = storage.get_connection_from_config(conf) + self._db = storage.get_connection_from_config() self.entity_equivalences = EquivalenceRepository().load(self._db) self.relationship_scenarios = defaultdict(list) self.entity_scenarios = defaultdict(list) diff --git a/vitrage/keystone_client.py b/vitrage/keystone_client.py index 27da538c3..673373c8a 100644 --- a/vitrage/keystone_client.py +++ b/vitrage/keystone_client.py @@ -24,22 +24,23 @@ from keystoneclient.v3 import client as ks_client_v3 from oslo_config import cfg from oslo_log import log +CONF = cfg.CONF LOG = log.getLogger(__name__) CFG_GROUP = "service_credentials" -def get_session(conf): +def get_session(): """Get a vitrage service credentials auth session.""" - auth_plugin = ka_loading.load_auth_from_conf_options(conf, CFG_GROUP) + auth_plugin = ka_loading.load_auth_from_conf_options(CONF, CFG_GROUP) return ka_loading.load_session_from_conf_options( - conf, CFG_GROUP, auth=auth_plugin + CONF, CFG_GROUP, auth=auth_plugin ) -def get_client(conf): +def get_client(): """Return a client for keystone v3 endpoint.""" - sess = get_session(conf) + sess = get_session() return ks_client_v3.Client(session=sess) @@ -57,10 +58,10 @@ def get_client_on_behalf_user(auth_plugin): return ks_client_v3.Client(session=sess) -def create_trust_id(conf, trustor_user_id, trustor_project_id, roles, +def create_trust_id(trustor_user_id, trustor_project_id, roles, auth_plugin): """Create a new trust using the vitrage service user.""" - admin_client = get_client(conf) + admin_client = get_client() trustee_user_id = admin_client.session.get_user_id() client = get_client_on_behalf_user(auth_plugin) @@ -98,10 +99,10 @@ OPTS = [ ] -def register_keystoneauth_opts(conf): - ka_loading.register_auth_conf_options(conf, CFG_GROUP) +def register_keystoneauth_opts(): + ka_loading.register_auth_conf_options(CONF, CFG_GROUP) ka_loading.register_session_conf_options( - conf, CFG_GROUP, + CONF, CFG_GROUP, deprecated_opts={'cacert': [ cfg.DeprecatedOpt('os-cacert', group=CFG_GROUP), cfg.DeprecatedOpt('os-cacert', group="DEFAULT")] diff --git a/vitrage/machine_learning/plugins/base.py b/vitrage/machine_learning/plugins/base.py index 449855ee0..2bb9c3eec 100644 --- a/vitrage/machine_learning/plugins/base.py +++ b/vitrage/machine_learning/plugins/base.py @@ -19,9 +19,6 @@ import six @six.add_metaclass(abc.ABCMeta) class MachineLearningBase(object): - def __init__(self, conf): - self.conf = conf - @abc.abstractmethod def process_event(self, data, event_type): pass diff --git a/vitrage/machine_learning/plugins/jaccard_correlation/alarm_processor.py b/vitrage/machine_learning/plugins/jaccard_correlation/alarm_processor.py index 816367340..a8fc19068 100644 --- a/vitrage/machine_learning/plugins/jaccard_correlation/alarm_processor.py +++ b/vitrage/machine_learning/plugins/jaccard_correlation/alarm_processor.py @@ -14,6 +14,8 @@ from collections import namedtuple from datetime import datetime + +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import NotifierEventTypes @@ -28,6 +30,8 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\ from vitrage.machine_learning.plugins.jaccard_correlation.correlation_manager\ import CorrelationManager as CM +CONF = cfg.CONF + LOG = log.getLogger(__name__) AlarmID = namedtuple('AlarmID', [VProps.VITRAGE_RESOURCE_ID, @@ -41,12 +45,12 @@ class AlarmDataProcessor(MachineLearningBase): def get_plugin_name(): return 'jaccard_correlation' - def __init__(self, conf): - super(AlarmDataProcessor, self).__init__(conf) + def __init__(self): + super(AlarmDataProcessor, self).__init__() self.data_manager = ADAcummulator(APersistor.load_data()) - self.correlation_manager = CM(conf) + self.correlation_manager = CM() self.num_of_events_to_flush = \ - conf.jaccard_correlation.num_of_events_to_flush + CONF.jaccard_correlation.num_of_events_to_flush self.event_counter = 0 def process_event(self, data, event_type): diff --git a/vitrage/machine_learning/plugins/jaccard_correlation/correlation_manager.py b/vitrage/machine_learning/plugins/jaccard_correlation/correlation_manager.py index e4bef33c3..611e5bae1 100644 --- a/vitrage/machine_learning/plugins/jaccard_correlation/correlation_manager.py +++ b/vitrage/machine_learning/plugins/jaccard_correlation/correlation_manager.py @@ -15,6 +15,7 @@ import os import time +from oslo_config import cfg from oslo_log import log from vitrage.machine_learning.plugins.jaccard_correlation.\ @@ -23,17 +24,18 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\ correlation_collection import CorrelationPriorities as CPriorities +CONF = cfg.CONF LOG = log.getLogger(__name__) class CorrelationManager(object): - def __init__(self, conf): - self.high_corr_score = conf.jaccard_correlation.high_corr_score - self.med_corr_score = conf.jaccard_correlation.med_corr_score + def __init__(self): + self.high_corr_score = CONF.jaccard_correlation.high_corr_score + self.med_corr_score = CONF.jaccard_correlation.med_corr_score self.correlation_threshold = \ - conf.jaccard_correlation.correlation_threshold - self.output_folder = conf.jaccard_correlation.output_folder + CONF.jaccard_correlation.correlation_threshold + self.output_folder = CONF.jaccard_correlation.output_folder self.last_written_file = "" self.correlation_table = CCollection(self.high_corr_score, self.med_corr_score) diff --git a/vitrage/machine_learning/service.py b/vitrage/machine_learning/service.py index ba2c7bfbd..2410e6bf2 100644 --- a/vitrage/machine_learning/service.py +++ b/vitrage/machine_learning/service.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. - +from oslo_config import cfg from oslo_log import log import oslo_messaging as oslo_m from oslo_utils import importutils @@ -21,18 +21,18 @@ from vitrage.coordination import service as coord from vitrage import messaging from vitrage.opts import register_opts +CONF = cfg.CONF LOG = log.getLogger(__name__) class MachineLearningService(coord.Service): - def __init__(self, worker_id, conf): - super(MachineLearningService, self).__init__(worker_id, conf) - self.conf = conf - self.machine_learning_plugins = self.get_machine_learning_plugins(conf) - transport = messaging.get_transport(conf) + def __init__(self, worker_id): + super(MachineLearningService, self).__init__(worker_id) + self.machine_learning_plugins = self.get_machine_learning_plugins() + transport = messaging.get_transport() target = \ - oslo_m.Target(topic=conf.machine_learning.machine_learning_topic) + oslo_m.Target(topic=CONF.machine_learning.machine_learning_topic) self.listener = messaging.get_notification_listener( transport, [target], [VitrageEventEndpoint(self.machine_learning_plugins)]) @@ -55,21 +55,21 @@ class MachineLearningService(coord.Service): LOG.info("Vitrage Machine Learning Service - Stopped!") @staticmethod - def get_machine_learning_plugins(conf): + def get_machine_learning_plugins(): machine_learning_plugins = [] machine_learning_plugins_names = \ - conf.machine_learning.plugins + CONF.machine_learning.plugins if not machine_learning_plugins_names: LOG.info('There are no Machine Learning plugins in configuration') return [] for machine_learning_plugin_name in machine_learning_plugins_names: - register_opts(conf, machine_learning_plugin_name, - conf.machine_learning.plugins_path) + register_opts(machine_learning_plugin_name, + CONF.machine_learning.plugins_path) LOG.info('Machine Learning plugin %s started', machine_learning_plugin_name) machine_learning_plugins.append(importutils.import_object( - conf[machine_learning_plugin_name].plugin_path, - conf)) + CONF[machine_learning_plugin_name].plugin_path, + CONF)) return machine_learning_plugins diff --git a/vitrage/messaging.py b/vitrage/messaging.py index 622edd965..589600fae 100644 --- a/vitrage/messaging.py +++ b/vitrage/messaging.py @@ -11,11 +11,12 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log import oslo_messaging as oslo_msg -# from oslo_messaging import serializer as oslo_serializer +CONF = cfg.CONF LOG = log.getLogger(__name__) DEFAULT_URL = "__default__" @@ -28,11 +29,11 @@ def setup(): oslo_msg.set_transport_defaults('vitrage') -def get_rpc_transport(conf, url=None, optional=False, cache=True): - return get_transport(conf, url, optional, cache, rpc=True) +def get_rpc_transport(url=None, optional=False, cache=True): + return get_transport(url, optional, cache, rpc=True) -def get_transport(conf, url=None, optional=False, cache=True, rpc=False): +def get_transport(url=None, optional=False, cache=True, rpc=False): """Initialise the oslo_messaging layer.""" global TRANSPORTS, DEFAULT_URL cache_key = url or DEFAULT_URL + '_rpc' if rpc else '' @@ -40,9 +41,9 @@ def get_transport(conf, url=None, optional=False, cache=True, rpc=False): if not transport or not cache: try: if rpc: - transport = oslo_msg.get_rpc_transport(conf, url) + transport = oslo_msg.get_rpc_transport(CONF, url) else: - transport = oslo_msg.get_notification_transport(conf, url) + transport = oslo_msg.get_notification_transport(CONF, url) except oslo_msg.InvalidTransportURL as e: if not optional or e.url: # NOTE(sileht): oslo_messaging is configured but unloadable @@ -65,8 +66,8 @@ def get_notification_listener(transport, targets, endpoints, class VitrageNotifier(object): """Allows writing to message bus""" - def __init__(self, conf, publisher_id, topics): - transport = get_transport(conf) + def __init__(self, publisher_id, topics): + transport = get_transport() self.notifier = oslo_msg.Notifier( transport, driver='messagingv2', diff --git a/vitrage/notifier/plugins/aodh/aodh_notifier.py b/vitrage/notifier/plugins/aodh/aodh_notifier.py index a2afa8d7d..a1dfa0a56 100644 --- a/vitrage/notifier/plugins/aodh/aodh_notifier.py +++ b/vitrage/notifier/plugins/aodh/aodh_notifier.py @@ -39,9 +39,9 @@ class AodhNotifier(NotifierBase): def get_notifier_name(): return AODH_DATASOURCE - def __init__(self, conf): - super(AodhNotifier, self).__init__(conf) - self.client = os_clients.aodh_client(conf) + def __init__(self): + super(AodhNotifier, self).__init__() + self.client = os_clients.aodh_client() def process_event(self, data, event_type): response = None diff --git a/vitrage/notifier/plugins/base.py b/vitrage/notifier/plugins/base.py index 6706265aa..248c870aa 100644 --- a/vitrage/notifier/plugins/base.py +++ b/vitrage/notifier/plugins/base.py @@ -19,9 +19,6 @@ import six @six.add_metaclass(abc.ABCMeta) class NotifierBase(object): - def __init__(self, conf): - self.conf = conf - @abc.abstractmethod def process_event(self, data, event_type): pass diff --git a/vitrage/notifier/plugins/mistral/mistral_notifier.py b/vitrage/notifier/plugins/mistral/mistral_notifier.py index 847784b45..0c6597091 100644 --- a/vitrage/notifier/plugins/mistral/mistral_notifier.py +++ b/vitrage/notifier/plugins/mistral/mistral_notifier.py @@ -25,9 +25,8 @@ LOG = logging.getLogger(__name__) class MistralNotifier(NotifierBase): - def __init__(self, conf): - super(MistralNotifier, self).__init__(conf) - self.conf = conf + def __init__(self): + super(MistralNotifier, self).__init__() self._client = None @staticmethod @@ -41,7 +40,7 @@ class MistralNotifier(NotifierBase): @property def client(self): if not self._client: - self._client = os_clients.mistral_client(self.conf) + self._client = os_clients.mistral_client() return self._client def info(self, ctxt, publisher_id, event_type, payload, metadata): diff --git a/vitrage/notifier/plugins/nova/nova_notifier.py b/vitrage/notifier/plugins/nova/nova_notifier.py index fa2d33681..906d2d153 100644 --- a/vitrage/notifier/plugins/nova/nova_notifier.py +++ b/vitrage/notifier/plugins/nova/nova_notifier.py @@ -30,9 +30,9 @@ class NovaNotifier(NotifierBase): def get_notifier_name(): return 'nova' - def __init__(self, conf): - super(NovaNotifier, self).__init__(conf) - self.client = os_clients.nova_client(conf) + def __init__(self): + super(NovaNotifier, self).__init__() + self.client = os_clients.nova_client() self.actions = { NOVA_HOST_DATASOURCE: self._mark_host_down, NOVA_INSTANCE_DATASOURCE: self._reset_instance_state diff --git a/vitrage/notifier/plugins/snmp/base.py b/vitrage/notifier/plugins/snmp/base.py index 46fbec183..7c4c24db9 100644 --- a/vitrage/notifier/plugins/snmp/base.py +++ b/vitrage/notifier/plugins/snmp/base.py @@ -20,9 +20,6 @@ import six class SnmpSenderBase(object): """Abstract Vitrage snmp trap sender""" - def __init__(self, conf): - self.conf = conf - @abc.abstractmethod def send_snmp(self, alarm_data): pass diff --git a/vitrage/notifier/plugins/snmp/snmp_notifier.py b/vitrage/notifier/plugins/snmp/snmp_notifier.py index d7d8f3432..de128b034 100644 --- a/vitrage/notifier/plugins/snmp/snmp_notifier.py +++ b/vitrage/notifier/plugins/snmp/snmp_notifier.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils @@ -19,6 +20,7 @@ from vitrage.common.constants import NotifierEventTypes from vitrage.common.constants import VertexProperties as VProps from vitrage.notifier.plugins.base import NotifierBase +CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -27,10 +29,10 @@ class SnmpNotifier(NotifierBase): def get_notifier_name(): return 'snmp' - def __init__(self, conf): - super(SnmpNotifier, self).__init__(conf) + def __init__(self): + super(SnmpNotifier, self).__init__() self.snmp_sender = \ - importutils.import_object(conf.snmp.snmp_sender_class, conf) + importutils.import_object(CONF.snmp.snmp_sender_class) def process_event(self, data, event_type): diff --git a/vitrage/notifier/plugins/snmp/snmp_sender.py b/vitrage/notifier/plugins/snmp/snmp_sender.py index 1c5080635..0b07ef570 100644 --- a/vitrage/notifier/plugins/snmp/snmp_sender.py +++ b/vitrage/notifier/plugins/snmp/snmp_sender.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log as logging from pysnmp.entity.engine import SnmpEngine from pysnmp.hlapi.asyncore.sync.compat.ntforg import sendNotification @@ -27,6 +28,7 @@ from vitrage.common.constants import VertexProperties as VProps from vitrage.notifier.plugins.snmp.base import SnmpSenderBase from vitrage.utils.file import load_yaml_file +CONF = cfg.CONF LOG = logging.getLogger(__name__) # TODO(annarez): change NA to N/A @@ -43,12 +45,11 @@ PORT_PAT = re.compile('\d+') class SnmpSender(SnmpSenderBase): - def __init__(self, conf): - super(SnmpSender, self).__init__(conf) - self.hosts = load_yaml_file(self.conf.snmp.consumers, True) - self.oid_tree = load_yaml_file(self.conf.snmp.oid_tree, True) + def __init__(self): + self.hosts = load_yaml_file(CONF.snmp.consumers, True) + self.oid_tree = load_yaml_file(CONF.snmp.oid_tree, True) self.alarm_mapping = \ - load_yaml_file(self.conf.snmp.alarm_oid_mapping, True) + load_yaml_file(CONF.snmp.alarm_oid_mapping, True) self.oids, self.var_fields = self._build_oids() def send_snmp(self, alarm_data): diff --git a/vitrage/notifier/plugins/webhook/webhook.py b/vitrage/notifier/plugins/webhook/webhook.py index 51ea3151d..66d471989 100644 --- a/vitrage/notifier/plugins/webhook/webhook.py +++ b/vitrage/notifier/plugins/webhook/webhook.py @@ -14,6 +14,7 @@ import ast import re +from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import uuidutils @@ -26,6 +27,7 @@ from vitrage.notifier.plugins.base import NotifierBase from vitrage.notifier.plugins.webhook import utils as webhook_utils from vitrage import storage +CONF = cfg.CONF LOG = logging.getLogger(__name__) URL = 'url' IS_ADMIN_WEBHOOK = 'is_admin_webhook' @@ -65,10 +67,10 @@ class Webhook(NotifierBase): def get_notifier_name(): return 'webhook' - def __init__(self, conf): - super(Webhook, self).__init__(conf) - self._db = storage.get_connection_from_config(self.conf) - self.max_retries = self.conf.webhook.max_retries + def __init__(self): + super(Webhook, self).__init__() + self._db = storage.get_connection_from_config() + self.max_retries = CONF.webhook.max_retries self.default_headers = {'content-type': 'application/json'} def process_event(self, data, event_type): diff --git a/vitrage/notifier/plugins/zaqar/zaqar_notifier.py b/vitrage/notifier/plugins/zaqar/zaqar_notifier.py index c44a4529b..a1616c762 100644 --- a/vitrage/notifier/plugins/zaqar/zaqar_notifier.py +++ b/vitrage/notifier/plugins/zaqar/zaqar_notifier.py @@ -11,22 +11,24 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from oslo_config import cfg from oslo_log import log from vitrage.common.constants import NotifierEventTypes from vitrage.notifier.plugins.base import NotifierBase from vitrage import os_clients - +CONF = cfg.CONF LOG = log.getLogger(__name__) class ZaqarNotifier(NotifierBase): - def __init__(self, conf): - super(ZaqarNotifier, self).__init__(conf) - client = os_clients.zaqar_client(self.conf) - self._queue = client.queue(self.conf.zaqar.queue) + def __init__(self): + super(ZaqarNotifier, self).__init__() + client = os_clients.zaqar_client() + self._queue = client.queue(CONF.zaqar.queue) @staticmethod def get_notifier_name(): diff --git a/vitrage/notifier/service.py b/vitrage/notifier/service.py index bb98d5f0f..c16baff40 100644 --- a/vitrage/notifier/service.py +++ b/vitrage/notifier/service.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 oslo_config import cfg from oslo_log import log import oslo_messaging from oslo_utils import importutils @@ -19,16 +21,16 @@ from vitrage.coordination import service as coord from vitrage import messaging from vitrage.opts import register_opts +CONF = cfg.CONF LOG = log.getLogger(__name__) class VitrageNotifierService(coord.Service): - def __init__(self, worker_id, conf): - super(VitrageNotifierService, self).__init__(worker_id, conf) - self.conf = conf - self.notifiers = self.get_notifier_plugins(conf) - self._init_listeners(self.conf) + def __init__(self, worker_id): + super(VitrageNotifierService, self).__init__(worker_id) + self.notifiers = self.get_notifier_plugins() + self._init_listeners() def run(self): super(VitrageNotifierService, self).run() @@ -51,31 +53,30 @@ class VitrageNotifierService(coord.Service): LOG.info("Vitrage Notifier Service - Stopped!") @staticmethod - def get_notifier_plugins(conf): + def get_notifier_plugins(): notifiers = [] - conf_notifier_names = conf.notifiers + conf_notifier_names = CONF.notifiers if not conf_notifier_names: LOG.info('There are no notifier plugins in configuration') return [] for notifier_name in conf_notifier_names: - register_opts(conf, notifier_name, conf.notifiers_path) + register_opts(notifier_name, CONF.notifiers_path) LOG.info('Notifier plugin %s started', notifier_name) notifiers.append(importutils.import_object( - conf[notifier_name].notifier, - conf)) + CONF[notifier_name].notifier)) return notifiers - def _init_listeners(self, conf): + def _init_listeners(self): self.listeners = [] - transport = messaging.get_transport(conf) + transport = messaging.get_transport() self._init_notifier(transport=transport, - topic=conf.entity_graph.notifier_topic, + topic=CONF.entity_graph.notifier_topic, endpoint=VitrageDefaultEventEndpoint( self.notifiers)) topic_prefix = \ - conf.evaluator_actions.evaluator_notification_topic_prefix + CONF.evaluator_actions.evaluator_notification_topic_prefix for notifier in self.notifiers: if notifier.use_private_topic(): diff --git a/vitrage/opts.py b/vitrage/opts.py index 76dbf7413..18cba634d 100644 --- a/vitrage/opts.py +++ b/vitrage/opts.py @@ -15,6 +15,8 @@ import itertools import os + +from oslo_config import cfg from oslo_log import log from oslo_utils import importutils @@ -37,6 +39,7 @@ import vitrage.rpc import vitrage.snmp_parsing import vitrage.storage +CONF = cfg.CONF LOG = log.getLogger(__name__) DATASOURCES_PATH = 'vitrage.datasources.' @@ -103,13 +106,13 @@ def _normalize_path_to_datasource_name(path_list, top=os.getcwd()): .replace(os.sep, '.') for path in path_list] -def register_opts(conf, package_name, paths): +def register_opts(package_name, paths): """register opts of package package_name, with base path in paths""" for path in paths: try: opt = importutils.import_module( "%s.%s" % (path, package_name)).OPTS - conf.register_opts( + CONF.register_opts( list(opt), group=None if package_name == 'DEFAULT' else package_name ) diff --git a/vitrage/os_clients.py b/vitrage/os_clients.py index 2f3d74f0b..8caca5e0a 100644 --- a/vitrage/os_clients.py +++ b/vitrage/os_clients.py @@ -18,7 +18,7 @@ from oslo_utils import importutils as utils from vitrage import keystone_client - +CONF = cfg.CONF LOG = log.getLogger(__name__) OPTS = [ @@ -62,38 +62,38 @@ def driver_module(driver): return module -def gnocchi_client(conf): +def gnocchi_client(): """Get an instance of the gnocchi client""" try: gn_client = driver_module('gnocchi') client = gn_client.Client( - session=keystone_client.get_session(conf)) + session=keystone_client.get_session()) LOG.info('Gnocchi client created') return client except Exception: LOG.exception('Create Gnocchi client - Got Exception') -def aodh_client(conf): +def aodh_client(): """Get an instance of aodh client""" try: ao_client = driver_module('aodh') client = ao_client.Client( - conf.aodh_version, - session=keystone_client.get_session(conf)) + CONF.aodh_version, + session=keystone_client.get_session()) LOG.info('Aodh client created') return client except Exception: LOG.exception('Create Aodh client - Got Exception.') -def ceilometer_client(conf): +def ceilometer_client(): """Get an instance of ceilometer client""" try: cm_client = driver_module('ceilometer') client = cm_client.get_client( - version=conf.ceilometer_version, - session=keystone_client.get_session(conf), + version=CONF.ceilometer_version, + session=keystone_client.get_session(), ) LOG.info('Ceilometer client created') return client @@ -101,13 +101,13 @@ def ceilometer_client(conf): LOG.exception('Create Ceilometer client - Got Exception.') -def nova_client(conf): +def nova_client(): """Get an instance of nova client""" try: n_client = driver_module('nova') client = n_client.Client( - version=conf.nova_version, - session=keystone_client.get_session(conf), + version=CONF.nova_version, + session=keystone_client.get_session(), ) LOG.info('Nova client created') return client @@ -115,13 +115,13 @@ def nova_client(conf): LOG.exception('Create Nova client - Got Exception.') -def trove_client(conf): +def trove_client(): """Get an instance of trove client""" try: tr_client = driver_module('trove') client = tr_client.Client( - version=conf.trove_version, - session=keystone_client.get_session(conf), + version=CONF.trove_version, + session=keystone_client.get_session(), ) LOG.info('Trove client created') return client @@ -129,13 +129,13 @@ def trove_client(conf): LOG.exception('Create Trove client - Got Exception.') -def cinder_client(conf): +def cinder_client(): """Get an instance of cinder client""" try: cin_client = driver_module('cinder') client = cin_client.Client( - version=conf.cinder_version, - session=keystone_client.get_session(conf), + version=CONF.cinder_version, + session=keystone_client.get_session(), ) LOG.info('Cinder client created') return client @@ -143,13 +143,13 @@ def cinder_client(conf): LOG.exception('Create Cinder client - Got Exception.') -def glance_client(conf): +def glance_client(): """Get an instance of glance client""" try: glan_client = driver_module('glance') client = glan_client.Client( - version=conf.glance_version, - session=keystone_client.get_session(conf), + version=CONF.glance_version, + session=keystone_client.get_session(), ) LOG.info('Glance client created') return client @@ -157,12 +157,12 @@ def glance_client(conf): LOG.exception('Create Glance client - Got Exception') -def neutron_client(conf): +def neutron_client(): """Get an instance of neutron client""" try: ne_client = driver_module('neutron') client = ne_client.Client( - session=keystone_client.get_session(conf) + session=keystone_client.get_session() ) LOG.info('Neutron client created') return client @@ -170,13 +170,13 @@ def neutron_client(conf): LOG.exception('Create Neutron client - Got Exception.') -def heat_client(conf): +def heat_client(): """Get an instance of heat client""" try: he_client = driver_module('heat') client = he_client.Client( - version=conf.heat_version, - session=keystone_client.get_session(conf) + version=CONF.heat_version, + session=keystone_client.get_session() ) LOG.info('Heat client created') return client @@ -184,12 +184,12 @@ def heat_client(conf): LOG.exception('Create Heat client - Got Exception.') -def mistral_client(conf): +def mistral_client(): """Get an instance of Mistral client""" try: mi_client = driver_module('mistral') client = mi_client.Client( - session=keystone_client.get_session(conf), + session=keystone_client.get_session(), ) LOG.info('Mistral client created') return client @@ -197,12 +197,12 @@ def mistral_client(conf): LOG.exception('Create Mistral client - Got Exception.') -def zaqar_client(conf): +def zaqar_client(): """Get an instance of Zaqar client""" try: z_client = driver_module('zaqar') client = z_client.Client( - session=keystone_client.get_session(conf), + session=keystone_client.get_session(), ) LOG.info('Zaqar client created') return client @@ -210,16 +210,16 @@ def zaqar_client(conf): LOG.exception('Create Zaqar client - Got Exception.') -def monasca_client(conf): +def monasca_client(): """Get an instance of Monasca client""" try: mon_client = driver_module('monasca') - session = keystone_client.get_session(conf) + session = keystone_client.get_session() endpoint = session.get_endpoint(service_type='monitoring', interface='publicURL') client = mon_client.Client( - api_version=conf.monasca_version, + api_version=CONF.monasca_version, session=session, endpoint=endpoint ) diff --git a/vitrage/persistency/service.py b/vitrage/persistency/service.py index 935f4ba50..e2acd8cbd 100644 --- a/vitrage/persistency/service.py +++ b/vitrage/persistency/service.py @@ -20,6 +20,7 @@ from concurrent.futures import ThreadPoolExecutor import dateutil.parser from futurist import periodics +from oslo_config import cfg from oslo_log import log import oslo_messaging as oslo_m from oslo_utils import timeutils @@ -35,21 +36,21 @@ from vitrage import messaging from vitrage.storage.sqlalchemy import models from vitrage.utils.datetime import utcnow +CONF = cfg.CONF LOG = log.getLogger(__name__) class PersistorService(coord.Service): - def __init__(self, worker_id, conf, db_connection): - super(PersistorService, self).__init__(worker_id, conf) - self.conf = conf + def __init__(self, worker_id, db_connection): + super(PersistorService, self).__init__(worker_id) self.db_connection = db_connection - transport = messaging.get_transport(conf) + transport = messaging.get_transport() target = \ - oslo_m.Target(topic=conf.persistency.persistor_topic) + oslo_m.Target(topic=CONF.persistency.persistor_topic) self.listener = messaging.get_notification_listener( transport, [target], [VitragePersistorEndpoint(self.db_connection)]) - self.scheduler = Scheduler(conf, db_connection) + self.scheduler = Scheduler(db_connection) def run(self): super(PersistorService, self).run() @@ -165,8 +166,7 @@ class VitragePersistorEndpoint(object): class Scheduler(object): - def __init__(self, conf, db): - self.conf = conf + def __init__(self, db): self.db = db self.periodic = None @@ -202,7 +202,7 @@ class Scheduler(object): def expirer_periodic(): expire_by = \ utcnow(with_timezone=False) - \ - timedelta(days=self.conf.persistency.alarm_history_ttl) + timedelta(days=CONF.persistency.alarm_history_ttl) try: self.db.alarms.delete_expired(expire_by) except Exception: diff --git a/vitrage/snmp_parsing/service.py b/vitrage/snmp_parsing/service.py index bef32b79d..e2eca731b 100644 --- a/vitrage/snmp_parsing/service.py +++ b/vitrage/snmp_parsing/service.py @@ -14,6 +14,7 @@ from datetime import datetime +from oslo_config import cfg from oslo_log import log import oslo_messaging from oslo_utils import uuidutils @@ -32,18 +33,18 @@ from vitrage.messaging import get_transport from vitrage.snmp_parsing.properties import SnmpEventProperties as SEProps from vitrage.utils.file import load_yaml_file +CONF = cfg.CONF LOG = log.getLogger(__name__) class SnmpParsingService(coord.Service): RUN_FOREVER = 1 - def __init__(self, worker_id, conf): - super(SnmpParsingService, self).__init__(worker_id, conf) - self.conf = conf - self.listening_port = conf.snmp_parsing.snmp_listening_port + def __init__(self, worker_id): + super(SnmpParsingService, self).__init__(worker_id) + self.listening_port = CONF.snmp_parsing.snmp_listening_port self.oid_mapping = \ - load_yaml_file(self.conf.snmp_parsing.oid_mapping) + load_yaml_file(CONF.snmp_parsing.oid_mapping) self._init_oslo_notifier() def run(self): @@ -120,7 +121,7 @@ class SnmpParsingService(coord.Service): try: self.publisher = 'vitrage-snmp-parsing' self.oslo_notifier = oslo_messaging.Notifier( - get_transport(self.conf), + get_transport(), driver='messagingv2', publisher_id=self.publisher, topics=['vitrage_notifications']) diff --git a/vitrage/storage/__init__.py b/vitrage/storage/__init__.py index 8e8edca42..0a8f11663 100644 --- a/vitrage/storage/__init__.py +++ b/vitrage/storage/__init__.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg from oslo_log import log import six.moves.urllib.parse as urlparse from stevedore import driver @@ -21,16 +22,16 @@ from vitrage.utils.datetime import utcnow _NAMESPACE = 'vitrage.storage' - +CONF = cfg.CONF LOG = log.getLogger(__name__) OPTS = [] -def get_connection_from_config(conf): - retries = conf.database.max_retries - url = conf.database.connection +def get_connection_from_config(): + retries = CONF.database.max_retries + url = CONF.database.connection try: # TOTO(iafek): check why this call randomly fails @@ -44,12 +45,12 @@ def get_connection_from_config(conf): return None @tenacity.retry( - wait=tenacity.wait_fixed(conf.database.retry_interval), + wait=tenacity.wait_fixed(CONF.database.retry_interval), stop=tenacity.stop_after_attempt(retries if retries >= 0 else 5), reraise=True) def _get_connection(): """Return an open connection to the database.""" - return mgr.driver(conf, url) + return mgr.driver(url) return _get_connection() diff --git a/vitrage/storage/base.py b/vitrage/storage/base.py index 1bfb72255..230b72edd 100644 --- a/vitrage/storage/base.py +++ b/vitrage/storage/base.py @@ -20,7 +20,7 @@ import six class Connection(object): """Base class for storage system connections.""" - def __init__(self, conf, url): + def __init__(self, url): pass @property diff --git a/vitrage/storage/impl_sqlalchemy.py b/vitrage/storage/impl_sqlalchemy.py index 73782fa43..8816f264b 100644 --- a/vitrage/storage/impl_sqlalchemy.py +++ b/vitrage/storage/impl_sqlalchemy.py @@ -15,6 +15,7 @@ from __future__ import absolute_import +from oslo_config import cfg from oslo_db.sqlalchemy import session as db_session from oslo_log import log from sqlalchemy import and_, or_ @@ -30,12 +31,13 @@ from vitrage.storage.history_facade import HistoryFacadeConnection from vitrage.storage.sqlalchemy import models from vitrage.storage.sqlalchemy.models import Template +CONF = cfg.CONF LOG = log.getLogger(__name__) class Connection(base.Connection): - def __init__(self, conf, url): - options = dict(conf.database.items()) + def __init__(self, url): + options = dict(CONF.database.items()) # set retries to 0 , since reconnection is already implemented # in storage.__init__.get_connection_from_config function options['max_retries'] = 0 @@ -44,7 +46,6 @@ class Connection(base.Connection): options.pop(opt.name, None) self._engine_facade = db_session.EngineFacade(self._dress_url(url), **options) - self.conf = conf self._active_actions = ActiveActionsConnection(self._engine_facade) self._events = EventsConnection(self._engine_facade) self._templates = TemplatesConnection(self._engine_facade) diff --git a/vitrage/tests/base.py b/vitrage/tests/base.py index 8b22bf340..d1aae686f 100644 --- a/vitrage/tests/base.py +++ b/vitrage/tests/base.py @@ -15,6 +15,8 @@ import logging import os +from oslo_config import cfg +from oslo_config import fixture as config_fixture from oslo_utils import timeutils # noinspection PyPackageRequirements from oslotest import base @@ -23,13 +25,40 @@ import sys from testtools import matchers from testtools.matchers import HasLength +from vitrage.common import config +CONF = cfg.CONF IsEmpty = lambda: HasLength(0) class BaseTest(base.BaseTestCase): """Test case base class for all unit tests.""" + def conf_reregister_opts(self, opts, group=None): + self.conf.reset() + if group in self.conf: + for opt in opts: + self.conf.unregister_opt(opt, group=group) + self.conf.register_opts(opts, group=group) + + def unregister_opts(): + self.conf.reset() + for opt in opts: + self.conf.unregister_opt(opt, group=group) + + self.addCleanup(unregister_opts) + + def setUp(self): + super(BaseTest, self).setUp() + self.cfg_fixture = self.useFixture( + config_fixture.Config(CONF)) + config.parse_config([]) + logging.disable(logging.CRITICAL) + self.conf = self.cfg_fixture.conf + + def config(self, **kw): + self.cfg_fixture.config(**kw) + def assert_list_equal(self, l1, l2, message=None): if tuple(sys.version_info)[0:2] < (2, 7): # for python 2.6 compatibility @@ -108,7 +137,3 @@ class BaseTest(base.BaseTestCase): return os.path.join(root, project_file) else: return root - - def setUp(self): - logging.disable(logging.CRITICAL) - super(BaseTest, self).setUp() diff --git a/vitrage/tests/functional/api/__init__.py b/vitrage/tests/functional/api/__init__.py index 2f361bd4c..ea7512ed6 100644 --- a/vitrage/tests/functional/api/__init__.py +++ b/vitrage/tests/functional/api/__init__.py @@ -18,13 +18,10 @@ """ import os -from oslo_config import fixture as fixture_config import sys import webtest from vitrage.api import app -from vitrage import service - from vitrage.tests import base @@ -37,28 +34,24 @@ class FunctionalTest(base.BaseTest): PATH_PREFIX = '' - # noinspection PyAttributeOutsideInit def setUp(self): super(FunctionalTest, self).setUp() - conf = service.prepare_service(args=[], config_files=[]) - self.CONF = self.useFixture(fixture_config.Config(conf)).conf vitrage_init_file = sys.modules['vitrage'].__file__ vitrage_root = os.path.abspath( os.path.join(os.path.dirname(vitrage_init_file), '..', )) - self.CONF.set_override('paste_config', os.path.join(vitrage_root, + self.conf.set_override('paste_config', os.path.join(vitrage_root, 'etc', 'vitrage', 'api-paste.ini'), group='api') - self.CONF.set_override('auth_mode', self.auth, group='api') + self.conf.set_override('auth_mode', self.auth, group='api') - self.CONF.set_override('connection', - 'sqlite:///test.db', + self.conf.set_override('connection', 'sqlite:///test.db', group='database') - self.app = webtest.TestApp(app.load_app(self.CONF)) + self.app = webtest.TestApp(app.load_app()) def put_json(self, path, params, expect_errors=False, headers=None, extra_environ=None, status=None): diff --git a/vitrage/tests/functional/api/v1/test_keycloak.py b/vitrage/tests/functional/api/v1/test_keycloak.py index 852a7a207..595611120 100644 --- a/vitrage/tests/functional/api/v1/test_keycloak.py +++ b/vitrage/tests/functional/api/v1/test_keycloak.py @@ -85,7 +85,7 @@ class KeycloakTest(FunctionalTest): req_mock.get(OPENID_CONNECT_USERINFO) req = self._build_request() - auth = KeycloakAuth(mock.Mock(), self.CONF) + auth = KeycloakAuth(mock.Mock(), self.conf) auth.process_request(req) self.assertEqual('Confirmed', req.headers['X-Identity-Status']) diff --git a/vitrage/tests/functional/api/v1/test_service.py b/vitrage/tests/functional/api/v1/test_service.py index 04a839d5b..baf992984 100644 --- a/vitrage/tests/functional/api/v1/test_service.py +++ b/vitrage/tests/functional/api/v1/test_service.py @@ -59,8 +59,12 @@ class ServiceTest(FunctionalTest): # NOTE(eyalb) we want to force coordinator to be initialized with a # custom name otherwise it will take the command line string as a name name = 'vitrage' + + def mock_coordinator(): + return Coordinator(name) + with mock.patch('vitrage.coordination.coordination.Coordinator', - new=lambda _: Coordinator(self.CONF, name)): + new=mock_coordinator): self._use_zake_as_backend() data = self.get_json('/service/') @@ -80,5 +84,6 @@ class ServiceTest(FunctionalTest): # noinspection PyAttributeOutsideInit def _use_zake_as_backend(self): - self.CONF.set_override('backend_url', 'zake://', 'coordination') - self.app = webtest.TestApp(app.load_app(self.CONF)) + self.conf.set_override('backend_url', 'zake://', 'coordination') + + self.app = webtest.TestApp(app.load_app()) diff --git a/vitrage/tests/functional/api_handler/test_apis.py b/vitrage/tests/functional/api_handler/test_apis.py index 82d28fa6a..3150b1b4a 100755 --- a/vitrage/tests/functional/api_handler/test_apis.py +++ b/vitrage/tests/functional/api_handler/test_apis.py @@ -17,8 +17,6 @@ import threading from testtools import matchers -from oslo_config import cfg - from vitrage.api_handler.apis.alarm import AlarmApis from vitrage.api_handler.apis.rca import RcaApis from vitrage.api_handler.apis.resource import ResourceApis @@ -49,17 +47,15 @@ from vitrage.utils.datetime import utcnow class TestApis(TestEntityGraphUnitBase, TestConfiguration): - @classmethod - def setUpClass(cls): - super(TestApis, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.add_db(cls.conf) - cls.api_lock = threading.RLock() + def setUp(self): + super(TestApis, self).setUp() + self.add_db() + self.api_lock = threading.RLock() def test_get_alarms_with_admin_project(self): # Setup graph = self._create_graph() - apis = AlarmApis(graph, self.conf, self.api_lock, self._db) + apis = AlarmApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_1', 'is_admin': True} # Action @@ -73,7 +69,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_alarms_with_not_admin_project(self): # Setup graph = self._create_graph() - apis = AlarmApis(graph, self.conf, self.api_lock, self._db) + apis = AlarmApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -87,7 +83,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_alarm_counts_with_not_admin_project(self): # Setup graph = self._create_graph() - apis = AlarmApis(graph, self.conf, self.api_lock, self._db) + apis = AlarmApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -104,7 +100,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_alarms_with_all_tenants(self): # Setup graph = self._create_graph() - apis = AlarmApis(graph, self.conf, self.api_lock, self._db) + apis = AlarmApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -118,7 +114,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_alarm_counts_with_all_tenants(self): # Setup graph = self._create_graph() - apis = AlarmApis(graph, self.conf, self.api_lock, self._db) + apis = AlarmApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -135,7 +131,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_rca_with_admin_project(self): # Setup graph = self._create_graph() - apis = RcaApis(graph, self.conf, self.api_lock, self._db) + apis = RcaApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_1', 'is_admin': True} # Action @@ -149,7 +145,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_rca_with_not_admin_project(self): # Setup graph = self._create_graph() - apis = RcaApis(graph, self.conf, self.api_lock, self._db) + apis = RcaApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -165,7 +161,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_rca_with_not_admin_bla_project(self): # Setup graph = self._create_graph() - apis = RcaApis(graph, self.conf, self.api_lock, self._db) + apis = RcaApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -179,7 +175,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_rca_with_all_tenants(self): # Setup graph = self._create_graph() - apis = RcaApis(graph, self.conf, self.api_lock, self._db) + apis = RcaApis(graph, self.api_lock, self._db) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -193,7 +189,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_topology_with_admin_project(self): # Setup graph = self._create_graph() - apis = TopologyApis(graph, None, self.api_lock) + apis = TopologyApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': True} # Action @@ -215,7 +211,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_topology_with_not_admin_project(self): # Setup graph = self._create_graph() - apis = TopologyApis(graph, None, self.api_lock) + apis = TopologyApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -237,7 +233,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_get_topology_with_all_tenants(self): # Setup graph = self._create_graph() - apis = TopologyApis(graph, None, self.api_lock) + apis = TopologyApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -256,7 +252,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_list_with_admin_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': True} # Action @@ -272,7 +268,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_list_with_admin_project_and_query(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': True} # Action @@ -289,7 +285,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_list_with_not_admin_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -305,7 +301,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_list_with_not_admin_project_and_no_existing_type(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -321,7 +317,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_list_with_not_admin_project_and_existing_type(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -337,7 +333,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_list_with_all_tenants(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -353,7 +349,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_admin_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': True} # Action @@ -372,7 +368,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_admin_project_and_query(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': True} # Action @@ -389,7 +385,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_not_admin_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -405,7 +401,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_not_admin_project_and_no_existing_type(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -421,7 +417,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_not_admin_project_and_existing_type(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -437,7 +433,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_all_tenants(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -456,7 +452,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_count_with_all_tenants_and_group_by(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -475,7 +471,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_show_with_admin_and_no_project_resource(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': True} # Action @@ -490,7 +486,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_show_with_not_admin_and_no_project_resource(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -502,7 +498,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_show_with_not_admin_and_resource_in_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action @@ -518,7 +514,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_show_with_not_admin_and_resource_in_other_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action @@ -530,7 +526,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_show_with_admin_and_resource_in_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': True} # Action @@ -546,7 +542,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration): def test_resource_show_with_admin_and_resource_in_other_project(self): # Setup graph = self._create_graph() - apis = ResourceApis(graph, None, self.api_lock) + apis = ResourceApis(graph, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': True} # Action diff --git a/vitrage/tests/functional/api_handler/test_templates.py b/vitrage/tests/functional/api_handler/test_templates.py index 021597570..7a5d4d875 100644 --- a/vitrage/tests/functional/api_handler/test_templates.py +++ b/vitrage/tests/functional/api_handler/test_templates.py @@ -13,7 +13,6 @@ # under the License. import json -from oslo_config import cfg from testtools import matchers from vitrage.api_handler.apis.template import TemplateApis @@ -31,13 +30,11 @@ class TestTemplates(TestEntityGraphUnitBase, TestConfiguration): def notify(self, event_type, data): pass - @classmethod - def setUpClass(cls): - super(TestTemplates, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.add_db(cls.conf) - cls.apis = TemplateApis(notifier=cls.MockNotifier(), db=cls._db) - cls.added_template = None + def setUp(self): + super(TestTemplates, self).setUp() + self.add_db() + self.apis = TemplateApis(notifier=self.MockNotifier(), db=self._db) + self.added_template = None def tearDown(self): super(TestTemplates, self).tearDown() diff --git a/vitrage/tests/functional/base.py b/vitrage/tests/functional/base.py index be03920c9..a13855b0e 100644 --- a/vitrage/tests/functional/base.py +++ b/vitrage/tests/functional/base.py @@ -20,11 +20,11 @@ from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase class TestFunctionalBase(TestEntityGraphUnitBase): - def _create_processor_with_graph(self, conf, processor=None): + def _create_processor_with_graph(self, processor=None): events = self._create_mock_events() if not processor: - processor = self.create_processor_and_graph(conf) + processor = self.create_processor_and_graph() for event in events: processor.process_event(event) diff --git a/vitrage/tests/functional/datasources/aodh/test_aodh.py b/vitrage/tests/functional/datasources/aodh/test_aodh.py index 7cc5f0c23..b53fc61ad 100644 --- a/vitrage/tests/functional/datasources/aodh/test_aodh.py +++ b/vitrage/tests/functional/datasources/aodh/test_aodh.py @@ -44,18 +44,20 @@ class TestAodhAlarms(TestDataSourcesBase): help='base path for data sources') ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestAodhAlarms, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestAodhAlarms, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + AODH_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE + ]) + self.load_datasources() def test_aodh_alarms_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py b/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py index c05b41acb..6220b4027 100644 --- a/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py +++ b/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py @@ -45,18 +45,19 @@ class TestCeilometerAlarms(TestDataSourcesBase): help='base path for data sources') ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestCeilometerAlarms, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestCeilometerAlarms, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + CEILOMETER_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE]) + self.load_datasources() def test_ceilometer_alarms_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py index d8eccde4b..679c0284b 100644 --- a/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py +++ b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py @@ -43,17 +43,21 @@ class TestCinderVolume(TestDataSourcesBase): ] # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestCinderVolume, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestCinderVolume, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + CINDER_VOLUME_DATASOURCE + ]) + self.load_datasources() def test_cinder_volume_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/datasources/collectd/test_collectd.py b/vitrage/tests/functional/datasources/collectd/test_collectd.py index 7f57e9ea6..2eaa25823 100644 --- a/vitrage/tests/functional/datasources/collectd/test_collectd.py +++ b/vitrage/tests/functional/datasources/collectd/test_collectd.py @@ -46,14 +46,16 @@ class TestCollectd(TestDataSourcesBase): help='base path for data sources') ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestCollectd, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestCollectd, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + COLLECTD_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE + ]) + self.load_datasources() def test_collectd_alarm_on_host(self): self._test_collectd_alarm(NOVA_HOST_DATASOURCE, 'host-2', 'host-2') @@ -63,7 +65,7 @@ class TestCollectd(TestDataSourcesBase): def _test_collectd_alarm(self, resource_type, resource_name, host_name): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/datasources/heat/test_heat_stack.py b/vitrage/tests/functional/datasources/heat/test_heat_stack.py index 952276f6a..32c588790 100644 --- a/vitrage/tests/functional/datasources/heat/test_heat_stack.py +++ b/vitrage/tests/functional/datasources/heat/test_heat_stack.py @@ -42,18 +42,20 @@ class TestHeatStack(TestDataSourcesBase): help='base path for data sources') ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestHeatStack, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestHeatStack, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + HEAT_STACK_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + CINDER_VOLUME_DATASOURCE]) + self.load_datasources() def test_heat_stack_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/datasources/listener_service/test_listener_service.py b/vitrage/tests/functional/datasources/listener_service/test_listener_service.py index 71830f403..97e43c4f1 100644 --- a/vitrage/tests/functional/datasources/listener_service/test_listener_service.py +++ b/vitrage/tests/functional/datasources/listener_service/test_listener_service.py @@ -35,10 +35,6 @@ class MyTestDriver(DriverBase): class TestListenerService(base.BaseTest): - @classmethod - def setUpClass(cls): - super(TestListenerService, cls).setUpClass() - def _add_event_to_actual_events(self, events): self.actual_events.extend(events) @@ -62,7 +58,6 @@ class TestListenerService(base.BaseTest): my_test_driver = MyTestDriver() enrich_callbacks_by_events = {"mock": [my_test_driver.enrich_event]} endpoint = DriversNotificationEndpoint( - None, self._add_event_to_actual_events) endpoint._enrich_event_methods = enrich_callbacks_by_events diff --git a/vitrage/tests/functional/datasources/nagios/test_nagios.py b/vitrage/tests/functional/datasources/nagios/test_nagios.py index a3079bc63..b7b2f02a3 100644 --- a/vitrage/tests/functional/datasources/nagios/test_nagios.py +++ b/vitrage/tests/functional/datasources/nagios/test_nagios.py @@ -42,18 +42,20 @@ class TestNagios(TestDataSourcesBase): help='base path for data sources') ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestNagios, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestNagios, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE + ]) + self.load_datasources() def test_nagios_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/datasources/nova/test_nova_datasources.py b/vitrage/tests/functional/datasources/nova/test_nova_datasources.py index 67e11d1a2..7dc05071e 100644 --- a/vitrage/tests/functional/datasources/nova/test_nova_datasources.py +++ b/vitrage/tests/functional/datasources/nova/test_nova_datasources.py @@ -12,25 +12,18 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg - from vitrage.tests.functional.datasources.base import \ TestDataSourcesBase class TestNovaDatasources(TestDataSourcesBase): - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestNovaDatasources, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestNovaDatasources, self).setUp() + self.load_datasources() def test_nova_datasources(self): - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertEqual(self._num_total_expected_vertices(), processor.entity_graph.num_vertices()) diff --git a/vitrage/tests/functional/datasources/trove/test_trove_instance.py b/vitrage/tests/functional/datasources/trove/test_trove_instance.py index 70cae9f25..1e8fc9ff5 100644 --- a/vitrage/tests/functional/datasources/trove/test_trove_instance.py +++ b/vitrage/tests/functional/datasources/trove/test_trove_instance.py @@ -43,18 +43,15 @@ class TestTroveInstance(TestDataSourcesBase): help='Base path for data sources') ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestTroveInstance, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestTroveInstance, self).setUp() + self.conf.register_opts(self.PROCESSOR_OPTS, group='entity_graph') + self.conf.register_opts(self.DATASOURCES_OPTS, group='datasources') + self.load_datasources() def test_trove_instance_validity(self): # Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertThat(processor.entity_graph, matchers.HasLength( self._num_total_expected_vertices()) diff --git a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py index e098b4da4..56421614e 100644 --- a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py +++ b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py @@ -56,21 +56,16 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): ), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestConsistencyFunctional, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - 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.DATASOURCES_OPTS, group='datasources') - cls.add_db(cls.conf) - cls.load_datasources(cls.conf) - cls.graph = NXGraph("Entity Graph") - cls.processor = Processor(cls.conf, cls.graph) + def setUp(self): + super(TestConsistencyFunctional, self).setUp() + self.conf_reregister_opts(self.CONSISTENCY_OPTS, 'consistency') + self.conf_reregister_opts(self.EVALUATOR_OPTS, 'evaluator') + self.add_db() + self.load_datasources() + self.graph = NXGraph("Entity Graph") + self.processor = Processor(self.graph) - cls.event_queue = queue.Queue() + self.event_queue = queue.Queue() def actions_callback(event_type, data): """Mock notify method @@ -80,16 +75,14 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): :param event_type: is currently always the same and is ignored :param data: """ - cls.event_queue.put(data) + self.event_queue.put(data) - scenario_repo = ScenarioRepository(cls.conf) - cls.evaluator = ScenarioEvaluator(cls.conf, - cls.processor.entity_graph, - scenario_repo, - actions_callback) - cls.consistency_enforcer = ConsistencyEnforcer( - cls.conf, - cls.processor.entity_graph, + scenario_repo = ScenarioRepository() + self.evaluator = ScenarioEvaluator(self.processor.entity_graph, + scenario_repo, + actions_callback) + self.consistency_enforcer = ConsistencyEnforcer( + self.processor.entity_graph, actions_callback) def test_periodic_process(self): @@ -206,7 +199,7 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): matchers.HasLength(num_marked_deleted)) def _periodic_process_setup_stage(self, consistency_interval): - self._create_processor_with_graph(self.conf, processor=self.processor) + self._create_processor_with_graph(processor=self.processor) current_time = utcnow() # set all vertices to be have timestamp that consistency won't get diff --git a/vitrage/tests/functional/entity_graph/graph_persistor/test_graph_persistor.py b/vitrage/tests/functional/entity_graph/graph_persistor/test_graph_persistor.py index 43179f419..23c47ac3e 100644 --- a/vitrage/tests/functional/entity_graph/graph_persistor/test_graph_persistor.py +++ b/vitrage/tests/functional/entity_graph/graph_persistor/test_graph_persistor.py @@ -11,7 +11,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from vitrage.common.constants import EdgeProperties from vitrage.common.constants import VertexProperties @@ -25,20 +24,16 @@ from vitrage.tests.mocks.graph_generator import GraphGenerator class TestGraphPersistor(TestFunctionalBase, TestConfiguration): - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestGraphPersistor, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.add_db(cls.conf) - cls.load_datasources(cls.conf) + def setUp(self): + super(TestGraphPersistor, self).setUp() + self.conf.register_opts(self.PROCESSOR_OPTS, group='entity_graph') + self.conf.register_opts(self.DATASOURCES_OPTS, group='datasources') + self.add_db() + self.load_datasources() def test_graph_store_and_query_recent_snapshot(self): g = GraphGenerator().create_graph() - graph_persistor = graph_persistency.GraphPersistency(self.conf, - self._db, g) + graph_persistor = graph_persistency.GraphPersistency(self._db, g) graph_persistor.store_graph() recovered_data = graph_persistor.query_recent_snapshot() recovered_graph = self.load_snapshot(recovered_data) @@ -47,8 +42,7 @@ class TestGraphPersistor(TestFunctionalBase, TestConfiguration): def test_event_store_and_replay_events(self): g = GraphGenerator().create_graph() vertices = g.get_vertices() - graph_persistor = graph_persistency.GraphPersistency(self.conf, - self._db, g) + graph_persistor = graph_persistency.GraphPersistency(self._db, g) self.fail_msg = None self.event_id = 1 diff --git a/vitrage/tests/functional/entity_graph/processor/test_processor.py b/vitrage/tests/functional/entity_graph/processor/test_processor.py index 37aafff19..dc9863836 100644 --- a/vitrage/tests/functional/entity_graph/processor/test_processor.py +++ b/vitrage/tests/functional/entity_graph/processor/test_processor.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg - from vitrage.tests.functional.base import \ TestFunctionalBase @@ -24,17 +22,12 @@ class TestProcessorFunctional(TestFunctionalBase): HOST_SPEC = 'HOST_SPEC' INSTANCE_SPEC = 'INSTANCE_SPEC' - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestProcessorFunctional, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestProcessorFunctional, self).setUp() + self.load_datasources() def test_create_entity_graph(self): - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() self.assertEqual(self._num_total_expected_vertices(), processor.entity_graph.num_vertices()) diff --git a/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py b/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py index a96c55876..17fd86dc4 100644 --- a/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py +++ b/vitrage/tests/functional/entity_graph/states/test_datasource_info_mapper.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg - from vitrage.common.constants import DatasourceAction as DSAction from vitrage.common.constants import GraphAction from vitrage.common.constants import VertexProperties as VProps @@ -24,18 +22,13 @@ from vitrage.tests.functional.base import TestFunctionalBase class TestDatasourceInfoMapperFunctional(TestFunctionalBase): - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestDatasourceInfoMapperFunctional, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) + def setUp(self): + super(TestDatasourceInfoMapperFunctional, self).setUp() + self.load_datasources() def test_state_on_update(self): # setup - processor = self.create_processor_and_graph(self.conf) + processor = self.create_processor_and_graph() event = self._create_event(spec_type='INSTANCE_SPEC', datasource_action=DSAction.INIT_SNAPSHOT) diff --git a/vitrage/tests/functional/evaluator/test_action_executor.py b/vitrage/tests/functional/evaluator/test_action_executor.py index c60a85aa8..e17f91bf3 100644 --- a/vitrage/tests/functional/evaluator/test_action_executor.py +++ b/vitrage/tests/functional/evaluator/test_action_executor.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from six.moves import queue from vitrage.common.constants import DatasourceAction @@ -48,17 +47,12 @@ from vitrage.tests.functional.test_configuration import TestConfiguration class TestActionExecutor(TestFunctionalBase, TestConfiguration): - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestActionExecutor, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.add_db(cls.conf) + def setUp(self): + super(TestActionExecutor, self).setUp() + self.add_db() - for vitrage_type in cls.conf.datasources.types: - register_opts(cls.conf, vitrage_type, cls.conf.datasources.path) + for datasource_name in self.conf.datasources.types: + register_opts(datasource_name, self.conf.datasources.path) def _init_executer(self): event_queue = queue.Queue() @@ -66,12 +60,12 @@ class TestActionExecutor(TestFunctionalBase, TestConfiguration): def actions_callback(event_type, data): event_queue.put(data) - return event_queue, ActionExecutor(self.conf, actions_callback) + return event_queue, ActionExecutor(actions_callback) def test_execute_set_state(self): # Test Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -123,7 +117,7 @@ class TestActionExecutor(TestFunctionalBase, TestConfiguration): def test_execute_mark_instance_down(self): # Test Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_INSTANCE_DATASOURCE} instance_vertices = processor.entity_graph.get_vertices( @@ -161,7 +155,7 @@ class TestActionExecutor(TestFunctionalBase, TestConfiguration): def test_execute_mark_down(self): # Test Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -199,7 +193,7 @@ class TestActionExecutor(TestFunctionalBase, TestConfiguration): def test_execute_add_edge(self): # Test Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -248,7 +242,7 @@ class TestActionExecutor(TestFunctionalBase, TestConfiguration): def test_execute_add_vertex(self): # Test Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( @@ -307,7 +301,7 @@ class TestActionExecutor(TestFunctionalBase, TestConfiguration): def test_execute_add_and_remove_vertex(self): # Test Setup - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE} host_vertices = processor.entity_graph.get_vertices( diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index a2091251d..0b60f1897 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -71,18 +71,15 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): ), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestScenarioEvaluator, cls).setUpClass() - 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.DATASOURCES_OPTS, group='datasources') - cls.add_db(cls.conf) - cls.add_templates(cls.conf.evaluator.templates_dir) - TestScenarioEvaluator.load_datasources(cls.conf) - cls.scenario_repository = ScenarioRepository(cls.conf) + def setUp(self): + super(TestScenarioEvaluator, self).setUp() + self.conf.register_opts(self.EVALUATOR_OPTS, group='evaluator') + templates_dir = utils.get_resources_dir() + \ + '/templates/evaluator' + self.add_db() + self.add_templates(templates_dir) + self.load_datasources() + self.scenario_repository = ScenarioRepository() def test_deduced_state(self): @@ -1348,7 +1345,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): return host_v def _init_system(self): - processor = self._create_processor_with_graph(self.conf) + processor = self._create_processor_with_graph() event_queue = queue.Queue() def actions_callback(event_type, data): @@ -1361,8 +1358,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): """ event_queue.put(data) - evaluator = ScenarioEvaluator(self.conf, - processor.entity_graph, + evaluator = ScenarioEvaluator(processor.entity_graph, self.scenario_repository, actions_callback, enabled=True) diff --git a/vitrage/tests/functional/test_configuration.py b/vitrage/tests/functional/test_configuration.py index c7b4c88d0..dfbf701fd 100644 --- a/vitrage/tests/functional/test_configuration.py +++ b/vitrage/tests/functional/test_configuration.py @@ -15,8 +15,6 @@ import os import sys import yaml -from oslo_db.options import database_opts - from vitrage.common.constants import TemplateStatus from vitrage.common.constants import TemplateTypes as TType from vitrage.evaluator.template_db.template_repository import \ @@ -27,29 +25,26 @@ from vitrage.storage.sqlalchemy import models class TestConfiguration(object): - @classmethod - def add_db(cls, conf): - conf.register_opts(database_opts, group='database') - db_name = "sqlite:///test-%s-%s.db" % (cls.__name__, + def add_db(self): + db_name = "sqlite:///test-%s-%s.db" % (type(self).__name__, sys.version_info[0]) - conf.set_override('connection', db_name, group='database') - cls._db = storage.get_connection_from_config(conf) - engine = cls._db._engine_facade.get_engine() + self.config(group='database', connection=db_name) + self._db = storage.get_connection_from_config() + engine = self._db._engine_facade.get_engine() models.Base.metadata.drop_all(engine) models.Base.metadata.create_all(engine) - return cls._db + return self._db - @classmethod - def add_templates(cls, templates_dir, templates_type=TType.STANDARD): + def add_templates(self, templates_dir, templates_type=TType.STANDARD): yamls = [t for t in TestConfiguration.load_yaml_files(templates_dir)] - templates = add_templates_to_db(cls._db, yamls, templates_type) + templates = add_templates_to_db(self._db, yamls, templates_type) for t in templates: if t.status == TemplateStatus.LOADING: - cls._db.templates.update(t.uuid, 'status', - TemplateStatus.ACTIVE) + self._db.templates.update(t.uuid, 'status', + TemplateStatus.ACTIVE) if t.status == TemplateStatus.DELETING: - cls._db.templates.update(t.uuid, 'status', - TemplateStatus.DELETED) + self._db.templates.update(t.uuid, 'status', + TemplateStatus.DELETED) return templates @staticmethod diff --git a/vitrage/tests/mocks/mock_graph_datasource/driver.py b/vitrage/tests/mocks/mock_graph_datasource/driver.py index aaf255d59..0e56e2a01 100644 --- a/vitrage/tests/mocks/mock_graph_datasource/driver.py +++ b/vitrage/tests/mocks/mock_graph_datasource/driver.py @@ -11,8 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from oslo_log import log +from oslo_config import cfg +from oslo_log import log from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.static.driver import StaticDriver @@ -20,14 +21,15 @@ from vitrage.datasources.static import StaticFields from vitrage.tests.mocks.graph_generator import GraphGenerator from vitrage.tests.mocks.mock_graph_datasource import MOCK_DATASOURCE +CONF = cfg.CONF LOG = log.getLogger(__name__) class MockDriver(StaticDriver): - def __init__(self, conf): + def __init__(self): super(StaticDriver, self).__init__() - mock_cfg = conf.mock_graph_datasource + mock_cfg = CONF.mock_graph_datasource e_graph = GraphGenerator( networks=mock_cfg.networks, zones_per_cluster=mock_cfg.zones_per_cluster, diff --git a/vitrage/tests/mocks/mock_graph_datasource/transformer.py b/vitrage/tests/mocks/mock_graph_datasource/transformer.py index 638a51ff6..7e76e11ae 100644 --- a/vitrage/tests/mocks/mock_graph_datasource/transformer.py +++ b/vitrage/tests/mocks/mock_graph_datasource/transformer.py @@ -20,8 +20,8 @@ LOG = logging.getLogger(__name__) class MockTransformer(StaticTransformer): - def __init__(self, transformers, conf): - super(MockTransformer, self).__init__(transformers, conf) + def __init__(self, transformers): + super(MockTransformer, self).__init__(transformers) def _create_vertex(self, entity_event): vertex = super(MockTransformer, self)._create_vertex(entity_event) diff --git a/vitrage/tests/unit/datasources/aodh/mock_driver.py b/vitrage/tests/unit/datasources/aodh/mock_driver.py index 7d0a505d8..5edd52891 100644 --- a/vitrage/tests/unit/datasources/aodh/mock_driver.py +++ b/vitrage/tests/unit/datasources/aodh/mock_driver.py @@ -20,8 +20,5 @@ class MockAodhDriver(AodhDriver): """ - def __init__(self, conf): - super(MockAodhDriver, self).__init__(conf) - def _cache_all_alarms(self): pass diff --git a/vitrage/tests/unit/datasources/aodh/test_aodh_driver.py b/vitrage/tests/unit/datasources/aodh/test_aodh_driver.py index eda60c0e8..cf8dd8f70 100644 --- a/vitrage/tests/unit/datasources/aodh/test_aodh_driver.py +++ b/vitrage/tests/unit/datasources/aodh/test_aodh_driver.py @@ -42,7 +42,7 @@ class AodhDriverTest(base.BaseTest): def test_event_alarm_notifications(self): - aodh_driver = MockAodhDriver(self.conf) + aodh_driver = MockAodhDriver() # 1. alarm creation with 'ok' state # prepare data @@ -183,7 +183,7 @@ class AodhDriverTest(base.BaseTest): self.assertIsNone(entity) def test_gnocchi_threshold_alarm_notifications(self): - aodh_driver = MockAodhDriver(self.conf) + aodh_driver = MockAodhDriver() # 1. alarm creation with 'ok' state # prepare data @@ -314,7 +314,7 @@ class AodhDriverTest(base.BaseTest): self.assertIsNone(entity) def test_gnocchi_aggregation_by_metrics_alarm_notifications(self): - aodh_driver = MockAodhDriver(self.conf) + aodh_driver = MockAodhDriver() # 1. alarm creation with 'ok' state # prepare data @@ -448,7 +448,7 @@ class AodhDriverTest(base.BaseTest): self.assertIsNone(entity) def test_gnocchi_aggregation_by_resource_alarm_notifications(self): - aodh_driver = MockAodhDriver(self.conf) + aodh_driver = MockAodhDriver() # 1. alarm creation with 'ok' state # prepare data @@ -583,7 +583,7 @@ class AodhDriverTest(base.BaseTest): self.assertIsNone(entity) def test_composite_alarm_notifications(self): - aodh_driver = MockAodhDriver(self.conf) + aodh_driver = MockAodhDriver() # 1. alarm creation with 'ok' state # prepare data diff --git a/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py b/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py index 60b4eb14d..07f3a9964 100644 --- a/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py +++ b/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py @@ -45,7 +45,7 @@ class TestAodhAlarmTransformer(AodhTransformerBaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=AODH_DATASOURCE) cls.transformers[AODH_DATASOURCE] = \ - AodhTransformer(cls.transformers, cls.conf) + AodhTransformer(cls.transformers) def test_key_values_with_vitrage_alarm(self): LOG.debug('Aodh transformer test: get key values(vitrage_alarm)') @@ -126,7 +126,7 @@ class TestAodhAlarmPushTransformer(AodhTransformerBaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=AODH_DATASOURCE) cls.transformers[AODH_DATASOURCE] = \ - AodhTransformer(cls.transformers, cls.conf) + AodhTransformer(cls.transformers) def test_update_transform(self): LOG.debug('Aodh update alarm transformer test:' diff --git a/vitrage/tests/unit/datasources/ceilometer/mock_driver.py b/vitrage/tests/unit/datasources/ceilometer/mock_driver.py index fdf009843..0d596aa4a 100644 --- a/vitrage/tests/unit/datasources/ceilometer/mock_driver.py +++ b/vitrage/tests/unit/datasources/ceilometer/mock_driver.py @@ -20,8 +20,5 @@ class MockCeilometerDriver(CeilometerDriver): """ - def __init__(self, conf): - super(MockCeilometerDriver, self).__init__(conf) - def _cache_all_alarms(self): pass diff --git a/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_driver.py b/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_driver.py index 37289a447..c61a9347c 100644 --- a/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_driver.py +++ b/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_driver.py @@ -43,7 +43,7 @@ class CeilometerDriverTest(base.BaseTest): def test_event_alarm_notifications(self): - aodh_driver = MockCeilometerDriver(self.conf) + aodh_driver = MockCeilometerDriver() # 1. alarm creation with 'ok' state # prepare data @@ -188,7 +188,7 @@ class CeilometerDriverTest(base.BaseTest): self.assertIsNone(entity) def test_gnocchi_threshold_alarm_notifications(self): - aodh_driver = MockCeilometerDriver(self.conf) + aodh_driver = MockCeilometerDriver() # 1. alarm creation with 'ok' state # prepare data diff --git a/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py b/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py index 6a919363c..3d26a2a96 100644 --- a/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py +++ b/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py @@ -48,7 +48,7 @@ class TestCeilometerAlarmTransformer(CeilometerTransformerBaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=CEILOMETER_DATASOURCE) cls.transformers[CEILOMETER_DATASOURCE] = \ - CeilometerTransformer(cls.transformers, cls.conf) + CeilometerTransformer(cls.transformers) def test_key_values_with_vitrage_alarm(self): LOG.debug('Ceilometer transformer test: ' @@ -130,7 +130,7 @@ class TestCeilometerAlarmPushTransformer(CeilometerTransformerBaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=CEILOMETER_DATASOURCE) cls.transformers[CEILOMETER_DATASOURCE] = \ - CeilometerTransformer(cls.transformers, cls.conf) + CeilometerTransformer(cls.transformers) def test_update_transform(self): LOG.debug('Ceilometer update alarm transformer test:' diff --git a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py index e419e134f..5b1c57294 100644 --- a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py +++ b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py @@ -54,9 +54,9 @@ class TestCinderVolumeTransformer(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=CINDER_VOLUME_DATASOURCE) cls.transformers[CINDER_VOLUME_DATASOURCE] = \ - CinderVolumeTransformer(cls.transformers, cls.conf) + CinderVolumeTransformer(cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ - InstanceTransformer(cls.transformers, cls.conf) + InstanceTransformer(cls.transformers) def test_create_placeholder_vertex(self): LOG.debug('Cinder Volume transformer test: Create placeholder ' diff --git a/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py b/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py index 946d74bdf..8aed5fa49 100644 --- a/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py +++ b/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py @@ -43,7 +43,7 @@ class TestCollectdDriver(base.BaseTest): # noinspection PyAttributeOutsideInit def setUp(self): super(TestCollectdDriver, self).setUp() - self.driver = CollectdDriver(self.conf) + self.driver = CollectdDriver() def test_enrich_event_with_alarm_up(self): now = datetime.now().isoformat() diff --git a/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py b/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py index 3d7a188e5..34effdd8c 100644 --- a/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py +++ b/vitrage/tests/unit/datasources/collectd/test_collectd_transformer.py @@ -41,18 +41,13 @@ class TestCollectdTransformer(BaseAlarmTransformerTest): default=UpdateMethod.PUSH), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestCollectdTransformer, cls).setUpClass() - cls.transformers = {} - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=COLLECTD_DATASOURCE) - cls.conf.register_opts(cls.OPTS, group=NOVA_HOST_DATASOURCE) - cls.transformers[COLLECTD_DATASOURCE] = \ - CollectdTransformer(cls.transformers, cls.conf) - cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + def setUp(self): + super(TestCollectdTransformer, self).setUp() + self.transformers = {} + self.transformers[COLLECTD_DATASOURCE] = \ + CollectdTransformer(self.transformers) + self.transformers[NOVA_HOST_DATASOURCE] = \ + HostTransformer(self.transformers) def test_create_update_entity_vertex(self): # Test setup diff --git a/vitrage/tests/unit/datasources/consistency/test_consistency_transformer.py b/vitrage/tests/unit/datasources/consistency/test_consistency_transformer.py index 5a35233eb..70fd9950d 100644 --- a/vitrage/tests/unit/datasources/consistency/test_consistency_transformer.py +++ b/vitrage/tests/unit/datasources/consistency/test_consistency_transformer.py @@ -43,7 +43,7 @@ class TestConsistencyTransformer(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=CONSISTENCY_DATASOURCE) cls.transformers[CONSISTENCY_DATASOURCE] = \ - ConsistencyTransformer(cls.transformers, cls.conf) + ConsistencyTransformer(cls.transformers) cls.actions = [GraphAction.DELETE_ENTITY, GraphAction.REMOVE_DELETED_ENTITY] diff --git a/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py b/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py index c7391a5cf..bce7b9987 100644 --- a/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py +++ b/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py @@ -39,7 +39,7 @@ class DoctorDriverTest(base.BaseTest): def test_enrich_event(self): # Test setup - driver = DoctorDriver(self.conf) + driver = DoctorDriver() event_type = DoctorProps.HOST_DOWN time1 = datetime.now().isoformat() diff --git a/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py b/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py index 055579654..c10187a49 100644 --- a/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py +++ b/vitrage/tests/unit/datasources/doctor/test_doctor_transformer.py @@ -41,17 +41,14 @@ class DoctorTransformerTest(BaseAlarmTransformerTest): default=UpdateMethod.PUSH), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - cls.transformers = {} - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=DOCTOR_DATASOURCE) - cls.conf.register_opts(cls.OPTS, group=NOVA_HOST_DATASOURCE) - cls.transformers[DOCTOR_DATASOURCE] = \ - DoctorTransformer(cls.transformers, cls.conf) - cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + def setUp(self): + super(DoctorTransformerTest, self).setUp() + self.conf_reregister_opts(self.OPTS, group=DOCTOR_DATASOURCE) + self.transformers = {} + self.transformers[DOCTOR_DATASOURCE] = \ + DoctorTransformer(self.transformers) + self.transformers[NOVA_HOST_DATASOURCE] = \ + HostTransformer(self.transformers) def test_create_update_entity_vertex(self): # Test setup diff --git a/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py b/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py index 449668d38..6139bf491 100644 --- a/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py +++ b/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py @@ -54,11 +54,11 @@ class TestHeatStackTransformer(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=HEAT_STACK_DATASOURCE) cls.transformers[HEAT_STACK_DATASOURCE] = \ - HeatStackTransformer(cls.transformers, cls.conf) + HeatStackTransformer(cls.transformers) cls.transformers[CINDER_VOLUME_DATASOURCE] = \ - CinderVolumeTransformer(cls.transformers, cls.conf) + CinderVolumeTransformer(cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ - InstanceTransformer(cls.transformers, cls.conf) + InstanceTransformer(cls.transformers) def test_create_placeholder_vertex(self): LOG.debug('Heat Stack transformer test: Create placeholder vertex') diff --git a/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_configuration.py b/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_configuration.py index bd2d1b476..3f801d494 100644 --- a/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_configuration.py +++ b/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_configuration.py @@ -42,12 +42,9 @@ class TestKapacitorConfig(base.BaseTest): + '/kapacitor/kapacitor_conf.yaml'), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestKapacitorConfig, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=KAPACITOR_DATASOURCE) + def setUp(self): + super(TestKapacitorConfig, self).setUp() + self.conf_reregister_opts(self.OPTS, group=KAPACITOR_DATASOURCE) def test_get_vitrage_resource(self): """Test the resource returned after processing a list of mappings @@ -55,7 +52,7 @@ class TestKapacitorConfig(base.BaseTest): :return: """ # Action - kapacitor_conf = KapacitorConfig(self.conf) + kapacitor_conf = KapacitorConfig() # Test assertions mapped_resource = kapacitor_conf.get_vitrage_resource(None) diff --git a/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_driver.py b/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_driver.py index efabc6442..c520721f5 100644 --- a/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_driver.py +++ b/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_driver.py @@ -46,17 +46,10 @@ class TestKapacitorDriver(base.BaseTest): + '/kapacitor/kapacitor_conf.yaml'), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestKapacitorDriver, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=KAPACITOR_DATASOURCE) - - # noinspection PyAttributeOutsideInit def setUp(self): super(TestKapacitorDriver, self).setUp() - self.driver = KapacitorDriver(self.conf) + self.conf_reregister_opts(self.OPTS, group=KAPACITOR_DATASOURCE) + self.driver = KapacitorDriver() def test_enrich_event(self): # Test event on host diff --git a/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_transformer.py b/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_transformer.py index cd45c3c61..10f7ade74 100644 --- a/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_transformer.py +++ b/vitrage/tests/unit/datasources/kapacitor/test_kapacitor_transformer.py @@ -55,11 +55,11 @@ class TestKapacitorTransformer(BaseAlarmTransformerTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=KAPACITOR_DATASOURCE) cls.transformers[KAPACITOR_DATASOURCE] = \ - KapacitorTransformer(cls.transformers, cls.conf) + KapacitorTransformer(cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ - InstanceTransformer(cls.transformers, cls.conf) + InstanceTransformer(cls.transformers) cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + HostTransformer(cls.transformers) def test_create_entity_key(self): LOG.debug('Test get key from nova host transformer') @@ -73,7 +73,7 @@ class TestKapacitorTransformer(BaseAlarmTransformerTest): KProps.RESOURCE_NAME: resource_name} event = self._generate_event(update_vals) - transformer = KapacitorTransformer(self.transformers, self.conf) + transformer = KapacitorTransformer(self.transformers) self.assertIsNotNone(event) # Test action diff --git a/vitrage/tests/unit/datasources/kubernetes/test_kubernetes_transformer.py b/vitrage/tests/unit/datasources/kubernetes/test_kubernetes_transformer.py index b0d20c35a..02d74fa0e 100644 --- a/vitrage/tests/unit/datasources/kubernetes/test_kubernetes_transformer.py +++ b/vitrage/tests/unit/datasources/kubernetes/test_kubernetes_transformer.py @@ -58,9 +58,9 @@ class KubernetesTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=KUBERNETES_DATASOURCE) cls.transformers[KUBERNETES_DATASOURCE] = KubernetesTransformer( - cls.transformers, cls.conf) + cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ - InstanceTransformer(cls.transformers, cls.conf) + InstanceTransformer(cls.transformers) def test_snapshot_event_transform(self): LOG.debug('Test tactual transform action for ' diff --git a/vitrage/tests/unit/datasources/nagios/mock_driver.py b/vitrage/tests/unit/datasources/nagios/mock_driver.py index d09c98313..e0fd80652 100644 --- a/vitrage/tests/unit/datasources/nagios/mock_driver.py +++ b/vitrage/tests/unit/datasources/nagios/mock_driver.py @@ -30,8 +30,8 @@ class MockNagiosDriver(NagiosDriver): def enrich_event(self, event, event_type): pass - def __init__(self, conf): - super(MockNagiosDriver, self).__init__(conf) + def __init__(self): + super(MockNagiosDriver, self).__init__() self.service_datas = None def set_service_datas(self, service_datas): diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_config.py b/vitrage/tests/unit/datasources/nagios/test_nagios_config.py index dd47dab65..9e5b7e0eb 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_config.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_config.py @@ -78,16 +78,13 @@ class TestNagiosConfig(base.BaseTest): NON_EXISTING_MAPPING_2, NON_EXISTING_MAPPING_3] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestNagiosConfig, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=NAGIOS_DATASOURCE) + def setUp(self): + super(TestNagiosConfig, self).setUp() + self.conf_reregister_opts(self.OPTS, NAGIOS_DATASOURCE) def test_nagios_configuration_loading(self): # Action - nagios_conf = NagiosConfig(self.conf) + nagios_conf = NagiosConfig() # Test assertions mappings = nagios_conf.mappings @@ -147,7 +144,7 @@ class TestNagiosConfig(base.BaseTest): :return: """ # Action - nagios_conf = NagiosConfig(self.conf) + nagios_conf = NagiosConfig() # Test assertions mapped_resource = nagios_conf.get_vitrage_resource(None) diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py index 21ce2994c..6ba52b2a8 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py @@ -40,12 +40,9 @@ class NagiosDriverTest(NagiosBaseTest): ), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(NagiosDriverTest, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=NAGIOS_DATASOURCE) + def setUp(self): + super(NagiosDriverTest, self).setUp() + self.conf_reregister_opts(self.OPTS, NAGIOS_DATASOURCE) def test_get_all(self): """Check get_all functionality. @@ -55,7 +52,7 @@ class NagiosDriverTest(NagiosBaseTest): """ # Setup - nagios_driver = MockNagiosDriver(self.conf) + nagios_driver = MockNagiosDriver() # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -166,7 +163,7 @@ class NagiosDriverTest(NagiosBaseTest): """ # Setup - nagios_driver = MockNagiosDriver(self.conf) + nagios_driver = MockNagiosDriver() # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -291,7 +288,7 @@ class NagiosDriverTest(NagiosBaseTest): """Check get_changes and get_all functionalities """ # Setup - nagios_driver = MockNagiosDriver(self.conf) + nagios_driver = MockNagiosDriver() # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -448,7 +445,7 @@ class NagiosDriverTest(NagiosBaseTest): """Check get_all and get_changes with a deleted service""" # Setup - nagios_driver = MockNagiosDriver(self.conf) + nagios_driver = MockNagiosDriver() # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py index 769104a6b..cafe7c0f2 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py @@ -56,7 +56,7 @@ class NagiosTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=NAGIOS_DATASOURCE) cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + HostTransformer(cls.transformers) def test_create_entity_key(self): LOG.debug('Test get key from nova instance transformer') @@ -65,7 +65,7 @@ class NagiosTransformerTest(base.BaseTest): spec_list = mock_sync.simple_nagios_alarm_generators(host_num=1, events_num=1) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) - transformer = NagiosTransformer(self.transformers, self.conf) + transformer = NagiosTransformer(self.transformers) event = nagios_alarms[0] # Test action @@ -90,7 +90,7 @@ class NagiosTransformerTest(base.BaseTest): events_num=10) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) - transformer = NagiosTransformer(self.transformers, self.conf) + transformer = NagiosTransformer(self.transformers) for alarm in nagios_alarms: @@ -186,7 +186,7 @@ class NagiosTransformerTest(base.BaseTest): edge = neighbor.edge self.assertEqual(EdgeLabel.ON, edge.label) - alarm_key = NagiosTransformer(self.transformers, self.conf).\ + alarm_key = NagiosTransformer(self.transformers).\ _create_entity_key(event) alarm_uuid = cur_alarm_uuid if cur_alarm_uuid else\ TransformerBase.uuid_from_deprecated_vitrage_id(alarm_key) diff --git a/vitrage/tests/unit/datasources/nova/base_nova_instance_transformer.py b/vitrage/tests/unit/datasources/nova/base_nova_instance_transformer.py index 1b9ff57d9..56217afd6 100644 --- a/vitrage/tests/unit/datasources/nova/base_nova_instance_transformer.py +++ b/vitrage/tests/unit/datasources/nova/base_nova_instance_transformer.py @@ -55,9 +55,9 @@ class BaseNovaInstanceTransformerTest(base.BaseTest): cls.conf.register_opts(cls.OPTS, group=NOVA_INSTANCE_DATASOURCE) cls.conf.register_opts(cls._get_default_group_opts()) cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( - cls.transformers, cls.conf) + cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ - InstanceTransformer(cls.transformers, cls.conf) + InstanceTransformer(cls.transformers) def _test_create_placeholder_vertex(self): LOG.debug('Test create placeholder vertex') diff --git a/vitrage/tests/unit/datasources/nova/test_instance_transformer_legacy_notifications.py b/vitrage/tests/unit/datasources/nova/test_instance_transformer_legacy_notifications.py index 22113a69e..2429081c5 100644 --- a/vitrage/tests/unit/datasources/nova/test_instance_transformer_legacy_notifications.py +++ b/vitrage/tests/unit/datasources/nova/test_instance_transformer_legacy_notifications.py @@ -31,10 +31,10 @@ class NovaInstanceTransformerLegacyNotifTest( default=False), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(NovaInstanceTransformerLegacyNotifTest, cls).setUpClass() + def setUp(self): + super(NovaInstanceTransformerLegacyNotifTest, self).setUp() + self.cfg_fixture.config( + use_nova_versioned_notifications=False) def test_update_event_transform(self): LOG.debug('Test actual transform action for update events') diff --git a/vitrage/tests/unit/datasources/nova/test_instance_transformer_versioned_notifications.py b/vitrage/tests/unit/datasources/nova/test_instance_transformer_versioned_notifications.py index f4523879c..0f79a7927 100644 --- a/vitrage/tests/unit/datasources/nova/test_instance_transformer_versioned_notifications.py +++ b/vitrage/tests/unit/datasources/nova/test_instance_transformer_versioned_notifications.py @@ -31,11 +31,6 @@ class NovaInstanceTransformerVersionedNotifTest( default=True), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(NovaInstanceTransformerVersionedNotifTest, cls).setUpClass() - def test_update_event_transform(self): LOG.debug('Test tactual transform action for update events') diff --git a/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py index 89b82e845..01bc75ebb 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py @@ -54,9 +54,9 @@ class NovaHostTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=NOVA_HOST_DATASOURCE) cls.transformers[NOVA_ZONE_DATASOURCE] = ZoneTransformer( - cls.transformers, cls.conf) + cls.transformers) cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( - cls.transformers, cls.conf) + cls.transformers) def test_create_placeholder_vertex(self): LOG.debug('Nova host transformer test: Test create placeholder vertex') diff --git a/vitrage/tests/unit/datasources/nova/test_nova_instance_driver.py b/vitrage/tests/unit/datasources/nova/test_nova_instance_driver.py index b50d53c09..5c7df3f97 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_instance_driver.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_instance_driver.py @@ -32,20 +32,13 @@ class NovaHostTransformerTest(base.BaseTest): default=UpdateMethod.PUSH), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(NovaHostTransformerTest, cls).setUpClass() - def test_use_versioned_notifications(self): LOG.debug('Nova instance driver test') # Test setup - driver = InstanceDriver(cfg.ConfigOpts()) - driver.conf.register_opts([ - cfg.BoolOpt('use_nova_versioned_notifications', - default=True, required=True), - ]) + driver = InstanceDriver() + self.cfg_fixture.config( + use_nova_versioned_notifications=True) update_versioned_event, update_legacy_event = self._create_events() # Test action @@ -62,11 +55,9 @@ class NovaHostTransformerTest(base.BaseTest): LOG.debug('Nova instance driver test') # Test setup - driver = InstanceDriver(cfg.ConfigOpts()) - driver.conf.register_opts([ - cfg.BoolOpt('use_nova_versioned_notifications', - default=False, required=True), - ]) + driver = InstanceDriver() + self.cfg_fixture.config( + use_nova_versioned_notifications=False) update_versioned_event, update_legacy_event = self._create_events() # Test action diff --git a/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py index c93bbede3..be364ab92 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py @@ -53,9 +53,9 @@ class NovaZoneTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=NOVA_ZONE_DATASOURCE) cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + HostTransformer(cls.transformers) cls.transformers[NOVA_ZONE_DATASOURCE] = \ - ZoneTransformer(cls.transformers, cls.conf) + ZoneTransformer(cls.transformers) def test_create_placeholder_vertex(self): diff --git a/vitrage/tests/unit/datasources/prometheus/test_prometheus_driver.py b/vitrage/tests/unit/datasources/prometheus/test_prometheus_driver.py index 7b5e70f43..e205be397 100644 --- a/vitrage/tests/unit/datasources/prometheus/test_prometheus_driver.py +++ b/vitrage/tests/unit/datasources/prometheus/test_prometheus_driver.py @@ -43,11 +43,9 @@ class PrometheusDriverTest(base.BaseTest): default=utils.get_resources_dir() + CONFIG_PATH), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=PROMETHEUS_DATASOURCE) + def setUp(self): + super(PrometheusDriverTest, self).setUp() + self.conf_reregister_opts(self.OPTS, group=PROMETHEUS_DATASOURCE) @mock.patch('socket.gethostbyaddr') def test_adjust_label_value(self, mock_socket): @@ -55,7 +53,7 @@ class PrometheusDriverTest(base.BaseTest): # Test setup hostname = 'devstack-rocky-release-4' mock_socket.return_value = [hostname] - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() valid_ip = '127.0.0.1' not_ip = 'localhost' invalid_ip = '127.1' @@ -78,7 +76,7 @@ class PrometheusDriverTest(base.BaseTest): # Test setup hostname = 'devstack-rocky-release-4' mock_socket.return_value = [hostname] - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() alerts = self._generate_alerts() host_alert_1 = alerts[0] host_alert_2 = alerts[1] @@ -102,7 +100,7 @@ class PrometheusDriverTest(base.BaseTest): # Test setup hostname = 'devstack-rocky-release-4' mock_socket.return_value = [hostname] - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() alerts = self._generate_alerts() vm_alert_1 = alerts[2] vm_alert_2 = alerts[3] @@ -122,7 +120,7 @@ class PrometheusDriverTest(base.BaseTest): def test_get_resource_alert_values(self): # Test setup - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() alerts = self._generate_alerts() alert_1 = alerts[0] alert_2 = alerts[3] @@ -141,7 +139,7 @@ class PrometheusDriverTest(base.BaseTest): def test_get_conf_resource(self): # Test setup - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() alerts = self._generate_alerts() alert_1 = alerts[0] alert_2 = alerts[3] @@ -160,7 +158,7 @@ class PrometheusDriverTest(base.BaseTest): def test_validate_ip(self): # Test setup - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() ipv4_without_port = '1.1.1.1' ipv4_with_port = '1.1.1.1:1' invalid_ipv4 = '1.1' @@ -192,7 +190,7 @@ class PrometheusDriverTest(base.BaseTest): # Test setup mock_nova_client.servers.list.return_value = None mock_socket.return_value = ['devstack-rocky-release-4'] - driver = PrometheusDriver(self.conf) + driver = PrometheusDriver() event = self._generate_event() # Test Action diff --git a/vitrage/tests/unit/datasources/prometheus/test_prometheus_transformer.py b/vitrage/tests/unit/datasources/prometheus/test_prometheus_transformer.py index 6313be22f..887a1149f 100644 --- a/vitrage/tests/unit/datasources/prometheus/test_prometheus_transformer.py +++ b/vitrage/tests/unit/datasources/prometheus/test_prometheus_transformer.py @@ -46,18 +46,16 @@ class PrometheusTransformerTest(BaseAlarmTransformerTest): default=UpdateMethod.PUSH), ] - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - cls.transformers = {} - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=PROMETHEUS_DATASOURCE) - cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) - cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ - InstanceTransformer(cls.transformers, cls.conf) - cls.transformers[PROMETHEUS_DATASOURCE] = \ - PrometheusTransformer(cls.transformers, cls.conf) + def setUp(self): + super(PrometheusTransformerTest, self).setUp() + self.transformers = {} + self.conf_reregister_opts(self.OPTS, group=PROMETHEUS_DATASOURCE) + self.transformers[NOVA_HOST_DATASOURCE] = \ + HostTransformer(self.transformers) + self.transformers[NOVA_INSTANCE_DATASOURCE] = \ + InstanceTransformer(self.transformers) + self.transformers[PROMETHEUS_DATASOURCE] = \ + PrometheusTransformer(self.transformers) def test_create_update_entity_vertex(self): # Test setup diff --git a/vitrage/tests/unit/datasources/static/test_static_driver.py b/vitrage/tests/unit/datasources/static/test_static_driver.py index 75e9cc53e..380561d52 100644 --- a/vitrage/tests/unit/datasources/static/test_static_driver.py +++ b/vitrage/tests/unit/datasources/static/test_static_driver.py @@ -33,7 +33,7 @@ class TestStaticDriver(base.BaseTest): @classmethod def setUpClass(cls): super(TestStaticDriver, cls).setUpClass() - cls.static_driver = driver.StaticDriver(None) + cls.static_driver = driver.StaticDriver() def test_get_all(self): self._set_conf() @@ -209,6 +209,4 @@ class TestStaticDriver(base.BaseTest): cfg.StrOpt('directory', default=default_dir), ] - self.conf = cfg.ConfigOpts() - self.conf.register_opts(opts, group=STATIC_DATASOURCE) - self.static_driver.cfg = self.conf + self.conf_reregister_opts(opts, group=STATIC_DATASOURCE) diff --git a/vitrage/tests/unit/datasources/static/test_static_transformer.py b/vitrage/tests/unit/datasources/static/test_static_transformer.py index 73610a978..b5ea08529 100644 --- a/vitrage/tests/unit/datasources/static/test_static_transformer.py +++ b/vitrage/tests/unit/datasources/static/test_static_transformer.py @@ -45,10 +45,10 @@ class TestStaticTransformer(base.BaseTest): cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=STATIC_DATASOURCE) - cls.transformer = StaticTransformer(cls.transformers, cls.conf) + cls.transformer = StaticTransformer(cls.transformers) cls.transformers[STATIC_DATASOURCE] = cls.transformer cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + HostTransformer(cls.transformers) # noinspection PyAttributeOutsideInit def setUp(self): diff --git a/vitrage/tests/unit/datasources/test_datasource_update_method.py b/vitrage/tests/unit/datasources/test_datasource_update_method.py index 026badbfc..64bd6267c 100644 --- a/vitrage/tests/unit/datasources/test_datasource_update_method.py +++ b/vitrage/tests/unit/datasources/test_datasource_update_method.py @@ -144,24 +144,21 @@ class DatasourceUpdateMethod(base.BaseTest): ' data source'), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(DatasourceUpdateMethod, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.conf.register_opts(cls.NOVA_HOST_OPTS, group=NOVA_HOST_DATASOURCE) - cls.conf.register_opts(cls.NOVA_INSTANCE_OPTS, - group=NOVA_INSTANCE_DATASOURCE) - cls.conf.register_opts(cls.NAGIOS_OPTS, group=NAGIOS_DATASOURCE) - cls.conf.register_opts(cls.ZABBIX_OPTS_NONE, - group=ZABBIX_DATASOURCE_NONE) - cls.conf.register_opts(cls.ZABBIX_OPTS_PULL, - group=ZABBIX_DATASOURCE_PULL) - cls.conf.register_opts(cls.ZABBIX_OPTS_PUSH, - group=ZABBIX_DATASOURCE_PUSH) - cls.conf.register_opts(cls.ZABBIX_OPTS_PULL_NO_INTERVAL, - group=ZABBIX_DATASOURCE_PULL_NO_INTERVAL) + def setUp(self): + super(DatasourceUpdateMethod, self).setUp() + self.conf_reregister_opts(self.DATASOURCES_OPTS, 'datasources') + self.conf_reregister_opts(self.NOVA_HOST_OPTS, NOVA_HOST_DATASOURCE) + self.conf_reregister_opts(self.NOVA_INSTANCE_OPTS, + NOVA_INSTANCE_DATASOURCE) + self.conf_reregister_opts(self.NAGIOS_OPTS, NAGIOS_DATASOURCE) + self.conf_reregister_opts(self.ZABBIX_OPTS_NONE, + ZABBIX_DATASOURCE_NONE) + self.conf_reregister_opts(self.ZABBIX_OPTS_PULL, + ZABBIX_DATASOURCE_PULL) + self.conf_reregister_opts(self.ZABBIX_OPTS_PUSH, + ZABBIX_DATASOURCE_PUSH) + self.conf_reregister_opts(self.ZABBIX_OPTS_PULL_NO_INTERVAL, + ZABBIX_DATASOURCE_PULL_NO_INTERVAL) def test_datasource_update_method_none(self): none_drivers = tuple(driver for driver in self.conf.datasources.types @@ -172,15 +169,15 @@ class DatasourceUpdateMethod(base.BaseTest): ZABBIX_DATASOURCE_NONE)) def test_datasource_update_method_push(self): - driver_names = ds_utils.get_push_drivers_names(self.conf) - push_drivers = ds_utils.get_drivers_by_name(self.conf, driver_names) + driver_names = ds_utils.get_push_drivers_names() + push_drivers = ds_utils.get_drivers_by_name(driver_names) self.assertSequenceEqual({utils.import_class( self.conf[NOVA_INSTANCE_DATASOURCE].driver), utils.import_class( self.conf[ZABBIX_DATASOURCE_PUSH].driver)}, set(d.__class__ for d in push_drivers)) def test_datasource_update_method_pull(self): - driver_names = ds_utils.get_pull_drivers_names(self.conf) + driver_names = ds_utils.get_pull_drivers_names() self.assertSequenceEqual( set([NAGIOS_DATASOURCE, ZABBIX_DATASOURCE_PULL]), set(driver_names)) diff --git a/vitrage/tests/unit/datasources/trove/test_trove_cluster_transformer.py b/vitrage/tests/unit/datasources/trove/test_trove_cluster_transformer.py index 8354b1c70..dda361138 100644 --- a/vitrage/tests/unit/datasources/trove/test_trove_cluster_transformer.py +++ b/vitrage/tests/unit/datasources/trove/test_trove_cluster_transformer.py @@ -50,7 +50,7 @@ class TroveClusterTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=TROVE_CLUSTER_DATASOURCE) cls.transformers[TROVE_CLUSTER_DATASOURCE] = \ - TroveClusterTransformer(cls.transformers, cls.conf) + TroveClusterTransformer(cls.transformers) def test_create_placeholder_vertex(self): # Tests setup diff --git a/vitrage/tests/unit/datasources/trove/test_trove_instance_transformer.py b/vitrage/tests/unit/datasources/trove/test_trove_instance_transformer.py index 45e18c744..7e2f258e4 100644 --- a/vitrage/tests/unit/datasources/trove/test_trove_instance_transformer.py +++ b/vitrage/tests/unit/datasources/trove/test_trove_instance_transformer.py @@ -50,7 +50,7 @@ class TroveInstanceTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=TROVE_INSTANCE_DATASOURCE) cls.transformers[TROVE_INSTANCE_DATASOURCE] = \ - TroveInstanceTransformer(cls.transformers, cls.conf) + TroveInstanceTransformer(cls.transformers) def test_create_placeholder_vertex(self): # Tests setup diff --git a/vitrage/tests/unit/datasources/zabbix/mock_driver.py b/vitrage/tests/unit/datasources/zabbix/mock_driver.py index b081079b3..4d0b2e42a 100644 --- a/vitrage/tests/unit/datasources/zabbix/mock_driver.py +++ b/vitrage/tests/unit/datasources/zabbix/mock_driver.py @@ -30,8 +30,8 @@ class MockZabbixDriver(ZabbixDriver): def enrich_event(self, event, event_type): pass - def __init__(self, conf): - super(MockZabbixDriver, self).__init__(conf) + def __init__(self): + super(MockZabbixDriver, self).__init__() self.alarm_datas = None def set_alarm_datas(self, alarm_datas): diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py index 4e97bfedf..c7cf5430f 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py @@ -67,16 +67,13 @@ class TestZabbixConfig(base.BaseTest): ZabbixProps.RESOURCE_NAME: 'compute-1'}, } - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestZabbixConfig, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=ZABBIX_DATASOURCE) + def setUp(self): + super(TestZabbixConfig, self).setUp() + self.conf_reregister_opts(self.OPTS, group=ZABBIX_DATASOURCE) def test_zabbix_configuration_loading(self): # Action - mappings = ZabbixDriver._configuration_mapping(self.conf) + mappings = ZabbixDriver._configuration_mapping() # Test assertions self.assertEqual(len(self.MAPPINGS), len(mappings)) diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py index 22f9a6779..915c62b86 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py @@ -39,16 +39,13 @@ class ZabbixDriverTest(ZabbixBaseTest): + '/zabbix/zabbix_conf.yaml'), ] - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(ZabbixDriverTest, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group=ZABBIX_DATASOURCE) + def setUp(self): + super(ZabbixDriverTest, self).setUp() + self.conf_reregister_opts(self.OPTS, group=ZABBIX_DATASOURCE) def test_get_all(self): # Test Setup - zabbix_driver = MockZabbixDriver(self.conf) + zabbix_driver = MockZabbixDriver() alarm_data1 = self._extract_alarm_data(triggerid='1', status='1') alarm_data2 = self._extract_alarm_data(triggerid='2', status='1', @@ -72,7 +69,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step 1 - Services with status OK should not be returned # Test setup scenario - zabbix_driver = MockZabbixDriver(self.conf) + zabbix_driver = MockZabbixDriver() alarm_data1 = self._extract_alarm_data() alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') @@ -160,7 +157,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step 1 - get changes when all alarms are OK # Test setup - zabbix_driver = MockZabbixDriver(self.conf) + zabbix_driver = MockZabbixDriver() alarm_data1 = self._extract_alarm_data(priority='2') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', @@ -266,7 +263,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step 1 - get changes # Step setup - zabbix_driver = MockZabbixDriver(self.conf) + zabbix_driver = MockZabbixDriver() alarm_data1 = self._extract_alarm_data(priority='2', value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', @@ -372,7 +369,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step 1 - delete inactive alarm # Step setup - zabbix_driver = MockZabbixDriver(self.conf) + zabbix_driver = MockZabbixDriver() zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2]) diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py index 7950a906f..8536009c4 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py @@ -58,7 +58,7 @@ class ZabbixTransformerTest(base.BaseTest): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=ZABBIX_DATASOURCE) cls.transformers[NOVA_HOST_DATASOURCE] = \ - HostTransformer(cls.transformers, cls.conf) + HostTransformer(cls.transformers) def test_create_entity_key(self): LOG.debug('Test get key from nova instance transformer') @@ -67,7 +67,7 @@ class ZabbixTransformerTest(base.BaseTest): spec_list = mock_sync.simple_zabbix_alarm_generators(host_num=1, events_num=1) zabbix_alarms = mock_sync.generate_sequential_events_list(spec_list) - transformer = ZabbixTransformer(self.transformers, self.conf) + transformer = ZabbixTransformer(self.transformers) event = zabbix_alarms[0] self.enrich_event(event) @@ -96,7 +96,7 @@ class ZabbixTransformerTest(base.BaseTest): for alarm in zabbix_alarms: # Test action self.enrich_event(alarm, format_timestamp=False) - wrapper = ZabbixTransformer(self.transformers, self.conf)\ + wrapper = ZabbixTransformer(self.transformers)\ .transform(alarm) self._validate_vertex(wrapper.vertex, alarm) @@ -173,7 +173,7 @@ class ZabbixTransformerTest(base.BaseTest): edge = neighbor.edge self.assertEqual(EdgeLabel.ON, edge.label) - alarm_key = ZabbixTransformer(self.transformers, self.conf).\ + alarm_key = ZabbixTransformer(self.transformers).\ _create_entity_key(event) alarm_uuid = TransformerBase.uuid_from_deprecated_vitrage_id(alarm_key) self.assertEqual(alarm_uuid, edge.source_id) diff --git a/vitrage/tests/unit/entity_graph/base.py b/vitrage/tests/unit/entity_graph/base.py index 4f5dd8238..05c8226e8 100644 --- a/vitrage/tests/unit/entity_graph/base.py +++ b/vitrage/tests/unit/entity_graph/base.py @@ -35,6 +35,9 @@ from vitrage.tests.mocks import utils from vitrage.utils.datetime import utcnow +CONF = cfg.CONF + + class TestEntityGraphUnitBase(base.BaseTest): PROCESSOR_OPTS = [ @@ -73,16 +76,20 @@ class TestEntityGraphUnitBase(base.BaseTest): NUM_HOSTS = 4 NUM_INSTANCES = 16 - @staticmethod - def load_datasources(conf): - for datasource in conf.datasources.types: - register_opts(conf, datasource, conf.datasources.path) + def setUp(self): + super(TestEntityGraphUnitBase, self).setUp() + self.conf_reregister_opts(self.DATASOURCES_OPTS, 'datasources') + self.conf_reregister_opts(self.PROCESSOR_OPTS, 'entity_graph') - def _create_processor_with_graph(self, conf, processor=None): + def load_datasources(self): + for datasource in CONF.datasources.types: + register_opts(datasource, CONF.datasources.path) + + def _create_processor_with_graph(self, processor=None): events = self._create_mock_events() if not processor: - processor = self.create_processor_and_graph(conf) + processor = self.create_processor_and_graph() for event in events: processor.process_event(event) @@ -124,7 +131,7 @@ class TestEntityGraphUnitBase(base.BaseTest): # add instance entity with host if processor is None: - processor = self.create_processor_and_graph(self.conf) + processor = self.create_processor_and_graph() vertex, neighbors, event_type = processor.transformer_manager\ .transform(event) @@ -133,9 +140,9 @@ class TestEntityGraphUnitBase(base.BaseTest): return vertex, neighbors, processor @staticmethod - def create_processor_and_graph(conf): + def create_processor_and_graph(): e_graph = NXGraph("Entity Graph") - return proc.Processor(conf, e_graph=e_graph) + return proc.Processor(e_graph=e_graph) @staticmethod def _create_event(spec_type=None, diff --git a/vitrage/tests/unit/entity_graph/processor/base.py b/vitrage/tests/unit/entity_graph/processor/base.py index 282f898a3..2ca40cce7 100644 --- a/vitrage/tests/unit/entity_graph/processor/base.py +++ b/vitrage/tests/unit/entity_graph/processor/base.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg - from vitrage.common.constants import VertexProperties as VProps from vitrage.entity_graph.processor import transformer_manager from vitrage.graph import driver as graph @@ -22,14 +20,10 @@ from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase class TestBaseProcessor(TestEntityGraphUnitBase): - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestBaseProcessor, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.load_datasources(cls.conf) - cls.transform = transformer_manager.TransformerManager(cls.conf) + def setUp(self): + super(TestBaseProcessor, self).setUp() + self.load_datasources() + self.transform = transformer_manager.TransformerManager() @staticmethod def _update_vertex_to_graph(entity_graph, diff --git a/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py b/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py index 20872cb49..17bcaddb9 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py +++ b/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py @@ -22,9 +22,8 @@ from vitrage.tests.unit.entity_graph.processor import base class TestEntityGraphManager(base.TestBaseProcessor): - @classmethod - def setUpClass(cls): - super(TestEntityGraphManager, cls).setUpClass() + def setUp(self): + super(TestEntityGraphManager, self).setUp() def test_delete_placeholder_vertex(self): entity_graph = NXGraph("Entity Graph") diff --git a/vitrage/tests/unit/entity_graph/processor/test_processor.py b/vitrage/tests/unit/entity_graph/processor/test_processor.py index 0d71b276f..3f24cf7a3 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_processor.py +++ b/vitrage/tests/unit/entity_graph/processor/test_processor.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from testtools import matchers from vitrage.common.constants import DatasourceAction as DSAction @@ -40,18 +39,13 @@ class TestProcessor(TestEntityGraphUnitBase): NUM_EDGES_AFTER_DELETION = 0 # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestProcessor, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls.conf.register_opts(cls.OS_CLIENTS_OPTS) - cls.load_datasources(cls.conf) + def setUp(self): + super(TestProcessor, self).setUp() + self.load_datasources() def test_process_event(self): # check create instance event - processor = self.create_processor_and_graph(self.conf) + processor = self.create_processor_and_graph() event = self._create_event(spec_type=self.INSTANCE_SPEC, datasource_action=DSAction.INIT_SNAPSHOT) processor.process_event(event) diff --git a/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py b/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py index 181d6b52f..e1dd11bd3 100644 --- a/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py +++ b/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from testtools import matchers from vitrage.common.constants import EntityCategory @@ -34,42 +33,28 @@ from vitrage.tests.mocks import utils class TestDatasourceInfoMapper(base.BaseTest): - ENTITY_GRAPH_OPTS = [ - cfg.StrOpt('datasources_values_dir', - default=utils.get_resources_dir() + '/datasources_values'), - ] + def _load_datasources(self): + for datasource_name in self.conf.datasources.types: + register_opts(datasource_name, self.conf.datasources.path) - DATASOURCES_OPTS = [ - cfg.ListOpt('types', - default=[NAGIOS_DATASOURCE, - NOVA_HOST_DATASOURCE, - NOVA_INSTANCE_DATASOURCE, - NOVA_ZONE_DATASOURCE, - AODH_DATASOURCE], - help='Names of supported data sources'), - - cfg.ListOpt('path', - default=['vitrage.datasources'], - help='base path for datasources') - ] - - @staticmethod - def _load_datasources(conf): - for vitrage_type in conf.datasources.types: - register_opts(conf, vitrage_type, conf.datasources.path) - - # noinspection PyAttributeOutsideInit,PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestDatasourceInfoMapper, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.ENTITY_GRAPH_OPTS, group='entity_graph') - cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') - cls._load_datasources(cls.conf) + def setUp(self): + super(TestDatasourceInfoMapper, self).setUp() + self.cfg_fixture.config( + group='entity_graph', + datasources_values_dir=utils.get_resources_dir() + + '/datasources_values') + self.cfg_fixture.config(group='datasources', + types=[ + NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE, + AODH_DATASOURCE]) + self._load_datasources() def test_load_datasource_value_without_errors(self): # action - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # test assertions @@ -80,30 +65,27 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_load_datasources_value_with_errors(self): # setup - entity_graph_opts = [ - cfg.StrOpt('datasources_values_dir', - default=utils.get_resources_dir() + - '/datasources_values/erroneous_values'), - ] - conf = cfg.ConfigOpts() - conf.register_opts(entity_graph_opts, group='entity_graph') - conf.register_opts(self.DATASOURCES_OPTS, group='datasources') - self._load_datasources(conf) + self.cfg_fixture.config( + group='entity_graph', + datasources_values_dir=utils.get_resources_dir() + + '/datasources_values/erroneous_values' + ) + self._load_datasources() # action - info_mapper = DatasourceInfoMapper(conf) + info_mapper = DatasourceInfoMapper() # test assertions missing_values = 1 erroneous_values = 1 num_valid_datasources = len(info_mapper.datasources_value_confs) + \ missing_values + erroneous_values - self.assertThat(conf.datasources.types, + self.assertThat(self.conf.datasources.types, matchers.HasLength(num_valid_datasources)) def test_vitrage_operational_value_exists(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action vitrage_operational_value = \ @@ -116,7 +98,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_operational_value_not_exists(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action vitrage_operational_value = \ @@ -129,7 +111,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_operational_value_DS_not_exists_and_value_not_exist(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action vitrage_operational_value = \ @@ -142,7 +124,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_operational_value_DS_not_exists_and_value_exist(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action vitrage_operational_value = \ @@ -155,7 +137,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_value_priority(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action value_priority = \ @@ -166,7 +148,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_value_priority_not_exists(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action value_priority = \ @@ -178,7 +160,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_value_priority_datasource_not_exists(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() # action value_priority = \ @@ -191,7 +173,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_aggregated_value(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() metadata1 = {VProps.VITRAGE_STATE: 'SUSPENDED'} new_vertex1 = create_vertex('12345', vitrage_category=EntityCategory.RESOURCE, @@ -221,7 +203,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_aggregated_value_functionalities(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() new_vertex1 = create_vertex('12345', vitrage_category=EntityCategory.RESOURCE, vitrage_type=NOVA_INSTANCE_DATASOURCE, @@ -266,7 +248,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_aggregated_value_datasource_not_exists(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() metadata = {VProps.VITRAGE_STATE: 'SUSPENDED'} new_vertex = create_vertex('12345', vitrage_category=EntityCategory.RESOURCE, @@ -285,7 +267,7 @@ class TestDatasourceInfoMapper(base.BaseTest): def test_vitrage_aggregated_value_DS_not_exists_and_wrong_state(self): # setup - info_mapper = DatasourceInfoMapper(self.conf) + info_mapper = DatasourceInfoMapper() metadata = {VProps.VITRAGE_STATE: 'SUSPENDED'} new_vertex = create_vertex('12345', vitrage_category=EntityCategory.RESOURCE, diff --git a/vitrage/tests/unit/entity_graph/test_processor_service.py b/vitrage/tests/unit/entity_graph/test_processor_service.py index 56685dc8a..ed11cce85 100644 --- a/vitrage/tests/unit/entity_graph/test_processor_service.py +++ b/vitrage/tests/unit/entity_graph/test_processor_service.py @@ -39,7 +39,7 @@ class EventsCoordinationTest(base.BaseTest): the result should be the number of low priority calls. 0*(2^n) + 1*n """ - priority_listener = EventsCoordination(None, self.do_work) + priority_listener = EventsCoordination(self.do_work) def write_high(): for i in range(10000): diff --git a/vitrage/tests/unit/entity_graph/test_transformer_manager.py b/vitrage/tests/unit/entity_graph/test_transformer_manager.py index 9c6d90247..f1feb9524 100644 --- a/vitrage/tests/unit/entity_graph/test_transformer_manager.py +++ b/vitrage/tests/unit/entity_graph/test_transformer_manager.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg - from vitrage.datasources.nagios import NAGIOS_DATASOURCE from vitrage.datasources.nagios.transformer import NagiosTransformer from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE @@ -30,30 +28,19 @@ from vitrage.tests import base class TransformerManagerTest(base.BaseTest): - OPTS = [ - cfg.ListOpt('types', - default=[NAGIOS_DATASOURCE, - NOVA_HOST_DATASOURCE, - NOVA_INSTANCE_DATASOURCE, - NOVA_ZONE_DATASOURCE], - help='Names of supported data sources'), + def setUp(self): + super(TransformerManagerTest, self).setUp() + self.cfg_fixture.config(group='datasources', + types=[ + NAGIOS_DATASOURCE, + NOVA_HOST_DATASOURCE, + NOVA_INSTANCE_DATASOURCE, + NOVA_ZONE_DATASOURCE]) - cfg.ListOpt('path', - default=['vitrage.datasources'], - help='base path for data sources') - ] + for datasource in self.conf.datasources.types: + register_opts(datasource, self.conf.datasources.path) - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TransformerManagerTest, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='datasources') - - for datasource in cls.conf.datasources.types: - register_opts(cls.conf, datasource, cls.conf.datasources.path) - - cls.manager = TransformerManager(cls.conf) + self.manager = TransformerManager() def test_transformer_registration_nagios(self): self.assertIsInstance(self.manager.get_transformer diff --git a/vitrage/tests/unit/evaluator/template_loading/test_template_loading_v3.py b/vitrage/tests/unit/evaluator/template_loading/test_template_loading_v3.py index 348d062d4..6a205727c 100644 --- a/vitrage/tests/unit/evaluator/template_loading/test_template_loading_v3.py +++ b/vitrage/tests/unit/evaluator/template_loading/test_template_loading_v3.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from vitrage.evaluator.template_data import ActionSpecs from vitrage.evaluator.template_data import EdgeDescription from vitrage.evaluator.template_data import Scenario @@ -59,11 +58,9 @@ class TemplateLoaderV3Test(BaseTest, TestConfiguration): Vertex('host', {'vitrage_type': 'nova.host'})), } - @classmethod - def setUpClass(cls): - super(TemplateLoaderV3Test, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.add_db(cls.conf) + def setUp(self): + super(TemplateLoaderV3Test, self).setUp() + self.add_db() def _load_scenarios(self, file=None, content=None): if file and not content: diff --git a/vitrage/tests/unit/evaluator/template_validation/test_template_validator_v3.py b/vitrage/tests/unit/evaluator/template_validation/test_template_validator_v3.py index 29200afad..4d383fa63 100644 --- a/vitrage/tests/unit/evaluator/template_validation/test_template_validator_v3.py +++ b/vitrage/tests/unit/evaluator/template_validation/test_template_validator_v3.py @@ -13,7 +13,6 @@ # under the License. import json -from oslo_config import cfg from vitrage.api_handler.apis.template import TemplateApis from vitrage.evaluator.actions.recipes import execute_mistral @@ -26,12 +25,10 @@ from vitrage.utils import file as file_utils class TemplateValidatorV3Test(base.BaseTest, TestConfiguration): - @classmethod - def setUpClass(cls): - super(TemplateValidatorV3Test, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.add_db(cls.conf) - cls.template_apis = TemplateApis(db=cls._db) + def setUp(self): + super(TemplateValidatorV3Test, self).setUp() + self.add_db() + self.template_apis = TemplateApis(db=self._db) def _test_validation(self, file=None, content=None, expected_code=0): if file and not content: diff --git a/vitrage/tests/unit/evaluator/test_equivalence_repository.py b/vitrage/tests/unit/evaluator/test_equivalence_repository.py index 25f6e7460..ab4d20f3c 100644 --- a/vitrage/tests/unit/evaluator/test_equivalence_repository.py +++ b/vitrage/tests/unit/evaluator/test_equivalence_repository.py @@ -14,8 +14,6 @@ import os -from oslo_config import cfg - from vitrage.common.constants import TemplateTypes from vitrage.common.exception import VitrageError from vitrage.evaluator.equivalence_repository import EquivalenceRepository @@ -29,8 +27,7 @@ class TestEquivalenceRepository(base.BaseTest, TestConfiguration): # noinspection PyPep8Naming def setUp(self): super(TestEquivalenceRepository, self).setUp() - conf = cfg.ConfigOpts() - self.add_db(conf) + self.add_db() self.equivalence_repository = EquivalenceRepository() def test_duplicate_entities_in_equivalence(self): diff --git a/vitrage/tests/unit/evaluator/test_scenario_repository.py b/vitrage/tests/unit/evaluator/test_scenario_repository.py index 5507388cf..fe51c92cf 100644 --- a/vitrage/tests/unit/evaluator/test_scenario_repository.py +++ b/vitrage/tests/unit/evaluator/test_scenario_repository.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from testtools import matchers from vitrage.common.constants import EntityCategory @@ -30,33 +29,19 @@ from vitrage.utils import file as file_utils class ScenarioRepositoryTest(base.BaseTest, TestConfiguration): - BASE_DIR = utils.get_resources_dir() + '/templates/general' - OPTS = [ - cfg.StrOpt('templates_dir', - default=BASE_DIR, - ), - cfg.StrOpt('equivalences_dir', - default='equivalences', - ), - ] - - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(ScenarioRepositoryTest, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='evaluator') - cls.add_db(cls.conf) - cls.add_templates(cls.conf.evaluator.templates_dir) - templates_dir_path = cls.conf.evaluator.templates_dir - cls.template_defs = file_utils.load_yaml_files(templates_dir_path) - - cls.scenario_repository = ScenarioRepository(cls.conf) + def setUp(self): + super(ScenarioRepositoryTest, self).setUp() + self.add_db() + templates_dir = utils.get_resources_dir() + '/templates/general' + self.add_templates(templates_dir) + templates_dir_path = templates_dir + self.template_defs = file_utils.load_yaml_files(templates_dir_path) + self.scenario_repository = ScenarioRepository() def test_template_loader(self): # Test Action - scenario_repository = ScenarioRepository(self.conf) + scenario_repository = ScenarioRepository() # Test assertions self.assertIsNotNone(scenario_repository) @@ -110,19 +95,12 @@ class ScenarioRepositoryTest(base.BaseTest, TestConfiguration): class RegExTemplateTest(base.BaseTest, TestConfiguration): - BASE_DIR = utils.get_resources_dir() + '/templates/regex' - OPTS = [ - cfg.StrOpt('templates_dir', - default=BASE_DIR)] - - @classmethod - def setUpClass(cls): - super(RegExTemplateTest, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='evaluator') - cls.add_db(cls.conf) - cls.add_templates(cls.conf.evaluator.templates_dir) - cls.scenario_repository = ScenarioRepository(cls.conf) + def setUp(self): + super(RegExTemplateTest, self).setUp() + templates_dir = utils.get_resources_dir() + '/templates/regex' + self.add_db() + self.add_templates(templates_dir) + self.scenario_repository = ScenarioRepository() def test_basic_regex(self): @@ -178,31 +156,20 @@ class RegExTemplateTest(base.BaseTest, TestConfiguration): class EquivalentScenarioTest(base.BaseTest, TestConfiguration): - BASE_DIR = utils.get_resources_dir() + '/templates/equivalent_scenarios/' - OPTS = [ - cfg.StrOpt('templates_dir', - default=BASE_DIR, - ), - cfg.StrOpt('def_templates_dir', - default=(utils.get_resources_dir() + - '/templates/def_template_tests'), - ), - cfg.StrOpt('equivalences_dir', - default=BASE_DIR + '/equivalences',), - ] - - @classmethod - def setUpClass(cls): - super(EquivalentScenarioTest, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='evaluator') - cls.add_db(cls.conf) - cls.add_templates(cls.conf.evaluator.templates_dir) - cls.add_templates(cls.conf.evaluator.equivalences_dir, - TType.EQUIVALENCE) - cls.add_templates(cls.conf.evaluator.def_templates_dir, - TType.DEFINITION) - cls.scenario_repository = ScenarioRepository(cls.conf) + def setUp(self): + super(EquivalentScenarioTest, self).setUp() + templates_dir = utils.get_resources_dir() + \ + '/templates/equivalent_scenarios/' + equivalences_dir = templates_dir + '/equivalences' + def_templates_dir = utils.get_resources_dir() + \ + '/templates/def_template_tests' + self.add_db() + self.add_templates(templates_dir) + self.add_templates(equivalences_dir, + TType.EQUIVALENCE) + self.add_templates(def_templates_dir, + TType.DEFINITION) + self.scenario_repository = ScenarioRepository() def test_expansion(self): entity_scenarios = self.scenario_repository.entity_scenarios diff --git a/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py b/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py index a715aa434..7501eadc4 100644 --- a/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py +++ b/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py @@ -42,6 +42,7 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\ correlation_collection import CorrelationPriorities as CPriorities from vitrage.tests import base +CONF = cfg.CONF ACTIVE_TIMESTAMP = datetime.datetime.utcnow() ACTIVE_TIMESTAMP = ACTIVE_TIMESTAMP.strftime(TIMESTAMP_FORMAT) @@ -149,36 +150,19 @@ INACTIVE_ALARMS = [DELETED_DEDUCED_ALARM_1, DELETED_AODH_ALARM_1, class JaccardCorrelationTest(base.BaseTest): - OPTS = [ - cfg.StrOpt('output_folder', default='/tmp', - help='folder to write all reports to'), - cfg.FloatOpt('correlation_threshold', default=0, - help='threshold of interesting correlations'), - cfg.FloatOpt('high_corr_score', default=0.9, - help='high correlation lower limit'), - cfg.FloatOpt('med_corr_score', default=0.5, - help='medium correlation lower limit'), - ] + def setUp(self): + super(JaccardCorrelationTest, self).setUp() - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(JaccardCorrelationTest, cls).setUpClass() + self.data_manager = ADAccumulator(AData({}, {})) + self.collection = \ + CCollection(CONF.jaccard_correlation.high_corr_score, + CONF.jaccard_correlation.med_corr_score) + self.correlation_manager = CManager() + self.activate_timestamps = {} + self.inactivate_timestamps = {} + self.alarm_ids = self._setup_expected_active_alarms_ids() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='jaccard_correlation') - - cls.data_manager = ADAccumulator(AData({}, {})) - cls.collection = \ - CCollection(cls.conf.jaccard_correlation.high_corr_score, - cls.conf.jaccard_correlation.med_corr_score) - cls.correlation_manager = CManager(cls.conf) - cls.activate_timestamps = {} - cls.inactivate_timestamps = {} - cls.alarm_ids = cls._setup_expected_active_alarms_ids() - - @staticmethod - def _setup_expected_active_alarms_ids(): + def _setup_expected_active_alarms_ids(self): alarm_ids = [] for alarm in ACTIVE_ALARMS: alarm_name = alarm[VProps.RAWTEXT] if alarm.get(VProps.RAWTEXT) \ @@ -379,7 +363,7 @@ class JaccardCorrelationTest(base.BaseTest): _dump_correlations(str(now) + "_correlations_test.out", report) - file_path = self.conf.jaccard_correlation.output_folder + '/' + \ + file_path = CONF.jaccard_correlation.output_folder + '/' + \ str(now) + "_correlations_test.out" is_file = os.path.isfile(file_path) diff --git a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py index eafc3a1b9..0ad1d8ea9 100644 --- a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py +++ b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from pysnmp.proto.rfc1902 import OctetString from testtools import matchers @@ -25,35 +24,18 @@ from vitrage.tests.unit.notifier.snmp_notifier import common class SnmpNotifierTest(base.BaseTest): - simple_opts = [ - cfg.StrOpt('notifier', - default='vitrage.notifier.plugins.snmp.' - 'snmp_notifier.SnmpNotifier', - required=True), - cfg.StrOpt('snmp_sender_class', - default='vitrage.notifier.plugins.snmp.' - 'snmp_sender.SnmpSender', - required=True), - cfg.StrOpt('alarm_oid_mapping', - default=utils.get_resources_dir() + - '/snmp_notifier/alarm_oid_mapping.yaml'), - cfg.StrOpt('consumers', - default=utils.get_resources_dir() + - '/snmp_notifier/dests.yaml'), - cfg.StrOpt('oid_tree', - default=utils.get_resources_dir() + - '/snmp_notifier/' - 'oid_tree_with_severity_mapping.yaml'), - ] + def setUp(self): + super(SnmpNotifierTest, self).setUp() - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(SnmpNotifierTest, cls).setUpClass() - - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.simple_opts, group='snmp') - cls.snmp_sender = SnmpSender(cls.conf) + self.cfg_fixture.config( + group='snmp', + alarm_oid_mapping=utils.get_resources_dir() + + '/snmp_notifier/alarm_oid_mapping.yaml', + consumers=utils.get_resources_dir() + '/snmp_notifier/dests.yaml', + oid_tree=utils.get_resources_dir() + + '/snmp_notifier/oid_tree_with_severity_mapping.yaml' + ) + self.snmp_sender = SnmpSender() def test_create_oids(self): diff --git a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py index 2e473487a..ff76c7e0f 100644 --- a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py +++ b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from testtools import matchers from vitrage.common.constants import VertexProperties as VProps @@ -24,35 +23,18 @@ from vitrage.tests.unit.notifier.snmp_notifier import common class SnmpNotifierTest(base.BaseTest): - simple_opts = [ - cfg.StrOpt('notifier', - default='vitrage.notifier.plugins.snmp.' - 'snmp_notifier.SnmpNotifier', - required=True), - cfg.StrOpt('snmp_sender_class', - default='vitrage.notifier.plugins.snmp.' - 'snmp_sender.SnmpSender', - required=True), - cfg.StrOpt('alarm_oid_mapping', - default=utils.get_resources_dir() + - '/snmp_notifier/alarm_oid_mapping.yaml'), - cfg.StrOpt('consumers', - default=utils.get_resources_dir() + - '/snmp_notifier/dests.yaml'), - cfg.StrOpt('oid_tree', - default=utils.get_resources_dir() + - '/snmp_notifier/' - 'oid_tree_without_severity_mapping.yaml'), - ] + def setUp(self): + super(SnmpNotifierTest, self).setUp() - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(SnmpNotifierTest, cls).setUpClass() - - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.simple_opts, group='snmp') - cls.snmp_sender = SnmpSender(cls.conf) + self.cfg_fixture.config( + group='snmp', + alarm_oid_mapping=utils.get_resources_dir() + + '/snmp_notifier/alarm_oid_mapping.yaml', + consumers=utils.get_resources_dir() + '/snmp_notifier/dests.yaml', + oid_tree=utils.get_resources_dir() + + '/snmp_notifier/oid_tree_without_severity_mapping.yaml' + ) + self.snmp_sender = SnmpSender() def test_create_oids(self): diff --git a/vitrage/tests/unit/snmp_parsing/test_snmp_parsing.py b/vitrage/tests/unit/snmp_parsing/test_snmp_parsing.py index abffac1ea..cd3297396 100644 --- a/vitrage/tests/unit/snmp_parsing/test_snmp_parsing.py +++ b/vitrage/tests/unit/snmp_parsing/test_snmp_parsing.py @@ -13,7 +13,6 @@ # under the License. import copy -from oslo_config import cfg from pysnmp.proto.rfc1902 import Integer from pysnmp.proto.rfc1902 import ObjectIdentifier @@ -109,32 +108,20 @@ DICT_EXPECTED = { class TestSnmpParsing(base.BaseTest): - OPTS = [ - cfg.IntOpt('snmp_listening_port', default=8162, - help='The listening port of snmp_parsing service'), - cfg.StrOpt('oid_mapping', - default='vitrage/tests/resources/snmp_parsing/' - 'snmp_parsing_conf.yaml', - help='The default path of oid_mapping yaml file'), - ] - - # noinspection PyPep8Naming - @classmethod - def setUpClass(cls): - super(TestSnmpParsing, cls).setUpClass() - cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='snmp_parsing') - cls.conf.register_opt( - cfg.StrOpt('backend_url', default='zake://'), group='coordination' - ) + def setUp(self): + super(TestSnmpParsing, self).setUp() + self.cfg_fixture.config( + group='snmp_parsing', + oid_mapping='vitrage/tests/resources/snmp_parsing/' + 'snmp_parsing_conf.yaml') def test_convert_binds_to_dict(self): - parsing_service = SnmpParsingService(1, self.conf) + parsing_service = SnmpParsingService(1) dict_converted = parsing_service._convert_binds_to_dict(BINDS_REPORTED) self.assert_dict_equal(dict_converted, DICT_EXPECTED) def test_get_event_type(self): - parsing_service = SnmpParsingService(1, self.conf) + parsing_service = SnmpParsingService(1) event_type = parsing_service._get_event_type(DICT_EXPECTED) self.assertEqual(event_type, 'vitrage.snmp.event') @@ -142,6 +129,6 @@ class TestSnmpParsing(base.BaseTest): converted_trap_diff_sys = copy.copy(DICT_EXPECTED) converted_trap_diff_sys.update( {u'1.3.6.1.4.1.3902.4101.1.3.1.12': u'Different System'}) - parsing_service = SnmpParsingService(1, self.conf) + parsing_service = SnmpParsingService(1) event_type = parsing_service._get_event_type(converted_trap_diff_sys) self.assertIsNone(event_type)