Merge "Implementing "no-op" task"
This commit is contained in:
commit
b885b87760
@ -158,16 +158,16 @@ class RunTask(EngineCommand):
|
||||
if self.task_db.state != states.RUNNING:
|
||||
return
|
||||
|
||||
task_name = self.task_db.name
|
||||
|
||||
if self.task_spec.get_action_name():
|
||||
WF_TRACE.info("Task '%s' is RUNNING [action_name = %s]"
|
||||
% (self.task_db.name,
|
||||
self.task_spec.get_action_name()))
|
||||
% (task_name, self.task_spec.get_action_name()))
|
||||
|
||||
self._run_action()
|
||||
elif self.task_spec.get_workflow_name():
|
||||
WF_TRACE.info("Task '%s' is RUNNING [workflow_name = %s]"
|
||||
% (self.task_db.name,
|
||||
self.task_spec.get_workflow_name()))
|
||||
% (task_name, self.task_spec.get_workflow_name()))
|
||||
|
||||
self._run_workflow()
|
||||
|
||||
|
131
mistral/tests/unit/engine1/test_noop_task.py
Normal file
131
mistral/tests/unit/engine1/test_noop_task.py
Normal file
@ -0,0 +1,131 @@
|
||||
# Copyright 2014 - Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from mistral.db.v2 import api as db_api
|
||||
from mistral.engine import states
|
||||
from mistral.openstack.common import log as logging
|
||||
from mistral.services import workflows as wf_service
|
||||
from mistral.tests.unit.engine1 import base
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
# Use the set_default method to set value otherwise in certain test cases
|
||||
# the change in value is not permanent.
|
||||
cfg.CONF.set_default('auth_enable', False, group='pecan')
|
||||
|
||||
WF = """
|
||||
---
|
||||
version: 2.0
|
||||
|
||||
wf:
|
||||
type: direct
|
||||
|
||||
input:
|
||||
- num1
|
||||
- num2
|
||||
|
||||
output:
|
||||
result: "{$.result4},{$.result5}"
|
||||
|
||||
tasks:
|
||||
task1:
|
||||
action: std.echo output={$.num1}
|
||||
publish:
|
||||
result1: $
|
||||
on-complete:
|
||||
- task3
|
||||
|
||||
task2:
|
||||
action: std.echo output={$.num2}
|
||||
publish:
|
||||
result2: $
|
||||
on-complete:
|
||||
- task3
|
||||
|
||||
task3:
|
||||
description: |
|
||||
This task doesn't "action" or "workflow" property. It works as "no-op"
|
||||
task and serves just a decision point in the workflow.
|
||||
join: all
|
||||
on-complete:
|
||||
- task4: $.num1 + $.num2 = 2
|
||||
- task5: $.num1 + $.num2 = 3
|
||||
|
||||
task4:
|
||||
action: std.echo output=4
|
||||
publish:
|
||||
result4: $
|
||||
|
||||
task5:
|
||||
action: std.echo output=5
|
||||
publish:
|
||||
result5: $
|
||||
"""
|
||||
|
||||
|
||||
class NoopTaskEngineTest(base.EngineTestCase):
|
||||
def test_noop_task1(self):
|
||||
wf_service.create_workflows(WF)
|
||||
|
||||
# Start workflow.
|
||||
exec_db = self.engine.start_workflow('wf', {'num1': 1, 'num2': 1})
|
||||
|
||||
self._await(lambda: self.is_execution_success(exec_db.id))
|
||||
|
||||
# Note: We need to reread execution to access related tasks.
|
||||
exec_db = db_api.get_execution(exec_db.id)
|
||||
|
||||
tasks = exec_db.tasks
|
||||
|
||||
self.assertEqual(4, len(tasks))
|
||||
|
||||
task1 = self._assert_single_item(tasks, name='task1')
|
||||
task2 = self._assert_single_item(tasks, name='task2')
|
||||
task3 = self._assert_single_item(tasks, name='task3')
|
||||
task4 = self._assert_single_item(tasks, name='task4')
|
||||
|
||||
self.assertEqual(states.SUCCESS, task1.state)
|
||||
self.assertEqual(states.SUCCESS, task2.state)
|
||||
self.assertEqual(states.SUCCESS, task3.state)
|
||||
self.assertEqual(states.SUCCESS, task4.state)
|
||||
|
||||
self.assertDictEqual({'result': '4,None'}, exec_db.output)
|
||||
|
||||
def test_noop_task2(self):
|
||||
wf_service.create_workflows(WF)
|
||||
|
||||
# Start workflow.
|
||||
exec_db = self.engine.start_workflow('wf', {'num1': 1, 'num2': 2})
|
||||
|
||||
self._await(lambda: self.is_execution_success(exec_db.id))
|
||||
|
||||
# Note: We need to reread execution to access related tasks.
|
||||
exec_db = db_api.get_execution(exec_db.id)
|
||||
|
||||
tasks = exec_db.tasks
|
||||
|
||||
self.assertEqual(4, len(tasks))
|
||||
|
||||
task1 = self._assert_single_item(tasks, name='task1')
|
||||
task2 = self._assert_single_item(tasks, name='task2')
|
||||
task3 = self._assert_single_item(tasks, name='task3')
|
||||
task5 = self._assert_single_item(tasks, name='task5')
|
||||
|
||||
self.assertEqual(states.SUCCESS, task1.state)
|
||||
self.assertEqual(states.SUCCESS, task2.state)
|
||||
self.assertEqual(states.SUCCESS, task3.state)
|
||||
self.assertEqual(states.SUCCESS, task5.state)
|
||||
|
||||
self.assertDictEqual({'result': 'None,5'}, exec_db.output)
|
@ -131,6 +131,9 @@ workflows:
|
||||
|
||||
task12:
|
||||
action: std.http url="http://site.com?q={$.query}" params=""
|
||||
|
||||
task13:
|
||||
description: No-op task
|
||||
"""
|
||||
|
||||
|
||||
@ -251,7 +254,7 @@ class DSLv2ModelTest(base.BaseTest):
|
||||
self.assertEqual('wf2', wf2_spec.get_name())
|
||||
self.assertListEqual(['test', 'v2'], wf2_spec.get_tags())
|
||||
self.assertEqual('direct', wf2_spec.get_type())
|
||||
self.assertEqual(10, len(wf2_spec.get_tasks()))
|
||||
self.assertEqual(11, len(wf2_spec.get_tasks()))
|
||||
|
||||
task_defaults_spec = wf2_spec.get_task_defaults()
|
||||
|
||||
@ -343,13 +346,18 @@ class DSLv2ModelTest(base.BaseTest):
|
||||
task12_spec.get_input()
|
||||
)
|
||||
|
||||
task13_spec = wf2_spec.get_tasks().get('task13')
|
||||
|
||||
self.assertEqual('std.noop', task13_spec.get_action_name())
|
||||
self.assertEqual('No-op task', task13_spec.get_description())
|
||||
|
||||
def test_adhoc_action_with_base_in_one_string(self):
|
||||
wb_spec = spec_parser.get_workbook_spec_from_yaml(VALID_WB)
|
||||
|
||||
act_specs = wb_spec.get_actions()
|
||||
action_spec = act_specs.get("action2")
|
||||
|
||||
self.assertEqual("std.echo", action_spec.get_base())
|
||||
self.assertEqual('std.echo', action_spec.get_base())
|
||||
self.assertEqual({'output': 'Echo output'},
|
||||
action_spec.get_base_input())
|
||||
|
||||
|
@ -89,11 +89,6 @@ class TaskSpec(base.BaseSpec):
|
||||
" specified both: %s" % self._data)
|
||||
raise exc.InvalidModelException(msg)
|
||||
|
||||
if not action and not workflow:
|
||||
msg = ("One of task properties 'action' or 'workflow' must be"
|
||||
" specified: %s" % self._data)
|
||||
raise exc.InvalidModelException(msg)
|
||||
|
||||
for_each = self._data.get('for-each')
|
||||
|
||||
if for_each:
|
||||
@ -111,6 +106,8 @@ class TaskSpec(base.BaseSpec):
|
||||
elif self._workflow:
|
||||
self._workflow, params = self._parse_cmd_and_input(
|
||||
self._workflow)
|
||||
else:
|
||||
self._action = 'std.noop'
|
||||
|
||||
utils.merge_dicts(self._input, params)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user