You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by ra...@apache.org on 2017/07/06 08:40:43 UTC
incubator-ariatosca git commit: ARIA-260 Send interface inputs as
arguments
Repository: incubator-ariatosca
Updated Branches:
refs/heads/master 6c0842429 -> 2195e1fb5
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/2195e1fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/2195e1fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/2195e1fb
Branch: refs/heads/master
Commit: 2195e1fb562245195718bb50c9ecddf94971ce74
Parents: 6c08424
Author: Tal Liron <ta...@gmail.com>
Authored: Fri Jun 2 13:35:21 2017 -0500
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Jul 6 11:39:59 2017 +0300
----------------------------------------------------------------------
aria/modeling/service_instance.py | 20 +--
aria/modeling/utils.py | 8 +
tests/instantiation/__init__.py | 14 ++
tests/instantiation/test_configuration.py | 172 +++++++++++++++++++
tests/parser/service_templates.py | 12 ++
.../node-cellar/node-cellar.yaml | 22 ++-
6 files changed, 234 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2195e1fb/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 002a87c..0d43650 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
@@ -2032,7 +2032,7 @@ class OperationBase(InstanceModelMixin):
OPERATION_DECORATOR_RESERVED_ARGUMENTS.intersection(self.arguments.keys())
if used_reserved_names:
context = ConsumptionContext.get_thread_local()
- context.validation.report('using reserved arguments in node "{0}": {1}'
+ context.validation.report('using reserved arguments in operation "{0}": {1}'
.format(
self.name,
formatting.string_list_as_string(used_reserved_names)),
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2195e1fb/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 5193cd9..e0fd11b 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -211,6 +211,14 @@ def dump_interfaces(interfaces, name='Interfaces'):
interface.dump()
+def parameters_as_values(the_dict):
+ return dict((k, v.value) for k, v in the_dict.iteritems())
+
+
+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/2195e1fb/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/2195e1fb/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..6ac0c9c
--- /dev/null
+++ b/tests/instantiation/test_configuration.py
@@ -0,0 +1,172 @@
+# 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
+from aria.modeling.utils import parameters_as_values
+
+
+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
+ interface_integer: # will override interface input
+ type: integer
+ default: 3
+
+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
+"""
+
+
+BROKEN_TEMPLATE = """
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+interface_types:
+ MyInterface:
+ derived_from: tosca.interfaces.Root
+ inputs:
+ ctx: # reserved name
+ type: string
+ default: value1
+ interface_integer:
+ type: integer
+ default: 1
+ operation:
+ implementation: operation.sh
+ inputs:
+ operation_string:
+ type: string
+ default: value2
+ toolbelt: # reserved name
+ type: integer
+ default: 2
+
+node_types:
+ LocalNode:
+ derived_from: tosca.nodes.Root
+ interfaces:
+ MyInterface:
+ type: MyInterface
+
+topology_template:
+ node_templates:
+ local_node:
+ type: LocalNode
+"""
+
+
+@pytest.fixture
+def service():
+ context, _ = consume_literal(TEMPLATE)
+ yield context.modeling.instance
+
+
+@pytest.fixture
+def broken_service_issues():
+ context, _ = consume_literal(BROKEN_TEMPLATE, no_issues=False)
+ yield context.validation.issues
+
+
+def test_local(service):
+ interface = service.nodes['local_node_1'].interfaces['MyInterface']
+ operation = interface.operations['operation']
+ assert parameters_as_values(interface.inputs) == {
+ 'interface_string': 'value1',
+ 'interface_integer': 1
+ }
+ assert parameters_as_values(operation.inputs) == {
+ 'operation_string': 'value2',
+ 'operation_integer': 2,
+ 'interface_integer': 3
+ }
+ assert parameters_as_values(operation.arguments) == {
+ 'process': {},
+ 'script_path': 'operation.sh',
+ 'interface_string': 'value1',
+ 'interface_integer': 3,
+ 'operation_string': 'value2',
+ 'operation_integer': 2
+ }
+
+
+def test_remote(service):
+ interface = service.nodes['remote_node_1'].interfaces['MyInterface']
+ operation = interface.operations['operation']
+ assert parameters_as_values(interface.inputs) == {
+ 'interface_string': 'value1',
+ 'interface_integer': 1
+ }
+ assert parameters_as_values(operation.inputs) == {
+ 'operation_string': 'value2',
+ 'operation_integer': 2,
+ 'interface_integer': 3
+ }
+ assert parameters_as_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': 3,
+ 'operation_string': 'value2',
+ 'operation_integer': 2
+ }
+
+
+def test_reserved_arguments(broken_service_issues):
+ assert len(broken_service_issues) == 1
+ message = broken_service_issues[0].message
+ assert message.startswith('using reserved arguments in operation "operation":')
+ assert '"ctx"' in message
+ assert '"toolbelt"' in message
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2195e1fb/tests/parser/service_templates.py
----------------------------------------------------------------------
diff --git a/tests/parser/service_templates.py b/tests/parser/service_templates.py
index 56f75ab..13712df 100644
--- a/tests/parser/service_templates.py
+++ b/tests/parser/service_templates.py
@@ -16,11 +16,23 @@
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, no_issues=True):
+ cachedmethod.ENABLED = cache
+ context = create_context(LiteralLocation(literal))
+ consumer, dumper = create_consumer(context, consumer_class_name)
+ consumer.consume()
+ if no_issues:
+ 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/2195e1fb/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: