ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: ARIA-42-Generic-ctx-serialization-mechanism
Date Thu, 09 Feb 2017 09:23:40 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/master d35d09a35 -> 1498ad397


ARIA-42-Generic-ctx-serialization-mechanism


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1498ad39
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1498ad39
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1498ad39

Branch: refs/heads/master
Commit: 1498ad397bcbed5a69c01f6d512a251e375792c7
Parents: d35d09a
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Wed Feb 1 16:16:01 2017 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Thu Feb 9 11:00:23 2017 +0200

----------------------------------------------------------------------
 aria/__init__.py                                | 25 +++---
 aria/orchestrator/context/operation.py          | 27 ++++++
 aria/orchestrator/context/serialization.py      | 95 --------------------
 aria/orchestrator/runner.py                     | 70 ++++-----------
 aria/orchestrator/workflows/executor/process.py | 11 +--
 aria/storage/api.py                             |  3 +-
 aria/storage/core.py                            | 55 ++++++++++--
 aria/storage/sql_mapi.py                        | 35 +++++++-
 setup.py                                        |  2 +-
 tests/mock/context.py                           | 32 ++++---
 tests/orchestrator/context/test_operation.py    |  7 +-
 .../context/test_resource_render.py             |  3 +-
 tests/orchestrator/context/test_serialize.py    | 19 ++--
 tests/orchestrator/context/test_toolbelt.py     |  2 +-
 tests/orchestrator/context/test_workflow.py     |  6 +-
 .../orchestrator/execution_plugin/test_local.py |  4 +-
 tests/orchestrator/execution_plugin/test_ssh.py |  4 +-
 tests/orchestrator/workflows/api/test_task.py   |  4 +-
 .../workflows/builtin/test_execute_operation.py |  2 +-
 .../orchestrator/workflows/builtin/test_heal.py |  2 +-
 .../workflows/builtin/test_install.py           |  2 +-
 .../workflows/builtin/test_uninstall.py         |  2 +-
 .../orchestrator/workflows/core/test_engine.py  |  2 +-
 tests/orchestrator/workflows/core/test_task.py  |  2 +-
 .../test_task_graph_into_exececution_graph.py   |  4 +-
 .../workflows/executor/test_executor.py         |  9 +-
 .../workflows/executor/test_process_executor.py | 26 ++++--
 .../executor/test_process_executor_extension.py |  2 +-
 .../test_process_executor_tracked_changes.py    |  2 +-
 tests/storage/__init__.py                       | 41 +++------
 tests/storage/test_instrumentation.py           |  9 +-
 tests/storage/test_model_storage.py             |  7 +-
 tests/storage/test_models.py                    |  4 +-
 tests/storage/test_structures.py                | 11 +--
 tests/utils/test_plugin.py                      |  6 +-
 35 files changed, 254 insertions(+), 283 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/aria/__init__.py
----------------------------------------------------------------------
diff --git a/aria/__init__.py b/aria/__init__.py
index 248aa1a..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, api_kwargs=None):
+def application_model_storage(api, api_kwargs=None, initiator=None, initiator_kwargs=None):
     """
     Initiate model storage
     """
@@ -78,19 +78,20 @@ def application_model_storage(api, api_kwargs=None):
         storage.model.Execution,
         storage.model.Task,
     ]
-    # if api not in _model_storage:
-    return storage.ModelStorage(api, items=models, api_kwargs=api_kwargs or {})
+    return storage.ModelStorage(api_cls=api,
+                                api_kwargs=api_kwargs,
+                                items=models,
+                                initiator=initiator,
+                                initiator_kwargs=initiator_kwargs or {})
 
 
-def application_resource_storage(api, api_kwargs=None):
+def application_resource_storage(api, api_kwargs=None, initiator=None, initiator_kwargs=None):
     """
     Initiate resource storage
     """
