def create_workbook(definition_path): return db_api.workbook_create({ 'name': 'my_workbook', 'definition': base.get_resource(definition_path) })
def _parse_dsl_spec(self, dsl_file=None, add_tasks=False, changes=None, expect_error=False): if dsl_file and add_tasks: raise Exception('The add_tasks option is not a valid ' 'combination with the dsl_file option.') if dsl_file: dsl_yaml = base.get_resource(self._resource_path + '/' + dsl_file) if changes: dsl_dict = yaml.safe_load(dsl_yaml) utils.merge_dicts(dsl_dict, changes) dsl_yaml = yaml.safe_dump(dsl_dict, default_flow_style=False) else: dsl_dict = copy.deepcopy(self._dsl_blank) if add_tasks: dsl_dict['test']['tasks'] = copy.deepcopy(self._dsl_tasks) if changes: utils.merge_dicts(dsl_dict, changes) dsl_yaml = yaml.safe_dump(dsl_dict, default_flow_style=False) if not expect_error: return self._spec_parser(dsl_yaml) else: return self.assertRaises(exc.DSLParsingException, self._spec_parser, dsl_yaml)
def test_resolve_adhoc_action_name(self): workbook = parser.get_workbook( base.get_resource('control_flow/one_sync_task.yaml')) action_name = 'MyActions.concat' action = a_f.resolve_adhoc_action_name(workbook, action_name) self.assertEqual('std.echo', action)
def test_convert_adhoc_action_result(self): workbook = parser.get_workbook( base.get_resource('control_flow/one_sync_task.yaml')) action_name = 'MyActions.concat' result = {'output': 'Stormin Stanley'} parameters = a_f.convert_adhoc_action_result(workbook, action_name, result) self.assertEqual({'string': 'Stormin Stanley'}, parameters)
class TestTransport(base.EngineTestCase): def setUp(self): super(TestTransport, self).setUp() # Run the Engine and Executor in the background. self.en_thread = eventlet.spawn(launch.launch_engine, self.transport) self.ex_thread = eventlet.spawn(launch.launch_executor, self.transport) def tearDown(self): # Stop the Engine and the Executor. self.en_thread.kill() self.ex_thread.kill() super(TestTransport, self).tearDown() @mock.patch.object( db_api, 'workbook_get', mock.MagicMock( return_value={'definition': base.get_resource('test_rest.yaml')})) @mock.patch.object(std_actions.HTTPAction, 'run', mock.MagicMock(return_value={})) def test_transport(self): """ Test if engine request traversed through the oslo.messaging transport. """ execution = self.engine.start_workflow_execution( WB_NAME, 'create-vms', CONTEXT) task = db_api.tasks_get(WB_NAME, execution['id'])[0] # Check task execution state. There is no timeout mechanism in # unittest. There is an example to add a custom timeout decorator that # can wrap this test function in another process and then manage the # process time. However, it seems more straightforward to keep the # loop finite. for i in range(0, 50): db_task = db_api.task_get(task['workbook_name'], task['execution_id'], task['id']) # Ensure the request reached the executor and the action has ran. if db_task['state'] != states.IDLE: # We have to wait sometime due to time interval between set # task state to RUNNING and invocation action.run() time.sleep(0.1) self.assertIn(db_task['state'], [states.RUNNING, states.SUCCESS, states.ERROR]) return time.sleep(0.1) # Task is not being processed. Throw an exception here. raise Exception('Timed out waiting for task to be processed.')
def test_convert_adhoc_action_params(self): workbook = parser.get_workbook( base.get_resource('control_flow/one_sync_task.yaml')) action_name = 'MyActions.concat' params = { 'left': 'Stormin', 'right': 'Stanley' } parameters = a_f.convert_adhoc_action_params(workbook, action_name, params) self.assertEqual({'output': 'Stormin Stanley'}, parameters)
def setUp(self): super(WorkflowTest, self).setUp() self.parser = parser.get_workbook(base.get_resource("test_rest.yaml"))
def setUp(self): super(DSLModelTest, self).setUp() self.doc = base.get_resource("test_rest.yaml")
@mock.patch.object( engine.EngineClient, 'start_workflow_execution', mock.MagicMock(side_effect=base.EngineTestCase.mock_start_workflow)) @mock.patch.object( engine.EngineClient, 'convey_task_result', mock.MagicMock(side_effect=base.EngineTestCase.mock_task_result)) @mock.patch.object( concrete_engine.DefaultEngine, '_run_tasks', mock.MagicMock(side_effect=base.EngineTestCase.mock_run_tasks)) @mock.patch.object( db_api, 'workbook_get', mock.MagicMock( return_value={ 'definition': base.get_resource('retry_task/retry_task.yaml')})) @mock.patch.object( std_actions.HTTPAction, 'run', mock.MagicMock(return_value='result')) class TaskRetryTest(base.EngineTestCase): def test_no_retry(self): execution = self.engine.start_workflow_execution(WB_NAME, 'retry_task', None) tasks = db_api.tasks_get(WB_NAME, execution['id']) self.engine.convey_task_result(WB_NAME, execution['id'], tasks[0]['id'], states.SUCCESS, {'output': 'result'}) # TODO(rakhmerov): It's not stable, need to avoid race condition.
# the change in value is not permanent. cfg.CONF.set_default('auth_enable', False, group='pecan') #TODO(rakhmerov): add more tests for errors, execution stop etc. @mock.patch.object( engine.EngineClient, 'start_workflow_execution', mock.MagicMock(side_effect=base.EngineTestCase.mock_start_workflow)) @mock.patch.object( engine.EngineClient, 'convey_task_result', mock.MagicMock(side_effect=base.EngineTestCase.mock_task_result)) @mock.patch.object( db_api, 'workbook_get', mock.MagicMock( return_value={'definition': base.get_resource('test_rest.yaml')})) @mock.patch.object( std_actions.HTTPAction, 'run', mock.MagicMock(return_value={'state': states.SUCCESS})) class TestScalableEngine(base.EngineTestCase): @mock.patch.object( concrete_engine.DefaultEngine, "_notify_task_executors", mock.MagicMock(return_value="")) def test_engine_one_task(self): execution = self.engine.start_workflow_execution(WB_NAME, "create-vms", CONTEXT) task = db_api.tasks_get(WB_NAME, execution['id'])[0] self.engine.convey_task_result(WB_NAME, execution['id'], task['id'], states.SUCCESS, None)
def setUp(self): self.doc = base.get_resource("test_rest.yaml")
# the change in value is not permanent. cfg.CONF.set_default('auth_enable', False, group='pecan') #TODO(rakhmerov): add more tests for errors, execution stop etc. @mock.patch.object( client.EngineClient, 'start_workflow_execution', mock.MagicMock(side_effect=base.EngineTestCase.mock_start_workflow)) @mock.patch.object( client.EngineClient, 'convey_task_result', mock.MagicMock(side_effect=base.EngineTestCase.mock_task_result)) @mock.patch.object( db_api, 'workbook_get', mock.MagicMock( return_value={'definition': base.get_resource('test_rest.yaml')})) @mock.patch.object( std_actions.HTTPAction, 'run', mock.MagicMock(return_value={'state': states.SUCCESS})) class TestScalableEngine(base.EngineTestCase): @mock.patch.object( engine.ScalableEngine, "_notify_task_executors", mock.MagicMock(return_value="")) def test_engine_one_task(self): execution = self.engine.start_workflow_execution(WB_NAME, "create-vms", CONTEXT) task = db_api.tasks_get(WB_NAME, execution['id'])[0] self.engine.convey_task_result(WB_NAME, execution['id'], task['id'], states.SUCCESS, None)
from mistral.engine import states from mistral.db import api as db_api from mistral.engine.actions import actions from mistral.engine.actions import action_types from mistral.engine.scalable.executor import server from mistral.engine.scalable.executor import client WORKBOOK_NAME = 'my_workbook' TASK_NAME = 'my_task' SAMPLE_WORKBOOK = { 'id': str(uuid.uuid4()), 'name': WORKBOOK_NAME, 'description': 'my description', 'definition': base.get_resource("test_rest.yaml"), 'tags': [], 'scope': 'public', 'updated_at': None, 'project_id': '123', 'trust_id': '1234' } SAMPLE_EXECUTION = { 'id': str(uuid.uuid4()), 'workbook_name': WORKBOOK_NAME, 'task': TASK_NAME, 'state': states.RUNNING, 'updated_at': None, 'context': None }
importutils.import_module("mistral.config") 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') WORKBOOK_NAME = 'my_workbook' TASK_NAME = 'create-vms' SAMPLE_WORKBOOK = { 'id': str(uuid.uuid4()), 'name': WORKBOOK_NAME, 'description': 'my description', 'definition': base.get_resource("test_rest.yaml"), 'tags': [], 'scope': 'public', 'updated_at': None, 'project_id': '123', 'trust_id': '1234' } SAMPLE_EXECUTION = { 'id': str(uuid.uuid4()), 'workbook_name': WORKBOOK_NAME, 'task': TASK_NAME, 'state': states.RUNNING, 'updated_at': None, 'context': None }
@mock.patch.object( client.EngineClient, 'start_workflow_execution', mock.MagicMock(side_effect=base.EngineTestCase.mock_start_workflow)) @mock.patch.object( client.EngineClient, 'convey_task_result', mock.MagicMock(side_effect=base.EngineTestCase.mock_task_result)) @mock.patch.object( engine.ScalableEngine, '_run_tasks', mock.MagicMock(side_effect=base.EngineTestCase.mock_run_tasks)) @mock.patch.object( db_api, 'workbook_get', mock.MagicMock( return_value={ 'definition': base.get_resource('retry_task/retry_task.yaml')})) @mock.patch.object( std_actions.HTTPAction, 'run', mock.MagicMock(return_value='result')) class TaskRetryTest(base.EngineTestCase): def test_no_retry(self): execution = self.engine.start_workflow_execution(WB_NAME, 'retry_task', None) tasks = db_api.tasks_get(WB_NAME, execution['id']) self.engine.convey_task_result(WB_NAME, execution['id'], tasks[0]['id'], states.SUCCESS, {'output': 'result'}) # TODO(rakhmerov): It's not stable, need to avoid race condition.