Merge "Add database configuration to unit tests"
This commit is contained in:
commit
4fd802919a
@ -18,7 +18,6 @@ import time
|
||||
import unittest
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_db.options import database_opts
|
||||
|
||||
from vitrage.common.constants import EdgeLabel
|
||||
from vitrage.common.constants import EntityCategory
|
||||
@ -39,10 +38,11 @@ from vitrage.graph.driver.networkx_graph import NXGraph
|
||||
import vitrage.graph.utils as graph_utils
|
||||
from vitrage.tests.functional.base import TestFunctionalBase
|
||||
from vitrage.tests.mocks import utils
|
||||
from vitrage.tests.test_configuration import TestConfiguration
|
||||
from vitrage.utils.datetime import utcnow
|
||||
|
||||
|
||||
class TestConsistencyFunctional(TestFunctionalBase):
|
||||
class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration):
|
||||
|
||||
CONSISTENCY_OPTS = [
|
||||
cfg.IntOpt('min_time_to_delete',
|
||||
@ -77,9 +77,7 @@ class TestConsistencyFunctional(TestFunctionalBase):
|
||||
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.conf.register_opts(database_opts, group='database')
|
||||
cls.conf.set_override('connection', 'sqlite:///:memory:',
|
||||
group='database')
|
||||
cls.add_db(cls.conf)
|
||||
cls.load_datasources(cls.conf)
|
||||
|
||||
cls.graph = NXGraph("Entity Graph")
|
||||
|
@ -15,7 +15,6 @@
|
||||
from six.moves import queue
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_db.options import database_opts
|
||||
|
||||
from vitrage.common.constants import DatasourceAction
|
||||
from vitrage.common.constants import DatasourceProperties as DSProp
|
||||
@ -43,12 +42,11 @@ from vitrage.evaluator.actions.recipes.base import EVALUATOR_EVENT_TYPE
|
||||
from vitrage.evaluator.template_data import ActionSpecs
|
||||
from vitrage.evaluator.template_fields import TemplateFields as TFields
|
||||
from vitrage.opts import register_opts
|
||||
from vitrage import storage
|
||||
from vitrage.storage.sqlalchemy import models
|
||||
from vitrage.tests.functional.base import TestFunctionalBase
|
||||
from vitrage.tests.test_configuration import TestConfiguration
|
||||
|
||||
|
||||
class TestActionExecutor(TestFunctionalBase):
|
||||
class TestActionExecutor(TestFunctionalBase, TestConfiguration):
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
@classmethod
|
||||
@ -56,12 +54,7 @@ class TestActionExecutor(TestFunctionalBase):
|
||||
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(database_opts, group='database')
|
||||
cls.conf.set_override('connection', 'sqlite:///:memory:',
|
||||
group='database')
|
||||
cls._db = storage.get_connection_from_config(cls.conf)
|
||||
engine = cls._db._engine_facade.get_engine()
|
||||
models.Base.metadata.create_all(engine)
|
||||
cls.add_db(cls.conf)
|
||||
|
||||
for datasource_name in cls.conf.datasources.types:
|
||||
register_opts(cls.conf, datasource_name, cls.conf.datasources.path)
|
||||
|
@ -11,13 +11,10 @@
|
||||
# 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
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
from oslo_db.options import database_opts
|
||||
from six.moves import queue
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import DatasourceAction
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
@ -42,14 +39,16 @@ from vitrage.evaluator.actions.evaluator_event_transformer \
|
||||
from vitrage.evaluator.scenario_evaluator import ScenarioEvaluator
|
||||
from vitrage.evaluator.scenario_repository import ScenarioRepository
|
||||
from vitrage.graph import create_edge
|
||||
from vitrage import storage
|
||||
from vitrage.storage.sqlalchemy import models
|
||||
from vitrage.tests.functional.base import \
|
||||
TestFunctionalBase
|
||||
import vitrage.tests.mocks.mock_driver as mock_driver
|
||||
from vitrage.tests.mocks import utils
|
||||
from vitrage.tests.test_configuration import TestConfiguration
|
||||
from vitrage.utils.datetime import utcnow
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
_TARGET_HOST = 'host-2'
|
||||
_TARGET_ZONE = 'zone-1'
|
||||
_NAGIOS_TEST_INFO = {NagiosProperties.RESOURCE_NAME: _TARGET_HOST,
|
||||
@ -57,7 +56,7 @@ _NAGIOS_TEST_INFO = {NagiosProperties.RESOURCE_NAME: _TARGET_HOST,
|
||||
DSProps.DATASOURCE_ACTION: DatasourceAction.SNAPSHOT}
|
||||
|
||||
|
||||
class TestScenarioEvaluator(TestFunctionalBase):
|
||||
class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration):
|
||||
|
||||
EVALUATOR_OPTS = [
|
||||
cfg.StrOpt('templates_dir',
|
||||
@ -80,12 +79,7 @@ class TestScenarioEvaluator(TestFunctionalBase):
|
||||
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.conf.register_opts(database_opts, group='database')
|
||||
cls.conf.set_override('connection', 'sqlite:///test.db',
|
||||
group='database')
|
||||
cls._db = storage.get_connection_from_config(cls.conf)
|
||||
engine = cls._db._engine_facade.get_engine()
|
||||
models.Base.metadata.create_all(engine)
|
||||
cls.add_db(cls.conf)
|
||||
|
||||
TestScenarioEvaluator.load_datasources(cls.conf)
|
||||
cls.scenario_repository = ScenarioRepository(cls.conf)
|
||||
|
33
vitrage/tests/test_configuration.py
Normal file
33
vitrage/tests/test_configuration.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Copyright 2017 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo_db.options import database_opts
|
||||
|
||||
from vitrage import storage
|
||||
from vitrage.storage.sqlalchemy import models
|
||||
|
||||
|
||||
TEMPLATE_DIR = '/etc/vitrage/templates'
|
||||
|
||||
|
||||
class TestConfiguration(object):
|
||||
|
||||
@classmethod
|
||||
def add_db(cls, conf):
|
||||
conf.register_opts(database_opts, group='database')
|
||||
conf.set_override('connection', 'sqlite:///:test.db:',
|
||||
group='database')
|
||||
cls._db = storage.get_connection_from_config(cls.conf)
|
||||
engine = cls._db._engine_facade.get_engine()
|
||||
models.Base.metadata.create_all(engine)
|
||||
return cls._db
|
@ -24,10 +24,12 @@ from vitrage.evaluator.template_validation.template_syntax_validator import \
|
||||
from vitrage.graph import Vertex
|
||||
from vitrage.tests import base
|
||||
from vitrage.tests.mocks import utils
|
||||
from vitrage.tests.test_configuration import TestConfiguration
|
||||
from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
|
||||
class ScenarioRepositoryTest(base.BaseTest):
|
||||
class ScenarioRepositoryTest(base.BaseTest, TestConfiguration):
|
||||
BASE_DIR = utils.get_resources_dir() + '/templates/general'
|
||||
OPTS = [
|
||||
cfg.StrOpt('templates_dir',
|
||||
@ -41,9 +43,10 @@ class ScenarioRepositoryTest(base.BaseTest):
|
||||
# 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)
|
||||
|
||||
templates_dir_path = cls.conf.evaluator.templates_dir
|
||||
cls.template_defs = file_utils.load_yaml_files(templates_dir_path)
|
||||
@ -100,7 +103,7 @@ class ScenarioRepositoryTest(base.BaseTest):
|
||||
pass
|
||||
|
||||
|
||||
class RegExTemplateTest(base.BaseTest):
|
||||
class RegExTemplateTest(TestEntityGraphUnitBase, TestConfiguration):
|
||||
|
||||
BASE_DIR = utils.get_resources_dir() + '/templates/regex'
|
||||
OPTS = [
|
||||
@ -111,9 +114,10 @@ class RegExTemplateTest(base.BaseTest):
|
||||
|
||||
@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.scenario_repository = ScenarioRepository(cls.conf)
|
||||
|
||||
def test_basic_regex(self):
|
||||
@ -169,7 +173,7 @@ class RegExTemplateTest(base.BaseTest):
|
||||
self.assertEqual(0, len(relevant_scenarios))
|
||||
|
||||
|
||||
class EquivalentScenarioTest(base.BaseTest):
|
||||
class EquivalentScenarioTest(base.BaseTest, TestConfiguration):
|
||||
BASE_DIR = utils.get_resources_dir() + '/templates/equivalent_scenarios/'
|
||||
OPTS = [
|
||||
cfg.StrOpt('templates_dir',
|
||||
@ -185,10 +189,10 @@ class EquivalentScenarioTest(base.BaseTest):
|
||||
|
||||
@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)
|
||||
templates_dir_path = cls.conf.evaluator.templates_dir
|
||||
cls.template_defs = file_utils.load_yaml_files(templates_dir_path)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user