diff --git a/murano/common/engine.py b/murano/common/engine.py index 77a59c75e..09601fbfe 100755 --- a/murano/common/engine.py +++ b/murano/common/engine.py @@ -32,7 +32,7 @@ from murano.common import rpc from murano.dsl import context_manager from murano.dsl import dsl_exception from murano.dsl import executor as dsl_executor -from murano.dsl import linked_context +from murano.dsl import helpers from murano.dsl import serializer from murano.engine import environment from murano.engine import package_loader @@ -91,7 +91,7 @@ class ContextManager(context_manager.ContextManager): def create_root_context(self, runtime_version): root_context = super(ContextManager, self).create_root_context( runtime_version) - return linked_context.link( + return helpers.link_contexts( root_context, yaql_functions.get_context(runtime_version)) diff --git a/murano/dsl/constants.py b/murano/dsl/constants.py index 499bb3c90..77a8dc131 100644 --- a/murano/dsl/constants.py +++ b/murano/dsl/constants.py @@ -48,3 +48,4 @@ CORE_LIBRARY_OBJECT = 'io.murano.Object' RUNTIME_VERSION_1_0 = semantic_version.Version('1.0.0') RUNTIME_VERSION_1_1 = semantic_version.Version('1.1.0') RUNTIME_VERSION_1_2 = semantic_version.Version('1.2.0') +RUNTIME_VERSION_1_3 = semantic_version.Version('1.3.0') diff --git a/murano/dsl/dsl.py b/murano/dsl/dsl.py index 51da1960e..ad3fdb95f 100644 --- a/murano/dsl/dsl.py +++ b/murano/dsl/dsl.py @@ -16,10 +16,10 @@ import inspect import os.path import six -from yaql.language import exceptions as yaql_exc from yaql.language import expressions as yaql_expressions from yaql.language import utils from yaql.language import yaqltypes +from yaql import yaql_interface from murano.dsl import constants from murano.dsl import dsl_types @@ -91,7 +91,7 @@ class InterfacesParameterType(yaqltypes.HiddenParameterType, return Interfaces(this) -class MuranoTypeName(yaqltypes.LazyParameterType, yaqltypes.PythonType): +class MuranoTypeName(yaqltypes.PythonType): def __init__(self, nullable=False, context=None): self._context = context super(MuranoTypeName, self).__init__( @@ -170,6 +170,17 @@ class MuranoObjectInterface(dsl_types.MuranoObjectInterface): def owner(self): return self.__object.owner + def find_owner(self, type, optional=False): + context = helpers.get_context().create_child_context() + yaql_engine = helpers.get_yaql_engine(context) + context['$1'] = self.object + context['$2'] = type + expr_str = '$1.find($2)' + if not optional: + expr_str += '.require()' + result = yaql_engine(expr_str).evaluate(context=context) + return None if result is None else MuranoObjectInterface(result) + @property def type(self): return self.__object.type @@ -219,59 +230,13 @@ class MuranoObjectInterface(dsl_types.MuranoObjectInterface): return '<{0}>'.format(repr(self.object)) -class YaqlInterface(object): - def __init__(self, sender=utils.NO_VALUE): - self.__sender = sender - - @property - def context(self): - return helpers.get_context() - - @property - def engine(self): - return helpers.get_yaql_engine(self.context) - - @property - def sender(self): - return self.__sender - - def on(self, sender): - return YaqlInterface(sender) - - def __getattr__(self, item): - def stub(*args, **kwargs): - context = self.context - args = tuple(helpers.evaluate(arg, context) for arg in args) - kwargs = dict((key, helpers.evaluate(value, context)) - for key, value in six.iteritems(kwargs)) - return to_mutable( - context(item, self.engine, self.sender)(*args, **kwargs), - self.engine) - return stub - - def __call__(self, __expression, *args, **kwargs): - context = helpers.get_context().create_child_context() - for i, param in enumerate(args): - context['$' + str(i + 1)] = helpers.evaluate(param, context) - for arg_name, arg_value in six.iteritems(kwargs): - context['$' + arg_name] = helpers.evaluate(arg_value, context) - parsed = self.engine(__expression) - res = parsed.evaluate(context=context) - return to_mutable(res, self.engine) - - def __getitem__(self, item): - return helpers.get_context()[item] - - def __setitem__(self, key, value): - helpers.get_context()[key] = value - - class Interfaces(object): def __init__(self, mpl_object): self.__object = mpl_object - def yaql(self, sender=utils.NO_VALUE): - return YaqlInterface(sender) + def yaql(self, receiver=utils.NO_VALUE): + return yaql_interface.YaqlInterface( + helpers.get_context(), helpers.get_yaql_engine(), receiver) def this(self): return self.methods(self.__object) @@ -319,7 +284,10 @@ class NativeInstruction(object): return self.instruction -def to_mutable(obj, yaql_engine): +def to_mutable(obj, yaql_engine=None): + if yaql_engine is None: + yaql_engine = helpers.get_yaql_engine() + def converter(value, limit_func, engine, rec): if isinstance(value, dsl_types.MuranoObject): return MuranoObjectInterface(value) @@ -330,54 +298,22 @@ def to_mutable(obj, yaql_engine): return converter(obj, limiter, yaql_engine, converter) -class OneOf(yaqltypes.SmartType): - def __init__(self, *args, **kwargs): - self.nullable = kwargs.pop('nullable', False) - super(OneOf, self).__init__(self.nullable) - - self.choices = [] - for item in args: - if isinstance(item, type): - item = yaqltypes.PythonType(item) - self.choices.append(item) - - def _check_match(self, value, context, engine, *args, **kwargs): - for type_to_check in self.choices: - check_result = type_to_check.check(value, context, engine, - *args, **kwargs) - if check_result: - return type_to_check - - def check(self, value, context, engine, *args, **kwargs): - if isinstance(value, yaql_expressions.Constant): - if value.value is None: - value = None - if value is None: - return self.nullable - - check_result = self._check_match(value, context, engine, - *args, **kwargs) - if check_result: - return True - return False - - def convert(self, value, receiver, context, function_spec, engine, - *args, **kwargs): - if isinstance(value, yaql_expressions.Constant): - if value.value is None: - value = None - if value is None: - if self.nullable: - return None - else: - suitable_type = False +class MuranoObjectParameterType(yaqltypes.PythonType): + def __init__(self, nullable=False, interface=False): + self.interface = interface + super(MuranoObjectParameterType, self).__init__( + (dsl_types.MuranoObject, MuranoObjectInterface), nullable=nullable) + def convert(self, value, *args, **kwargs): + result = super(MuranoObjectParameterType, self).convert( + value, *args, **kwargs) + if result is None: + return None + if self.interface: + if isinstance(result, MuranoObjectInterface): + return result + return MuranoObjectInterface(result) else: - suitable_type = self._check_match(value, context, engine, - *args, **kwargs) - if suitable_type: - converted_value = suitable_type.convert(value, receiver, context, - function_spec, engine, - *args, **kwargs) - return converted_value - raise yaql_exc.ArgumentValueException() + if isinstance(result, dsl_types.MuranoObject): + return result + return result.object diff --git a/murano/dsl/executor.py b/murano/dsl/executor.py index 6a37b7b6d..fffa11827 100644 --- a/murano/dsl/executor.py +++ b/murano/dsl/executor.py @@ -22,13 +22,13 @@ import eventlet.event from oslo_log import log as logging import six from yaql.language import specs +from yaql.language import utils from murano.common.i18n import _LW from murano.dsl import attribute_store from murano.dsl import constants from murano.dsl import dsl from murano.dsl import helpers -from murano.dsl import linked_context from murano.dsl import murano_method from murano.dsl import object_store from murano.dsl.principal_objects import stack_trace @@ -67,7 +67,7 @@ class MuranoDslExecutor(object): skip_stub=False): if isinstance(this, dsl.MuranoObjectInterface): this = this.object - kwargs = helpers.filter_parameters_dict(kwargs) + kwargs = utils.filter_parameters_dict(kwargs) runtime_version = method.murano_class.package.runtime_version yaql_engine = yaql_integration.choose_yaql_engine(runtime_version) if context is None or not skip_stub: @@ -177,7 +177,7 @@ class MuranoDslExecutor(object): @staticmethod def _canonize_parameters(arguments_scheme, args, kwargs): arg_names = arguments_scheme.keys() - parameter_values = helpers.filter_parameters_dict(kwargs) + parameter_values = utils.filter_parameters_dict(kwargs) for i, arg in enumerate(args): name = arg_names[i] parameter_values[name] = arg @@ -246,7 +246,7 @@ class MuranoDslExecutor(object): def create_package_context(self, package): root_context = self.create_root_context(package.runtime_version) - context = linked_context.link( + context = helpers.link_contexts( root_context, self.context_manager.create_package_context(package)) return context @@ -254,7 +254,7 @@ class MuranoDslExecutor(object): def create_class_context(self, murano_class): package_context = self.create_package_context( murano_class.package) - context = linked_context.link( + context = helpers.link_contexts( package_context, self.context_manager.create_class_context( murano_class)).create_child_context() @@ -263,7 +263,7 @@ class MuranoDslExecutor(object): def create_object_context(self, obj, caller_context=None): class_context = self.create_class_context(obj.type) - context = linked_context.link( + context = helpers.link_contexts( class_context, self.context_manager.create_object_context( obj)).create_child_context() context[constants.CTX_THIS] = obj.real_this diff --git a/murano/dsl/helpers.py b/murano/dsl/helpers.py index 0bfccfef2..9ab08c733 100644 --- a/murano/dsl/helpers.py +++ b/murano/dsl/helpers.py @@ -15,7 +15,6 @@ import collections import contextlib import functools -import re import string import sys import uuid @@ -24,7 +23,7 @@ import eventlet.greenpool import eventlet.greenthread import semantic_version import six -from six.moves import reduce +from yaql.language import contexts import yaql.language.exceptions import yaql.language.expressions from yaql.language import utils as yaqlutils @@ -35,8 +34,6 @@ from murano.dsl import constants from murano.dsl import dsl_types from murano.dsl import exceptions -KEYWORD_REGEX = re.compile(r'^(?!__)\b[^\W\d]\w*\b$') - _threads_sequencer = 0 @@ -211,10 +208,6 @@ def get_class(name, context=None): return murano_class.package.find_class(name) -def is_keyword(text): - return KEYWORD_REGEX.match(text) is not None - - def get_current_thread_id(): global _threads_sequencer @@ -334,14 +327,6 @@ def is_instance_of(obj, class_name, pov_or_version_spec=None): return False -def filter_parameters_dict(parameters): - parameters = parameters.copy() - for name in parameters.keys(): - if not is_keyword(name): - del parameters[name] - return parameters - - def memoize(func): cache = {} @@ -395,7 +380,7 @@ def normalize_version_spec(version_spec): for op, funcs in transformations[item.kind]: new_parts.append('{0}{1}'.format( op, - reduce(lambda v, f: f(v), funcs, item.spec) + six.moves.reduce(lambda v, f: f(v), funcs, item.spec) )) if not new_parts: return semantic_version.Spec('*') @@ -421,3 +406,9 @@ def breakdown_spec_to_query(normalized_spec): res.append("%s:%s" % (semver_to_api_map[item.kind], item.spec)) return res + + +def link_contexts(parent_context, context): + if not context: + return parent_context + return contexts.LinkedContext(parent_context, context) diff --git a/murano/dsl/linked_context.py b/murano/dsl/linked_context.py deleted file mode 100644 index 13cf3f44c..000000000 --- a/murano/dsl/linked_context.py +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2015 Mirantis, Inc. -# -# Licensed 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 yaql.language import contexts -from yaql.language import utils - - -class LinkedContext(contexts.ContextBase): - """Context that is as a proxy to another context but has its own parent.""" - - def __init__(self, parent_context, linked_context, convention=None): - self.linked_context = linked_context - if linked_context.parent: - super(LinkedContext, self).__init__( - LinkedContext(parent_context, linked_context.parent, - convention), convention) - else: - super(LinkedContext, self).__init__(parent_context, convention) - - def register_function(self, spec, *args, **kwargs): - return self.linked_context.register_function(spec, *args, **kwargs) - - def keys(self): - return self.linked_context.keys() - - def get_data(self, name, default=None, ask_parent=True): - result = self.linked_context.get_data( - name, default=utils.NO_VALUE, ask_parent=False) - if result is utils.NO_VALUE: - if not ask_parent or not self.parent: - return default - return self.parent.get_data(name, default=default, ask_parent=True) - return result - - def get_functions(self, name, predicate=None, use_convention=False): - return self.linked_context.get_functions( - name, predicate=predicate, use_convention=use_convention) - - def delete_function(self, spec): - return self.linked_context.delete_function(spec) - - def __contains__(self, item): - return item in self.linked_context - - def __delitem__(self, name): - del self.linked_context[name] - - def __setitem__(self, name, value): - self.linked_context[name] = value - - def create_child_context(self): - return type(self.linked_context)(self) - - -def link(parent_context, context): - if not context: - return parent_context - return LinkedContext(parent_context, context) diff --git a/murano/dsl/yaql_functions.py b/murano/dsl/yaql_functions.py index afdd09839..ce9f157e5 100644 --- a/murano/dsl/yaql_functions.py +++ b/murano/dsl/yaql_functions.py @@ -22,33 +22,32 @@ from murano.dsl import constants from murano.dsl import dsl from murano.dsl import dsl_types from murano.dsl import helpers -from murano.dsl import linked_context -@specs.parameter('value', dsl_types.MuranoObject) -def id_(value): - return value.object_id +@specs.parameter('object_', dsl.MuranoObjectParameterType()) +def id_(object_): + return object_.object_id -@specs.parameter('value', dsl_types.MuranoObject) +@specs.parameter('object_', dsl.MuranoObjectParameterType()) @specs.parameter('type__', dsl.MuranoTypeName()) @specs.parameter('version_spec', yaqltypes.String(True)) -def cast(context, value, type__, version_spec=None): +def cast(context, object_, type__, version_spec=None): return helpers.cast( - value, type__.murano_class.name, + object_, type__.murano_class.name, version_spec or helpers.get_type(context)) @specs.parameter('__type_name', dsl.MuranoTypeName()) @specs.parameter('__extra', utils.MappingType) -@specs.parameter('__owner', dsl_types.MuranoObject) +@specs.parameter('__owner', dsl.MuranoObjectParameterType(nullable=True)) @specs.parameter('__object_name', yaqltypes.String(True)) def new(__context, __type_name, __owner=None, __object_name=None, __extra=None, **parameters): object_store = helpers.get_object_store(__context) new_context = __context.create_child_context() for key, value in six.iteritems(parameters): - if helpers.is_keyword(key): + if utils.is_keyword(key): new_context[key] = value return __type_name.murano_class.new( __owner, object_store, name=__object_name)(new_context, **parameters) @@ -57,31 +56,31 @@ def new(__context, __type_name, __owner=None, __object_name=None, __extra=None, @specs.parameter('type_name', dsl.MuranoTypeName()) @specs.parameter('parameters', utils.MappingType) @specs.parameter('extra', utils.MappingType) -@specs.parameter('owner', dsl_types.MuranoObject) +@specs.parameter('owner', dsl.MuranoObjectParameterType(nullable=True)) @specs.parameter('object_name', yaqltypes.String(True)) @specs.name('new') def new_from_dict(type_name, context, parameters, owner=None, object_name=None, extra=None): return new(context, type_name, owner, object_name, extra, - **helpers.filter_parameters_dict(parameters)) + **utils.filter_parameters_dict(parameters)) -@specs.parameter('sender', dsl_types.MuranoObject) +@specs.parameter('object_', dsl.MuranoObjectParameterType()) @specs.parameter('func', yaqltypes.Lambda()) -def super_(context, sender, func=None): +def super_(context, object_, func=None): cast_type = helpers.get_type(context) if func is None: - return [sender.cast(type) for type in cast_type.parents( - sender.real_this.type)] - return six.moves.map(func, super_(context, sender)) + return [object_.cast(type) for type in cast_type.parents( + object_.real_this.type)] + return six.moves.map(func, super_(context, object_)) -@specs.parameter('value', dsl_types.MuranoObject) +@specs.parameter('object_', dsl.MuranoObjectParameterType()) @specs.parameter('func', yaqltypes.Lambda()) -def psuper(context, value, func=None): +def psuper(context, object_, func=None): if func is None: - return super_(context, value) - return helpers.parallel_select(super_(context, value), func) + return super_(context, object_) + return helpers.parallel_select(super_(context, object_), func) @specs.extension_method @@ -91,7 +90,7 @@ def require(value): return value -@specs.parameter('obj', dsl_types.MuranoObject) +@specs.parameter('obj', dsl.MuranoObjectParameterType()) @specs.parameter('murano_class_ref', dsl.MuranoTypeName()) @specs.extension_method def find(obj, murano_class_ref): @@ -108,35 +107,35 @@ def sleep_(seconds): eventlet.sleep(seconds) -@specs.parameter('object_', dsl_types.MuranoObject) +@specs.parameter('object_', dsl.MuranoObjectParameterType(nullable=True)) def type_(object_): - return object_.type.name + return None if object_ is None else object_.type.name -@specs.parameter('object_', dsl_types.MuranoObject) +@specs.parameter('object_', dsl.MuranoObjectParameterType(nullable=True)) def name(object_): - return object_.name + return None if object_ is None else object_.name -@specs.parameter('obj', dsl_types.MuranoObject) +@specs.parameter('obj', dsl.MuranoObjectParameterType()) @specs.parameter('property_name', yaqltypes.Keyword()) @specs.name('#operator_.') def obj_attribution(context, obj, property_name): return obj.get_property(property_name, context) -@specs.parameter('sender', dsl_types.MuranoObject) +@specs.parameter('receiver', dsl.MuranoObjectParameterType()) @specs.parameter('expr', yaqltypes.Lambda(method=True)) @specs.inject('operator', yaqltypes.Super(with_context=True)) @specs.name('#operator_.') -def op_dot(context, sender, expr, operator): +def op_dot(context, receiver, expr, operator): executor = helpers.get_executor(context) - type_context = executor.context_manager.create_class_context(sender.type) - obj_context = executor.context_manager.create_object_context(sender) - ctx2 = linked_context.link( - linked_context.link(context, type_context), + type_context = executor.context_manager.create_class_context(receiver.type) + obj_context = executor.context_manager.create_object_context(receiver) + ctx2 = helpers.link_contexts( + helpers.link_contexts(context, type_context), obj_context) - return operator(ctx2, sender, expr) + return operator(ctx2, receiver, expr) @specs.parameter('prefix', yaqltypes.Keyword()) @@ -150,22 +149,8 @@ def ns_resolve(context, prefix, name): prefix + ':' + name), context)) -@specs.parameter('obj1', dsl_types.MuranoObject, nullable=True) -@specs.parameter('obj2', dsl_types.MuranoObject, nullable=True) -@specs.name('*equal') -def equal(obj1, obj2): - return obj1 is obj2 - - -@specs.parameter('obj1', dsl_types.MuranoObject, nullable=True) -@specs.parameter('obj2', dsl_types.MuranoObject, nullable=True) -@specs.name('*not_equal') -def not_equal(obj1, obj2): - return obj1 is not obj2 - - -@specs.parameter('obj', dsl_types.MuranoObject, nullable=True) -@specs.parameter('type_', dsl.MuranoTypeName(), nullable=False) +@specs.parameter('obj', dsl.MuranoObjectParameterType(nullable=True)) +@specs.parameter('type_', dsl.MuranoTypeName()) @specs.name('#operator_is') def is_instance_of(obj, type_): if obj is None: @@ -188,8 +173,6 @@ def register(context, runtime_version): context.register_function(obj_attribution) context.register_function(op_dot) context.register_function(ns_resolve) - context.register_function(equal) - context.register_function(not_equal) context.register_function(is_instance_of) if runtime_version <= constants.RUNTIME_VERSION_1_1: diff --git a/murano/dsl/yaql_integration.py b/murano/dsl/yaql_integration.py index 9d86f5c3c..3ab3b6b4b 100644 --- a/murano/dsl/yaql_integration.py +++ b/murano/dsl/yaql_integration.py @@ -20,6 +20,7 @@ from yaql.language import contexts from yaql.language import conventions from yaql.language import factory from yaql.language import specs +from yaql.language import utils from yaql.language import yaqltypes from yaql import legacy @@ -264,7 +265,7 @@ def filter_parameters(__fd, *args, **kwargs): args = args[:position_args] kwargs = kwargs.copy() for name in kwargs.keys(): - if not helpers.is_keyword(name): + if not utils.is_keyword(name): del kwargs[name] if '**' not in __fd.parameters: names = {p.alias or p.name for p in six.itervalues(__fd.parameters)} diff --git a/murano/engine/mock_context_manager.py b/murano/engine/mock_context_manager.py index 56957121d..02513292c 100644 --- a/murano/engine/mock_context_manager.py +++ b/murano/engine/mock_context_manager.py @@ -22,7 +22,6 @@ from murano.dsl import constants from murano.dsl import dsl from murano.dsl import dsl_types from murano.dsl import helpers -from murano.dsl import linked_context from murano.dsl import yaql_integration @@ -59,7 +58,7 @@ class MockContextManager(engine.ContextManager): mock_context = self._create_new_ctx_for_class(murano_class.name) if mock_context: - result_context = linked_context.link( + result_context = helpers.link_contexts( original_context, mock_context).create_child_context() else: result_context = original_context @@ -71,7 +70,7 @@ class MockContextManager(engine.ContextManager): mock_context = self._create_new_ctx_for_obj(murano_obj.type.name) if mock_context: - result_context = linked_context.link( + result_context = helpers.link_contexts( original_context, mock_context).create_child_context() else: result_context = original_context @@ -99,7 +98,7 @@ def with_original(context, **kwargs): @specs.parameter('target', - dsl.OneOf(dsl.MuranoTypeName(), dsl_types.MuranoObject)) + yaqltypes.AnyOf(dsl.MuranoTypeName(), dsl_types.MuranoObject)) @specs.parameter('target_method', yaqltypes.String()) @specs.parameter('mock_object', dsl_types.MuranoObject) @specs.parameter('mock_name', yaqltypes.String()) @@ -130,7 +129,7 @@ def inject_method_with_str(context, target, target_method, @specs.parameter('target', - dsl.OneOf(dsl.MuranoTypeName(), dsl_types.MuranoObject)) + yaqltypes.AnyOf(dsl.MuranoTypeName(), dsl_types.MuranoObject)) @specs.parameter('target_method', yaqltypes.String()) @specs.parameter('expr', yaqltypes.Lambda(with_context=True)) def inject_method_with_yaql_expr(context, target, target_method, expr): diff --git a/murano/engine/system/agent.py b/murano/engine/system/agent.py index 860966c02..32ef701de 100644 --- a/murano/engine/system/agent.py +++ b/murano/engine/system/agent.py @@ -46,15 +46,11 @@ class Agent(object): 'by the server configuration') return - self._environment = self._get_environment(interfaces, host) + self._environment = host.find_owner('io.murano.Environment') self._enabled = True self._queue = str('e%s-h%s' % ( self._environment.id, host.id)).lower() - def _get_environment(self, interfaces, host): - return interfaces.yaql()( - "$.find('io.murano.Environment').require()", host) - @property def enabled(self): return self._enabled diff --git a/murano/packages/load_utils.py b/murano/packages/load_utils.py index 000833d94..21e5b8a46 100644 --- a/murano/packages/load_utils.py +++ b/murano/packages/load_utils.py @@ -35,7 +35,7 @@ def get_plugin_loader(): if PLUGIN_LOADER is None: PLUGIN_LOADER = package_types_loader.PluginLoader() - for runtime_version in ('1.0', '1.1', '1.2'): + for runtime_version in ('1.0', '1.1', '1.2', '1.3'): format_string = 'MuranoPL/' + runtime_version PLUGIN_LOADER.register_format( format_string, murano.packages.mpl_package.MuranoPlPackage) diff --git a/murano/tests/unit/dsl/foundation/runner.py b/murano/tests/unit/dsl/foundation/runner.py index bbc14d309..511fbae88 100644 --- a/murano/tests/unit/dsl/foundation/runner.py +++ b/murano/tests/unit/dsl/foundation/runner.py @@ -21,7 +21,7 @@ from murano.dsl import context_manager from murano.dsl import dsl from murano.dsl import dsl_exception from murano.dsl import executor -from murano.dsl import linked_context +from murano.dsl import helpers from murano.dsl import murano_object from murano.dsl import serializer from murano.dsl import yaql_integration @@ -37,7 +37,7 @@ class TestContextManager(context_manager.ContextManager): def create_root_context(self, runtime_version): root_context = super(TestContextManager, self).create_root_context( runtime_version) - context = linked_context.link( + context = helpers.link_contexts( root_context, yaql_functions.get_context(runtime_version)) context = context.create_child_context() for name, func in six.iteritems(self.__functions): diff --git a/murano/tests/unit/dsl/meta/OneOfSmartType.yaml b/murano/tests/unit/dsl/meta/OneOfSmartType.yaml deleted file mode 100644 index f063f59a4..000000000 --- a/murano/tests/unit/dsl/meta/OneOfSmartType.yaml +++ /dev/null @@ -1,39 +0,0 @@ -Name: OneOfSmartType - -Namespaces: - sys: io.murano.system - -Methods: - testNegative1: - Body: - - testOneOf(1, 'test') - - testNegative2: - Body: - - testOneOf('test', 1) - - testNegative3: - Body: - - testOneOf() - - testNegative4: - Body: - - testOneOf(null, null) - - testNullable: - Body: - - trace(testOneOf('io.murano.system.AgentListener', null)) - - testPositive1: - Body: - - trace(testOneOf(sys:AgentListener, 2)) - - testPositive2: - Body: - - $agentListener: new(sys:AgentListener) - - trace(testOneOf($agentListener, 2)) - - testPositive3: - Body: - - $agentListener: new(sys:AgentListener) - - trace(testOneOf($agentListener, true)) \ No newline at end of file diff --git a/murano/tests/unit/dsl/test_agent.py b/murano/tests/unit/dsl/test_agent.py index cce44412e..2faca14d0 100644 --- a/murano/tests/unit/dsl/test_agent.py +++ b/murano/tests/unit/dsl/test_agent.py @@ -74,7 +74,8 @@ class TestAgent(test_case.DslTestCase): m = mock.MagicMock() # Necessary because otherwise there'll be an Environment lookup agent_cls = 'murano.engine.system.agent.Agent' - with mock.patch(agent_cls + '._get_environment') as f: + obj_if_cls = 'murano.dsl.dsl.MuranoObjectInterface' + with mock.patch(obj_if_cls + '.find_owner') as f: f.return_value = m a = self.runner.testAgent().extension self.assertTrue(a.enabled) diff --git a/murano/tests/unit/dsl/test_dsl.py b/murano/tests/unit/dsl/test_dsl.py deleted file mode 100644 index 291584ed4..000000000 --- a/murano/tests/unit/dsl/test_dsl.py +++ /dev/null @@ -1,56 +0,0 @@ -# Licensed 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 yaql.language import exceptions as yaql_exc -from yaql.language import specs -from yaql.language import yaqltypes - -from murano.dsl import dsl -from murano.dsl import dsl_types -from murano.dsl import exceptions as dsl_exc -from murano.tests.unit.dsl.foundation import object_model as om -from murano.tests.unit.dsl.foundation import test_case - - -@specs.parameter('param1', dsl.OneOf(dsl.MuranoTypeName(), - dsl_types.MuranoObject)) -@specs.parameter('param2', dsl.OneOf(yaqltypes.NumericConstant(), - yaqltypes.BooleanConstant(), - nullable=True)) -def test_one_of(param1, param2): - return 'Passed' - - -class TestOneOf(test_case.DslTestCase): - def setUp(self): - super(TestOneOf, self).setUp() - - self.register_function(test_one_of, 'testOneOf') - self.runner = self.new_runner(om.Object('OneOfSmartType')) - - def test_negative(self): - self.assertRaises(yaql_exc.NoMatchingFunctionException, - self.runner.testNegative1) - self.assertRaises(dsl_exc.NoClassFound, self.runner.testNegative2) - self.assertRaises(yaql_exc.NoMatchingFunctionException, - self.runner.testNegative3) - - def test_nullable(self): - self.runner.testNullable() - self.assertEqual(['Passed'], self.traces) - - def test_positive(self): - self.runner.testPositive1() - self.runner.testPositive2() - self.runner.testPositive3() - - self.assertEqual(['Passed', 'Passed', 'Passed'], self.traces) diff --git a/murano/tests/unit/engine/system/test_agent.py b/murano/tests/unit/engine/system/test_agent.py index 5f0b86249..93bfb8e24 100644 --- a/murano/tests/unit/engine/system/test_agent.py +++ b/murano/tests/unit/engine/system/test_agent.py @@ -40,9 +40,8 @@ class TestExecutionPlan(base.MuranoTestCase): object_interface = mock.Mock(spec=murano_object.MuranoObject) object_interface.id = '1234' + object_interface.find_owner = lambda *args, **kwargs: object_interface - agent.Agent._get_environment = \ - lambda this, iface, host: object_interface self.agent = agent.Agent(None, object_interface) self.resources = mock.Mock(spec=resource_manager.ResourceManager) self.resources.string.return_value = 'text' diff --git a/releasenotes/notes/yaql11-822b503f13992890.yaml b/releasenotes/notes/yaql11-822b503f13992890.yaml new file mode 100644 index 000000000..43300707c --- /dev/null +++ b/releasenotes/notes/yaql11-822b503f13992890.yaml @@ -0,0 +1,8 @@ +--- +features: + - Murano was migrated to yaql 1.1 + - New format MuranoPL/1.3 can be specified in manifest files. + MuranoPL/1.3 is identical to MuranoPL/1.2 but except for the fact + that MuranoPL/1.3 packages cannot be imported to earlier Murano versions. + Thus applications that use new features of yaql 1.1 should use this format + version.