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 2017/06/13 09:26:46 UTC

incubator-ariatosca git commit: review fix

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-276-Support-model-instrumentation-for-workflows 24df3f5ef -> 3bca25d2e


review fix


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

Branch: refs/heads/ARIA-276-Support-model-instrumentation-for-workflows
Commit: 3bca25d2e50f6a4ba196cc1a8a6668c5d93b0451
Parents: 24df3f5
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Jun 13 12:26:41 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Jun 13 12:26:41 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/api/task.py         |  2 -
 .../context/test_context_instrumentation.py     |  2 +-
 tests/orchestrator/context/test_workflow.py     | 93 +++++++++++++++-----
 3 files changed, 73 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bca25d2/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index 342448f..ca125a8 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -107,8 +107,6 @@ class OperationTask(BaseTask):
         :raises aria.orchestrator.workflows.exceptions.OperationNotFoundException: if
                 ``interface_name`` and ``operation_name`` to not refer to an operation on the actor
         """
-        # If the actor is wrapped we retrieve the original class, o/w we compare the actor itself
-        assert isinstance(getattr(actor, '_wrapped', actor), (models.Node, models.Relationship))
 
         # Creating OperationTask directly should raise an error when there is no
         # interface/operation.

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bca25d2/tests/orchestrator/context/test_context_instrumentation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_context_instrumentation.py b/tests/orchestrator/context/test_context_instrumentation.py
index 69819a9..6cc8096 100644
--- a/tests/orchestrator/context/test_context_instrumentation.py
+++ b/tests/orchestrator/context/test_context_instrumentation.py
@@ -48,13 +48,13 @@ class TestContextInstrumentation(object):
             model_storage=workflow_ctx.model, resource_storage=workflow_ctx.resource,
             execution_id=1)
 
-
         with ctx.model.instrument(models.Node.attributes):
             self._run_op_assertions(ctx, True)
             self._run_common_assertions(ctx, True)
 
         self._run_op_assertions(ctx, False)
         self._run_common_assertions(ctx, False)
+
     @staticmethod
     def ctx_assert(expr, is_under_ctx):
         if is_under_ctx:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bca25d2/tests/orchestrator/context/test_workflow.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_workflow.py b/tests/orchestrator/context/test_workflow.py
index 3c35435..6d53c2a 100644
--- a/tests/orchestrator/context/test_workflow.py
+++ b/tests/orchestrator/context/test_workflow.py
@@ -17,11 +17,14 @@ from datetime import datetime
 
 import pytest
 
-from aria import application_model_storage
+from aria import application_model_storage, workflow
 from aria.orchestrator import context
 from aria.storage import sql_mapi
-from tests import storage as test_storage
-from tests.mock import models
+from aria.orchestrator.workflows.executor import thread, process
+
+from tests import storage as test_storage, ROOT_DIR
+from ... import mock
+from . import execute
 
 
 class TestWorkflowContext(object):
@@ -30,10 +33,10 @@ class TestWorkflowContext(object):
         ctx = self._create_ctx(storage)
         execution = storage.execution.get(ctx.execution.id)             # pylint: disable=no-member
         assert execution.service == storage.service.get_by_name(
-            models.SERVICE_NAME)
-        assert execution.workflow_name == models.WORKFLOW_NAME
+            mock.models.SERVICE_NAME)
+        assert execution.workflow_name == mock.models.WORKFLOW_NAME
         assert execution.service_template == storage.service_template.get_by_name(
-            models.SERVICE_TEMPLATE_NAME)
+            mock.models.SERVICE_TEMPLATE_NAME)
         assert execution.status == storage.execution.model_cls.PENDING
         assert execution.inputs == {}
         assert execution.created_at <= datetime.utcnow()
@@ -49,27 +52,75 @@ class TestWorkflowContext(object):
         :param storage:
         :return WorkflowContext:
         """
-        service = storage.service.get_by_name(models.SERVICE_NAME)
+        service = storage.service.get_by_name(mock.models.SERVICE_NAME)
         return context.workflow.WorkflowContext(
             name='simple_context',
             model_storage=storage,
             resource_storage=None,
             service_id=service,
             execution_id=storage.execution.list(filters=dict(service=service))[0].id,
-            workflow_name=models.WORKFLOW_NAME,
-            task_max_attempts=models.TASK_MAX_ATTEMPTS,
-            task_retry_interval=models.TASK_RETRY_INTERVAL
+            workflow_name=mock.models.WORKFLOW_NAME,
+            task_max_attempts=mock.models.TASK_MAX_ATTEMPTS,
+            task_retry_interval=mock.models.TASK_RETRY_INTERVAL
         )
 
+    @pytest.fixture
+    def storage(self):
+        workflow_storage = application_model_storage(
+            sql_mapi.SQLAlchemyModelAPI, initiator=test_storage.init_inmemory_model_storage)
+        workflow_storage.service_template.put(mock.models.create_service_template())
+        service_template = workflow_storage.service_template.get_by_name(
+            mock.models.SERVICE_TEMPLATE_NAME)
+        service = mock.models.create_service(service_template)
+        workflow_storage.service.put(service)
+        workflow_storage.execution.put(mock.models.create_execution(service))
+        yield workflow_storage
+        test_storage.release_sqlite_storage(workflow_storage)
+
+
+@pytest.fixture
+def ctx(tmpdir):
+    context = mock.context.simple(
+        str(tmpdir),
+        context_kwargs=dict(workdir=str(tmpdir.join('workdir')))
+    )
+    yield context
+    test_storage.release_sqlite_storage(context.model)
+
+
+@pytest.fixture(params=[
+    (thread.ThreadExecutor, {}),
+    (process.ProcessExecutor, {'python_path': [ROOT_DIR]}),
+])
+def executor(request):
+    executor_cls, executor_kwargs = request.param
+    result = executor_cls(**executor_kwargs)
+    try:
+        yield result
+    finally:
+        result.close()
+
+
+def test_attribute_consumption(ctx, executor):
+
+    node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
+    node.attributes['key'] = ctx.model.attribute.model_cls.wrap('key', 'value')
+    node.attributes['key2'] = ctx.model.attribute.model_cls.wrap('key2', 'value_to_change')
+    ctx.model.node.update(node)
+
+    assert node.attributes['key'].value == 'value'
+    assert node.attributes['key2'].value == 'value_to_change'
+
+    @workflow
+    def basic_workflow(ctx, **_):
+        node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
+        node.attributes['new_key'] = 'new_value'
+        node.attributes['key2'] = 'changed_value'
+
+    execute(workflow_func=basic_workflow, workflow_context=ctx, executor=executor)
+    node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
 
-@pytest.fixture(scope='function')
-def storage():
-    workflow_storage = application_model_storage(
-        sql_mapi.SQLAlchemyModelAPI, initiator=test_storage.init_inmemory_model_storage)
-    workflow_storage.service_template.put(models.create_service_template())
-    service_template = workflow_storage.service_template.get_by_name(models.SERVICE_TEMPLATE_NAME)
-    service = models.create_service(service_template)
-    workflow_storage.service.put(service)
-    workflow_storage.execution.put(models.create_execution(service))
-    yield workflow_storage
-    test_storage.release_sqlite_storage(workflow_storage)
+    assert len(node.attributes) == 3
+    assert node.attributes['key'].value == 'value'
+    assert node.attributes['new_key'].value == 'new_value'
+    assert node.attributes['key2'].value == 'changed_value'