ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran-z <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #193: ARIA-348 Validate substitution_mappin...
Date Mon, 21 Aug 2017 15:29:50 GMT
Github user ran-z commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/193#discussion_r134229923
  
    --- Diff: extensions/aria_extension_tosca/simple_v1_0/modeling/substitution_mappings.py
---
    @@ -17,114 +17,149 @@
     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 node_template_requirement_capability_type._is_descendant(
    +            context, substitution_type_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 substitution_type_capability_type._is_descendant(context, node_template_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(
    +                node_template_capability_type._name,
    +                presentation._name,
    +                substitution_type_capability_type._name),
                 locator=presentation._locator, level=Issue.BETWEEN_TYPES)
     
     
     #
     # 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):
    --- End diff --
    
    `_`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message