Add 'uuid' YAQL function

Change-Id: I34098a72a098c460f6352344b7797edde1e604a6
This commit is contained in:
Renat Akhmerov 2016-08-31 15:19:39 +07:00
parent e29f95ee3f
commit 471ce2d043
3 changed files with 37 additions and 0 deletions

View File

@ -132,3 +132,34 @@ class YAQLFunctionsEngineTest(engine_test_base.EngineTestCase):
self.assertEqual(states.ERROR, wf_ex.state) self.assertEqual(states.ERROR, wf_ex.state)
self.assertIn('non_existing_task', wf_ex.state_info) 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('-'))

View File

@ -16,6 +16,7 @@
import yaql import yaql
from mistral.db.v2 import api as db_api from mistral.db.v2 import api as db_api
from mistral import utils
from mistral.workflow import utils as wf_utils from mistral.workflow import utils as wf_utils
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from stevedore import extension from stevedore import extension
@ -107,3 +108,7 @@ def task_(context, task_name):
'result': data_flow.get_task_execution_result(task_ex), 'result': data_flow.get_task_execution_result(task_ex),
'published': task_ex.published 'published': task_ex.published
} }
def uuid_(context):
return utils.generate_unicode_uuid()

View File

@ -74,3 +74,4 @@ mistral.yaql_functions =
task = mistral.utils.yaql_utils:task_ task = mistral.utils.yaql_utils:task_
execution = mistral.utils.yaql_utils:execution_ execution = mistral.utils.yaql_utils:execution_
env = mistral.utils.yaql_utils:env_ env = mistral.utils.yaql_utils:env_
uuid = mistral.utils.yaql_utils:uuid_