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: cleaning up [Forced Update!]
Date Mon, 06 Feb 2017 14:53:32 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-42-Generic-ctx-serialization-mechanism 641cf81d7 -> 69fb70da2 (forced
update)


cleaning up


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

Branch: refs/heads/ARIA-42-Generic-ctx-serialization-mechanism
Commit: 69fb70da2f4183e71a19e67ad403aeebf3ac0fbf
Parents: 0324696
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Mon Feb 6 16:52:06 2017 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Mon Feb 6 16:53:23 2017 +0200

----------------------------------------------------------------------
 aria/__init__.py                                |  5 ++--
 aria/orchestrator/workflows/executor/process.py |  6 -----
 aria/storage/api.py                             | 24 ++++++++++++++------
 tests/__init__.py                               |  4 ++++
 tests/mock/context.py                           |  5 +++-
 tests/orchestrator/context/test_workflow.py     |  5 ++--
 .../workflows/executor/test_process_executor.py |  6 +++--
 tests/storage/__init__.py                       |  2 +-
 tests/storage/test_model_storage.py             |  3 ++-
 tests/storage/test_models.py                    |  3 ++-
 tests/storage/test_structures.py                |  5 ++--
 tests/utils/test_plugin.py                      |  5 ++--
 12 files changed, 45 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/aria/__init__.py
----------------------------------------------------------------------
diff --git a/aria/__init__.py b/aria/__init__.py
index f3bc043..da77f03 100644
--- a/aria/__init__.py
+++ b/aria/__init__.py
@@ -78,8 +78,7 @@ def application_model_storage(api, api_kwargs=None, storage_initiator_func=None)
         storage.model.Execution,
         storage.model.Task,
     ]
-    # if api not in _model_storage:
-    api.storage_initiator(storage_initiator_func or storage.sql_mapi.init_storage)
+    api.storage_initiator(storage_initiator_func)
     return storage.ModelStorage(api, items=models, api_kwargs=api_kwargs or {})
 
 
@@ -88,6 +87,6 @@ def application_resource_storage(api, api_kwargs=None, storage_initiator_func=No
     Initiate resource storage
     """
 
-    # api.storage_initiator(storage_initiator_func or (lambda **kwargs: kwargs))
+    api.storage_initiator(storage_initiator_func)
     return storage.ResourceStorage(
         api, api_kwargs=api_kwargs or {}, items=['blueprint', 'deployment', 'plugin', ])

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index cf50ac6..f670dfe 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -327,7 +327,6 @@ def _main():
     storage_type.remove_mutable_association_listener()
 
     with instrumentation.track_changes() as instrument:
-        ctx = None
         try:
             ctx = serialization.operation_context_from_dict(context_dict)
             _patch_session(ctx=ctx, messenger=messenger, instrument=instrument)
@@ -339,11 +338,6 @@ def _main():
             messenger.succeeded(tracked_changes=instrument.tracked_changes)
         except BaseException as e:
             messenger.failed(exception=e, tracked_changes=instrument.tracked_changes)
-        finally:
-            if not ctx:
-                return
-            for session in set(mapi._session for mapi in ctx.model.registered.values() or
[]):
-                session.close()
 
 
 if __name__ == '__main__':

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/aria/storage/api.py
----------------------------------------------------------------------
diff --git a/aria/storage/api.py b/aria/storage/api.py
index 59ee2e8..e9f2917 100644
--- a/aria/storage/api.py
+++ b/aria/storage/api.py
@@ -19,6 +19,8 @@ from functools import partial
 
 
 class StorageAPI(object):
+    NO_INITIATOR = 'no_initiatior_func'
+
     """
     General storage Base API
     """
@@ -31,21 +33,29 @@ class StorageAPI(object):
         raise NotImplementedError('Subclass must implement abstract create method')
 
     @classmethod
-    def storage_initiator(cls, func=None):
-        if func is None:
+    def storage_initiator(cls, func=NO_INITIATOR):
+        if func is cls.NO_INITIATOR:
+            # Support for decoration syntax
             return partial(cls.storage_initiator, cls=cls)
+
+        if func is None:
+            # If func is None, no storage initiator was set, and nothing should happen.
+            return
+
+        if hasattr(cls, '_original_init') and cls._init_func.__func__ == func:
+            # setting the same function twice could cause a loop. we need to avoid that.
+            return
+
         cls._original_init = cls.__init__
         cls._init_func = func
         cls.__init__ = \
             lambda self, *args, **kwargs: cls._original_init(self, **func(cls=cls, *args,
**kwargs))
 
     @classmethod
-    def free_storage_initiator(cls, safe=False):
-        if not hasattr(cls, '_original_init'):
-            if not safe:
-                raise Exception('No storage initiator was registered')
-        elif cls.__init__ != cls._original_init:
+    def free_storage_initiator(cls):
+        if hasattr(cls, '_original_init') and cls.__init__ != cls._original_init:
             cls.__init__ = cls._original_init
+            delattr(cls, '_original_init')
 
         if hasattr(cls, '_engine'):
             delattr(cls, '_engine')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/__init__.py
----------------------------------------------------------------------
diff --git a/tests/__init__.py b/tests/__init__.py
index d2858d2..e51dd69 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -15,4 +15,8 @@
 
 import os
 
+from aria.storage import sql_mapi
+
+sql_mapi.SQLAlchemyModelAPI.storage_initiator(sql_mapi.init_storage)
+
 ROOT_DIR = os.path.dirname(os.path.dirname(__file__))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/mock/context.py
----------------------------------------------------------------------
diff --git a/tests/mock/context.py b/tests/mock/context.py
index c5da063..d1fa5ed 100644
--- a/tests/mock/context.py
+++ b/tests/mock/context.py
@@ -25,7 +25,10 @@ from .topology import create_simple_topology_two_nodes
 def simple(tmpdir, model_driver_kwargs=None, resources_driver_kwargs=None, context_kwargs=None):
 
     model_storage = aria.application_model_storage(
-        sql_mapi.SQLAlchemyModelAPI, api_kwargs=model_driver_kwargs or {})
+        sql_mapi.SQLAlchemyModelAPI,
+        api_kwargs=model_driver_kwargs or {},
+        storage_initiator_func=sql_mapi.init_storage
+    )
 
     resource_storage = aria.application_resource_storage(
         FileSystemResourceAPI, api_kwargs=resources_driver_kwargs or dict(directory=str(tmpdir)))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/orchestrator/context/test_workflow.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_workflow.py b/tests/orchestrator/context/test_workflow.py
index 7ae7c1b..6d9ed39 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,7 +60,8 @@ class TestWorkflowContext(object):
 
 @pytest.fixture(scope='function')
 def storage():
-    workflow_storage = application_model_storage(SQLAlchemyModelAPI)
+    workflow_storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                                 storage_initiator_func=sql_mapi.init_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/69fb70da/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 c6a3fa1..ab47bca 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -24,7 +24,7 @@ import pytest
 from aria import application_model_storage
 from aria.storage import model as aria_model
 from aria.utils.plugin import create as create_plugin
-from aria.storage.sql_mapi import SQLAlchemyModelAPI
+from aria.storage import sql_mapi
 from aria.orchestrator import events
 from aria.orchestrator import plugin
 from aria.orchestrator.workflows.executor import process
@@ -74,7 +74,9 @@ class TestProcessExecutor(object):
 
 @pytest.fixture
 def model(tmpdir):
-    result = application_model_storage(SQLAlchemyModelAPI, api_kwargs=dict(base_dir=str(tmpdir)))
+    result = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                       api_kwargs=dict(base_dir=str(tmpdir)),
+                                       storage_initiator_func=sql_mapi.init_storage)
     yield result
     tests.storage.release_sqlite_storage(result)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 589a01f..10c2ee2 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -62,7 +62,7 @@ def release_sqlite_storage(storage):
 
     if mapis:
         for mapi in mapis:
-            mapi.free_storage_initiator(safe=True)
+            mapi.free_storage_initiator()
         for session in set(mapi._session for mapi in mapis):
             session.rollback()
             session.close()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 02bcee7..3ba92fe 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -61,7 +61,8 @@ def test_model_storage(storage):
 
 
 def test_application_storage_factory():
-    storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI)
+    storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                        storage_initiator_func=sql_mapi.init_storage)
     assert storage.node
     assert storage.node_instance
     assert storage.plugin

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/storage/test_models.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py
index a3fa623..c5b1c62 100644
--- a/tests/storage/test_models.py
+++ b/tests/storage/test_models.py
@@ -54,7 +54,8 @@ def sql_storage(storage_func):
 
 
 def _empty_storage():
-    return application_model_storage(sql_mapi.SQLAlchemyModelAPI)
+    return application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                     storage_initiator_func=sql_mapi.init_storage)
 
 
 def _blueprint_storage():

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/69fb70da/tests/storage/test_structures.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_structures.py b/tests/storage/test_structures.py
index 853a667..6caa4ff 100644
--- a/tests/storage/test_structures.py
+++ b/tests/storage/test_structures.py
@@ -50,7 +50,9 @@ def module_cleanup():
 
 @pytest.fixture
 def context(tmpdir):
-    return mock_context.simple(str(tmpdir))
+    ctx = mock_context.simple(str(tmpdir))
+    yield ctx
+    release_sqlite_storage(ctx.model)
 
 
 def test_inner_dict_update(storage):
@@ -175,7 +177,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/69fb70da/tests/utils/test_plugin.py
----------------------------------------------------------------------
diff --git a/tests/utils/test_plugin.py b/tests/utils/test_plugin.py
index 2602488..6a45f19 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,7 +49,8 @@ class TestPluginManager(object):
 
 @pytest.fixture
 def model():
-    model = application_model_storage(SQLAlchemyModelAPI)
+    model = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                      storage_initiator_func=sql_mapi.init_storage)
     yield model
     storage.release_sqlite_storage(model)
 


Mime
View raw message