ARIA-277 Support for Type Qualified Name
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/c2b8e65b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/c2b8e65b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/c2b8e65b Branch: refs/heads/new_wagon_setuptools Commit: c2b8e65b41c013bfd4ee14ea47268083f8b20822 Parents: 67a0675 Author: djay87 <[email protected]> Authored: Wed Jul 19 12:26:19 2017 +0300 Committer: max-orlov <[email protected]> Committed: Wed Jul 19 12:38:12 2017 +0300 ---------------------------------------------------------------------- .../workflows/core/events_handler.py | 3 +- examples/hello-world/helloworld.yaml | 2 +- .../simple_v1_0/assignments.py | 15 ++- .../simple_v1_0/definitions.py | 25 +++-- .../aria_extension_tosca/simple_v1_0/misc.py | 8 +- .../simple_v1_0/modeling/data_types.py | 6 +- .../simple_v1_0/modeling/policies.py | 8 +- .../presentation/field_validators.py | 18 +-- .../simple_v1_0/presentation/types.py | 14 ++- .../simple_v1_0/templates.py | 20 ++-- .../aria_extension_tosca/simple_v1_0/types.py | 42 ++++--- tests/parser/service_templates.py | 13 +++ tests/parser/test_tosca_simple_v1_0.py | 112 ------------------- tests/parser/test_tosca_simple_v1_0/__init__.py | 14 +++ .../presentation/__init__.py | 0 .../presentation/test_types.py | 23 ++++ .../test_tosca_simple_v1_0/test_end2end.py | 112 +++++++++++++++++++ .../types/shorthand-1/shorthand-1.yaml | 23 ++++ .../types/typequalified-1/typequalified-1.yaml | 23 ++++ 19 files changed, 286 insertions(+), 195 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/aria/orchestrator/workflows/core/events_handler.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/core/events_handler.py b/aria/orchestrator/workflows/core/events_handler.py index 219d2df..473475e 100644 --- a/aria/orchestrator/workflows/core/events_handler.py +++ b/aria/orchestrator/workflows/core/events_handler.py @@ -155,7 +155,8 @@ def _update_node_state_if_necessary(ctx, is_transitional=False): # and also will *never* be the type name node = ctx.task.node if ctx.task is not None else None if (node is not None) and \ - (ctx.task.interface_name in ('Standard', 'tosca.interfaces.node.lifecycle.Standard')): + (ctx.task.interface_name in ('Standard', 'tosca.interfaces.node.lifecycle.Standard', + 'tosca:Standard')): state = node.determine_state(op_name=ctx.task.operation_name, is_transitional=is_transitional) if state: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/examples/hello-world/helloworld.yaml ---------------------------------------------------------------------- diff --git a/examples/hello-world/helloworld.yaml b/examples/hello-world/helloworld.yaml index d3369b7..2fdc4d4 100644 --- a/examples/hello-world/helloworld.yaml +++ b/examples/hello-world/helloworld.yaml @@ -3,7 +3,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0 node_types: WebServer: - derived_from: tosca.nodes.Root + derived_from: tosca:Root capabilities: host: type: tosca.capabilities.Container http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/assignments.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/assignments.py b/extensions/aria_extension_tosca/simple_v1_0/assignments.py index 2cfc9e5..d507042 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/assignments.py +++ b/extensions/aria_extension_tosca/simple_v1_0/assignments.py @@ -29,8 +29,8 @@ from .presentation.field_validators import (node_template_or_type_validator, relationship_template_or_type_validator, capability_definition_or_type_validator, node_filter_validator) -from .presentation.types import (convert_shorthand_to_full_type_name, - get_type_by_full_or_shorthand_name) +from .presentation.types import (convert_name_to_full_type_name, get_type_by_name) + @implements_specification('3.5.9', 'tosca-simple-1.0') @@ -201,7 +201,7 @@ class RelationshipAssignment(ExtensiblePresentation): 'relationship_templates', type_name) if the_type is not None: return the_type, 'relationship_template' - the_type = get_type_by_full_or_shorthand_name(context, type_name, 'relationship_types') + the_type = get_type_by_name(context, type_name, 'relationship_types') if the_type is not None: return the_type, 'relationship_type' return None, None @@ -283,7 +283,7 @@ class RequirementAssignment(ExtensiblePresentation): 'node_templates', node) if node_template is not None: return node_template, 'node_template' - node_type = get_type_by_full_or_shorthand_name(context, node, 'node_types') + node_type = get_type_by_name(context, node, 'node_types') if node_type is not None: return node_type, 'node_type' @@ -299,8 +299,7 @@ class RequirementAssignment(ExtensiblePresentation): capabilities = node._get_capabilities(context) if capability in capabilities: return capabilities[capability], 'capability_assignment' - capability_type = get_type_by_full_or_shorthand_name(context, capability, - 'capability_types') + capability_type = get_type_by_name(context, capability, 'capability_types') if capability_type is not None: return capability_type, 'capability_type' @@ -375,7 +374,7 @@ class ArtifactAssignment(ExtensiblePresentation): #DEFN_ENTITY_ARTIFACT_DEF>`__ """ - @field_validator(type_validator('artifact type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('artifact type', convert_name_to_full_type_name, 'artifact_types')) @primitive_field(str, required=True) def type(self): @@ -431,7 +430,7 @@ class ArtifactAssignment(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'artifact_types') + return get_type_by_name(context, self.type, 'artifact_types') @cachedmethod def _get_repository(self, context): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/definitions.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/definitions.py b/extensions/aria_extension_tosca/simple_v1_0/definitions.py index eaa1ac9..9158776 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/definitions.py +++ b/extensions/aria_extension_tosca/simple_v1_0/definitions.py @@ -28,8 +28,7 @@ from .presentation.extensible import ExtensiblePresentation from .presentation.field_getters import data_type_class_getter from .presentation.field_validators import (data_type_validator, data_value_validator, entry_schema_validator) -from .presentation.types import (convert_shorthand_to_full_type_name, - get_type_by_full_or_shorthand_name) +from .presentation.types import (convert_name_to_full_type_name, get_type_by_name) from .modeling.data_types import get_data_type, get_property_constraints from .modeling.interfaces import (get_and_override_input_definitions_from_type, get_and_override_operation_definitions_from_type) @@ -282,7 +281,7 @@ class InterfaceDefinition(ExtensiblePresentation): #DEFN_ELEMENT_INTERFACE_DEF>`__ """ - @field_validator(type_validator('interface type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('interface type', convert_name_to_full_type_name, 'interface_types')) @primitive_field(str) def type(self): @@ -311,7 +310,7 @@ class InterfaceDefinition(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'interface_types') + return get_type_by_name(context, self.type, 'interface_types') @cachedmethod def _get_inputs(self, context): @@ -335,7 +334,7 @@ class RelationshipDefinition(ExtensiblePresentation): Relationship definition. """ - @field_validator(type_validator('relationship type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('relationship type', convert_name_to_full_type_name, 'relationship_types')) @primitive_field(str, required=True) def type(self): @@ -358,7 +357,8 @@ class RelationshipDefinition(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'relationship_types') + return get_type_by_name(context, self.type, 'relationship_types') + @short_form_field('capability') @@ -378,7 +378,7 @@ class RequirementDefinition(ExtensiblePresentation): #DEFN_ELEMENT_REQUIREMENT_DEF>`__ """ - @field_validator(type_validator('capability type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('capability type', convert_name_to_full_type_name, 'capability_types')) @primitive_field(str, required=True) def capability(self): @@ -389,7 +389,8 @@ class RequirementDefinition(ExtensiblePresentation): :type: :obj:`basestring` """ - @field_validator(type_validator('node type', convert_shorthand_to_full_type_name, 'node_types')) + @field_validator(type_validator('node type', convert_name_to_full_type_name, + 'node_types')) @primitive_field(str) def node(self): """ @@ -421,7 +422,7 @@ class RequirementDefinition(ExtensiblePresentation): @cachedmethod def _get_capability_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.capability, 'capability_types') + return get_type_by_name(context, self.capability, 'capability_types') @cachedmethod def _get_node_type(self, context): @@ -442,7 +443,7 @@ class CapabilityDefinition(ExtensiblePresentation): #DEFN_ELEMENT_CAPABILITY_DEFN>`__ """ - @field_validator(type_validator('capability type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('capability type', convert_name_to_full_type_name, 'capability_types')) @primitive_field(str, required=True) def type(self): @@ -476,7 +477,7 @@ class CapabilityDefinition(ExtensiblePresentation): :type: {:obj:`basestring`: :class:`AttributeDefinition`} """ - @field_validator(list_type_validator('node type', convert_shorthand_to_full_type_name, + @field_validator(list_type_validator('node type', convert_name_to_full_type_name, 'node_types')) @primitive_list_field(str) def valid_source_types(self): @@ -506,7 +507,7 @@ class CapabilityDefinition(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'capability_types') + return get_type_by_name(context, self.type, 'capability_types') @cachedmethod def _get_parent(self, context): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/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 fb86157..23beb3c 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/misc.py +++ b/extensions/aria_extension_tosca/simple_v1_0/misc.py @@ -33,8 +33,8 @@ from .presentation.field_validators import (constraint_clause_field_validator, constraint_clause_valid_values_validator, constraint_clause_pattern_validator, data_type_validator) -from .presentation.types import (convert_shorthand_to_full_type_name, - get_type_by_full_or_shorthand_name) +from .presentation.types import (convert_name_to_full_type_name, get_type_by_name) + @implements_specification('3.5.1', 'tosca-simple-1.0') @@ -410,7 +410,7 @@ class SubstitutionMappings(ExtensiblePresentation): Substitution mappings. """ - @field_validator(type_validator('node type', convert_shorthand_to_full_type_name, 'node_types')) + @field_validator(type_validator('node type', convert_name_to_full_type_name, 'node_types')) @primitive_field(str, required=True) def node_type(self): """ @@ -431,7 +431,7 @@ class SubstitutionMappings(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.node_type, 'node_types') + return get_type_by_name(context, self.node_type, 'node_types') def _validate(self, context): super(SubstitutionMappings, self)._validate(context) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py index ba94c70..fbb8280 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py @@ -24,7 +24,7 @@ from aria.parser.presentation import (get_locator, validate_primitive) from aria.parser.validation import Issue from .functions import get_function -from ..presentation.types import get_type_by_full_or_shorthand_name +from ..presentation.types import get_type_by_name # @@ -169,7 +169,7 @@ def get_data_type(context, presentation, field_name, allow_none=False): return None # Try complex data type - data_type = get_type_by_full_or_shorthand_name(context, type_name, 'data_types') + data_type = get_type_by_name(context, type_name, 'data_types') if data_type is not None: return data_type @@ -322,7 +322,7 @@ def apply_constraint_to_value(context, presentation, constraint_clause, value): # def get_data_type_value(context, presentation, field_name, type_name): - the_type = get_type_by_full_or_shorthand_name(context, type_name, 'data_types') + the_type = get_type_by_name(context, type_name, 'data_types') if the_type is not None: value = getattr(presentation, field_name) if value is not None: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py index 7dd803b..0376798 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..presentation.types import convert_shorthand_to_full_type_name +from ..presentation.types import convert_name_to_full_type_name # @@ -40,12 +40,10 @@ def get_inherited_targets(context, presentation): for our_target in our_targets: if our_target in all_node_types: - our_target = convert_shorthand_to_full_type_name(context, our_target, - all_node_types) + our_target = convert_name_to_full_type_name(context, our_target, all_node_types) node_types.append(all_node_types[our_target]) elif our_target in all_group_types: - our_target = convert_shorthand_to_full_type_name(context, our_target, - all_group_types) + our_target = convert_name_to_full_type_name(context, our_target, all_group_types) group_types.append(all_group_types[our_target]) return node_types, group_types http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py b/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py index fc9a9bc..e5853d8 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py +++ b/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py @@ -22,7 +22,8 @@ from aria.parser.validation import Issue from ..modeling.data_types import (get_primitive_data_type, get_data_type_name, coerce_value, get_container_data_type) -from .types import get_type_by_full_or_shorthand_name, convert_shorthand_to_full_type_name +from .types import (get_type_by_name, convert_name_to_full_type_name) + # @@ -88,7 +89,7 @@ def data_type_validator(type_name='data type'): locator=presentation._get_child_locator('type'), level=Issue.BETWEEN_TYPES) # Can be a complex data type - if get_type_by_full_or_shorthand_name(context, value, 'data_types') is not None: + if get_type_by_name(context, value, 'data_types') is not None: return True # Can be a primitive data type @@ -170,7 +171,7 @@ def data_value_validator(field, presentation, context): # _data_type_validator = data_type_validator() -_data_type_derived_from_validator = derived_from_validator(convert_shorthand_to_full_type_name, +_data_type_derived_from_validator = derived_from_validator(convert_name_to_full_type_name, 'data_types') @@ -349,7 +350,7 @@ def node_template_or_type_validator(field, presentation, context): context.presentation.get('service_template', 'topology_template', 'node_templates') \ or {} if (value not in node_templates) and \ - (get_type_by_full_or_shorthand_name(context, value, 'node_types') is None): + (get_type_by_name(context, value, 'node_types') is None): report_issue_for_unknown_type(context, presentation, 'node template or node type', field.name) @@ -375,7 +376,7 @@ def capability_definition_or_type_validator(field, presentation, context): if value in capabilities: return - if get_type_by_full_or_shorthand_name(context, value, 'capability_types') is not None: + if get_type_by_name(context, value, 'capability_types') is not None: if node is not None: context.validation.report( '"%s" refers to a capability type even though "node" has a value in "%s"' @@ -438,7 +439,7 @@ def relationship_template_or_type_validator(field, presentation, context): 'relationship_templates') \ or {} if (value not in relationship_templates) and \ - (get_type_by_full_or_shorthand_name(context, value, 'relationship_types') is None): + (get_type_by_name(context, value, 'relationship_types') is None): report_issue_for_unknown_type(context, presentation, 'relationship template or relationship type', field.name) @@ -460,9 +461,8 @@ def list_node_type_or_group_type_validator(field, presentation, context): values = getattr(presentation, field.name) if values is not None: for value in values: - if \ - (get_type_by_full_or_shorthand_name(context, value, 'node_types') is None) and \ - (get_type_by_full_or_shorthand_name(context, value, 'group_types') is None): + if (get_type_by_name(context, value, 'node_types') is None) and \ + (get_type_by_name(context, value, 'group_types') is None): report_issue_for_unknown_type(context, presentation, 'node type or group type', field.name, value) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py index 2f30e0f..920ebed 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py @@ -14,9 +14,9 @@ # limitations under the License. -def convert_shorthand_to_full_type_name(context, name, types_dict): # pylint: disable=unused-argument +def convert_name_to_full_type_name(context, name, types_dict): # pylint: disable=unused-argument """ - Converts a shorthand type name to its full type name, or else returns it unchanged. + Converts a type name to its full type name, or else returns it unchanged. Works by checking for ``shorthand_name`` in the types' ``_extensions`` field. See also :class:`aria_extension_tosca.v1_0.presentation.extensible.ExtensiblePresentation`. @@ -28,14 +28,15 @@ def convert_shorthand_to_full_type_name(context, name, types_dict): # pylint: di if (name is not None) and types_dict and (name not in types_dict): for full_name, the_type in types_dict.iteritems(): if hasattr(the_type, '_extensions') and the_type._extensions \ - and (the_type._extensions.get('shorthand_name') == name): + and ((the_type._extensions.get('shorthand_name') == name) \ + or (the_type._extensions.get('type_qualified_name') == name)): return full_name return name -def get_type_by_full_or_shorthand_name(context, name, *types_dict_names): +def get_type_by_name(context, name, *types_dict_names): """ - Gets a type either by its full name or its shorthand name. + Gets a type either by its full name or its shorthand name or typequalified name. Works by checking for ``shorthand_name`` in the types' ``_extensions`` field. See also :class:`~aria_extension_tosca.v1_0.presentation.extensible.ExtensiblePresentation`. @@ -53,7 +54,8 @@ def get_type_by_full_or_shorthand_name(context, name, *types_dict_names): return the_type for the_type in types_dict.itervalues(): if hasattr(the_type, '_extensions') and the_type._extensions \ - and (the_type._extensions.get('shorthand_name') == name): + and ((the_type._extensions.get('shorthand_name') == name) \ + or (the_type._extensions.get('type_qualified_name') == name)): # Shorthand name return the_type return None http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/extensions/aria_extension_tosca/simple_v1_0/templates.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/templates.py b/extensions/aria_extension_tosca/simple_v1_0/templates.py index 9a44ea6..3c36bb8 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/templates.py +++ b/extensions/aria_extension_tosca/simple_v1_0/templates.py @@ -35,8 +35,7 @@ from .modeling.policies import get_policy_targets from .modeling.copy import get_default_raw_from_copy from .presentation.extensible import ExtensiblePresentation from .presentation.field_validators import copy_validator, policy_targets_validator -from .presentation.types import (convert_shorthand_to_full_type_name, - get_type_by_full_or_shorthand_name) +from .presentation.types import (convert_name_to_full_type_name, get_type_by_name) from .types import (ArtifactType, DataType, CapabilityType, InterfaceType, RelationshipType, NodeType, GroupType, PolicyType) @@ -55,7 +54,7 @@ class NodeTemplate(ExtensiblePresentation): #DEFN_ENTITY_NODE_TEMPLATE>`__ """ - @field_validator(type_validator('node type', convert_shorthand_to_full_type_name, 'node_types')) + @field_validator(type_validator('node type', convert_name_to_full_type_name, 'node_types')) @primitive_field(str, required=True) def type(self): """ @@ -154,7 +153,7 @@ class NodeTemplate(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'node_types') + return get_type_by_name(context, self.type, 'node_types') @cachedmethod def _get_property_values(self, context): @@ -218,7 +217,7 @@ class RelationshipTemplate(ExtensiblePresentation): #DEFN_ENTITY_RELATIONSHIP_TEMPLATE>`__ """ - @field_validator(type_validator('relationship type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('relationship type', convert_name_to_full_type_name, 'relationship_types')) @primitive_field(str, required=True) def type(self): @@ -278,7 +277,7 @@ class RelationshipTemplate(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'relationship_types') + return get_type_by_name(context, self.type, 'relationship_types') @cachedmethod def _get_property_values(self, context): @@ -315,7 +314,7 @@ class GroupTemplate(ExtensiblePresentation): #DEFN_ELEMENT_GROUP_DEF>`__ """ - @field_validator(type_validator('group type', convert_shorthand_to_full_type_name, + @field_validator(type_validator('group type', convert_name_to_full_type_name, 'group_types')) @primitive_field(str, required=True) def type(self): @@ -361,7 +360,7 @@ class GroupTemplate(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'group_types') + return get_type_by_name(context, self.type, 'group_types') @cachedmethod def _get_property_values(self, context): @@ -389,8 +388,7 @@ class PolicyTemplate(ExtensiblePresentation): #DEFN_ELEMENT_POLICY_DEF>`__ """ - @field_validator(type_validator('policy type', convert_shorthand_to_full_type_name, - 'policy_types')) + @field_validator(type_validator('policy type', convert_name_to_full_type_name, 'policy_types')) @primitive_field(str, required=True) def type(self): """ @@ -426,7 +424,7 @@ class PolicyTemplate(ExtensiblePresentation): @cachedmethod def _get_type(self, context): - return get_type_by_full_or_shorthand_name(context, self.type, 'policy_types') + return get_type_by_name(context, self.type, 'policy_types') @cachedmethod def _get_property_values(self, context): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/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 47332f0..787aac2 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/types.py @@ -43,7 +43,8 @@ from .presentation.field_validators import (data_type_derived_from_validator, data_type_constraints_validator, data_type_properties_validator, list_node_type_or_group_type_validator) -from .presentation.types import convert_shorthand_to_full_type_name +from .presentation.types import convert_name_to_full_type_name + @has_fields @@ -59,7 +60,7 @@ class ArtifactType(ExtensiblePresentation): #DEFN_ENTITY_ARTIFACT_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, 'artifact_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'artifact_types')) @primitive_field(str) def derived_from(self): """ @@ -111,7 +112,7 @@ class ArtifactType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'artifact_types') @cachedmethod @@ -240,8 +241,7 @@ class CapabilityType(ExtensiblePresentation): #DEFN_ENTITY_CAPABILITY_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, - 'capability_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'capability_types')) @primitive_field(str) def derived_from(self): """ @@ -284,8 +284,7 @@ class CapabilityType(ExtensiblePresentation): :type: {:obj:`basestring`: :class:`AttributeDefinition`} """ - @field_validator(list_type_validator('node type', convert_shorthand_to_full_type_name, - 'node_types')) + @field_validator(list_type_validator('node type', convert_name_to_full_type_name, 'node_types')) @primitive_list_field(str) def valid_source_types(self): """ @@ -297,7 +296,7 @@ class CapabilityType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'capability_types') @cachedmethod @@ -343,7 +342,7 @@ class InterfaceType(ExtensiblePresentation): #DEFN_ENTITY_INTERFACE_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, 'interface_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'interface_types')) @primitive_field(str) def derived_from(self): """ @@ -384,7 +383,7 @@ class InterfaceType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'interface_types') @cachedmethod @@ -422,8 +421,7 @@ class RelationshipType(ExtensiblePresentation): #DEFN_ENTITY_RELATIONSHIP_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, - 'relationship_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'relationship_types')) @primitive_field(str) def derived_from(self): """ @@ -472,7 +470,7 @@ class RelationshipType(ExtensiblePresentation): :type: {:obj:`basestring`: :class:`InterfaceDefinition`} """ - @field_validator(list_type_validator('capability type', convert_shorthand_to_full_type_name, + @field_validator(list_type_validator('capability type', convert_name_to_full_type_name, 'capability_types')) @primitive_list_field(str) def valid_target_types(self): @@ -485,7 +483,7 @@ class RelationshipType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'relationship_types') @cachedmethod @@ -538,7 +536,7 @@ class NodeType(ExtensiblePresentation): #DEFN_ENTITY_NODE_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, 'node_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'node_types')) @primitive_field(str) def derived_from(self): """ @@ -617,8 +615,7 @@ class NodeType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, - 'node_types') + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'node_types') @cachedmethod def _is_descendant(self, context, the_type): @@ -695,7 +692,7 @@ class GroupType(ExtensiblePresentation): #DEFN_ENTITY_GROUP_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, 'group_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'group_types')) @primitive_field(str) def derived_from(self): """ @@ -728,8 +725,7 @@ class GroupType(ExtensiblePresentation): :type: {:obj:`basestring`: :class:`PropertyDefinition`} """ - @field_validator(list_type_validator('node type', convert_shorthand_to_full_type_name, - 'node_types')) + @field_validator(list_type_validator('node type', convert_name_to_full_type_name, 'node_types')) @primitive_list_field(str) def members(self): """ @@ -754,7 +750,7 @@ class GroupType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'group_types') @cachedmethod @@ -802,7 +798,7 @@ class PolicyType(ExtensiblePresentation): #DEFN_ENTITY_POLICY_TYPE>`__ """ - @field_validator(derived_from_validator(convert_shorthand_to_full_type_name, 'policy_types')) + @field_validator(derived_from_validator(convert_name_to_full_type_name, 'policy_types')) @primitive_field(str) def derived_from(self): """ @@ -851,7 +847,7 @@ class PolicyType(ExtensiblePresentation): @cachedmethod def _get_parent(self, context): - return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, + return get_parent_presentation(context, self, convert_name_to_full_type_name, 'policy_types') @cachedmethod http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/parser/service_templates.py ---------------------------------------------------------------------- diff --git a/tests/parser/service_templates.py b/tests/parser/service_templates.py index 13712df..55cd4ad 100644 --- a/tests/parser/service_templates.py +++ b/tests/parser/service_templates.py @@ -47,6 +47,19 @@ def consume_use_case(use_case_name, consumer_class_name='instance', cache=True): assert not context.validation.has_issues return context, dumper +def consume_types_use_case(use_case_name, consumer_class_name='instance', cache=True): + cachedmethod.ENABLED = cache + uri = get_service_template_uri('tosca-simple-1.0', 'types', use_case_name, + '{0}.yaml'.format(use_case_name)) + context = create_context(uri) + inputs_file = get_example_uri('tosca-simple-1.0', 'types', use_case_name, 'inputs.yaml') + if os.path.isfile(inputs_file): + context.args.append('--inputs={0}'.format(inputs_file)) + consumer, dumper = create_consumer(context, consumer_class_name) + consumer.consume() + context.validation.dump_issues() + assert not context.validation.has_issues + return context, dumper def consume_node_cellar(consumer_class_name='instance', cache=True): cachedmethod.ENABLED = cache http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/parser/test_tosca_simple_v1_0.py ---------------------------------------------------------------------- diff --git a/tests/parser/test_tosca_simple_v1_0.py b/tests/parser/test_tosca_simple_v1_0.py deleted file mode 100644 index a583db5..0000000 --- a/tests/parser/test_tosca_simple_v1_0.py +++ /dev/null @@ -1,112 +0,0 @@ -# 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. - -from .service_templates import (consume_use_case, consume_node_cellar) - - -# Use Cases - -def test_use_case_compute_1(): - consume_use_case('compute-1', 'instance') - - -def test_use_case_software_component_1(): - consume_use_case('software-component-1', 'instance') - - -def test_use_case_block_storage_1(): - consume_use_case('block-storage-1', 'instance') - - -def test_use_case_block_storage_2(): - consume_use_case('block-storage-2', 'instance') - - -def test_use_case_block_storage_3(): - consume_use_case('block-storage-3', 'instance') - - -def test_use_case_block_storage_4(): - consume_use_case('block-storage-4', 'instance') - - -def test_use_case_block_storage_5(): - consume_use_case('block-storage-5', 'instance') - - -def test_use_case_block_storage_6(): - consume_use_case('block-storage-6', 'instance') - - -def test_use_case_object_storage_1(): - consume_use_case('object-storage-1', 'instance') - - -def test_use_case_network_1(): - consume_use_case('network-1', 'instance') - - -def test_use_case_network_2(): - consume_use_case('network-2', 'instance') - - -def test_use_case_network_3(): - consume_use_case('network-3', 'instance') - - -def test_use_case_network_4(): - consume_use_case('network-4', 'instance') - - -def test_use_case_webserver_dbms_1(): - consume_use_case('webserver-dbms-1', 'template') - - -def test_use_case_webserver_dbms_2(): - consume_use_case('webserver-dbms-2', 'instance') - - -def test_use_case_multi_tier_1(): - consume_use_case('multi-tier-1', 'instance') - - -def test_use_case_container_1(): - consume_use_case('container-1', 'template') - - -# NodeCellar - -def test_node_cellar_validation(): - consume_node_cellar('validate') - - -def test_node_cellar_validation_no_cache(): - consume_node_cellar('validate', False) - - -def test_node_cellar_presentation(): - consume_node_cellar('presentation') - - -def test_node_cellar_model(): - consume_node_cellar('template') - - -def test_node_cellar_types(): - consume_node_cellar('types') - - -def test_node_cellar_instance(): - consume_node_cellar('instance') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/parser/test_tosca_simple_v1_0/__init__.py ---------------------------------------------------------------------- diff --git a/tests/parser/test_tosca_simple_v1_0/__init__.py b/tests/parser/test_tosca_simple_v1_0/__init__.py new file mode 100644 index 0000000..ae1e83e --- /dev/null +++ b/tests/parser/test_tosca_simple_v1_0/__init__.py @@ -0,0 +1,14 @@ +# 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. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/parser/test_tosca_simple_v1_0/presentation/__init__.py ---------------------------------------------------------------------- diff --git a/tests/parser/test_tosca_simple_v1_0/presentation/__init__.py b/tests/parser/test_tosca_simple_v1_0/presentation/__init__.py new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/parser/test_tosca_simple_v1_0/presentation/test_types.py ---------------------------------------------------------------------- diff --git a/tests/parser/test_tosca_simple_v1_0/presentation/test_types.py b/tests/parser/test_tosca_simple_v1_0/presentation/test_types.py new file mode 100644 index 0000000..cfd4d3c --- /dev/null +++ b/tests/parser/test_tosca_simple_v1_0/presentation/test_types.py @@ -0,0 +1,23 @@ +# 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. + +from tests.parser.service_templates import consume_types_use_case + + +def test_use_case_shorthand_1_name(): + consume_types_use_case('shorthand-1', 'types') + +def test_use_case_typequalified_1_name(): + consume_types_use_case('typequalified-1', 'types') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/parser/test_tosca_simple_v1_0/test_end2end.py ---------------------------------------------------------------------- diff --git a/tests/parser/test_tosca_simple_v1_0/test_end2end.py b/tests/parser/test_tosca_simple_v1_0/test_end2end.py new file mode 100644 index 0000000..474d90e --- /dev/null +++ b/tests/parser/test_tosca_simple_v1_0/test_end2end.py @@ -0,0 +1,112 @@ +# 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. + +from ..service_templates import (consume_use_case, consume_node_cellar) + + +# Use Cases + +def test_use_case_compute_1(): + consume_use_case('compute-1', 'instance') + + +def test_use_case_software_component_1(): + consume_use_case('software-component-1', 'instance') + + +def test_use_case_block_storage_1(): + consume_use_case('block-storage-1', 'instance') + + +def test_use_case_block_storage_2(): + consume_use_case('block-storage-2', 'instance') + + +def test_use_case_block_storage_3(): + consume_use_case('block-storage-3', 'instance') + + +def test_use_case_block_storage_4(): + consume_use_case('block-storage-4', 'instance') + + +def test_use_case_block_storage_5(): + consume_use_case('block-storage-5', 'instance') + + +def test_use_case_block_storage_6(): + consume_use_case('block-storage-6', 'instance') + + +def test_use_case_object_storage_1(): + consume_use_case('object-storage-1', 'instance') + + +def test_use_case_network_1(): + consume_use_case('network-1', 'instance') + + +def test_use_case_network_2(): + consume_use_case('network-2', 'instance') + + +def test_use_case_network_3(): + consume_use_case('network-3', 'instance') + + +def test_use_case_network_4(): + consume_use_case('network-4', 'instance') + + +def test_use_case_webserver_dbms_1(): + consume_use_case('webserver-dbms-1', 'template') + + +def test_use_case_webserver_dbms_2(): + consume_use_case('webserver-dbms-2', 'instance') + + +def test_use_case_multi_tier_1(): + consume_use_case('multi-tier-1', 'instance') + + +def test_use_case_container_1(): + consume_use_case('container-1', 'template') + + +# NodeCellar + +def test_node_cellar_validation(): + consume_node_cellar('validate') + + +def test_node_cellar_validation_no_cache(): + consume_node_cellar('validate', False) + + +def test_node_cellar_presentation(): + consume_node_cellar('presentation') + + +def test_node_cellar_model(): + consume_node_cellar('template') + + +def test_node_cellar_types(): + consume_node_cellar('types') + + +def test_node_cellar_instance(): + consume_node_cellar('instance') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml ---------------------------------------------------------------------- diff --git a/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml b/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml new file mode 100644 index 0000000..b295f95 --- /dev/null +++ b/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: >- + TOSCA simple profile that defines a compute instance and a block storage with the "shorthand type" + +topology_template: + + node_templates: + + my_server: + type: Compute + requirements: + - local_storage: + node: my_block_storage + relationship: + type: AttachesTo + properties: + location: /path1/path2 + + my_block_storage: + type: BlockStorage + properties: + size: 10 GB http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2b8e65b/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml ---------------------------------------------------------------------- diff --git a/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml b/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml new file mode 100644 index 0000000..5f11fd4 --- /dev/null +++ b/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: >- + TOSCA simple profile that defines a compute instance and a block storage with the "typequalified type" + +topology_template: + + node_templates: + + my_server: + type: tosca:Compute + requirements: + - local_storage: + node: my_block_storage + relationship: + type: AttachesTo + properties: + location: /path1/path2 + + my_block_storage: + type: tosca:BlockStorage + properties: + size: 10 GB
