コード例 #1
0
    def test_get(self):
        url = self.TEST_URL + URL_TEMPLATE_ID % TASK['id']
        self.requests_mock.get(url, json=TASK)

        task = self.tasks.get(TASK['id'])

        self.assertEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())
コード例 #2
0
    def test_get(self):
        mock = self.mock_http_get(content=TASK)

        task = self.tasks.get(TASK['id'])

        self.assertEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())
        mock.assert_called_once_with(URL_TEMPLATE_ID % TASK['id'])
コード例 #3
0
    def test_rerun_no_reset(self):
        url = self.TEST_URL + URL_TEMPLATE_ID % TASK['id']
        self.requests_mock.put(url, json=TASK)

        task = self.tasks.rerun(TASK['id'], reset=False)

        self.assertDictEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())

        body = {'reset': False, 'state': 'RUNNING', 'id': TASK['id']}
        self.assertDictEqual(body, self.requests_mock.last_request.json())
コード例 #4
0
    def test_list(self):
        self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
                               json={'tasks': [TASK]})

        task_list = self.tasks.list()

        self.assertEqual(1, len(task_list))
        task = task_list[0]

        self.assertEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())
コード例 #5
0
    def test_list(self):
        mock = self.mock_http_get(content={'tasks': [TASK]})

        task_list = self.tasks.list()

        self.assertEqual(1, len(task_list))
        task = task_list[0]

        self.assertEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())
        mock.assert_called_once_with(URL_TEMPLATE)
コード例 #6
0
    def test_rerun_update_env(self):
        url = self.TEST_URL + URL_TEMPLATE_ID % TASK['id']
        self.requests_mock.put(url, json=TASK)

        task = self.tasks.rerun(TASK['id'], env={'k1': 'foobar'})

        self.assertDictEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())

        body = {
            'reset': True,
            'state': 'RUNNING',
            'id': TASK['id'],
            'env': json.dumps({'k1': 'foobar'})
        }
        self.assertDictEqual(body, self.requests_mock.last_request.json())
コード例 #7
0
    def test_rerun_no_reset(self):
        mock = self.mock_http_put(content=TASK)

        task = self.tasks.rerun(TASK['id'], reset=False)

        self.assertDictEqual(
            tasks.Task(self.tasks, TASK).to_dict(), task.to_dict())

        self.assertEqual(1, mock.call_count)
        self.assertEqual(URL_TEMPLATE_ID % TASK['id'], mock.call_args[0][0])
        self.assertDictEqual(
            {
                'reset': False,
                'state': 'RUNNING',
                'id': TASK['id']
            }, json.loads(mock.call_args[0][1]))
コード例 #8
0
        'id': uuid.uuid4().hex,
        'name': 'task2',
        'workflow_execution_id': MOCK_WF_EX_DATA['id'],
        'workflow_name': MOCK_WF_EX_DATA['name'],
        'created_at': str(datetime.datetime.utcnow()),
        'updated_at': str(datetime.datetime.utcnow()),
        'state': 'SUCCESS',
        'state_info': None,
        'input': '{"e": "f", "g": "h"}',
        'result': '{"i": "j", "k": "l"}',
        'published': '{"k": "l"}'
    }
]

MOCK_WF_EX_TASKS = [
    tasks.Task(None, MOCK_WF_EX_TASKS_DATA[0]),
    tasks.Task(None, MOCK_WF_EX_TASKS_DATA[1])
]

MOCK_QRY_CONTEXT = {
    'mistral': {
        'execution_id': uuid.uuid4().hex
    }
}


class MistralQuerierTest(DbTestCase):

    def setUp(self):
        super(MistralQuerierTest, self).setUp()
        self.querier = mistral.get_query_instance()
コード例 #9
0
    'ERROR',
    None,
    '2020-02-07 08:10:32',
    '2020-02-07 08:10:41',
    '0:00:09'
)

TASK_RESULT = {"test": "is", "passed": "successfully"}
TASK_PUBLISHED = {"bar1": "val1", "var2": 2}

TASK_WITH_RESULT_DICT = TASK_DICT.copy()
TASK_WITH_RESULT_DICT.update({'result': jsonutils.dumps(TASK_RESULT)})
TASK_WITH_PUBLISHED_DICT = TASK_DICT.copy()
TASK_WITH_PUBLISHED_DICT.update({'published': jsonutils.dumps(TASK_PUBLISHED)})

TASK = tasks.Task(mock, TASK_DICT)
TASK_WITH_RESULT = tasks.Task(mock, TASK_WITH_RESULT_DICT)
TASK_WITH_PUBLISHED = tasks.Task(mock, TASK_WITH_PUBLISHED_DICT)

EXPECTED_TASK_RESULT = (
    '123', 'some', 'thing', '', '321', 'SUCCESS', None,
    '2020-02-07 08:10:32', '2020-02-07 08:10:32',
    '2020-02-07 08:10:41', '0:00:09'
)


class TestCLITasksV2(base.BaseCommandTest):
    def test_list(self):
        self.client.tasks.list.return_value = [TASK]

        result = self.call(task_cmd.List)
コード例 #10
0
}, {
    'id': uuid.uuid4().hex,
    'name': 'task2',
    'workflow_execution_id': MOCK_WF_EX_DATA['id'],
    'workflow_name': MOCK_WF_EX_DATA['name'],
    'created_at': str(datetime.datetime.utcnow()),
    'updated_at': str(datetime.datetime.utcnow()),
    'state': 'SUCCESS',
    'state_info': None,
    'input': '{"e": "f", "g": "h"}',
    'result': '{"i": "j", "k": "l"}',
    'published': '{"k": "l"}'
}]

MOCK_WF_EX_TASKS = [
    tasks.Task(None, MOCK_WF_EX_TASKS_DATA[0]),
    tasks.Task(None, MOCK_WF_EX_TASKS_DATA[1])
]

MOCK_QRY_CONTEXT = {'mistral': {'execution_id': uuid.uuid4().hex}}

MOCK_LIVEACTION_RESULT = {
    'tasks': [{
        'id':
        MOCK_WF_EX_TASKS_DATA[0]['id'],
        'name':
        MOCK_WF_EX_TASKS_DATA[0]['name'],
        'workflow_execution_id':
        MOCK_WF_EX_TASKS_DATA[0]['workflow_execution_id'],
        'workflow_name':
        MOCK_WF_EX_TASKS_DATA[0]['workflow_name'],
コード例 #11
0
WB1_META_FILE_PATH = TEST_PACK_PATH + '/actions/' + WB1_META_FILE_NAME
WB1_META_CONTENT = loader.load_meta_file(WB1_META_FILE_PATH)
WB1_NAME = WB1_META_CONTENT['pack'] + '.' + WB1_META_CONTENT['name']
WB1_ENTRY_POINT = TEST_PACK_PATH + '/actions/' + WB1_META_CONTENT['entry_point']
WB1_ENTRY_POINT_X = WB1_ENTRY_POINT.replace(WB1_META_FILE_NAME,
                                            'xformed_' + WB1_META_FILE_NAME)
WB1_SPEC = yaml.safe_load(
    MistralRunner.get_workflow_definition(WB1_ENTRY_POINT_X))
WB1_YAML = yaml.safe_dump(WB1_SPEC, default_flow_style=False)
WB1 = workbooks.Workbook(None, {'name': WB1_NAME, 'definition': WB1_YAML})
WB1_MAIN_EXEC = {'id': str(uuid.uuid4()), 'state': 'RUNNING'}
WB1_MAIN_EXEC['workflow_name'] = WB1_NAME + '.main'
WB1_MAIN_EXEC_ERRORED = copy.deepcopy(WB1_MAIN_EXEC)
WB1_MAIN_EXEC_ERRORED['state'] = 'ERROR'
WB1_MAIN_TASK1 = {'id': str(uuid.uuid4()), 'name': 'greet', 'state': 'ERROR'}
WB1_MAIN_TASKS = [tasks.Task(None, WB1_MAIN_TASK1)]
WB1_MAIN_TASK_ID = WB1_MAIN_TASK1['id']
WB1_SUB1_EXEC = {
    'id': str(uuid.uuid4()),
    'state': 'RUNNING',
    'task_execution_id': WB1_MAIN_TASK_ID
}
WB1_SUB1_EXEC['workflow_name'] = WB1_NAME + '.subflow1'
WB1_SUB1_EXEC_ERRORED = copy.deepcopy(WB1_SUB1_EXEC)
WB1_SUB1_EXEC_ERRORED['state'] = 'ERROR'
WB1_SUB1_TASK1 = {
    'id': str(uuid.uuid4()),
    'name': 'say-greeting',
    'state': 'SUCCESS'
}
WB1_SUB1_TASK2 = {
コード例 #12
0
def data(TEST):
    # MistralActions
    TEST.mistralclient_actions = test_data_utils.TestDataContainer()
    action_1 = actions.Action(
        actions.ActionManager(None),
        {'name': 'a',
         'is_system': True,
         'input': 'param1',
         'description': 'my cool action',
         'tags': ['test'],
         'created_at': '1',
         'updated_at': '1'
         }
    )
    TEST.mistralclient_actions.add(action_1)

    # MistralExecutions
    TEST.mistralclient_executions = test_data_utils.TestDataContainer()
    execution_1 = executions.Execution(
        executions.ExecutionManager(None),
        {'id': '123',
         'workflow_name': 'my_wf',
         'description': '',
         'state': 'RUNNING',
         'input': {
             'person': {
                 'first_name': 'John',
                 'last_name': 'Doe'
             }
         }}
    )
    TEST.mistralclient_executions.add(execution_1)

    # Tasks
    TEST.mistralclient_tasks = test_data_utils.TestDataContainer()
    task_1 = tasks.Task(
        tasks.TaskManager(None),
        {'id': '1',
         'workflow_execution_id': '123',
         'name': 'my_task',
         'workflow_name': 'my_wf',
         'state': 'RUNNING',
         'type': 'ACTION',
         'tags': ['deployment', 'demo'],
         'result': {'some': 'result'}})
    TEST.mistralclient_tasks.add(task_1)

    # Workbooks
    TEST.mistralclient_workbooks = test_data_utils.TestDataContainer()
    workbook_1 = workbooks.Workbook(
        workbooks.WorkbookManager(None),
        {'name': 'a',
         'tags': ['a', 'b'],
         'created_at': '1',
         'updated_at': '1',
         'definition': WB_DEF}
    )
    TEST.mistralclient_workbooks.add(workbook_1)

    # Workflows
    TEST.mistralclient_workflows = test_data_utils.TestDataContainer()
    workflow_1 = workflows.Workflow(
        workflows.WorkflowManager(None),
        {'name': 'a',
         'tags': ['a', 'b'],
         'input': 'param',
         'created_at': '1',
         'updated_at': '1',
         'definition': WF_DEF}
    )
    TEST.mistralclient_workflows.add(workflow_1)

    # MistralActionsExecutions
    TEST.mistralclient_action_executions = test_data_utils.TestDataContainer()
    action_executions_1 = action_executions.ActionExecution(
        action_executions.ActionExecutionManager(None),
        {'id': '1',
         'name': 'a',
         'tags': ['a', 'b'],
         'workflow_name': 'my work flow',
         'task_execution_id': '1',
         'task_name': 'b',
         'description': '',
         'created_at': '1',
         'updated_at': '1',
         'accepted': True,
         'state': 'RUNNING'
         }
    )
    TEST.mistralclient_action_executions.add(action_executions_1)

    # MistralCronTriggers
    TEST.mistralclient_cron_triggers = test_data_utils.TestDataContainer()
    cron_triggers_1 = cron_triggers.CronTrigger(
        cron_triggers.CronTriggerManager(None),
        {'id': '1',
         'name': 'a',
         'workflow_name': 'my work flow',
         'pattern': '',
         'next_execution_time': '',
         'remaining_executions': '',
         'first_execution_time': '',
         'created_at': '1',
         'updated_at': '1'
         })
    TEST.mistralclient_cron_triggers.add(cron_triggers_1)