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: moved to filesystem base tests storage
Date Sun, 07 May 2017 09:17:09 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-160-Operation-toolbelt-unit-tests-fail-spordically 179a2279d -> 968f22bed


moved to filesystem base tests storage


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

Branch: refs/heads/ARIA-160-Operation-toolbelt-unit-tests-fail-spordically
Commit: 968f22bedeb7dfbfc9fa8b2c793ada48e5147f9f
Parents: 179a227
Author: max-orlov <maxim@gigaspaces.com>
Authored: Sun May 7 12:17:04 2017 +0300
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Sun May 7 12:17:04 2017 +0300

----------------------------------------------------------------------
 tests/helpers.py                             | 37 +++++++----
 tests/orchestrator/context/test_operation.py | 80 +++++++++++++----------
 tests/orchestrator/context/test_toolbelt.py  | 15 ++---
 3 files changed, 76 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/968f22be/tests/helpers.py
----------------------------------------------------------------------
diff --git a/tests/helpers.py b/tests/helpers.py
index 329b848..423e63f 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -14,7 +14,8 @@
 # limitations under the License.
 
 import os
-from threading import local
+import tempfile
+import json
 
 from . import ROOT_DIR
 from .resources import DIR as RESOURCES_DIR
@@ -32,25 +33,37 @@ def get_service_template_uri(*args):
     return os.path.join(RESOURCES_DIR, 'service-templates', *args)
 
 
-class GlobalTestHolder(local):
+class FilesystemDataHolder(object):
+    _tmpfile = tempfile.NamedTemporaryFile('w')
+
+    def _load(self):
+        return json.load(open(self._tmpfile.name))
+
+    def _dump(self, value):
+        return json.dump(value, open(self._tmpfile.name, 'w'))
+
     def __init__(self):
-        super(GlobalTestHolder, self).__init__()
-        self._holder = {}
+        self.clear()
 
     def __setitem__(self, key, value):
-        self._holder[key] = value
+        dict_ = self._load()
+        dict_[key] = value
+        self._dump(dict_)
 
     def __getitem__(self, item):
-        return self._holder[item]
-
-    def clear(self):
-        self._holder.clear()
+        return self._load()[item]
 
     def __iter__(self):
-        return iter(self._holder)
+        return iter(self._load())
+
+    def clear(self):
+        self._dump({})
 
     def get(self, item, default=None):
-        return self._holder.get(item, default)
+        return self._load().get(item, default)
 
     def setdefault(self, key, value):
-        return self._holder.setdefault(key, value)
+        dict_ = self._load()
+        return_value = dict_.setdefault(key, value)
+        self._dump(dict_)
+        return return_value

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/968f22be/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py
index d351846..3180d89 100644
--- a/tests/orchestrator/context/test_operation.py
+++ b/tests/orchestrator/context/test_operation.py
@@ -38,7 +38,7 @@ from . import (
     execute,
 )
 
-global_test_holder = helpers.GlobalTestHolder()
+global_test_holder = helpers.FilesystemDataHolder()
 
 @pytest.fixture
 def ctx(tmpdir):
@@ -78,7 +78,7 @@ def test_node_operation_task_execution(ctx, thread_executor):
         node.service,
         interface_name,
         operation_name,
-        operation_kwargs=dict(implementation=op_path(basic_operation, module_path=__name__),
+        operation_kwargs=dict(implementation=op_path(basic_node_operation, module_path=__name__),
                               inputs=inputs)
     )
     node.interfaces[interface.name] = interface
@@ -97,18 +97,11 @@ def test_node_operation_task_execution(ctx, thread_executor):
 
     execute(workflow_func=basic_workflow, workflow_context=ctx, executor=thread_executor)
 
-    operation_context = global_test_holder[api.task.OperationTask.NAME_FORMAT.format(
-        type='node',
-        name=node.name,
-        interface=interface_name,
-        operation=operation_name
-    )]
-
-    assert isinstance(operation_context, context.operation.NodeOperationContext)
+    assert global_test_holder['ctx_name'] == context.operation.NodeOperationContext.__name__
 
     # Task bases assertions
