diff --git a/mistral/tests/unit/engine/test_yaql_functions.py b/mistral/tests/unit/engine/test_yaql_functions.py index f370c32d0..5810ffa2c 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 8e42c8464..0b5a6b564 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 74f682c50..085655ace 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_