From 471ce2d043c12ebfa5a8e69dfa642b8f43fb25b4 Mon Sep 17 00:00:00 2001 From: Renat Akhmerov Date: Wed, 31 Aug 2016 15:19:39 +0700 Subject: [PATCH] Add 'uuid' YAQL function Change-Id: I34098a72a098c460f6352344b7797edde1e604a6 --- .../tests/unit/engine/test_yaql_functions.py | 31 +++++++++++++++++++ mistral/utils/yaql_utils.py | 5 +++ setup.cfg | 1 + 3 files changed, 37 insertions(+) diff --git a/mistral/tests/unit/engine/test_yaql_functions.py b/mistral/tests/unit/engine/test_yaql_functions.py index f370c32d..5810ffa2 100644 --- a/mistral/tests/unit/engine/test_yaql_functions.py +++ b/mistral/tests/unit/engine/test_yaql_functions.py @@ -132,3 +132,34 @@ class YAQLFunctionsEngineTest(engine_test_base.EngineTestCase): self.assertEqual(states.ERROR, wf_ex.state) self.assertIn('non_existing_task', wf_ex.state_info) + + def test_uuid_function(self): + wf_text = """--- + version: '2.0' + + wf: + tasks: + task1: + action: std.echo output=<% uuid() %> + publish: + result: <% task(task1).result %> + """ + + wf_service.create_workflows(wf_text) + + wf_ex = self.engine.start_workflow('wf', {}) + + self.await_workflow_success(wf_ex.id) + + with db_api.transaction(): + wf_ex = db_api.get_workflow_execution(wf_ex.id) + + task_execs = wf_ex.task_executions + + task_ex = task_execs[0] + + result = task_ex.published['result'] + + self.assertIsNotNone(result) + self.assertEqual(36, len(result)) + self.assertEqual(4, result.count('-')) diff --git a/mistral/utils/yaql_utils.py b/mistral/utils/yaql_utils.py index 8e42c846..0b5a6b56 100644 --- a/mistral/utils/yaql_utils.py +++ b/mistral/utils/yaql_utils.py @@ -16,6 +16,7 @@ import yaql from mistral.db.v2 import api as db_api +from mistral import utils from mistral.workflow import utils as wf_utils from oslo_serialization import jsonutils from stevedore import extension @@ -107,3 +108,7 @@ def task_(context, task_name): 'result': data_flow.get_task_execution_result(task_ex), 'published': task_ex.published } + + +def uuid_(context): + return utils.generate_unicode_uuid() diff --git a/setup.cfg b/setup.cfg index 74f682c5..085655ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,3 +74,4 @@ mistral.yaql_functions = task = mistral.utils.yaql_utils:task_ execution = mistral.utils.yaql_utils:execution_ env = mistral.utils.yaql_utils:env_ + uuid = mistral.utils.yaql_utils:uuid_