Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-42-Generic-ctx-serialization-mechanism 4c5126e18 -> 7ef512da6
review fixups Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7ef512da Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7ef512da Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7ef512da Branch: refs/heads/ARIA-42-Generic-ctx-serialization-mechanism Commit: 7ef512da6090e58e6787d835c46de6cf8d2b6c98 Parents: 4c5126e Author: mxmrlv <[email protected]> Authored: Wed Feb 8 18:58:21 2017 +0200 Committer: mxmrlv <[email protected]> Committed: Wed Feb 8 18:58:21 2017 +0200 ---------------------------------------------------------------------- aria/__init__.py | 10 ++++--- aria/orchestrator/runner.py | 3 +- aria/storage/core.py | 21 ++++++++------ aria/storage/sql_mapi.py | 30 ++++++++------------ tests/mock/context.py | 18 ++++++------ tests/orchestrator/context/test_operation.py | 2 +- .../context/test_resource_render.py | 2 +- tests/orchestrator/context/test_serialize.py | 3 +- tests/orchestrator/context/test_toolbelt.py | 4 +-- tests/orchestrator/context/test_workflow.py | 4 +-- .../orchestrator/execution_plugin/test_local.py | 3 +- tests/orchestrator/execution_plugin/test_ssh.py | 3 +- tests/orchestrator/workflows/api/test_task.py | 2 +- .../workflows/builtin/test_execute_operation.py | 3 +- .../orchestrator/workflows/builtin/test_heal.py | 3 +- .../workflows/builtin/test_install.py | 3 +- .../workflows/builtin/test_uninstall.py | 3 +- .../orchestrator/workflows/core/test_engine.py | 4 +-- tests/orchestrator/workflows/core/test_task.py | 4 +-- .../executor/test_process_executor_extension.py | 3 +- .../test_process_executor_tracked_changes.py | 3 +- tests/storage/__init__.py | 11 +++++++ tests/storage/test_instrumentation.py | 8 +++--- tests/storage/test_model_storage.py | 7 +++-- tests/storage/test_models.py | 4 +-- tests/storage/test_resource_storage.py | 6 ++-- tests/storage/test_structures.py | 4 +-- tests/utils/test_plugin.py | 2 +- 28 files changed, 85 insertions(+), 88 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/aria/__init__.py ---------------------------------------------------------------------- diff --git a/aria/__init__.py b/aria/__init__.py index ec279fc..8b87473 100644 --- a/aria/__init__.py +++ b/aria/__init__.py @@ -57,7 +57,7 @@ def install_aria_extensions(): extension.init() -def application_model_storage(api, initiator=None, initiator_kwargs=None): +def application_model_storage(api, api_kwargs=None, initiator=None, initiator_kwargs=None): """ Initiate model storage """ @@ -78,18 +78,20 @@ def application_model_storage(api, initiator=None, initiator_kwargs=None): storage.model.Execution, storage.model.Task, ] - return storage.ModelStorage(api, + return storage.ModelStorage(api_cls=api, + api_kwargs=api_kwargs, items=models, initiator=initiator, initiator_kwargs=initiator_kwargs or {}) -def application_resource_storage(api, initiator=None, initiator_kwargs=None): +def application_resource_storage(api, api_kwargs=None, initiator=None, initiator_kwargs=None): """ Initiate resource storage """ - return storage.ResourceStorage(api, + return storage.ResourceStorage(api_cls=api, + api_kwargs=api_kwargs, items=['blueprint', 'deployment', 'plugin'], initiator=initiator, initiator_kwargs=initiator_kwargs) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/aria/orchestrator/runner.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/runner.py b/aria/orchestrator/runner.py index 97fe410..5950dc5 100644 --- a/aria/orchestrator/runner.py +++ b/aria/orchestrator/runner.py @@ -81,11 +81,10 @@ class Runner(object): self.cleanup() model_storage = application_model_storage( sql_mapi.SQLAlchemyModelAPI, - initiator=sql_mapi.init_storage, initiator_kwargs=dict(base_dir=self._storage_dir, filename=self._storage_name)) initialize_model_storage_fn(model_storage) resource_storage = application_resource_storage( - filesystem_rapi.FileSystemResourceAPI, initiator_kwargs=dict(directory='.')) + filesystem_rapi.FileSystemResourceAPI, api_kwargs=dict(directory='.')) return WorkflowContext( name=workflow_name, model_storage=model_storage, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/aria/storage/core.py ---------------------------------------------------------------------- diff --git a/aria/storage/core.py b/aria/storage/core.py index 4f7cd02..aa9e1a9 100644 --- a/aria/storage/core.py +++ b/aria/storage/core.py @@ -57,6 +57,7 @@ class Storage(LoggerMixin): """ def __init__(self, api_cls, + api_kwargs=None, items=(), initiator=None, initiator_kwargs=None, @@ -66,10 +67,10 @@ class Storage(LoggerMixin): self.registered = {} self._initiator = initiator self._initiator_kwargs = initiator_kwargs or {} + self._api_kwargs = api_kwargs or {} + self._additional_api_kwargs = {} if self._initiator: - self._api_kwargs = self._initiator(**self._initiator_kwargs) - else: - self._api_kwargs = self._initiator_kwargs + self._additional_api_kwargs = self._initiator(**self._initiator_kwargs) for item in items: self.register(item) self.logger.debug('{name} object is ready: {0!r}'.format( @@ -88,6 +89,7 @@ class Storage(LoggerMixin): def serialization_dict(self): return { 'api': self.api, + 'api_kwargs': self._api_kwargs, 'initiator': self._initiator, 'initiator_kwargs': self._initiator_kwargs } @@ -111,7 +113,9 @@ class ResourceStorage(Storage): :param name: :return: """ - self.registered[name] = self.api(name=name, **self._api_kwargs) + kwargs = self._api_kwargs.copy() + kwargs.update(self._additional_api_kwargs) + self.registered[name] = self.api(name=name, **kwargs) self.registered[name].create() self.logger.debug('setup {name} in storage {self!r}'.format(name=name, self=self)) @@ -121,7 +125,8 @@ class ModelStorage(Storage): Represents model storage. """ def __init__(self, *args, **kwargs): - kwargs.setdefault('initiator', sql_mapi.init_storage) + if kwargs.get('initiator', None) is None: + kwargs['initiator'] = sql_mapi.init_storage super(ModelStorage, self).__init__(*args, **kwargs) def register(self, model_cls): @@ -135,9 +140,9 @@ class ModelStorage(Storage): self.logger.debug('{name} in already storage {self!r}'.format(name=model_name, self=self)) return - self.registered[model_name] = self.api(name=model_name, - model_cls=model_cls, - **self._api_kwargs) + kwargs = self._api_kwargs.copy() + kwargs.update(self._additional_api_kwargs) + self.registered[model_name] = self.api(name=model_name, model_cls=model_cls, **kwargs) self.registered[model_name].create() self.logger.debug('setup {name} in storage {self!r}'.format(name=model_name, self=self)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/aria/storage/sql_mapi.py ---------------------------------------------------------------------- diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py index 6a2ca5b..c9a29ea 100644 --- a/aria/storage/sql_mapi.py +++ b/aria/storage/sql_mapi.py @@ -18,9 +18,10 @@ SQLAlchemy based MAPI import os import platform -from sqlalchemy import create_engine -from sqlalchemy import orm -from sqlalchemy import pool +from sqlalchemy import ( + create_engine, + orm, +) from sqlalchemy.exc import SQLAlchemyError from aria.utils.collections import OrderedDict @@ -369,24 +370,17 @@ class SQLAlchemyModelAPI(api.ModelAPI): getattr(instance, rel.key) -def init_storage(base_dir=None, filename='db.sqlite'): - if base_dir is not None: - uri = 'sqlite:///{platform_char}{path}'.format( - # Handles the windows behavior where there is not root, but drivers. - # Thus behaving as relative path. - platform_char='' if 'Windows' in platform.system() else '/', +def init_storage(base_dir, filename='db.sqlite'): + uri = 'sqlite:///{platform_char}{path}'.format( + # Handles the windows behavior where there is not root, but drivers. + # Thus behaving as relative path. + platform_char='' if 'Windows' in platform.system() else '/', - path=os.path.join(base_dir, filename)) - engine_kwargs = {} - else: - uri = 'sqlite:///:memory:' - engine_kwargs = dict(connect_args={'check_same_thread': False}, - poolclass=pool.StaticPool) + path=os.path.join(base_dir, filename)) - engine = create_engine(uri, **engine_kwargs) + engine = create_engine(uri) session_factory = orm.sessionmaker(bind=engine) - session = orm.scoped_session(session_factory=session_factory) if base_dir else \ - session_factory() + session = orm.scoped_session(session_factory=session_factory) return dict(engine=engine, session=session) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/mock/context.py ---------------------------------------------------------------------- diff --git a/tests/mock/context.py b/tests/mock/context.py index e485761..cb040ae 100644 --- a/tests/mock/context.py +++ b/tests/mock/context.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + import aria from aria.orchestrator import context from aria.storage import ( @@ -21,22 +23,20 @@ from aria.storage import ( ) from . import models +from ..storage import init_inmemory_model_storage from .topology import create_simple_topology_two_nodes -def simple(tmpdir, - model_initiator_kwargs=None, - resources_initiator_kwargs=None, - context_kwargs=None): +def simple(tmpdir, inmemory=False, context_kwargs=None): + initiator = init_inmemory_model_storage if inmemory else None + initiator_kwargs = {} if inmemory else dict(base_dir=tmpdir) model_storage = aria.application_model_storage( - sql_mapi.SQLAlchemyModelAPI, - initiator=sql_mapi.init_storage, - initiator_kwargs=model_initiator_kwargs or {}, - ) + sql_mapi.SQLAlchemyModelAPI, initiator=initiator, initiator_kwargs=initiator_kwargs) resource_storage = aria.application_resource_storage( filesystem_rapi.FileSystemResourceAPI, - initiator_kwargs=resources_initiator_kwargs or dict(directory=str(tmpdir))) + api_kwargs=dict(directory=os.path.join(tmpdir, 'resources')) + ) deployment_id = create_simple_topology_two_nodes(model_storage) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/context/test_operation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py index 38d3682..e8c7cca 100644 --- a/tests/orchestrator/context/test_operation.py +++ b/tests/orchestrator/context/test_operation.py @@ -39,7 +39,7 @@ global_test_holder = {} def ctx(tmpdir): context = mock.context.simple( str(tmpdir.join('workdir')), - model_initiator_kwargs=dict(base_dir=str(tmpdir)), + inmemory=True, context_kwargs=dict(workdir=str(tmpdir.join('workdir'))) ) yield context http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/context/test_resource_render.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_resource_render.py b/tests/orchestrator/context/test_resource_render.py index 20ad694..ded18c8 100644 --- a/tests/orchestrator/context/test_resource_render.py +++ b/tests/orchestrator/context/test_resource_render.py @@ -53,7 +53,7 @@ def test_download_resource_and_render_provided_variables(tmpdir, ctx): @pytest.fixture def ctx(tmpdir): - context = mock.context.simple(str(tmpdir.join('resources'))) + context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/context/test_serialize.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py index 899a963..ee123a7 100644 --- a/tests/orchestrator/context/test_serialize.py +++ b/tests/orchestrator/context/test_serialize.py @@ -88,8 +88,7 @@ def executor(): @pytest.fixture def context(tmpdir): result = mock.context.simple( - str(tmpdir.join('resources')), - model_initiator_kwargs=dict(base_dir=str(tmpdir)), + str(tmpdir), context_kwargs=dict(workdir=str(tmpdir.join('workdir'))) ) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/context/test_toolbelt.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py index 4e42972..beb5730 100644 --- a/tests/orchestrator/context/test_toolbelt.py +++ b/tests/orchestrator/context/test_toolbelt.py @@ -33,9 +33,7 @@ global_test_holder = {} @pytest.fixture def workflow_context(tmpdir): - context = mock.context.simple( - str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + context = mock.context.simple(str(tmpdir), inmemory=True) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/context/test_workflow.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_workflow.py b/tests/orchestrator/context/test_workflow.py index b1d1875..bb54037 100644 --- a/tests/orchestrator/context/test_workflow.py +++ b/tests/orchestrator/context/test_workflow.py @@ -60,8 +60,8 @@ class TestWorkflowContext(object): @pytest.fixture(scope='function') def storage(): - workflow_storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI, - initiator=sql_mapi.init_storage) + workflow_storage = application_model_storage( + sql_mapi.SQLAlchemyModelAPI, initiator=test_storage.init_inmemory_model_storage) workflow_storage.blueprint.put(models.get_blueprint()) blueprint = workflow_storage.blueprint.get_by_name(models.BLUEPRINT_NAME) workflow_storage.deployment.put(models.get_deployment(blueprint)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/execution_plugin/test_local.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/execution_plugin/test_local.py b/tests/orchestrator/execution_plugin/test_local.py index 29de453..86f2aa7 100644 --- a/tests/orchestrator/execution_plugin/test_local.py +++ b/tests/orchestrator/execution_plugin/test_local.py @@ -503,8 +503,7 @@ if __name__ == '__main__': @pytest.fixture def workflow_context(self, tmpdir): - workflow_context = mock.context.simple( - str(tmpdir.join('resources')), model_initiator_kwargs=dict(base_dir=str(tmpdir))) + workflow_context = mock.context.simple(str(tmpdir), inmemory=False) workflow_context.states = [] workflow_context.exception = None yield workflow_context http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/execution_plugin/test_ssh.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/execution_plugin/test_ssh.py b/tests/orchestrator/execution_plugin/test_ssh.py index 631b29b..65195c8 100644 --- a/tests/orchestrator/execution_plugin/test_ssh.py +++ b/tests/orchestrator/execution_plugin/test_ssh.py @@ -265,8 +265,7 @@ class TestWithActualSSHServer(object): @pytest.fixture def workflow_context(self, tmpdir): - workflow_context = mock.context.simple(str(tmpdir.join('resources')), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + workflow_context = mock.context.simple(str(tmpdir)) workflow_context.states = [] workflow_context.exception = None yield workflow_context http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/api/test_task.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/api/test_task.py b/tests/orchestrator/workflows/api/test_task.py index 433c763..bb629ef 100644 --- a/tests/orchestrator/workflows/api/test_task.py +++ b/tests/orchestrator/workflows/api/test_task.py @@ -30,7 +30,7 @@ def ctx(tmpdir): dependency_node <------ dependent_node :return: """ - simple_context = mock.context.simple(tmpdir) + simple_context = mock.context.simple(str(tmpdir), inmemory=False) simple_context.model.execution.put(mock.models.get_execution(simple_context.deployment)) yield simple_context storage.release_sqlite_storage(simple_context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/builtin/test_execute_operation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/builtin/test_execute_operation.py b/tests/orchestrator/workflows/builtin/test_execute_operation.py index 61e3b88..87e3425 100644 --- a/tests/orchestrator/workflows/builtin/test_execute_operation.py +++ b/tests/orchestrator/workflows/builtin/test_execute_operation.py @@ -24,8 +24,7 @@ from tests import storage @pytest.fixture def ctx(tmpdir): - context = mock.context.simple(str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/builtin/test_heal.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/builtin/test_heal.py b/tests/orchestrator/workflows/builtin/test_heal.py index 100e02a..3e4498f 100644 --- a/tests/orchestrator/workflows/builtin/test_heal.py +++ b/tests/orchestrator/workflows/builtin/test_heal.py @@ -26,8 +26,7 @@ from . import (assert_node_install_operations, @pytest.fixture def ctx(tmpdir): - context = mock.context.simple(str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/builtin/test_install.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/builtin/test_install.py b/tests/orchestrator/workflows/builtin/test_install.py index c822cd7..1791719 100644 --- a/tests/orchestrator/workflows/builtin/test_install.py +++ b/tests/orchestrator/workflows/builtin/test_install.py @@ -25,8 +25,7 @@ from . import assert_node_install_operations @pytest.fixture def ctx(tmpdir): - context = mock.context.simple(str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/builtin/test_uninstall.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/builtin/test_uninstall.py b/tests/orchestrator/workflows/builtin/test_uninstall.py index e1bca10..791291f 100644 --- a/tests/orchestrator/workflows/builtin/test_uninstall.py +++ b/tests/orchestrator/workflows/builtin/test_uninstall.py @@ -26,8 +26,7 @@ from . import assert_node_uninstall_operations @pytest.fixture def ctx(tmpdir): - context = mock.context.simple(str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/core/test_engine.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/core/test_engine.py b/tests/orchestrator/workflows/core/test_engine.py index fd7c442..05a3d90 100644 --- a/tests/orchestrator/workflows/core/test_engine.py +++ b/tests/orchestrator/workflows/core/test_engine.py @@ -124,9 +124,7 @@ class BaseTest(object): @pytest.fixture def workflow_context(self, tmpdir): - workflow_context = mock.context.simple( - str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + workflow_context = mock.context.simple(str(tmpdir)) workflow_context.states = [] workflow_context.exception = None yield workflow_context http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/core/test_task.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/core/test_task.py b/tests/orchestrator/workflows/core/test_task.py index 5e54e2f..b39a81f 100644 --- a/tests/orchestrator/workflows/core/test_task.py +++ b/tests/orchestrator/workflows/core/test_task.py @@ -31,9 +31,7 @@ from tests import mock, storage @pytest.fixture def ctx(tmpdir): - context = mock.context.simple( - str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/executor/test_process_executor_extension.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_process_executor_extension.py b/tests/orchestrator/workflows/executor/test_process_executor_extension.py index 550fa9c..18957f1 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor_extension.py +++ b/tests/orchestrator/workflows/executor/test_process_executor_extension.py @@ -75,7 +75,6 @@ def executor(): @pytest.fixture def context(tmpdir): - result = mock.context.simple(str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + result = mock.context.simple(str(tmpdir)) yield result storage.release_sqlite_storage(result.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py index 48c387a..e383859 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py +++ b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py @@ -148,7 +148,6 @@ def executor(): @pytest.fixture def context(tmpdir): - result = mock.context.simple(str(tmpdir), - model_initiator_kwargs=dict(base_dir=str(tmpdir))) + result = mock.context.simple(str(tmpdir)) yield result storage.release_sqlite_storage(result.model) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/storage/__init__.py ---------------------------------------------------------------------- diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index e97b4eb..b798e01 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -65,3 +65,14 @@ def release_sqlite_storage(storage): session.close() for engine in set(mapi._engine for mapi in mapis): model.DeclarativeBase.metadata.drop_all(engine) + + +def init_inmemory_model_storage(): + uri = 'sqlite:///:memory:' + engine_kwargs = dict(connect_args={'check_same_thread': False}, poolclass=pool.StaticPool) + + engine = create_engine(uri, **engine_kwargs) + session_factory = orm.sessionmaker(bind=engine) + session = session_factory() + + return dict(engine=engine, session=session) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/storage/test_instrumentation.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_instrumentation.py b/tests/storage/test_instrumentation.py index db888b3..771342c 100644 --- a/tests/storage/test_instrumentation.py +++ b/tests/storage/test_instrumentation.py @@ -25,7 +25,7 @@ from aria.storage import ( instrumentation, exceptions ) -from ..storage import release_sqlite_storage +from ..storage import release_sqlite_storage, init_inmemory_model_storage STUB = instrumentation._STUB @@ -328,9 +328,9 @@ def restore_instrumentation(): @pytest.fixture def storage(): - result = ModelStorage( - api_cls=sql_mapi.SQLAlchemyModelAPI, - items=(MockModel1, MockModel2, StrictMockModel)) + result = ModelStorage(api_cls=sql_mapi.SQLAlchemyModelAPI, + items=(MockModel1, MockModel2, StrictMockModel), + initiator=init_inmemory_model_storage) yield result release_sqlite_storage(result) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/storage/test_model_storage.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py index c02f2a0..34cc5df 100644 --- a/tests/storage/test_model_storage.py +++ b/tests/storage/test_model_storage.py @@ -22,14 +22,15 @@ from aria.storage import ( sql_mapi, ) from aria import application_model_storage -from ..storage import release_sqlite_storage +from ..storage import release_sqlite_storage, init_inmemory_model_storage from . import MockModel @pytest.fixture def storage(): - base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI) + base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI, + initiator=init_inmemory_model_storage) base_storage.register(MockModel) yield base_storage release_sqlite_storage(base_storage) @@ -61,7 +62,7 @@ def test_model_storage(storage): def test_application_storage_factory(): storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI, - initiator=sql_mapi.init_storage) + initiator=init_inmemory_model_storage) assert storage.node assert storage.node_instance assert storage.plugin http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/storage/test_models.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py index f2c2531..6450152 100644 --- a/tests/storage/test_models.py +++ b/tests/storage/test_models.py @@ -39,7 +39,7 @@ from aria.storage.model import ( from tests import mock -from tests.storage import release_sqlite_storage +from ..storage import release_sqlite_storage, init_inmemory_model_storage @contextmanager @@ -55,7 +55,7 @@ def sql_storage(storage_func): def _empty_storage(): return application_model_storage(sql_mapi.SQLAlchemyModelAPI, - initiator=sql_mapi.init_storage) + initiator=init_inmemory_model_storage) def _blueprint_storage(): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/storage/test_resource_storage.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_resource_storage.py b/tests/storage/test_resource_storage.py index 6db27db..9b5f782 100644 --- a/tests/storage/test_resource_storage.py +++ b/tests/storage/test_resource_storage.py @@ -45,13 +45,13 @@ class TestResourceStorage(TestFileSystem): def _create_storage(self): return ResourceStorage(FileSystemResourceAPI, - initiator_kwargs=dict(directory=self.path)) + api_kwargs=dict(directory=self.path)) def test_name(self): api = FileSystemResourceAPI storage = ResourceStorage(FileSystemResourceAPI, items=['blueprint'], - initiator_kwargs=dict(directory=self.path)) + api_kwargs=dict(directory=self.path)) assert repr(storage) == 'ResourceStorage(api={api})'.format(api=api) assert 'directory={resource_dir}'.format(resource_dir=self.path) in \ repr(storage.registered['blueprint']) @@ -62,7 +62,7 @@ class TestResourceStorage(TestFileSystem): assert os.path.exists(os.path.join(self.path, 'blueprint')) def test_upload_file(self): - storage = ResourceStorage(FileSystemResourceAPI, initiator_kwargs=dict(directory=self.path)) + storage = ResourceStorage(FileSystemResourceAPI, api_kwargs=dict(directory=self.path)) self._create(storage) tmpfile_path = tempfile.mkstemp(suffix=self.__class__.__name__, dir=self.path)[1] self._upload(storage, tmpfile_path, id='blueprint_id') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/storage/test_structures.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_structures.py b/tests/storage/test_structures.py index ae1e956..4127905 100644 --- a/tests/storage/test_structures.py +++ b/tests/storage/test_structures.py @@ -25,7 +25,7 @@ from aria.storage import ( exceptions ) -from ..storage import release_sqlite_storage, structure +from ..storage import release_sqlite_storage, structure, init_inmemory_model_storage from . import MockModel from ..mock import ( models, @@ -36,7 +36,7 @@ from ..mock import ( @pytest.fixture def storage(): - base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI) + base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI, initiator=init_inmemory_model_storage) base_storage.register(MockModel) yield base_storage release_sqlite_storage(base_storage) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ef512da/tests/utils/test_plugin.py ---------------------------------------------------------------------- diff --git a/tests/utils/test_plugin.py b/tests/utils/test_plugin.py index e5d3583..09885ef 100644 --- a/tests/utils/test_plugin.py +++ b/tests/utils/test_plugin.py @@ -50,7 +50,7 @@ class TestPluginManager(object): @pytest.fixture def model(): model = application_model_storage(sql_mapi.SQLAlchemyModelAPI, - initiator=sql_mapi.init_storage) + initiator=storage.init_inmemory_model_storage) yield model storage.release_sqlite_storage(model)
