You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2016/12/07 12:36:52 UTC
incubator-ariatosca git commit: added cleanup func, better cleaning,
and actor/instace.id test
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-30-SQL-based-storage-implementation 0003e47f8 -> a8e9b3cc3
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/a8e9b3cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/a8e9b3cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/a8e9b3cc
Branch: refs/heads/ARIA-30-SQL-based-storage-implementation
Commit: a8e9b3cc3ab740d418bb8549311d170f255030d7
Parents: 0003e47
Author: mxmrlv <mx...@gmail.com>
Authored: Wed Dec 7 14:36:43 2016 +0200
Committer: mxmrlv <mx...@gmail.com>
Committed: Wed Dec 7 14:36:43 2016 +0200
----------------------------------------------------------------------
aria/orchestrator/context/operation.py | 2 +-
tests/mock/context.py | 1 -
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 | 4 +-
tests/orchestrator/workflows/core/test_task.py | 2 +-
tests/storage/__init__.py | 26 +++++++++++--
tests/storage/test_model_storage.py | 9 ++---
13 files changed, 76 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a8e9b3cc/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/a8e9b3cc/tests/mock/context.py
----------------------------------------------------------------------
diff --git a/tests/mock/context.py b/tests/mock/context.py
index 7eb57ed..504b6d8 100644
--- a/tests/mock/context.py
+++ b/tests/mock/context.py
@@ -22,7 +22,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/a8e9b3cc/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py
index f3af0c5..db8aeda 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.id == node_instance.id
+ assert op_node_instance_id.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
+
+
@pytest.fixture(autouse=True)
def cleanup():
global_test_holder.clear()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a8e9b3cc/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/a8e9b3cc/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/a8e9b3cc/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/a8e9b3cc/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/a8e9b3cc/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/a8e9b3cc/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/a8e9b3cc/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..3b9fecd 100644
--- a/tests/orchestrator/workflows/core/test_engine.py
+++ b/tests/orchestrator/workflows/core/test_engine.py
@@ -130,9 +130,7 @@ class BaseTest(object):
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/a8e9b3cc/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..024bdd8 100644
--- a/tests/orchestrator/workflows/core/test_task.py
+++ b/tests/orchestrator/workflows/core/test_task.py
@@ -35,7 +35,7 @@ def ctx(tmpdir):
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/a8e9b3cc/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 90e113c..1faa547 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,19 @@ 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()
+
+
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a8e9b3cc/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):