Add database configuration to unit tests
Change-Id: Ia3ad0f97eb3b0c9f73c543d8b1e315384873ae23
This commit is contained in:
parent
0eb920268a
commit
7629494905
@ -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
|
||||
@ -40,9 +39,10 @@ import vitrage.graph.utils as graph_utils
|
||||
from vitrage.tests.functional.base import TestFunctionalBase
|
||||
from vitrage.tests.mocks import utils
|
||||
from vitrage.utils.datetime import utcnow
|
||||
from vitrage_tempest_tests.tests.test_configuration import TestConfiguration
|
||||
|
||||
|
||||
class TestConsistencyFunctional(TestFunctionalBase):
|
||||
class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration):
|
||||
|
||||
CONSISTENCY_OPTS = [
|
||||
cfg.IntOpt('min_time_to_delete',
|
||||
@ -77,11 +77,8 @@ 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")
|
||||
cls.initialization_status = VitrageInit(cls.conf, cls.graph)
|
||||
cls.processor = Processor(cls.conf, cls.initialization_status,
|
||||
|
@ -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_tempest_tests.tests.test_configuration import TestConfiguration
|
||||
|
||||
|
||||
class TestActionExecutor(TestFunctionalBase):
|
||||
class TestActionExecutor(TestFunctionalBase, TestConfiguration):
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
@classmethod
|
||||
@ -57,12 +55,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)
|
||||
|
34
vitrage_tempest_tests/tests/test_configuration.py
Normal file
34
vitrage_tempest_tests/tests/test_configuration.py
Normal file
@ -0,0 +1,34 @@
|
||||
# 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')
|
||||
db_name = "sqlite:///test_%s.db" % cls.__name__
|
||||
conf.set_override('connection', db_name, group='database')
|
||||
cls._db = storage.get_connection_from_config(conf)
|
||||
engine = cls._db._engine_facade.get_engine()
|
||||
models.Base.metadata.drop_all(engine)
|
||||
models.Base.metadata.create_all(engine)
|
||||
return cls._db
|
Loading…
x
Reference in New Issue
Block a user