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/2e50cfa4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/2e50cfa4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/2e50cfa4 Branch: refs/heads/ARIA-260-send-interface-inputs Commit: 2e50cfa4047b653661acf75fbbe0596571e0837b Parents: 180e0a1 Author: Tal Liron <[email protected]> Authored: Fri Jun 2 13:35:21 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Tue Jun 6 14:16:08 2017 -0500 ---------------------------------------------------------------------- aria/modeling/service_instance.py | 18 ++++---- aria/modeling/utils.py | 4 ++ tests/instantiation/__init__.py | 14 ++++++ tests/instantiation/test_configuration.py | 48 ++++++++++++++++++++ .../node-cellar/node-cellar.yaml | 22 +++++++-- 5 files changed, 93 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e50cfa4/aria/modeling/service_instance.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py index 2bf9872..4f1712c 100644 --- a/aria/modeling/service_instance.py +++ b/aria/modeling/service_instance.py @@ -1742,19 +1742,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/2e50cfa4/aria/modeling/utils.py ---------------------------------------------------------------------- diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py index 43be410..02fde23 100644 --- a/aria/modeling/utils.py +++ b/aria/modeling/utils.py @@ -201,6 +201,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/2e50cfa4/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/2e50cfa4/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..304e0c3 --- /dev/null +++ b/tests/instantiation/test_configuration.py @@ -0,0 +1,48 @@ +# 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_node_cellar + + [email protected] +def service(): + context, _ = consume_node_cellar() + yield context.modeling.instance + + +def test_execution_plugin_remote_with_operation_input(service): + assert set(service.nodes['loadbalancer_host_1'].interfaces['Standard'].operations['create'] \ + .arguments.keys()) == set(( + 'process', + 'use_sudo', + 'fabric_env', + 'script_path', + 'hide_output', + 'openstack_credential' + )) + + +def test_execution_plugin_remote_with_interface_input(service): + assert set(service.nodes['node_cellar_1'].interfaces['Maintenance'].operations['enable'] \ + .arguments.keys()) == set(( + 'process', + 'use_sudo', + 'fabric_env', + 'script_path', + 'hide_output', + 'mode' + )) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e50cfa4/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 4d53f9b..6d650bd 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:
