Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id EE9A7200CC6 for ; Mon, 3 Jul 2017 21:56:28 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id ED782160BD2; Mon, 3 Jul 2017 19:56:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F0D49160C03 for ; Mon, 3 Jul 2017 21:56:27 +0200 (CEST) Received: (qmail 93693 invoked by uid 500); 3 Jul 2017 19:56:27 -0000 Mailing-List: contact commits-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list commits@ariatosca.incubator.apache.org Received: (qmail 93663 invoked by uid 99); 3 Jul 2017 19:56:27 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2017 19:56:27 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B70C1CF568 for ; Mon, 3 Jul 2017 19:56:26 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.131 X-Spam-Level: X-Spam-Status: No, score=-0.131 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, URIBL_SBL=4, URIBL_SBL_A=0.1] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Oqe_nBG422wU for ; Mon, 3 Jul 2017 19:56:23 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 7AAD25FE6E for ; Mon, 3 Jul 2017 19:56:22 +0000 (UTC) Received: (qmail 93352 invoked by uid 99); 3 Jul 2017 19:56:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2017 19:56:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4265BF5500; Mon, 3 Jul 2017 19:56:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: emblemparade@apache.org To: commits@ariatosca.incubator.apache.org Date: Mon, 03 Jul 2017 19:56:48 -0000 Message-Id: <3c356f4111c2414ba8d5ca7c94252947@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [31/31] incubator-ariatosca git commit: ARIA-260 Send interface inputs as arguments archived-at: Mon, 03 Jul 2017 19:56:29 -0000 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/e6d9b4cf Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e6d9b4cf Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e6d9b4cf Branch: refs/heads/ARIA-260-send-interface-inputs Commit: e6d9b4cf22b6f11f3335c00af95fc097e5362e89 Parents: 3583f8c Author: Tal Liron Authored: Fri Jun 2 13:35:21 2017 -0500 Committer: Tal Liron Committed: Mon Jul 3 14:56:05 2017 -0500 ---------------------------------------------------------------------- aria/modeling/service_instance.py | 18 +-- aria/modeling/utils.py | 4 + tests/instantiation/__init__.py | 14 +++ tests/instantiation/test_configuration.py | 117 +++++++++++++++++++ tests/parser/service_templates.py | 11 ++ .../node-cellar/node-cellar.yaml | 22 +++- 6 files changed, 173 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e6d9b4cf/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/e6d9b4cf/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/e6d9b4cf/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/e6d9b4cf/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..2d2cec0 --- /dev/null +++ b/tests/instantiation/test_configuration.py @@ -0,0 +1,117 @@ +# 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 + +""" + + +@pytest.fixture +def service(): + context, _ = consume_literal(TEMPLATE) + yield context.modeling.instance + + +def test_local_with_interface_inputs(service): + interface = service.nodes['local_node_1'].interfaces['MyInterface'] + operation = interface.operations['operation'] + assert set(interface.inputs.keys()) == set(( + 'interface_string', + 'interface_integer' + )) + assert set(operation.inputs.keys()) == set(( + 'operation_string', + 'operation_integer' + )) + assert set(operation.arguments.keys()) == set(( + 'process', + 'script_path', + 'interface_string', + 'interface_integer', + 'operation_string', + 'operation_integer' + )) + + +def test_remote_with_interface_inputs(service): + interface = service.nodes['remote_node_1'].interfaces['MyInterface'] + operation = interface.operations['operation'] + assert set(interface.inputs.keys()) == set(( + 'interface_string', + 'interface_integer' + )) + assert set(operation.inputs.keys()) == set(( + 'operation_string', + 'operation_integer' + )) + assert set(operation.arguments.keys()) == set(( + 'process', + 'use_sudo', + 'fabric_env', + 'script_path', + 'hide_output', + 'interface_string', + 'interface_integer', + 'operation_string', + 'operation_integer' + )) + http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e6d9b4cf/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/e6d9b4cf/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: