Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-42-Generic-ctx-serialization-mechanism 34369879c -> 6311e453f (forced update)
review 2 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/6311e453 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/6311e453 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/6311e453 Branch: refs/heads/ARIA-42-Generic-ctx-serialization-mechanism Commit: 6311e453fa7003238cf5d0ef917dfaee69a00831 Parents: 7ef512d Author: mxmrlv <[email protected]> Authored: Wed Feb 8 21:33:12 2017 +0200 Committer: mxmrlv <[email protected]> Committed: Thu Feb 9 10:52:58 2017 +0200 ---------------------------------------------------------------------- aria/storage/core.py | 11 +++++++++++ aria/storage/sql_mapi.py | 10 ++++++++++ .../orchestrator/workflows/executor/test_executor.py | 14 ++++++++++---- .../workflows/executor/test_process_executor.py | 14 ++++++++++---- 4 files changed, 41 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6311e453/aria/storage/core.py ---------------------------------------------------------------------- diff --git a/aria/storage/core.py b/aria/storage/core.py index aa9e1a9..3878dca 100644 --- a/aria/storage/core.py +++ b/aria/storage/core.py @@ -62,6 +62,17 @@ class Storage(LoggerMixin): 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.registered = {} http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6311e453/aria/storage/sql_mapi.py ---------------------------------------------------------------------- diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py index c9a29ea..9dae08a 100644 --- a/aria/storage/sql_mapi.py +++ b/aria/storage/sql_mapi.py @@ -371,6 +371,16 @@ class SQLAlchemyModelAPI(api.ModelAPI): 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. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6311e453/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 0b33ae6..d983fe9 100644 --- a/tests/orchestrator/workflows/executor/test_executor.py +++ b/tests/orchestrator/workflows/executor/test_executor.py @@ -30,7 +30,6 @@ except ImportError: from aria.storage import model from aria.orchestrator import events -from aria.orchestrator.context import operation from aria.orchestrator.workflows.executor import ( thread, process, @@ -81,13 +80,20 @@ class MockException(Exception): pass -class MockContext(operation.BaseOperationContext): +class MockContext(object): - def __init__(self, *args, **kwargs): # pylint: disable=super-init-not-called + def __init__(self, *args, **kwargs): 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/6311e453/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 9f0d1db..ff5dce6 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor.py +++ b/tests/orchestrator/workflows/executor/test_process_executor.py @@ -30,7 +30,6 @@ from aria.orchestrator import ( events, plugin ) -from aria.orchestrator.context import operation from aria.utils.plugin import create as create_plugin from aria.orchestrator.workflows.executor import process @@ -112,13 +111,20 @@ def mock_plugin(plugin_manager, tmpdir): return plugin_manager.install(source=plugin_path) -class MockContext(operation.BaseOperationContext): +class MockContext(object): - def __init__(self, *args, **kwargs): # pylint: disable=super-init-not-called + def __init__(self, *args, **kwargs): 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):
