Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-30-SQL-based-storage-implementation 66c128668 -> e01575cbc 
(forced update)


added cleanup func, better cleaning, and actor/instace.id test


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

Branch: refs/heads/ARIA-30-SQL-based-storage-implementation
Commit: e01575cbce357d890b3efd804739a28c76fb8399
Parents: 0003e47
Author: mxmrlv <mxm...@gmail.com>
Authored: Wed Dec 7 14:36:43 2016 +0200
Committer: mxmrlv <mxm...@gmail.com>
Committed: Wed Dec 7 14:55:11 2016 +0200

----------------------------------------------------------------------
 aria/orchestrator/context/operation.py          |  2 +-
 tests/mock/context.py                           |  3 --
 tests/orchestrator/context/test_operation.py    | 40 +++++++++++++++++++-
 tests/orchestrator/context/test_toolbelt.py     |  2 +-
 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  |  8 +---
 tests/orchestrator/workflows/core/test_task.py  |  6 +--
 tests/storage/__init__.py                       | 25 ++++++++++--
 tests/storage/test_model_storage.py             |  9 ++---
 13 files changed, 77 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py 
b/aria/orchestrator/context/operation.py
index a789e24..a73bad1 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -71,7 +71,7 @@ class NodeOperationContext(BaseOperationContext):
         The node instance of the current operation
         :return:
         """
-        return self.model.node_instance.get(self._task_id)
+        return self.model.node_instance.get(self._actor_id)
 
 
 class RelationshipOperationContext(BaseOperationContext):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/tests/mock/context.py
----------------------------------------------------------------------
diff --git a/tests/mock/context.py b/tests/mock/context.py
index 7eb57ed..1904140 100644
--- a/tests/mock/context.py
+++ b/tests/mock/context.py
@@ -13,8 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import pytest
-
 from aria import application_model_storage
 from aria.orchestrator import context
 from aria.storage.sql_mapi import SQLAlchemyModelAPI
@@ -22,7 +20,6 @@ from aria.storage.sql_mapi import SQLAlchemyModelAPI
 from . import models
 
 
-@pytest.fixture
 def simple(api_kwargs, **kwargs):
     model_storage = application_model_storage(SQLAlchemyModelAPI, 
api_kwargs=api_kwargs)
     blueprint = models.get_blueprint()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py 
b/tests/orchestrator/context/test_operation.py
index f3af0c5..f820bcc 100644
--- a/tests/orchestrator/context/test_operation.py
+++ b/tests/orchestrator/context/test_operation.py
@@ -39,7 +39,7 @@ def ctx(tmpdir):
         storage.get_sqlite_api_kwargs(str(tmpdir))
     )
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 @pytest.fixture
@@ -142,11 +142,49 @@ def test_relationship_operation_task_execution(ctx, 
executor):
     assert operation_context.source_node_instance == dependent_node_instance
 
 
+def test_invalid_task_operation_id(ctx, executor):
+    """
+    Checks that the right id is used. The task created with id == 1, thus 
running the task on
+    node_instance with id == 2. will check that indeed the node_instance uses 
the correct id.
+    :param ctx:
+    :param executor:
+    :return:
+    """
+    operation_name = 'aria.interfaces.lifecycle.create'
+    other_node_instance, node_instance = ctx.model.node_instance.list()
+    assert other_node_instance.id == 1
+    assert node_instance.id == 2
+
+    node = node_instance.node
+    node.operations[operation_name] = {
+        'operation': op_path(get_node_instance_id, module_path=__name__)
+
+    }
+    ctx.model.node.update(node)
+
+    @workflow
+    def basic_workflow(graph, **_):
+        graph.add_tasks(
+            api.task.OperationTask.node_instance(name=operation_name, 
instance=node_instance)
+        )
+
+    execute(workflow_func=basic_workflow, workflow_context=ctx, 
executor=executor)
+
+    op_node_instance_id = global_test_holder[op_name(node_instance, 
operation_name)]
+    assert op_node_instance_id == node_instance.id
+    assert op_node_instance_id != other_node_instance.id
+
+
 @operation
 def my_operation(ctx, **_):
     global_test_holder[ctx.name] = ctx
 
 
+@operation
+def get_node_instance_id(ctx, **_):
+    global_test_holder[ctx.name] = ctx.node_instance.id
+
+
 @pytest.fixture(autouse=True)
 def cleanup():
     global_test_holder.clear()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/tests/orchestrator/context/test_toolbelt.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_toolbelt.py 
b/tests/orchestrator/context/test_toolbelt.py
index 235004e..da46696 100644
--- a/tests/orchestrator/context/test_toolbelt.py
+++ b/tests/orchestrator/context/test_toolbelt.py
@@ -35,7 +35,7 @@ global_test_holder = {}
 def workflow_context(tmpdir):
     context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)))
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 @pytest.fixture

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 d87e2be..1a90338 100644
--- a/tests/orchestrator/workflows/api/test_task.py
+++ b/tests/orchestrator/workflows/api/test_task.py
@@ -31,9 +31,9 @@ def ctx():
     """
     simple_context = mock.context.simple(storage.get_sqlite_api_kwargs())
     
simple_context.model.execution.put(mock.models.get_execution(simple_context.deployment))
-
     yield simple_context
-    simple_context.model.drop()
+    storage.release_sqlite_storage(simple_context.model)
+
 
 class TestOperationTask(object):
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 56f8ef3..6fc5f28 100644
--- a/tests/orchestrator/workflows/builtin/test_execute_operation.py
+++ b/tests/orchestrator/workflows/builtin/test_execute_operation.py
@@ -28,7 +28,7 @@ def ctx(tmpdir):
         storage.get_sqlite_api_kwargs(str(tmpdir))
     )
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 def test_execute_operation(ctx):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 854f379..59c6331 100644
--- a/tests/orchestrator/workflows/builtin/test_heal.py
+++ b/tests/orchestrator/workflows/builtin/test_heal.py
@@ -30,7 +30,7 @@ def ctx(tmpdir):
         storage.get_sqlite_api_kwargs(str(tmpdir))
     )
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 def test_heal_dependent_node(ctx):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 b285ebd..a8fc807 100644
--- a/tests/orchestrator/workflows/builtin/test_install.py
+++ b/tests/orchestrator/workflows/builtin/test_install.py
@@ -29,7 +29,7 @@ def ctx(tmpdir):
         storage.get_sqlite_api_kwargs(str(tmpdir))
     )
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 def test_install(ctx):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 d7d919a..b2e2a41 100644
--- a/tests/orchestrator/workflows/builtin/test_uninstall.py
+++ b/tests/orchestrator/workflows/builtin/test_uninstall.py
@@ -30,7 +30,7 @@ def ctx(tmpdir):
         storage.get_sqlite_api_kwargs(str(tmpdir))
     )
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 def test_uninstall(ctx):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 0416ab8..c3e5532 100644
--- a/tests/orchestrator/workflows/core/test_engine.py
+++ b/tests/orchestrator/workflows/core/test_engine.py
@@ -124,15 +124,11 @@ class BaseTest(object):
 
     @pytest.fixture(scope='function')
     def workflow_context(self, tmpdir):
-        workflow_context = mock.context.simple(
-            storage.get_sqlite_api_kwargs(str(tmpdir))
-        )
+        workflow_context = 
mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)))
         workflow_context.states = []
         workflow_context.exception = None
         yield workflow_context
-        workflow_context.model.drop()
-        for mapi in workflow_context.model.registered.values():
-            mapi._session.remove()
+        storage.release_sqlite_storage(workflow_context.model)
 
 
 class TestEngine(BaseTest):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/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 ae50c24..c572501 100644
--- a/tests/orchestrator/workflows/core/test_task.py
+++ b/tests/orchestrator/workflows/core/test_task.py
@@ -31,11 +31,9 @@ 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(storage.get_sqlite_api_kwargs(str(tmpdir)))
     yield context
-    context.model.drop()
+    storage.release_sqlite_storage(context.model)
 
 
 class TestOperationTask(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 90e113c..c1d6f18 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -20,7 +20,11 @@ from shutil import rmtree
 from sqlalchemy import (
     create_engine,
     orm)
-from sqlalchemy.orm import scoped_session
+from sqlalchemy.orm import (
+    Session,
+    scoped_session
+)
+from sqlalchemy.orm.scoping import ScopedSession
 from sqlalchemy.pool import StaticPool
 
 from aria.storage import structures
@@ -35,12 +39,12 @@ class TestFileSystem(object):
         rmtree(self.path, ignore_errors=True)
 
 
-def get_sqlite_api_kwargs(base_dir=None, filename='memory'):
+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 'memory'.
+    :param str filename: the file name - defaults to 'db.sqlite'.
     :return:
     """
     if base_dir is not None:
@@ -62,3 +66,18 @@ def get_sqlite_api_kwargs(base_dir=None, filename='memory'):
 
     structures.Model.metadata.create_all(engine)
     return dict(engine=engine, session=session)
+
+
+def release_sqlite_storage(storage):
+    """
+    Drops the tables and clears the session
+    :param storage:
+    :return:
+    """
+    storage.drop()
+    for mapi in storage.registered.values():
+        if isinstance(mapi._session, ScopedSession):
+            mapi._session.remove()
+        elif isinstance(mapi._session, Session):
+            mapi._session.close()
+        mapi._engine.dispose()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e01575cb/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py 
b/tests/storage/test_model_storage.py
index e602884..1c3cf8a 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -22,15 +22,14 @@ from aria.storage import (
     sql_mapi,
 )
 from aria import application_model_storage
-from tests.storage import get_sqlite_api_kwargs
+from tests.storage import get_sqlite_api_kwargs, release_sqlite_storage
 
 
 @pytest.fixture
 def storage():
-    storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI,
-                           api_kwargs=get_sqlite_api_kwargs())
-    yield storage
-    storage.drop()
+    base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI, 
api_kwargs=get_sqlite_api_kwargs())
+    yield base_storage
+    release_sqlite_storage(base_storage)
 
 
 def test_storage_base(storage):

Reply via email to