Rolling back YAQL to v0.2.4

* YAQL 1.0 will come back in Liberty

Change-Id: I4272b35e2b11b92e481bff6f8ecaa7c8aa8d936e
This commit is contained in:
Nikolay Mahotkin 2015-04-16 15:06:56 +03:00
parent a6af4d38c6
commit 7b4c52190d
7 changed files with 43 additions and 21 deletions

View File

@ -19,8 +19,8 @@ import inspect
import re
import six
from yaql.language import exceptions as yaql_exc
from yaql.language import factory
import yaql
from yaql import exceptions as yaql_exc
from mistral import exceptions as exc
from mistral.openstack.common import log as logging
@ -28,7 +28,6 @@ from mistral import yaql_utils
LOG = logging.getLogger(__name__)
YAQL_ENGINE = factory.YaqlFactory().create()
class Evaluator(object):
@ -76,7 +75,7 @@ class YAQLEvaluator(Evaluator):
LOG.debug("Validating YAQL expression [expression='%s']", expression)
try:
YAQL_ENGINE(expression)
yaql.parse(expression)
except (yaql_exc.YaqlException, KeyError, ValueError, TypeError) as e:
raise exc.YaqlEvaluationException(e.message)
@ -86,7 +85,7 @@ class YAQLEvaluator(Evaluator):
% (expression, data_context))
try:
result = YAQL_ENGINE(expression).evaluate(
result = yaql.parse(expression).evaluate(
data=data_context,
context=yaql_utils.create_yaql_context()
)

View File

@ -257,7 +257,7 @@ class TestWorkbooksController(base.FunctionalTest):
self.assertEqual(resp.status_int, 200)
self.assertFalse(resp.json['valid'])
self.assertIn("unexpected '*' at position 1 of expression",
self.assertIn("unexpected '*' at position 1",
resp.json['error'])
def test_validate_empty(self):

View File

@ -282,7 +282,7 @@ class TestWorkflowsController(base.FunctionalTest):
self.assertEqual(resp.status_int, 200)
self.assertFalse(resp.json['valid'])
self.assertIn("unexpected '*' at position 1 of expression",
self.assertIn("unexpected '*' at position 1",
resp.json['error'])
def test_validate_empty(self):

View File

@ -312,8 +312,8 @@ class JoinEngineTest(base.EngineTestCase):
action: std.echo
input:
output: |
<% result1 in $.keys() %>,<% result2 in $.keys() %>,
<%result3 in $.keys()%>,<%result4 in $.keys()%>
<% result1 in $ %>,<% result2 in $ %>,
<% result3 in $ %>,<% result4 in $ %>
publish:
result5: <% $.task5 %>
"""
@ -386,8 +386,8 @@ class JoinEngineTest(base.EngineTestCase):
action: std.echo
input:
output: |
<% result1 in $.keys() %>,<% result2 in $.keys() %>,
<% result3 in $.keys() %>
<% result1 in $ %>,<% result2 in $ %>,
<% result3 in $ %>
publish:
result4: <% $.task4 %>
"""

View File

@ -59,12 +59,7 @@ class YaqlEvaluatorTest(base.BaseTest):
res = self._evaluator.evaluate("$.status = 'Invalid value'", DATA)
self.assertFalse(res)
self.assertRaises(
exc.YaqlEvaluationException,
self._evaluator.evaluate,
'$.wrong_key',
DATA
)
self.assertIsNone(self._evaluator.evaluate('$.wrong_key', DATA))
expression_str = 'invalid_expression_string'
res = self._evaluator.evaluate(expression_str, DATA)

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
#
# Copyright 2014 - Mirantis, Inc.
# Copyright 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.
@ -14,10 +12,40 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
import six
import types
import yaql
from yaql import context
def create_yaql_context():
ctx = yaql.create_context()
_register_functions(ctx)
return ctx
def _register_functions(yaql_ctx):
yaql_ctx.register_function(_string_and_iterable_length, 'len')
yaql_ctx.register_function(_generator_length, 'len')
yaql_ctx.register_function(to_str, 'str')
# Additional convenience YAQL functions.
@context.EvalArg('a', arg_type=(six.string_types, collections.Iterable))
def _string_and_iterable_length(a):
return len(a)
@context.EvalArg('a', arg_type=types.GeneratorType)
def _generator_length(a):
return sum(1 for i in a)
def to_str(value):
return str(value())

View File

@ -27,7 +27,7 @@ networkx>=1.8
six>=1.7.0
SQLAlchemy>=0.9.7,<=0.9.99
stevedore>=1.0.0 # Apache-2.0
yaql>0.3 # This is not in global requirements
yaql==0.2.4 # This is not in global requirements
jsonschema>=2.0.0,<3.0.0
mock>=1.0
keystonemiddleware>=1.0.0