-    assert operation_context.task.actor == node
-    assert operation_context.task.name == api.task.OperationTask.NAME_FORMAT.format(
+    assert global_test_holder['actor_name'] == node.name
+    assert global_test_holder['task_name'] == api.task.OperationTask.NAME_FORMAT.format(
         type='node',
         name=node.name,
         interface=interface_name,
@@ -116,12 +109,12 @@ def test_node_operation_task_execution(ctx, thread_executor):
     )
     operations = interface.operations
     assert len(operations) == 1
-    assert operation_context.task.implementation == operations.values()[0].implementation
          # pylint: disable=no-member
-    assert operation_context.task.inputs['putput'].value is True
+    assert global_test_holder['implementation'] == operations.values()[0].implementation
            # pylint: disable=no-member
+    assert global_test_holder['inputs']['putput'] is True
 
     # Context based attributes (sugaring)
-    assert operation_context.node_template == node.node_template
-    assert operation_context.node == node
+    assert global_test_holder['template_name'] == node.node_template.name
+    assert global_test_holder['node_name'] == node.name
 
 
 def test_relationship_operation_task_execution(ctx, thread_executor):
@@ -134,7 +127,8 @@ def test_relationship_operation_task_execution(ctx, thread_executor):
         relationship.source_node.service,
         interface_name,
         operation_name,
-        operation_kwargs=dict(implementation=op_path(basic_operation, module_path=__name__),
+        operation_kwargs=dict(implementation=op_path(basic_relationship_operation,
+                                                     module_path=__name__),
                               inputs=inputs),
     )
 
@@ -154,21 +148,14 @@ def test_relationship_operation_task_execution(ctx, thread_executor):
 
     execute(workflow_func=basic_workflow, workflow_context=ctx, executor=thread_executor)
 
-    operation_context = global_test_holder[api.task.OperationTask.NAME_FORMAT.format(
-        type='relationship',
-        name=relationship.name,
-        interface=interface_name,
-        operation=operation_name
-    )]
-
-    assert isinstance(operation_context, context.operation.RelationshipOperationContext)
+    assert global_test_holder['ctx_name'] == context.operation.RelationshipOperationContext.__name__
 
     # Task bases assertions
-    assert operation_context.task.actor == relationship
-    assert interface_name in operation_context.task.name
+    assert global_test_holder['actor_name'] == relationship.name
+    assert interface_name in global_test_holder['task_name']
     operations = interface.operations
-    assert operation_context.task.implementation == operations.values()[0].implementation
          # pylint: disable=no-member
-    assert operation_context.task.inputs['putput'].value is True
+    assert global_test_holder['implementation'] == operations.values()[0].implementation
          # pylint: disable=no-member
+    assert global_test_holder['inputs']['putput'] is True
 
     # Context based attributes (sugaring)
     dependency_node_template = ctx.model.node_template.get_by_name(
@@ -178,11 +165,11 @@ def test_relationship_operation_task_execution(ctx, thread_executor):
         mock.models.DEPENDENT_NODE_TEMPLATE_NAME)
     dependent_node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
 
-    assert operation_context.target_node_template == dependency_node_template
-    assert operation_context.target_node == dependency_node
-    assert operation_context.relationship == relationship
-    assert operation_context.source_node_template == dependent_node_template
-    assert operation_context.source_node == dependent_node
+    assert global_test_holder['target_node_template_name'] == dependency_node_template.name
+    assert global_test_holder['target_node_name'] == dependency_node.name
+    assert global_test_holder['relationship_name'] == relationship.name
+    assert global_test_holder['source_node_template_name'] == dependent_node_template.name
+    assert global_test_holder['source_node_name'] == dependent_node.name
 
 
 def test_invalid_task_operation_id(ctx, thread_executor):
@@ -389,8 +376,29 @@ def logged_operation(ctx, **_):
 
 
 @operation
-def basic_operation(ctx, **_):
-    global_test_holder[ctx.name] = ctx
+def basic_node_operation(ctx, **_):
+    operation_common(ctx)
+    global_test_holder['template_name'] = ctx.node_template.name
+    global_test_holder['node_name'] = ctx.node.name
+
+
+@operation
+def basic_relationship_operation(ctx, **_):
+    operation_common(ctx)
+    global_test_holder['target_node_template_name'] = ctx.target_node_template.name
+    global_test_holder['target_node_name'] = ctx.target_node.name
+    global_test_holder['relationship_name'] = ctx.relationship.name
+    global_test_holder['source_node_template_name'] = ctx.source_node_template.name
+    global_test_holder['source_node_name'] = ctx.source_node.name
+
+
+def operation_common(ctx):
+    global_test_holder['ctx_name'] = ctx.__class__.__name__
+
+    global_test_holder['actor_name'] = ctx.task.actor.name
+    global_test_holder['task_name'] = ctx.task.name
+    global_test_holder['implementation'] = ctx.task.implementation
+    global_test_holder['inputs'] = dict(i.unwrap() for i in ctx.task.inputs.values())
 
 
 @operation

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/968f22be/tests/orchestrator/context/test_toolbelt.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py
index 5a319cc..0e3cf1a 100644
--- a/tests/orchestrator/context/test_toolbelt.py
+++ b/tests/orchestrator/context/test_toolbelt.py
@@ -31,7 +31,7 @@ from . import (
     execute,
 )
 
-global_test_holder = helpers.GlobalTestHolder()
+global_test_holder = helpers.FilesystemDataHolder()
 
 
 @pytest.fixture
@@ -89,6 +89,8 @@ def test_host_ip(workflow_context, executor):
                               inputs=inputs)
     )
     dependency_node.interfaces[interface.name] = interface
+    dependency_node.runtime_properties['ip'] = '1.1.1.1'
+
     workflow_context.model.node.update(dependency_node)
 
     @workflow
@@ -135,12 +137,9 @@ def test_relationship_tool_belt(workflow_context, executor):
 
     execute(workflow_func=basic_workflow, workflow_context=workflow_context, executor=executor)
 
-    assert isinstance(global_test_holder.get(api.task.OperationTask.NAME_FORMAT.format(
-        type='relationship',
-        name=relationship.name,
-        interface=interface_name,
-        operation=operation_name
-    )), RelationshipToolBelt)
+    assert global_test_holder.get(api.task.OperationTask.NAME_FORMAT.format(
+        type='relationship', name=relationship.name, interface=interface_name, operation=operation_name)
+    ) == relationship.source_node.name
 
 
 def test_wrong_model_toolbelt():
@@ -155,7 +154,7 @@ def host_ip(toolbelt, **_):
 
 @operation(toolbelt=True)
 def relationship_operation(ctx, toolbelt, **_):
-    global_test_holder[ctx.name] = toolbelt
+    global_test_holder[ctx.name] = toolbelt._op_context.source_node.name
 
 
 @pytest.fixture(autouse=True)


Mime
View raw message