def test_handle_task(self): # Create a new workbook. workbook = db_api.workbook_create(SAMPLE_WORKBOOK) self.assertIsInstance(workbook, dict) # Create a new execution. execution = db_api.execution_create(SAMPLE_EXECUTION['workbook_name'], SAMPLE_EXECUTION) self.assertIsInstance(execution, dict) # Create a new task. SAMPLE_TASK['execution_id'] = execution['id'] task = db_api.task_create(SAMPLE_TASK['workbook_name'], SAMPLE_TASK['execution_id'], SAMPLE_TASK) self.assertIsInstance(task, dict) self.assertIn('id', task) # Send the task request to the Executor. ex_client = executor.ExecutorClient(self.transport) ex_client.handle_task(SAMPLE_CONTEXT, task=task) # Check task execution state. db_task = db_api.task_get(task['workbook_name'], task['execution_id'], task['id']) self.assertEqual(db_task['state'], states.SUCCESS)
def create_workbook(definition_path): return db_api.workbook_create({ 'name': 'my_workbook', 'definition': base.get_resource(definition_path) })
def create_workbook(values): workbook = db_api.workbook_create(values) if cfg.CONF.pecan.auth_enable: workbook = trusts.create_trust(workbook) # TODO(akuznetsov) filter fields # TODO(akuznetsov) create triggers return workbook
def create_workbook(values): workbook = db_api.workbook_create(values) if cfg.CONF.pecan.auth_enable: workbook = trusts.create_trust(workbook) ##TODO(akuznetsov) filter fields ##TODO(akuznetsov) create triggers return workbook
def setUp(self): super(TestExecutor, self).setUp() # Create a new workbook. self.workbook = db_api.workbook_create(SAMPLE_WORKBOOK) # Create a new execution. self.execution = db_api.execution_create( SAMPLE_EXECUTION['workbook_name'], SAMPLE_EXECUTION) # Create a new task. SAMPLE_TASK['execution_id'] = self.execution['id'] self.task = db_api.task_create( SAMPLE_TASK['execution_id'], SAMPLE_TASK)
def test_handle_task(self): # Mock the RestAction mock_rest_action = self.mock_action_run() # Create a new workbook. workbook = db_api.workbook_create(SAMPLE_WORKBOOK) self.assertIsInstance(workbook, dict) # Create a new execution. execution = db_api.execution_create(SAMPLE_EXECUTION['workbook_name'], SAMPLE_EXECUTION) self.assertIsInstance(execution, dict) # Create a new task. SAMPLE_TASK['execution_id'] = execution['id'] task = db_api.task_create(SAMPLE_TASK['workbook_name'], SAMPLE_TASK['execution_id'], SAMPLE_TASK) self.assertIsInstance(task, dict) self.assertIn('id', task) # Send the task request to the Executor. transport = self.server.transport ex_client = client.ExecutorClient(transport) ex_client.handle_task(SAMPLE_CONTEXT, task=task) # 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: mock_rest_action.assert_called_once_with() 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.')