You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by av...@apache.org on 2017/08/20 13:20:21 UTC

[1/2] incubator-ariatosca git commit: ARIA-349 get_attribute is not calculated at runtime [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-348-validate-substitution-mapping 78e535a52 -> 8839eb375 (forced update)


ARIA-349 get_attribute is not calculated at runtime


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

Branch: refs/heads/ARIA-348-validate-substitution-mapping
Commit: 8981791a10f91cb4f99ff8c01fd6b130b470ffae
Parents: df2b916
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Aug 15 15:20:16 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Aug 15 15:20:16 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py | 2 +-
 aria/modeling/utils.py          | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8981791a/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index f130d95..cecbbc5 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -185,7 +185,7 @@ def resume(execution_id,
         logger.info("Can't resume execution {execution.id} - "
                     "execution is in status {execution.status}. "
                     "Can only resume executions in status {valid_status}"
-                    .format(execution=execution, valid_status=execution.status.CANCELLED))
+                    .format(execution=execution, valid_status=execution.CANCELLED))
         return
 
     workflow_runner = \

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8981791a/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 305020b..6e851f2 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -131,7 +131,11 @@ def merge_parameter_values(provided_values, declared_parameters, model_cls=None)
                 value=value)
         else:
             # Copy default value from declaration
-            model_parameters[declared_parameter_name] = model_cls(**declared_parameter.as_raw)
+            model_parameters[declared_parameter_name] = model_cls(
+                value=declared_parameter._value,
+                name=declared_parameter.name,
+                type_name=declared_parameter.type_name,
+                description=declared_parameter.description)
 
     if provided_values_of_wrong_type:
         error_message = StringIO()


[2/2] incubator-ariatosca git commit: ARIA-348 Validate substitution_mapping field

Posted by av...@apache.org.
ARIA-348 Validate substitution_mapping field


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

Branch: refs/heads/ARIA-348-validate-substitution-mapping
Commit: 8839eb3752026fe2fd323bd131455d93216d25fe
Parents: 8981791
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Aug 16 18:54:57 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Aug 20 16:20:12 2017 +0300

----------------------------------------------------------------------
 .../aria_extension_tosca/simple_v1_0/misc.py    |   8 +-
 .../modeling/substitution_mappings.py           | 171 +++++++++++--------
 2 files changed, 107 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8839eb37/extensions/aria_extension_tosca/simple_v1_0/misc.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/misc.py b/extensions/aria_extension_tosca/simple_v1_0/misc.py
