Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-260-send-interface-inputs 600152328 -> 05be799b2 (forced update)
ARIA-260 Send interface inputs as arguments Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/05be799b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/05be799b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/05be799b Branch: refs/heads/ARIA-260-send-interface-inputs Commit: 05be799b2e473badab2ea098035037ffcfe82c96 Parents: 3583f8c Author: Tal Liron <[email protected]> Authored: Fri Jun 2 13:35:21 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Mon Jul 3 15:08:58 2017 -0500 ---------------------------------------------------------------------- aria/modeling/service_instance.py | 18 +-- aria/modeling/utils.py | 4 + tests/instantiation/__init__.py | 14 +++ tests/instantiation/test_configuration.py | 121 +++++++++++++++++++ tests/parser/service_templates.py | 11 ++ .../node-cellar/node-cellar.yaml | 22 +++- 6 files changed, 177 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/05be799b/aria/modeling/service_instance.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py index 002a87c..741764e 100644 --- a/aria/modeling/service_instance.py +++ b/aria/modeling/service_instance.py @@ -2012,19 +2012,19 @@ class OperationBase(InstanceModelMixin): # In the future plugins may be able to add their own "configure_operation" hook that # can validate the configuration and otherwise create specially derived arguments. For # now, we just send all configuration parameters as arguments without validation. - configurations_as_arguments = {} - for configuration in self.configurations.itervalues(): - configurations_as_arguments[configuration.name] = configuration.as_argument() + utils.instantiate_dict(self, self.arguments, + utils.dict_as_arguments(self.configurations)) - utils.instantiate_dict(self, self.arguments, configurations_as_arguments) + if self.interface is not None: + # Send all interface inputs as extra arguments + # ("interface" is None for workflow operations) + # Note that they will override existing arguments of the same names + utils.instantiate_dict(self, self.arguments, + utils.dict_as_arguments(self.interface.inputs)) # Send all inputs as extra arguments # Note that they will override existing arguments of the same names - inputs_as_arguments = {} - for input in self.inputs.itervalues(): - inputs_as_arguments[input.name] = input.as_argument() - - utils.instantiate_dict(self, self.arguments, inputs_as_arguments) + utils.instantiate_dict(self, self.arguments, utils.dict_as_arguments(self.inputs)) # Check for reserved arguments from ..orchestrator.decorators import OPERATION_DECORATOR_RESERVED_ARGUMENTS http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/05be799b/aria/modeling/utils.py ---------------------------------------------------------------------- diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py index 5193cd9..64e7c74 100644 --- a/aria/modeling/utils.py +++ b/aria/modeling/utils.py @@ -211,6 +211,10 @@ def dump_interfaces(interfaces, name='Interfaces'): interface.dump() +def dict_as_arguments(the_dict): + return OrderedDict((name, value.as_argument()) for name, value in the_dict.iteritems()) + + class classproperty(object): # pylint: disable=invalid-name def __init__(self, f): self._func = f http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/05be799b/tests/instantiation/__init__.py ---------------------------------------------------------------------- diff --git a/tests/instantiation/__init__.py b/tests/instantiation/__init__.py new file mode 100644 index 0000000..ae1e83e --- /dev/null +++ b/tests/instantiation/__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/05be799b/tests/instantiation/test_configuration.py ---------------------------------------------------------------------- diff --git a/tests/instantiation/test_configuration.py b/tests/instantiation/test_configuration.py new file mode 100644 index 0000000..27c4ab3 --- /dev/null +++ b/tests/instantiation/test_configuration.py @@ -0,0 +1,121 @@ +# 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 tests.parser.service_templates import consume_literal + + +TEMPLATE = """ +tosca_definitions_version: tosca_simple_yaml_1_0 + +interface_types: + MyInterface: + derived_from: tosca.interfaces.Root + inputs: + interface_string: + type: string + default: value1 + interface_integer: + type: integer + default: 1 + operation: + implementation: operation.sh + inputs: + operation_string: + type: string + default: value2 + operation_integer: + type: integer + default: 2 + +node_types: + LocalNode: + derived_from: tosca.nodes.Root + interfaces: + MyInterface: + type: MyInterface + + RemoteNode: + derived_from: tosca.nodes.Compute + interfaces: + MyInterface: + type: MyInterface + +topology_template: + node_templates: + local_node: + type: LocalNode + + remote_node: + type: RemoteNode +""" + + [email protected] +def service(): + context, _ = consume_literal(TEMPLATE) + yield context.modeling.instance + + +def _values(the_dict): + return dict((k, v.value) for k, v in the_dict.iteritems()) + + +def test_local_with_interface_inputs(service): + interface = service.nodes['local_node_1'].interfaces['MyInterface'] + operation = interface.operations['operation'] + assert _values(interface.inputs) == { + 'interface_string': 'value1', + 'interface_integer': 1 + } + assert _values(operation.inputs) == { + 'operation_string': 'value2', + 'operation_integer': 2 + } + print _values(operation.arguments) + assert _values(operation.arguments) == { + 'process': {}, + 'script_path': 'operation.sh', + 'interface_string': 'value1', + 'interface_integer': 1, + 'operation_string': 'value2', + 'operation_integer': 2 + } + + +def test_remote_with_interface_inputs(service): + interface = service.nodes['remote_node_1'].interfaces['MyInterface'] + operation = interface.operations['operation'] + assert _values(interface.inputs) == { + 'interface_string': 'value1', + 'interface_integer': 1 + } + assert _values(operation.inputs) == { + 'operation_string': 'value2', + 'operation_integer': 2 + } + print _values(operation.arguments) + assert _values(operation.arguments) == { + 'process': {}, + 'use_sudo': False, + 'fabric_env': {'user': '', 'password': '', 'key': None, 'key_filename': None}, + 'script_path': 'operation.sh', + 'hide_output': [], + 'interface_string': 'value1', + 'interface_integer': 1, + 'operation_string': 'value2', + 'operation_integer': 2 + } http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/05be799b/tests/parser/service_templates.py ---------------------------------------------------------------------- diff --git a/tests/parser/service_templates.py b/tests/parser/service_templates.py index 56f75ab..2e21548 100644 --- a/tests/parser/service_templates.py +++ b/tests/parser/service_templates.py @@ -16,11 +16,22 @@ import os from aria.utils.caching import cachedmethod +from aria.parser.loading import LiteralLocation from .utils import (create_context, create_consumer) from ..helpers import (get_example_uri, get_service_template_uri) +def consume_literal(literal, consumer_class_name='instance', cache=True): + cachedmethod.ENABLED = cache + context = create_context(LiteralLocation(literal)) + 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_use_case(use_case_name, consumer_class_name='instance', cache=True): cachedmethod.ENABLED = cache uri = get_example_uri('tosca-simple-1.0', 'use-cases', use_case_name, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/05be799b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml ---------------------------------------------------------------------- diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml index a34301c..a5df3e8 100644 --- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml +++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml @@ -54,8 +54,20 @@ interface_types: Maintenance: derived_from: tosca.interfaces.Root - enable: {} - disable: {} + inputs: + mode: + type: string + default: immediate + constraints: + - valid_values: [ immediate, eventual ] + description: >- + The mode in which maintenance mode is enabled/disabled. + enable: + description: >- + Enable maintenance mode. + disable: + description: >- + Disable maintenance mode. node_types: @@ -102,8 +114,10 @@ topology_template: #token: { token: [ 'zero.one|two-three', '.|-', 3 ] } interfaces: Maintenance: - enable: juju > charm.maintenance_on - disable: juju > charm.maintenance_off + inputs: + mode: eventual + enable: maintenance_node_cellar.sh + disable: maintenance_node_cellar.sh Standard: create: implementation:
