From 9a4bafa5d4ab71a6e828846403b430d2e3fb4302 Mon Sep 17 00:00:00 2001 From: Margarita Shakhova Date: Mon, 3 Jul 2017 13:18:38 -0700 Subject: [PATCH] Add dsl_iterators_limit config option To remove hardcoded constant called 'ITERATORS_LIMIT', that can be exceeded (2000) having big amount of objects. It is easy to achieve in big cloud with user that is allowed to view lots of resources. Change-Id: I818561ca044bad505402b69d22a41ea892e15fcc Closes-Bug: #1690179 --- murano/common/config.py | 4 ++++ murano/dsl/constants.py | 1 - murano/dsl/dsl.py | 5 ++++- murano/dsl/helpers.py | 4 +++- murano/dsl/yaql_integration.py | 6 ++++-- releasenotes/notes/bug-1690179-375599ff3e8f2cd9.yaml | 8 ++++++++ 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/bug-1690179-375599ff3e8f2cd9.yaml diff --git a/murano/common/config.py b/murano/common/config.py index 144a5fa0d..a359105cc 100644 --- a/murano/common/config.py +++ b/murano/common/config.py @@ -176,6 +176,10 @@ murano_opts = [ cfg.IntOpt('api_workers', help=_('Number of API workers')), + cfg.IntOpt('dsl_iterators_limit', default=2000, + help=_('Maximum number of elements that can be iterated per ' + 'object type.')), + ] networking_opts = [ diff --git a/murano/dsl/constants.py b/murano/dsl/constants.py index d288275a7..0b7c88f99 100644 --- a/murano/dsl/constants.py +++ b/murano/dsl/constants.py @@ -16,7 +16,6 @@ import semantic_version EXPRESSION_MEMORY_QUOTA = 512 * 1024 -ITERATORS_LIMIT = 2000 CTX_ACTIONS_ONLY = '?actionsOnly' CTX_ALLOW_PROPERTY_WRITES = '$?allowPropertyWrites' diff --git a/murano/dsl/dsl.py b/murano/dsl/dsl.py index fdf62cbda..4ff5ba2b4 100644 --- a/murano/dsl/dsl.py +++ b/murano/dsl/dsl.py @@ -16,6 +16,7 @@ import inspect import os.path import eventlet +from oslo_config import cfg import six from yaql.language import expressions as yaql_expressions from yaql.language import specs @@ -28,6 +29,7 @@ from murano.dsl import dsl_types from murano.dsl import helpers +CONF = cfg.CONF NO_VALUE = utils.create_marker('NO_VALUE') @@ -349,7 +351,8 @@ def to_mutable(obj, yaql_engine=None): else: return utils.convert_output_data(value, limit_func, engine, rec) - limiter = lambda it: utils.limit_iterable(it, constants.ITERATORS_LIMIT) + limiter = lambda it: utils.limit_iterable( + it, CONF.murano.dsl_iterators_limit) return converter(obj, limiter, yaql_engine, converter) diff --git a/murano/dsl/helpers.py b/murano/dsl/helpers.py index be0deab61..6d0911487 100644 --- a/murano/dsl/helpers.py +++ b/murano/dsl/helpers.py @@ -26,6 +26,7 @@ import weakref import eventlet.greenpool import eventlet.greenthread +from oslo_config import cfg import semantic_version import six from yaql.language import contexts @@ -41,6 +42,7 @@ from murano.dsl import exceptions _threads_sequencer = 0 # type string: ns.something.MyApp[/1.2.3-alpha][@my.package.fqn] TYPE_RE = re.compile(r'([a-zA-Z0-9_.]+)(?:/([^@]+))?(?:@([a-zA-Z0-9_.]+))?$') +CONF = cfg.CONF def evaluate(value, context, freeze=True): @@ -64,7 +66,7 @@ def evaluate(value, context, freeze=True): return list_type( evaluate(t, context, freeze) for t in yaqlutils.limit_iterable( - value, constants.ITERATORS_LIMIT)) + value, CONF.murano.dsl_iterators_limit)) elif isinstance(value, dsl_types.MuranoObjectInterface): return value.object else: diff --git a/murano/dsl/yaql_integration.py b/murano/dsl/yaql_integration.py index f328c76d2..fa27d297a 100644 --- a/murano/dsl/yaql_integration.py +++ b/murano/dsl/yaql_integration.py @@ -14,6 +14,7 @@ import weakref +from oslo_config import cfg import yaql from yaql.language import contexts from yaql.language import conventions @@ -30,8 +31,9 @@ from murano.dsl import helpers from murano.dsl import yaql_functions +CONF = cfg.CONF ENGINE_10_OPTIONS = { - 'yaql.limitIterators': constants.ITERATORS_LIMIT, + 'yaql.limitIterators': CONF.murano.dsl_iterators_limit, 'yaql.memoryQuota': constants.EXPRESSION_MEMORY_QUOTA, 'yaql.convertSetsToLists': True, 'yaql.convertTuplesToLists': True, @@ -39,7 +41,7 @@ ENGINE_10_OPTIONS = { } ENGINE_12_OPTIONS = { - 'yaql.limitIterators': constants.ITERATORS_LIMIT, + 'yaql.limitIterators': CONF.murano.dsl_iterators_limit, 'yaql.memoryQuota': constants.EXPRESSION_MEMORY_QUOTA, 'yaql.convertSetsToLists': True, 'yaql.convertTuplesToLists': True diff --git a/releasenotes/notes/bug-1690179-375599ff3e8f2cd9.yaml b/releasenotes/notes/bug-1690179-375599ff3e8f2cd9.yaml new file mode 100644 index 000000000..114bd632e --- /dev/null +++ b/releasenotes/notes/bug-1690179-375599ff3e8f2cd9.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Remove hardcoded constant called 'ITERATORS_LIMIT', that can be + exceeded (2000) having big amount of objects. + Introduce dsl_iterators_limit configuration option instead of + constant. +