index a65ff41..221163c 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/misc.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/misc.py
@@ -25,8 +25,8 @@ from aria.parser.presentation import (AsIsPresentation, has_fields, allow_unknow
 
 from .modeling.data_types import (get_data_type, get_data_type_value, get_property_constraints,
                                   apply_constraint_to_value)
-from .modeling.substitution_mappings import (validate_subtitution_mappings_requirement,
-                                             validate_subtitution_mappings_capability)
+from .modeling.substitution_mappings import (validate_substitution_mappings_requirement,
+                                             validate_substitution_mappings_capability)
 from .presentation.extensible import ExtensiblePresentation
 from .presentation.field_validators import (constraint_clause_field_validator,
                                             constraint_clause_in_range_validator,
@@ -380,7 +380,7 @@ class SubstitutionMappingsRequirement(AsIsPresentation):
 
     def _validate(self, context):
         super(SubstitutionMappingsRequirement, self)._validate(context)
-        validate_subtitution_mappings_requirement(context, self)
+        validate_substitution_mappings_requirement(context, self)
 
 
 class SubstitutionMappingsCapability(AsIsPresentation):
@@ -400,7 +400,7 @@ class SubstitutionMappingsCapability(AsIsPresentation):
 
     def _validate(self, context):
         super(SubstitutionMappingsCapability, self)._validate(context)
-        validate_subtitution_mappings_capability(context, self)
+        validate_substitution_mappings_capability(context, self)
 
 
 @has_fields

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8839eb37/extensions/aria_extension_tosca/simple_v1_0/modeling/substitution_mappings.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/substitution_mappings.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/substitution_mappings.py
index 8f7ec4c..c10f1a6 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/substitution_mappings.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/substitution_mappings.py
@@ -17,88 +17,112 @@ from aria.utils.formatting import safe_repr
 from aria.parser.validation import Issue
 
 
-def validate_subtitution_mappings_requirement(context, presentation):
-    if not validate_format(context, presentation, 'requirement'):
+def validate_substitution_mappings_requirement(context, presentation):
+    if not validate_format(presentation):
+        report_invalid_format(context, presentation, field='requirement')
         return
 
-    node_template = get_node_template(context, presentation, 'requirement')
-    if node_template is None:
-        return
-
-    node_type = presentation._container._get_type(context)
-    if node_type is None:
+    # validate that the requirement in substitution_mapping is defined in the substitution node type
+    substitution_node_type = presentation._container._get_type(context)
+    if substitution_node_type is None:
         return
-
-    requirements = node_type._get_requirements(context)
-    type_requirement = None
-    for name, the_requirement in requirements:
-        if name == presentation._name:
-            type_requirement = the_requirement
+    for req_name, req in substitution_node_type._get_requirements(context):
+        if req_name == presentation._name:
+            substitution_type_requirement = req
             break
-    if type_requirement is None:
+    else:
         context.validation.report(
-            'substitution mappings requirement "%s" is not declared in node type "%s"'
-            % (presentation._name, node_type._name),
+            'substitution mapping requirement "{0}" is not declared in node type "{1}"'.format(
+                presentation._name, substitution_node_type._name),
             locator=presentation._locator, level=Issue.BETWEEN_TYPES)
         return
 
-    requirement_name = presentation._raw[1]
-    requirements = node_template._get_requirements(context)
-    requirement = None
-    for name, the_requirement in requirements:
-        if name == requirement_name:
-            requirement = the_requirement
+    # validate that the mapped requirement is defined in the corresponding node template
+    node_template = get_node_template(context, presentation)
+    if node_template is None:
+        report_missing_node_template(context, presentation, field='requirement')
+        return
+    mapped_requirement_name = presentation._raw[1]
+    for req_name, req in node_template._get_requirements(context):
+        if req_name == mapped_requirement_name:
+            node_template_requirement = req
             break
-
-    if requirement is None:
+    else:
         context.validation.report(
-            'substitution mappings requirement "%s" refers to an unknown requirement of node '
-            'template "%s": %s'
-            % (presentation._name, node_template._name, safe_repr(requirement_name)),
+            'substitution mapping requirement "{0}" refers to an unknown requirement of node '
+            'template "{1}": {mapped_requirement_name}'.format(
+                presentation._name, node_template._name,
+                mapped_requirement_name=safe_repr(mapped_requirement_name)),
             locator=presentation._locator, level=Issue.BETWEEN_TYPES)
         return
 
+    # validate that the requirement's capability type in substitution_mapping is derived from the
+    # requirement's capability type in the corresponding node template
+    substitution_type_requirement_capability_type = \
+        substitution_type_requirement._get_capability_type(context)
+    node_template_requirement_capability_type = \
+        node_template_requirement._get_capability(context)[0]
+    if not substitution_type_requirement_capability_type ._is_descendant(
+            context, node_template_requirement_capability_type):
+        context.validation.report(
+            'substitution mapping requirement "{0}" of capability type "{1}" is not a descendant '
+            'of the mapped node template capability type "{2}"'.format(
+                presentation._name,
+                substitution_type_requirement_capability_type._name,
+                node_template_requirement_capability_type._name),
+            locator=presentation._locator, level=Issue.BETWEEN_TYPES)
 
-def validate_subtitution_mappings_capability(context, presentation):
-    if not validate_format(context, presentation, 'capability'):
-        return
 
-    node_template = get_node_template(context, presentation, 'capability')
-    if node_template is None:
+def validate_substitution_mappings_capability(context, presentation):
+    if not validate_format(presentation):
+        report_invalid_format(context, presentation, field='capability')
         return
 
-    node_type = presentation._container._get_type(context)
-    if node_type is None:
+    # validate that the capability in substitution_mapping has the same name as the capability in
+    # the substitution node type.
+    substitution_node_type = presentation._container._get_type(context)
+    if substitution_node_type is None:
         return
-
-    capabilities = node_type._get_capabilities(context)
-    type_capability = capabilities.get(presentation._name)
-    if type_capability is None:
+    substitution_type_capabilities = substitution_node_type._get_capabilities(context)
+    substitution_type_capability = substitution_type_capabilities.get(presentation._name)
+    if substitution_type_capability is None:
         context.validation.report(
-            'substitution mappings capability "%s" is not declared in node type "%s"'
-            % (presentation._name, node_type._name), locator=presentation._locator,
-            level=Issue.BETWEEN_TYPES)
+            'substitution mapping capability "{0}" '
+            'is not declared in node type "{substitution_type}"'.format(
+                presentation._name, substitution_type=substitution_node_type._name),
+            locator=presentation._locator, level=Issue.BETWEEN_TYPES)
         return
 
-    capability_name = presentation._raw[1]
-    capabilities = node_template._get_capabilities(context)
-    capability = capabilities.get(capability_name)
+    # validate that the capability in substitution_mapping is declared in the corresponding
+    # node template
+    node_template = get_node_template(context, presentation)
+    if node_template is None:
+        report_missing_node_template(context, presentation, field='capability')
+        return
+    mapped_capability_name = presentation._raw[1]
+    node_template_capability = node_template._get_capabilities(context).get(mapped_capability_name)
 
-    if capability is None:
+    if node_template_capability is None:
         context.validation.report(
-            'substitution mappings capability "%s" refers to an unknown capability of node template'
-            ' "%s": %s'
-            % (presentation._name, node_template._name, safe_repr(capability_name)),
+            'substitution mapping capability "{0}" refers to an unknown '
+            'capability of node template "{1}": {mapped_capability_name}'.format(
+                presentation._name, node_template._name,
+                mapped_capability_name=safe_repr(mapped_capability_name)),
             locator=presentation._locator, level=Issue.BETWEEN_TYPES)
         return
 
-    type_capability_type = type_capability._get_type(context)
-    capability_type = capability._get_type(context)
+    # validate that the capability type in substitution_mapping is derived from the capability type
+    # in the corresponding node template
+    substitution_type_capability_type = substitution_type_capability._get_type(context)
+    node_template_capability_type = node_template_capability._get_type(context)
 
-    if not type_capability_type._is_descendant(context, capability_type):
+    if not node_template_capability_type._is_descendant(context, substitution_type_capability_type):
         context.validation.report(
-            'type "%s" of substitution mappings capability "%s" is not a descendant of "%s"'
-            % (capability_type._name, presentation._name, type_capability_type._name),
+            'node template capability type "{0}" is not a descendant of substitution mapping '
+            'capability "{1}" of type "{2}"'.format(
+                presentation._name,
+                node_template_capability_type._name,
+                substitution_type_capability_type._name),
             locator=presentation._locator, level=Issue.BETWEEN_TYPES)
 
 
@@ -106,25 +130,36 @@ def validate_subtitution_mappings_capability(context, presentation):
 # Utils
 #
 
-def validate_format(context, presentation, name):
-    if (not isinstance(presentation._raw, list)) or (len(presentation._raw) != 2) \
-        or (not isinstance(presentation._raw[0], basestring)) \
-        or (not isinstance(presentation._raw[1], basestring)):
-        context.validation.report(
-            'substitution mappings %s "%s" is not a list of 2 strings: %s'
-            % (name, presentation._name, safe_repr(presentation._raw)),
-            locator=presentation._locator, level=Issue.FIELD)
+def validate_format(presentation):
+    if not isinstance(presentation._raw, list) or \
+            len(presentation._raw) != 2 or \
+            not isinstance(presentation._raw[0], basestring) or \
+            not isinstance(presentation._raw[1], basestring):
         return False
     return True
 
 
-def get_node_template(context, presentation, name):
+def get_node_template(context, presentation):
     node_template_name = presentation._raw[0]
     node_template = context.presentation.get_from_dict('service_template', 'topology_template',
                                                        'node_templates', node_template_name)
-    if node_template is None:
-        context.validation.report(
-            'substitution mappings %s "%s" refers to an unknown node template: %s'
-            % (name, presentation._name, safe_repr(node_template_name)),
-            locator=presentation._locator, level=Issue.FIELD)
     return node_template
+
+
+def report_missing_node_template(context, presentation, field):
+    context.validation.report(
+        'substitution mappings {field} "{node_template_mapping}" '
+        'refers to an unknown node template: {node_template_name}'.format(
+            field=field,
+            node_template_mapping=presentation._name,
+            node_template_name=safe_repr(presentation._raw[0])),
+        locator=presentation._locator, level=Issue.FIELD)
+
+
+def report_invalid_format(context, presentation, field):
+    context.validation.report(
+        'substitution mapping {field} "{field_name}" is not a list of 2 strings: {value}'.format(
+            field=field,
+            field_name=presentation._name,
+            value=safe_repr(presentation._raw)),
+        locator=presentation._locator, level=Issue.FIELD)