-    return storage.ResourceStorage(
-        api,
-        api_kwargs=api_kwargs or {},
-        items=[
-            'blueprint',
-            'deployment',
-            'plugin',
-        ])
+
+    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/1498ad39/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py
index 23a6fd4..d1f61b2 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -17,6 +17,7 @@
 Workflow and operation contexts
 """
 
+import aria
 from aria.utils import file
 from .common import BaseContext
 
@@ -73,6 +74,32 @@ class BaseOperationContext(BaseContext):
         file.makedirs(plugin_workdir)
         return plugin_workdir
 
+    @property
+    def serialization_dict(self):
+        context_cls = self.__class__
+        context_dict = {
+            'name': self.name,
+            'deployment_id': self._deployment_id,
+            'task_id': self._task_id,
+            'actor_id': self._actor_id,
+            'workdir': self._workdir,
+            'model_storage': self.model.serialization_dict if self.model else None,
+            'resource_storage': self.resource.serialization_dict if self.resource else None
+        }
+        return {
+            'context_cls': context_cls,
+            'context': context_dict
+        }
+
+    @classmethod
+    def deserialize_from_dict(cls, model_storage=None, resource_storage=None, **kwargs):
+        if model_storage:
+            model_storage = aria.application_model_storage(**model_storage)
+        if resource_storage:
+            resource_storage = aria.application_resource_storage(**resource_storage)
+
+        return cls(model_storage=model_storage, resource_storage=resource_storage, **kwargs)
+
 
 class NodeOperationContext(BaseOperationContext):
     """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/aria/orchestrator/context/serialization.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/serialization.py b/aria/orchestrator/context/serialization.py
deleted file mode 100644
index 760818f..0000000
--- a/aria/orchestrator/context/serialization.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import sqlalchemy.orm
-import sqlalchemy.pool
-
-import aria
-
-
-def operation_context_to_dict(context):
-    context_cls = context.__class__
-    context_dict = {
-        'name': context.name,
-        'deployment_id': context._deployment_id,
-        'task_id': context._task_id,
-        'actor_id': context._actor_id,
-        'workdir': context._workdir
-    }
-    if context.model:
-        model = context.model
-        context_dict['model_storage'] = {
-            'api_cls': model.api,
-            'api_kwargs': _serialize_sql_mapi_kwargs(model)
-        }
-    else:
-        context_dict['model_storage'] = None
-    if context.resource:
-        resource = context.resource
-        context_dict['resource_storage'] = {
-            'api_cls': resource.api,
-            'api_kwargs': _serialize_file_rapi_kwargs(resource)
-        }
-    else:
-        context_dict['resource_storage'] = None
-    return {
-        'context_cls': context_cls,
-        'context': context_dict
-    }
-
-
-def operation_context_from_dict(context_dict):
-    context_cls = context_dict['context_cls']
-    context = context_dict['context']
-
-    model_storage = context['model_storage']
-    if model_storage:
-        api_cls = model_storage['api_cls']
-        api_kwargs = _deserialize_sql_mapi_kwargs(model_storage.get('api_kwargs', {}))
-        context['model_storage'] = aria.application_model_storage(api=api_cls,
-                                                                  api_kwargs=api_kwargs)
-
-    resource_storage = context['resource_storage']
-    if resource_storage:
-        api_cls = resource_storage['api_cls']
-        api_kwargs = _deserialize_file_rapi_kwargs(resource_storage.get('api_kwargs', {}))
-        context['resource_storage'] = aria.application_resource_storage(api=api_cls,
-                                                                        api_kwargs=api_kwargs)
-
-    return context_cls(**context)
-
-
-def _serialize_sql_mapi_kwargs(model):
-    engine_url = str(model._api_kwargs['engine'].url)
-    assert ':memory:' not in engine_url
-    return {'engine_url': engine_url}
-
-
-def _deserialize_sql_mapi_kwargs(api_kwargs):
-    engine_url = api_kwargs.get('engine_url')
-    if not engine_url:
-        return {}
-    engine = sqlalchemy.create_engine(engine_url)
-    session_factory = sqlalchemy.orm.sessionmaker(bind=engine)
-    session = sqlalchemy.orm.scoped_session(session_factory=session_factory)
-    return {'session': session, 'engine': engine}
-
-
-def _serialize_file_rapi_kwargs(resource):
-    return {'directory': resource._api_kwargs['directory']}
-
-
-def _deserialize_file_rapi_kwargs(api_kwargs):
-    return api_kwargs

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/aria/orchestrator/runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/runner.py b/aria/orchestrator/runner.py
index 16acc19..5950dc5 100644
--- a/aria/orchestrator/runner.py
+++ b/aria/orchestrator/runner.py
@@ -17,20 +17,20 @@
 Workflow runner
 """
 
-import platform
 import tempfile
 import os
 
-from sqlalchemy import (create_engine, orm) # @UnresolvedImport
-from sqlalchemy.pool import StaticPool # @UnresolvedImport
-
 from .context.workflow import WorkflowContext
 from .workflows.core.engine import Engine
 from .workflows.executor.thread import ThreadExecutor
-from ..storage import model
-from ..storage.sql_mapi import SQLAlchemyModelAPI
-from ..storage.filesystem_rapi import FileSystemResourceAPI
-from .. import (application_model_storage, application_resource_storage)
+from ..storage import (
+    sql_mapi,
+    filesystem_rapi,
+)
+from .. import (
+    application_model_storage,
+    application_resource_storage
+)
 
 
 SQLITE_IN_MEMORY = 'sqlite:///:memory:'
@@ -57,6 +57,8 @@ class Runner(object):
             os.close(the_file)
 
         self._storage_path = storage_path
+        self._storage_dir = os.path.dirname(storage_path)
+        self._storage_name = os.path.basename(storage_path)
         self._is_storage_temporary = is_storage_temporary
 
         workflow_context = self.create_workflow_context(workflow_name, deployment_id,
@@ -76,9 +78,13 @@ class Runner(object):
             self.cleanup()
 
     def create_workflow_context(self, workflow_name, deployment_id, initialize_model_storage_fn):
-        model_storage = self.create_sqlite_model_storage()
+        self.cleanup()
+        model_storage = application_model_storage(
+            sql_mapi.SQLAlchemyModelAPI,
+            initiator_kwargs=dict(base_dir=self._storage_dir, filename=self._storage_name))
         initialize_model_storage_fn(model_storage)
-        resource_storage = self.create_fs_resource_storage()
+        resource_storage = application_resource_storage(
+            filesystem_rapi.FileSystemResourceAPI, api_kwargs=dict(directory='.'))
         return WorkflowContext(
             name=workflow_name,
             model_storage=model_storage,
@@ -88,48 +94,8 @@ class Runner(object):
             task_max_attempts=1,
             task_retry_interval=1)
 
-    def create_sqlite_model_storage(self): # pylint: disable=no-self-use
-        self.cleanup()
-
-        # Engine
-        if self._storage_path is None:
-            # In memory
-            # Causes serious threading problems:
-            # https://gehrcke.de/2015/05/in-memory-sqlite-database-and-flask-a-threading-trap/
-            sqlite_engine = create_engine(
-                SQLITE_IN_MEMORY,
-                connect_args={'check_same_thread': False},
-                poolclass=StaticPool)
-        else:
-            path_prefix = '' if 'Windows' in platform.system() else '/'
-            sqlite_engine = create_engine(
-                'sqlite:///%s%s' % (path_prefix, self._storage_path))
-
-        # Models
-        model.DeclarativeBase.metadata.create_all(bind=sqlite_engine) # @UndefinedVariable
-
-        # Session
-        sqlite_session_factory = orm.sessionmaker(bind=sqlite_engine)
-        if self._storage_path is None:
-            sqlite_session = sqlite_session_factory()
-        else:
-            # File-based storage only
-            sqlite_session = orm.scoped_session(session_factory=sqlite_session_factory)
-
-        # Storage
-        sqlite_kwargs = dict(engine=sqlite_engine, session=sqlite_session)
-        return application_model_storage(
-            SQLAlchemyModelAPI,
-            api_kwargs=sqlite_kwargs)
-
-    def create_fs_resource_storage(self, directory='.'): # pylint: disable=no-self-use
-        fs_kwargs = dict(directory=directory)
-        return application_resource_storage(
-            FileSystemResourceAPI,
-            api_kwargs=fs_kwargs)
 
     def cleanup(self):
-        if self._is_storage_temporary \
-            and (self._storage_path is not None) \
-            and os.path.isfile(self._storage_path):
+        if (self._is_storage_temporary and (self._storage_path is not None) and
+                os.path.isfile(self._storage_path)):
             os.remove(self._storage_path)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index 7d990fa..c4b8ba1 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -37,6 +37,7 @@ import struct
 import subprocess
 import tempfile
 import Queue
+import pickle
 
 import jsonpickle
 
@@ -45,7 +46,6 @@ from aria.extension import process_executor
 from aria.utils import imports
 from aria.utils import exceptions
 from aria.orchestrator.workflows.executor import base
-from aria.orchestrator.context import serialization
 from aria.storage import instrumentation
 from aria.storage import type as storage_type
 
@@ -113,7 +113,7 @@ class ProcessExecutor(base.BaseExecutor):
         file_descriptor, arguments_json_path = tempfile.mkstemp(prefix='executor-', suffix='.json')
         os.close(file_descriptor)
         with open(arguments_json_path, 'wb') as f:
-            f.write(jsonpickle.dumps(self._create_arguments_dict(task)))
+            f.write(pickle.dumps(self._create_arguments_dict(task)))
 
         env = os.environ.copy()
         # See _update_env for plugin_prefix usage
@@ -193,7 +193,7 @@ class ProcessExecutor(base.BaseExecutor):
             'operation_mapping': task.operation_mapping,
             'operation_inputs': task.inputs,
             'port': self._server_port,
-            'context': serialization.operation_context_to_dict(task.context),
+            'context': task.context.serialization_dict,
         }
 
     def _update_env(self, env, plugin_prefix):
@@ -306,7 +306,7 @@ def _patch_session(ctx, messenger, instrument):
 def _main():
     arguments_json_path = sys.argv[1]
     with open(arguments_json_path) as f:
-        arguments = jsonpickle.loads(f.read())
+        arguments = pickle.loads(f.read())
 
     # arguments_json_path is a temporary file created by the parent process.
     # so we remove it here
@@ -327,7 +327,7 @@ def _main():
 
     with instrumentation.track_changes() as instrument:
         try:
-            ctx = serialization.operation_context_from_dict(context_dict)
+            ctx = context_dict['context_cls'].deserialize_from_dict(**context_dict['context'])
             _patch_session(ctx=ctx, messenger=messenger, instrument=instrument)
             task_func = imports.load_attribute(operation_mapping)
             aria.install_aria_extensions()
@@ -338,5 +338,6 @@ def _main():
         except BaseException as e:
             messenger.failed(exception=e, tracked_changes=instrument.tracked_changes)
 
+
 if __name__ == '__main__':
     _main()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/aria/storage/api.py
----------------------------------------------------------------------
diff --git a/aria/storage/api.py b/aria/storage/api.py
index d6fc3b8..f6da6de 100644
--- a/aria/storage/api.py
+++ b/aria/storage/api.py
@@ -119,11 +119,12 @@ class ResourceAPI(StorageAPI):
     """
     A Base object for the resource.
     """
-    def __init__(self, name):
+    def __init__(self, name, **kwargs):
         """
         Base resource API
         :param str name: the resource type
         """
+        super(ResourceAPI, self).__init__(**kwargs)
         self._name = name
 
     @property

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/aria/storage/core.py
----------------------------------------------------------------------
diff --git a/aria/storage/core.py b/aria/storage/core.py
index 94b4fe0..3878dca 100644
--- a/aria/storage/core.py
+++ b/aria/storage/core.py
@@ -39,7 +39,10 @@ API:
 """
 
 from aria.logger import LoggerMixin
-from . import api as storage_api
+from . import (
+    api as storage_api,
+    sql_mapi
+)
 
 __all__ = (
     'Storage',
@@ -52,11 +55,33 @@ class Storage(LoggerMixin):
     """
     Represents the storage
     """
-    def __init__(self, api_cls, api_kwargs=None, items=(), **kwargs):
+    def __init__(self,
+                 api_cls,
+                 api_kwargs=None,
+                 items=(),
+                 initiator=None,
+                 initiator_kwargs=None,
+                 **kwargs):
+        """
+
+        :param api_cls: API cls for each model.
+        :param api_kwargs:
+        :param items: the items to register
+        :param initiator: a func which initializes the storage before the first use.
+        This function should return a dict, this dict would be passed in addition to the api kwargs.
+        This enables the creation of any unpickable objects across process.
+        :param initiator_kwargs:
+        :param kwargs:
+        """
         super(Storage, self).__init__(**kwargs)
         self.api = api_cls
-        self._api_kwargs = api_kwargs or {}
         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._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(
@@ -71,6 +96,15 @@ class Storage(LoggerMixin):
         except KeyError:
             return super(Storage, self).__getattribute__(item)
 
+    @property
+    def serialization_dict(self):
+        return {
+            'api': self.api,
+            'api_kwargs': self._api_kwargs,
+            'initiator': self._initiator,
+            'initiator_kwargs': self._initiator_kwargs
+        }
+
     def register(self, entry):
         """
         Register the entry to the storage
@@ -90,7 +124,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))
 
@@ -99,6 +135,11 @@ class ModelStorage(Storage):
     """
     Represents model storage.
     """
+    def __init__(self, *args, **kwargs):
+        if kwargs.get('initiator', None) is None:
+            kwargs['initiator'] = sql_mapi.init_storage
+        super(ModelStorage, self).__init__(*args, **kwargs)
+
     def register(self, model_cls):
         """
         Register the model into the model storage.
@@ -110,9 +151,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/1498ad39/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index 809f677..9dae08a 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -15,13 +15,19 @@
 """
 SQLAlchemy based MAPI
 """
+import os
+import platform
 
+from sqlalchemy import (
+    create_engine,
+    orm,
+)
 from sqlalchemy.exc import SQLAlchemyError
 
 from aria.utils.collections import OrderedDict
-from aria.storage import (
+from . import (
     api,
-    exceptions
+    exceptions,
 )
 
 
@@ -364,6 +370,31 @@ class SQLAlchemyModelAPI(api.ModelAPI):
             getattr(instance, rel.key)
 
 
+def init_storage(base_dir, filename='db.sqlite'):
+    """
+    A builtin ModelStorage initiator.
+    Creates a sqlalchemy engine and a session to be passed to the mapi.
+
+    Initiator_kwargs must be passed to the ModelStorage which must hold the base_dir for the
+    location of the db file, and an option filename. This would create an sqlite db.
+    :param base_dir: the dir of the db
+    :param filename: the db file name.
+    :return:
+    """
+    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 = create_engine(uri)
+    session_factory = orm.sessionmaker(bind=engine)
+    session = orm.scoped_session(session_factory=session_factory)
+
+    return dict(engine=engine, session=session)
+
+
 class ListResult(object):
     """
     a ListResult contains results about the requested items.

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index 2d1106d..7a1a3f4 100644
--- a/setup.py
+++ b/setup.py
@@ -64,7 +64,7 @@ console_scripts = ['aria = aria.cli.cli:main']
 
 class InstallCommand(install):
     user_options = install.user_options + [
-        ('skip-ctx', None, 'Install with or without the ctx (Defaults to False')
+        ('skip-ctx', None, 'Install with or without the ctx (Defaults to False)')
     ]
     boolean_options = install.boolean_options + ['skip-ctx']
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/mock/context.py
----------------------------------------------------------------------
diff --git a/tests/mock/context.py b/tests/mock/context.py
index ec4bfb8..cb040ae 100644
--- a/tests/mock/context.py
+++ b/tests/mock/context.py
@@ -13,28 +13,32 @@
 # 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.filesystem_rapi import FileSystemResourceAPI
-from aria.storage.sql_mapi import SQLAlchemyModelAPI
+from aria.storage import (
+    sql_mapi,
+    filesystem_rapi,
+)
 
 from . import models
+from ..storage import init_inmemory_model_storage
 from .topology import create_simple_topology_two_nodes
 
 
-def simple(mapi_kwargs, resources_dir=None, **kwargs):
-    model_storage = aria.application_model_storage(SQLAlchemyModelAPI, api_kwargs=mapi_kwargs)
+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)
 
-    deployment_id = create_simple_topology_two_nodes(model_storage)
+    model_storage = aria.application_model_storage(
+        sql_mapi.SQLAlchemyModelAPI, initiator=initiator, initiator_kwargs=initiator_kwargs)
+    resource_storage = aria.application_resource_storage(
+        filesystem_rapi.FileSystemResourceAPI,
+        api_kwargs=dict(directory=os.path.join(tmpdir, 'resources'))
+    )
 
-    # pytest tmpdir
-    if resources_dir:
-        resource_storage = aria.application_resource_storage(
-            FileSystemResourceAPI,
-            api_kwargs={'directory': resources_dir}
-        )
-    else:
-        resource_storage = None
+    deployment_id = create_simple_topology_two_nodes(model_storage)
 
     final_kwargs = dict(
         name='simple_context',
@@ -45,5 +49,5 @@ def simple(mapi_kwargs, resources_dir=None, **kwargs):
         task_max_attempts=models.TASK_MAX_ATTEMPTS,
         task_retry_interval=models.TASK_RETRY_INTERVAL
     )
-    final_kwargs.update(kwargs)
+    final_kwargs.update(context_kwargs or {})
     return context.workflow.WorkflowContext(**final_kwargs)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py
index b0918d1..e8c7cca 100644
--- a/tests/orchestrator/context/test_operation.py
+++ b/tests/orchestrator/context/test_operation.py
@@ -37,8 +37,11 @@ global_test_holder = {}
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)),
-                                  workdir=str(tmpdir.join('workdir')))
+    context = mock.context.simple(
+        str(tmpdir.join('workdir')),
+        inmemory=True,
+        context_kwargs=dict(workdir=str(tmpdir.join('workdir')))
+    )
     yield context
     storage.release_sqlite_storage(context.model)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/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 ca2ef42..ded18c8 100644
--- a/tests/orchestrator/context/test_resource_render.py
+++ b/tests/orchestrator/context/test_resource_render.py
@@ -53,8 +53,7 @@ def test_download_resource_and_render_provided_variables(tmpdir, ctx):
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(),
-                                  resources_dir=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/1498ad39/tests/orchestrator/context/test_serialize.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py
index 76930b1..ee123a7 100644
--- a/tests/orchestrator/context/test_serialize.py
+++ b/tests/orchestrator/context/test_serialize.py
@@ -16,13 +16,11 @@
 import pytest
 
 import aria
-from aria.storage.sql_mapi import SQLAlchemyModelAPI
+from aria.storage import sql_mapi
 from aria.orchestrator.workflows import api
 from aria.orchestrator.workflows.core import engine
 from aria.orchestrator.workflows.executor import process
 from aria.orchestrator import workflow, operation
-from aria.orchestrator.context import serialization
-
 import tests
 from tests import mock
 from tests import storage
@@ -42,10 +40,6 @@ def test_serialize_operation_context(context, executor, tmpdir):
     eng.execute()
 
 
-def test_illegal_serialize_of_memory_model_storage(memory_model_storage):
-    with pytest.raises(AssertionError):
-        serialization._serialize_sql_mapi_kwargs(memory_model_storage)
-
 
 @workflow
 def _mock_workflow(ctx, graph):
@@ -93,16 +87,17 @@ def executor():
 
 @pytest.fixture
 def context(tmpdir):
-    result = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)),
-                                 resources_dir=str(tmpdir.join('resources')),
-                                 workdir=str(tmpdir.join('workdir')))
+    result = mock.context.simple(
+        str(tmpdir),
+        context_kwargs=dict(workdir=str(tmpdir.join('workdir')))
+    )
+
     yield result
     storage.release_sqlite_storage(result.model)
 
 
 @pytest.fixture
 def memory_model_storage():
-    result = aria.application_model_storage(
-        SQLAlchemyModelAPI, api_kwargs=storage.get_sqlite_api_kwargs())
+    result = aria.application_model_storage(sql_mapi.SQLAlchemyModelAPI)
     yield result
     storage.release_sqlite_storage(result)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/orchestrator/context/test_toolbelt.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py
index b63811b..beb5730 100644
--- a/tests/orchestrator/context/test_toolbelt.py
+++ b/tests/orchestrator/context/test_toolbelt.py
@@ -33,7 +33,7 @@ global_test_holder = {}
 
 @pytest.fixture
 def workflow_context(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/tests/orchestrator/context/test_workflow.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_workflow.py b/tests/orchestrator/context/test_workflow.py
index 496c1ff..bb54037 100644
--- a/tests/orchestrator/context/test_workflow.py
+++ b/tests/orchestrator/context/test_workflow.py
@@ -19,7 +19,7 @@ import pytest
 
 from aria import application_model_storage
 from aria.orchestrator import context
-from aria.storage.sql_mapi import SQLAlchemyModelAPI
+from aria.storage import sql_mapi
 from tests import storage as test_storage
 from tests.mock import models
 
@@ -60,8 +60,8 @@ class TestWorkflowContext(object):
 
 @pytest.fixture(scope='function')
 def storage():
-    api_kwargs = test_storage.get_sqlite_api_kwargs()
-    workflow_storage = application_model_storage(SQLAlchemyModelAPI, api_kwargs=api_kwargs)
+    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/1498ad39/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 497da48..86f2aa7 100644
--- a/tests/orchestrator/execution_plugin/test_local.py
+++ b/tests/orchestrator/execution_plugin/test_local.py
@@ -503,9 +503,7 @@ if __name__ == '__main__':
 
     @pytest.fixture
     def workflow_context(self, tmpdir):
-        workflow_context = mock.context.simple(
-            storage.get_sqlite_api_kwargs(str(tmpdir)),
-            resources_dir=str(tmpdir.join('resources')))
+        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/1498ad39/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 6b5c783..65195c8 100644
--- a/tests/orchestrator/execution_plugin/test_ssh.py
+++ b/tests/orchestrator/execution_plugin/test_ssh.py
@@ -265,9 +265,7 @@ class TestWithActualSSHServer(object):
 
     @pytest.fixture
     def workflow_context(self, tmpdir):
-        workflow_context = mock.context.simple(
-            storage.get_sqlite_api_kwargs(str(tmpdir)),
-            resources_dir=str(tmpdir.join('resources')))
+        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/1498ad39/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 601c437..bb629ef 100644
--- a/tests/orchestrator/workflows/api/test_task.py
+++ b/tests/orchestrator/workflows/api/test_task.py
@@ -24,13 +24,13 @@ from tests import mock, storage
 
 
 @pytest.fixture
-def ctx():
+def ctx(tmpdir):
     """
     Create the following graph in storage:
     dependency_node <------ dependent_node
     :return:
     """
-    simple_context = mock.context.simple(storage.get_sqlite_api_kwargs())
+    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/1498ad39/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 b7e5678..87e3425 100644
--- a/tests/orchestrator/workflows/builtin/test_execute_operation.py
+++ b/tests/orchestrator/workflows/builtin/test_execute_operation.py
@@ -24,7 +24,7 @@ from tests import storage
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/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 b470790..3e4498f 100644
--- a/tests/orchestrator/workflows/builtin/test_heal.py
+++ b/tests/orchestrator/workflows/builtin/test_heal.py
@@ -26,7 +26,7 @@ from . import (assert_node_install_operations,
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/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 789a161..1791719 100644
--- a/tests/orchestrator/workflows/builtin/test_install.py
+++ b/tests/orchestrator/workflows/builtin/test_install.py
@@ -25,7 +25,7 @@ from . import assert_node_install_operations
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/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 126c4cf..791291f 100644
--- a/tests/orchestrator/workflows/builtin/test_uninstall.py
+++ b/tests/orchestrator/workflows/builtin/test_uninstall.py
@@ -26,7 +26,7 @@ from . import assert_node_uninstall_operations
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/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 d9b50a9..05a3d90 100644
--- a/tests/orchestrator/workflows/core/test_engine.py
+++ b/tests/orchestrator/workflows/core/test_engine.py
@@ -124,7 +124,7 @@ class BaseTest(object):
 
     @pytest.fixture
     def workflow_context(self, tmpdir):
-        workflow_context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/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 061a3f2..b39a81f 100644
--- a/tests/orchestrator/workflows/core/test_task.py
+++ b/tests/orchestrator/workflows/core/test_task.py
@@ -31,7 +31,7 @@ from tests import mock, storage
 
 @pytest.fixture
 def ctx(tmpdir):
-    context = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py b/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
index cd37bde..57be075 100644
--- a/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
+++ b/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
@@ -22,9 +22,9 @@ from tests import mock
 from tests import storage
 
 
-def test_task_graph_into_execution_graph():
+def test_task_graph_into_execution_graph(tmpdir):
     operation_name = 'tosca.interfaces.node.lifecycle.Standard.create'
-    task_context = mock.context.simple(storage.get_sqlite_api_kwargs())
+    task_context = mock.context.simple(str(tmpdir))
     node_instance = \
         task_context.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
     def sub_workflow(name, **_):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/orchestrator/workflows/executor/test_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py
index 2486a1e..d983fe9 100644
--- a/tests/orchestrator/workflows/executor/test_executor.py
+++ b/tests/orchestrator/workflows/executor/test_executor.py
@@ -86,7 +86,14 @@ class MockContext(object):
         pass
 
     def __getattr__(self, item):
-        return None
+        if item == 'serialization_dict':
+            return {'context_cls': self.__class__, 'context': {}}
+        else:
+            return None
+
+    @classmethod
+    def deserialize_from_dict(cls, **kwargs):
+        return cls()
 
 
 class MockTask(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/orchestrator/workflows/executor/test_process_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py
index 687e245..ff5dce6 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -22,11 +22,15 @@ from contextlib import contextmanager
 import pytest
 
 from aria import application_model_storage
-from aria.storage import model as aria_model
+from aria.storage import (
+    model as aria_model,
+    sql_mapi
+)
+from aria.orchestrator import (
+    events,
+    plugin
+)
 from aria.utils.plugin import create as create_plugin
-from aria.storage.sql_mapi import SQLAlchemyModelAPI
-from aria.orchestrator import events
-from aria.orchestrator import plugin
 from aria.orchestrator.workflows.executor import process
 
 
@@ -74,8 +78,9 @@ class TestProcessExecutor(object):
 
 @pytest.fixture
 def model(tmpdir):
-    api_kwargs = tests.storage.get_sqlite_api_kwargs(str(tmpdir))
-    result = application_model_storage(SQLAlchemyModelAPI, api_kwargs=api_kwargs)
+    result = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                       initiator_kwargs=dict(base_dir=str(tmpdir)),
+                                       initiator=sql_mapi.init_storage)
     yield result
     tests.storage.release_sqlite_storage(result)
 
@@ -112,7 +117,14 @@ class MockContext(object):
         pass
 
     def __getattr__(self, item):
-        return None
+        if item == 'serialization_dict':
+            return {'context_cls': self.__class__, 'context': {}}
+        else:
+            return None
+
+    @classmethod
+    def deserialize_from_dict(cls, **kwargs):
+        return cls()
 
 
 class MockTask(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/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 4a8ef57..18957f1 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor_extension.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor_extension.py
@@ -75,6 +75,6 @@ def executor():
 
 @pytest.fixture
 def context(tmpdir):
-    result = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/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 bd1fa96..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,6 +148,6 @@ def executor():
 
 @pytest.fixture
 def context(tmpdir):
-    result = mock.context.simple(storage.get_sqlite_api_kwargs(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/1498ad39/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 3b3715e..b798e01 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -42,7 +42,6 @@ class MockModel(model.DeclarativeBase, structure.ModelMixin): #pylint: disable=a
     name = Column(Text)
 
 
-
 class TestFileSystem(object):
 
     def setup_method(self):
@@ -52,35 +51,6 @@ class TestFileSystem(object):
         rmtree(self.path, ignore_errors=True)
 
 
-def get_sqlite_api_kwargs(base_dir=None, filename='db.sqlite'):
-    """
-    Create sql params. works in in-memory and in filesystem mode.
-    If base_dir is passed, the mode will be filesystem mode. while the default mode is in-memory.
-    :param str base_dir: The base dir for the filesystem memory file.
-    :param str filename: the file name - defaults to 'db.sqlite'.
-    :return:
-    """
-    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 '/',
-
-            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)
-
-    engine = create_engine(uri, **engine_kwargs)
-    session_factory = orm.sessionmaker(bind=engine)
-    session = orm.scoped_session(session_factory=session_factory) if base_dir else session_factory()
-
-    model.DeclarativeBase.metadata.create_all(bind=engine)
-    return dict(engine=engine, session=session)
-
-
 def release_sqlite_storage(storage):
     """
     Drops the tables and clears the session
@@ -95,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/1498ad39/tests/storage/test_instrumentation.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_instrumentation.py b/tests/storage/test_instrumentation.py
index 9b4da4f..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 get_sqlite_api_kwargs, release_sqlite_storage
+from ..storage import release_sqlite_storage, init_inmemory_model_storage
 
 
 STUB = instrumentation._STUB
@@ -328,10 +328,9 @@ def restore_instrumentation():
 
 @pytest.fixture
 def storage():
-    result = ModelStorage(
-        api_cls=sql_mapi.SQLAlchemyModelAPI,
-        api_kwargs=get_sqlite_api_kwargs(),
-        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/1498ad39/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index d1596e3..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 get_sqlite_api_kwargs, 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, api_kwargs=get_sqlite_api_kwargs())
+    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,
-                                        api_kwargs=get_sqlite_api_kwargs())
+                                        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/1498ad39/tests/storage/test_models.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py
index 2088676..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 get_sqlite_api_kwargs, 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,
-                                     api_kwargs=get_sqlite_api_kwargs())
+                                     initiator=init_inmemory_model_storage)
 
 
 def _blueprint_storage():

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/storage/test_structures.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_structures.py b/tests/storage/test_structures.py
index 0223a98..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 get_sqlite_api_kwargs, 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, api_kwargs=get_sqlite_api_kwargs())
+    base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI, initiator=init_inmemory_model_storage)
     base_storage.register(MockModel)
     yield base_storage
     release_sqlite_storage(base_storage)
@@ -48,8 +48,10 @@ def module_cleanup():
 
 
 @pytest.fixture
-def context():
-    return mock_context.simple(get_sqlite_api_kwargs())
+def context(tmpdir):
+    ctx = mock_context.simple(str(tmpdir))
+    yield ctx
+    release_sqlite_storage(ctx.model)
 
 
 def test_inner_dict_update(storage):
@@ -174,7 +176,6 @@ def test_relationship_model_ordering(context):
         target_node_instance=target_node_instance,
     )
 
-
     context.model.node.put(new_node)
     context.model.node_instance.put(new_node_instance)
     context.model.relationship.put(source_to_new_relationship)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1498ad39/tests/utils/test_plugin.py
----------------------------------------------------------------------
diff --git a/tests/utils/test_plugin.py b/tests/utils/test_plugin.py
index 6f2dd92..09885ef 100644
--- a/tests/utils/test_plugin.py
+++ b/tests/utils/test_plugin.py
@@ -21,7 +21,7 @@ from aria import application_model_storage
 from aria.orchestrator import exceptions
 from aria.orchestrator import plugin
 from aria.utils.plugin import create as create_plugin
-from aria.storage.sql_mapi import SQLAlchemyModelAPI
+from aria.storage import sql_mapi
 
 from .. import storage
 
@@ -49,8 +49,8 @@ class TestPluginManager(object):
 
 @pytest.fixture
 def model():
-    api_kwargs = storage.get_sqlite_api_kwargs()
-    model = application_model_storage(SQLAlchemyModelAPI, api_kwargs=api_kwargs)
+    model = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                      initiator=storage.init_inmemory_model_storage)
     yield model
     storage.release_sqlite_storage(model)
 


Mime
View raw message