ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [03/16] incubator-ariatosca git commit: ARIA-65 Add validation for relationship assignment type
Date Sun, 29 Jan 2017 13:23:03 GMT
ARIA-65 Add validation for relationship assignment type


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

Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models
Commit: 8ecf5bba9a53135f993a43cf6e3b499857b19701
Parents: c4429dd
Author: Tal Liron <tal.liron@gmail.com>
Authored: Sun Jan 22 12:49:12 2017 +0200
Committer: Ran Ziv <ran@gigaspaces.com>
Committed: Sun Jan 22 12:50:54 2017 +0200

----------------------------------------------------------------------
 .../simple_v1_0/modeling/requirements.py           | 17 +++++++++++++----
 .../aria_extension_tosca/simple_v1_0/types.py      |  8 ++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8ecf5bba/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py
index 8f6c38f..97e30ee 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py
@@ -159,12 +159,21 @@ def convert_requirement_from_definition_to_assignment(context, requirement_defin
             relationship_template = relationship_type
             relationship_type = relationship_template._get_type(context)
 
+    definition_relationship_type = None
+    relationship_definition = requirement_definition.relationship # RelationshipDefinition
+    if relationship_definition is not None:
+        definition_relationship_type = relationship_definition._get_type(context)
+
     # If not exists, try at the node type
-    relationship_definition = None
     if relationship_type is None:
-        relationship_definition = requirement_definition.relationship # RelationshipDefinition
-        if relationship_definition is not None:
-            relationship_type = relationship_definition._get_type(context)
+        relationship_type = definition_relationship_type
+    else:
+        # Make sure the type is derived
+        if not definition_relationship_type._is_descendant(context, relationship_type):
+            context.validation.report(
+                'assigned relationship type "%s" is not a descendant of declared relationship
type "%s"'
+                % (relationship_type._name, definition_relationship_type._name),
+                locator=container._locator, level=Issue.BETWEEN_TYPES)
 
     if relationship_type is not None:
         raw['relationship'] = OrderedDict()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8ecf5bba/extensions/aria_extension_tosca/simple_v1_0/types.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/types.py b/extensions/aria_extension_tosca/simple_v1_0/types.py
index 39843ac..2112f7f 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/types.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/types.py
@@ -484,6 +484,14 @@ class RelationshipType(ExtensiblePresentation):
                                        'relationship_types')
 
     @cachedmethod
+    def _is_descendant(self, context, the_type):
+        if the_type is None:
+            return False
+        elif the_type._name == self._name:
+            return True
+        return self._is_descendant(context, the_type._get_parent(context))
+
+    @cachedmethod
     def _get_properties(self, context):
         return FrozenDict(get_inherited_property_definitions(context, self, 'properties'))
 


Mime
View raw message