Merge "Make 'task' function work w/o a task name"
This commit is contained in:
commit
15bb38fb24
@ -174,6 +174,61 @@ 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_task_function_no_arguments(self):
|
||||||
|
wf_text = """---
|
||||||
|
version: '2.0'
|
||||||
|
|
||||||
|
wf:
|
||||||
|
tasks:
|
||||||
|
task1:
|
||||||
|
action: std.echo output=1
|
||||||
|
publish:
|
||||||
|
task1_id: <% task().id %>
|
||||||
|
task1_result: <% task().result %>
|
||||||
|
task1_state: <% task().state %>
|
||||||
|
on-success: task2
|
||||||
|
|
||||||
|
task2:
|
||||||
|
action: std.echo output=2
|
||||||
|
publish:
|
||||||
|
task2_id: <% task().id %>
|
||||||
|
task2_result: <% task().result %>
|
||||||
|
task2_state: <% task().state %>
|
||||||
|
"""
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
task1_ex = self._assert_single_item(
|
||||||
|
wf_ex.task_executions, name='task1'
|
||||||
|
)
|
||||||
|
task2_ex = self._assert_single_item(
|
||||||
|
wf_ex.task_executions, name='task2'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertDictEqual(
|
||||||
|
{
|
||||||
|
'task1_id': task1_ex.id,
|
||||||
|
'task1_result': 1,
|
||||||
|
'task1_state': states.SUCCESS
|
||||||
|
},
|
||||||
|
task1_ex.published
|
||||||
|
)
|
||||||
|
self.assertDictEqual(
|
||||||
|
{
|
||||||
|
'task2_id': task2_ex.id,
|
||||||
|
'task2_result': 2,
|
||||||
|
'task2_state': states.SUCCESS
|
||||||
|
},
|
||||||
|
task2_ex.published
|
||||||
|
)
|
||||||
|
|
||||||
def test_uuid_function(self):
|
def test_uuid_function(self):
|
||||||
wf_text = """---
|
wf_text = """---
|
||||||
version: '2.0'
|
version: '2.0'
|
||||||
|
@ -119,12 +119,18 @@ def json_pp_(context, data=None):
|
|||||||
).replace("\\n", "\n").replace(" \n", "\n")
|
).replace("\\n", "\n").replace(" \n", "\n")
|
||||||
|
|
||||||
|
|
||||||
def task_(context, task_name):
|
def task_(context, task_name=None):
|
||||||
# This section may not exist in a context if it's calculated not in
|
# This section may not exist in a context if it's calculated not in
|
||||||
# task scope.
|
# task scope.
|
||||||
cur_task = context['__task_execution']
|
cur_task = context['__task_execution']
|
||||||
|
|
||||||
if cur_task and cur_task['name'] == task_name:
|
# 1. If task_name is empty it's 'task()' use case, we need to get the
|
||||||
|
# current task.
|
||||||
|
# 2. if task_name is not empty but it's equal to the current task name
|
||||||
|
# we need to take exactly the current instance of this task. Otherwise
|
||||||
|
# there may be ambiguity if there are many tasks with this name.
|
||||||
|
# 3. In other case we just find a task in DB by the given name.
|
||||||
|
if cur_task and (not task_name or cur_task['name'] == task_name):
|
||||||
task_ex = db_api.get_task_execution(cur_task['id'])
|
task_ex = db_api.get_task_execution(cur_task['id'])
|
||||||
else:
|
else:
|
||||||
task_execs = db_api.get_task_executions(
|
task_execs = db_api.get_task_executions(
|
||||||
|
Loading…
Reference in New Issue
Block a user