summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Kumar <chkumar@redhat.com>2019-02-15 11:01:54 +0000
committerChandan Kumar <chkumar@redhat.com>2019-02-15 11:01:54 +0000
commit1d16d2ffba04d1470f260a419dedef4b9a2c4b7b (patch)
tree21d25bf4420d2efdab8a497a1ff11ad5cde2e613
parenta39db2d3dc21afbe8b9e1d6f8dd870da272b9671 (diff)
Revert "Fix how Mistral prepares data for evaluating a YAQL expression"
Notes
Notes (review): Code-Review+2: Renat Akhmerov <renat.akhmerov@gmail.com> Code-Review+2: Dougal Matthews <dougal@redhat.com> Workflow+1: Dougal Matthews <dougal@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 19 Feb 2019 12:35:30 +0000 Reviewed-on: https://review.openstack.org/637170 Project: openstack/mistral Branch: refs/heads/master
-rw-r--r--mistral/tests/unit/engine/test_yaql_functions.py40
-rw-r--r--mistral/utils/expression_utils.py24
2 files changed, 1 insertions, 63 deletions
diff --git a/mistral/tests/unit/engine/test_yaql_functions.py b/mistral/tests/unit/engine/test_yaql_functions.py
index 76e1d41..c3a6c68 100644
--- a/mistral/tests/unit/engine/test_yaql_functions.py
+++ b/mistral/tests/unit/engine/test_yaql_functions.py
@@ -13,7 +13,6 @@
13# limitations under the License. 13# limitations under the License.
14 14
15from oslo_config import cfg 15from oslo_config import cfg
16import six
17 16
18from mistral.db.v2 import api as db_api 17from mistral.db.v2 import api as db_api
19from mistral.services import workflows as wf_service 18from mistral.services import workflows as wf_service
@@ -432,42 +431,3 @@ class YAQLFunctionsEngineTest(engine_test_base.EngineTestCase):
432 self.assertIsNotNone(json_str) 431 self.assertIsNotNone(json_str)
433 self.assertIn('"key1": "foo"', json_str) 432 self.assertIn('"key1": "foo"', json_str)
434 self.assertIn('"key2": "bar"', json_str) 433 self.assertIn('"key2": "bar"', json_str)
435
436 def test_built_in_str_function(self):
437 wf_text = """---
438 version: '2.0'
439
440 wf:
441 input:
442 - my_list
443
444 tasks:
445 task1:
446 publish:
447 val: <% str($.my_list) %>
448 """
449
450 wf_service.create_workflows(wf_text)
451
452 wf_ex = self.engine.start_workflow(
453 'wf',
454 wf_input={
455 'my_list': [
456 {
457 'k1': 'v1',
458 'k2': 'v2'
459 }
460 ]
461 }
462 )
463
464 self.await_workflow_success(wf_ex.id)
465
466 with db_api.transaction(read_only=True):
467 wf_ex = db_api.get_workflow_execution(wf_ex.id)
468
469 val = wf_ex.task_executions[0].published['val']
470
471 self.assertIsInstance(val, six.string_types)
472 self.assertIn('[', val)
473 self.assertIn(']', val)
diff --git a/mistral/utils/expression_utils.py b/mistral/utils/expression_utils.py
index 2e4f403..1155b10 100644
--- a/mistral/utils/expression_utils.py
+++ b/mistral/utils/expression_utils.py
@@ -14,7 +14,6 @@
14# limitations under the License. 14# limitations under the License.
15 15
16from functools import partial 16from functools import partial
17import six
18import warnings 17import warnings
19 18
20from oslo_log import log as logging 19from oslo_log import log as logging
@@ -40,27 +39,6 @@ LOG = logging.getLogger(__name__)
40ROOT_YAQL_CONTEXT = None 39ROOT_YAQL_CONTEXT = None
41 40
42 41
43def _convert_yaql_input_data(obj, rec=None):
44 # NOTE(rakhmerov): We have to define our own wrapper function
45 # around the function 'convert_input_data' from 'yaql_utils'
46 # because the latter always converts all sequences (except strings)
47 # into tuples, and it in turn breaks a number of things. For example,
48 # if we use the built-in 'str' YAQL function with an argument of the
49 # type 'list' then the result will be '(item1, item2 ..., itemN,)'
50 # instead of '[item1, item2 ..., itemN]'.
51 # So we override this behavior for sequences that are not strings and
52 # tuples.
53 if rec is None:
54 rec = _convert_yaql_input_data
55
56 if (isinstance(obj, yaql_utils.SequenceType) and
57 not isinstance(obj, six.string_types) and
58 not isinstance(obj, tuple)):
59 return list(rec(t, rec) for t in obj)
60 else:
61 return yaql_utils.convert_input_data(obj, rec)
62
63
64def get_yaql_context(data_context): 42def get_yaql_context(data_context):
65 global ROOT_YAQL_CONTEXT 43 global ROOT_YAQL_CONTEXT
66 44
@@ -70,7 +48,7 @@ def get_yaql_context(data_context):
70 _register_yaql_functions(ROOT_YAQL_CONTEXT) 48 _register_yaql_functions(ROOT_YAQL_CONTEXT)
71 49
72 new_ctx = ROOT_YAQL_CONTEXT.create_child_context() 50 new_ctx = ROOT_YAQL_CONTEXT.create_child_context()
73 new_ctx['$'] = _convert_yaql_input_data(data_context) 51 new_ctx['$'] = yaql_utils.convert_input_data(data_context)
74 52
75 if isinstance(data_context, dict): 53 if isinstance(data_context, dict):
76 new_ctx['__env'] = data_context.get('__env') 54 new_ctx['__env'] = data_context.get('__env')