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/10/27 17:57:51 UTC
incubator-ariatosca git commit: small fixes and testing framework
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIATOSCA-9-API-for-operation-context caa561018 -> d671f47f0
small fixes and testing framework
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/d671f47f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d671f47f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d671f47f
Branch: refs/heads/ARIATOSCA-9-API-for-operation-context
Commit: d671f47f0e1b1153fa1a73b7f92bb1421e7b5672
Parents: caa5610
Author: mxmrlv <mx...@gmail.com>
Authored: Thu Oct 27 20:56:59 2016 +0300
Committer: mxmrlv <mx...@gmail.com>
Committed: Thu Oct 27 20:56:59 2016 +0300
----------------------------------------------------------------------
aria/contexts.py | 6 +-
tests/mocks/__init__.py | 0
tests/mocks/context_mock.py | 136 +++++++++++++++++++++++++++++++++++++++
tests/test_context.py | 34 ++++++++++
4 files changed, 173 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d671f47f/aria/contexts.py
----------------------------------------------------------------------
diff --git a/aria/contexts.py b/aria/contexts.py
index 7d1421e..143faef 100644
--- a/aria/contexts.py
+++ b/aria/contexts.py
@@ -54,7 +54,7 @@ class WorkflowContext(LoggerMixin):
@property
def model(self):
- return self.model
+ return self._model
@property
def resource(self):
@@ -87,7 +87,7 @@ class WorkflowContext(LoggerMixin):
self,
name,
operation_details,
- model,
+ operation_host,
inputs=None):
"""
Called during workflow creation, return an operation context. This object should be added to
@@ -97,7 +97,7 @@ class WorkflowContext(LoggerMixin):
name=name,
operation_details=operation_details,
workflow_context=self,
- model=model,
+ operation_host=operation_host,
inputs=inputs or {})
@property
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d671f47f/tests/mocks/__init__.py
----------------------------------------------------------------------
diff --git a/tests/mocks/__init__.py b/tests/mocks/__init__.py
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d671f47f/tests/mocks/context_mock.py
----------------------------------------------------------------------
diff --git a/tests/mocks/context_mock.py b/tests/mocks/context_mock.py
new file mode 100644
index 0000000..5e92694
--- /dev/null
+++ b/tests/mocks/context_mock.py
@@ -0,0 +1,136 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+
+from aria import contexts
+from aria.storage import ModelStorage, models
+
+from ..storage import InMemoryModelDriver
+
+NODE_OPERATIONS = [
+ 'aria.interfaces.lifecycle.create',
+ 'aria.interfaces.lifecycle.configure',
+ 'aria.interfaces.lifecycle.start',
+ 'aria.interfaces.lifecycle.stop',
+ 'aria.interfaces.lifecycle.delete',
+]
+
+RELATIONSHIP_OPERATIONS = [
+ 'aria.interfaces.relationship_lifecycle.preconfigure',
+ 'aria.interfaces.relationship_lifecycle.postconfigure',
+ 'aria.interfaces.relationship_lifecycle.establish',
+ 'aria.interfaces.relationship_lifecycle.unlink'
+]
+
+
+def simple_context():
+ """
+ Create the following graph in storage:
+ dependency_node <------ dependent_node
+ :return:
+ """
+
+ storage = ModelStorage(InMemoryModelDriver(),
+ model_classes=[models.NodeInstance,
+ models.Node,
+ models.Relationship,
+ models.RelationshipInstance])
+ storage.setup()
+
+ dependency_node = models.Node(
+ id='dependency_node',
+ host_id='dependency_node',
+ blueprint_id='test_blueprint_id',
+ type='test_node_type',
+ type_hierarchy=[],
+ number_of_instances=1,
+ planned_number_of_instances=1,
+ deploy_number_of_instances=1,
+ properties={},
+ operations=dict((key, None) for key in NODE_OPERATIONS),
+ relationships=[],
+ min_number_of_instances=1,
+ max_number_of_instances=1,
+ )
+
+ dependency_node_instance = models.NodeInstance(
+ id='dependency_node_instance',
+ host_id='dependency_node_instance',
+ deployment_id='test_deployment_id',
+ runtime_properties={},
+ version=None,
+ relationship_instances=[],
+ node=dependency_node
+ )
+
+ relationship = models.Relationship(
+ target_id=dependency_node.id,
+ source_interfaces={},
+ source_operations=dict((key, None) for key in RELATIONSHIP_OPERATIONS),
+ target_interfaces={},
+ target_operations=dict((key, None) for key in RELATIONSHIP_OPERATIONS),
+ type='rel_type',
+ type_hierarchy=[],
+ properties={},
+ )
+
+ relationship_instance = models.RelationshipInstance(
+ target_id=dependency_node_instance.id,
+ target_name='test_target_name',
+ type='some_type',
+ relationship=relationship,
+
+ )
+
+ dependent_node = models.Node(
+ id='dependent_node',
+ host_id='dependent_node',
+ blueprint_id='test_blueprint_id',
+ type='test_node_type',
+ type_hierarchy=[],
+ number_of_instances=1,
+ planned_number_of_instances=1,
+ deploy_number_of_instances=1,
+ properties={},
+ operations=dict((key, None) for key in NODE_OPERATIONS),
+ relationships=[relationship],
+ min_number_of_instances=1,
+ max_number_of_instances=1,
+ )
+
+ dependent_node_instance = models.NodeInstance(
+ id='dependent_node_instance',
+ host_id='dependent_node_instance',
+ deployment_id='test_deployment_id',
+ runtime_properties={},
+ version=None,
+ relationship_instances=[relationship_instance],
+ node=dependent_node
+ )
+
+ storage.node.store(dependency_node)
+ storage.node.store(dependent_node)
+ storage.node_instance.store(dependency_node_instance)
+ storage.node_instance.store(dependent_node_instance)
+ storage.relationship.store(relationship)
+ storage.relationship_instance.store(relationship_instance)
+
+ wf_context = contexts.WorkflowContext(name='test_context',
+ model_storage=storage,
+ resource_storage=None,
+ deployment_id='test_deployment_id',
+ workflow_id='test_workflow_id')
+ return wf_context
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d671f47f/tests/test_context.py
----------------------------------------------------------------------
diff --git a/tests/test_context.py b/tests/test_context.py
new file mode 100644
index 0000000..48bb742
--- /dev/null
+++ b/tests/test_context.py
@@ -0,0 +1,34 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+
+from .mocks.context_mock import simple_context
+
+
+@pytest.fixture
+def context():
+ return simple_context()
+
+
+class TestOperationContext():
+ def test_operation(self, context):
+ operation = context.operation(
+ name='test_operation_name',
+ operation_details={},
+ operation_host=context.model.node.get('dependency_node'),
+ )
+
+ pass
\ No newline at end of file