Ejemplo n.º 1
0
def test_get_task():
    with mock.patch(
        'paasta_tools.mesos_tools.get_running_tasks_from_frameworks', autospec=True,
    ) as mock_get_running_tasks_from_frameworks:
        mock_task_1 = {'id': '123'}
        mock_task_2 = {'id': '789'}
        mock_task_3 = {'id': '789'}
        mock_get_running_tasks_from_frameworks.return_value = [mock_task_1, mock_task_2, mock_task_3]
        ret = mesos_tools.get_task('123', app_id='app_id')
        mock_get_running_tasks_from_frameworks.assert_called_with('app_id')
        assert ret == mock_task_1

        with raises(mesos_tools.TaskNotFound):
            mesos_tools.get_task('111', app_id='app_id')

        with raises(mesos_tools.TooManyTasks):
            mesos_tools.get_task('789', app_id='app_id')
Ejemplo n.º 2
0
def test_get_task():
    with contextlib.nested(
        mock.patch('paasta_tools.mesos_tools.get_running_tasks_from_active_frameworks', autospec=True),
    ) as (
        mock_get_running_tasks_from_active_frameworks,
    ):
        mock_task_1 = {'id': '123'}
        mock_task_2 = {'id': '789'}
        mock_task_3 = {'id': '789'}
        mock_get_running_tasks_from_active_frameworks.return_value = [mock_task_1, mock_task_2, mock_task_3]
        ret = mesos_tools.get_task('123', app_id='app_id')
        mock_get_running_tasks_from_active_frameworks.assert_called_with('app_id')
        assert ret == mock_task_1

        with raises(mesos_tools.TaskNotFound):
            mesos_tools.get_task('111', app_id='app_id')

        with raises(mesos_tools.TooManyTasks):
            mesos_tools.get_task('789', app_id='app_id')
Ejemplo n.º 3
0
def instance_task(request):
    status = instance_status(request)
    task_id = request.swagger_data.get('task_id', None)
    verbose = request.swagger_data.get('verbose', False)
    try:
        mstatus = status['marathon']
    except KeyError:
        raise ApiFailure("Only marathon tasks supported", 400)
    try:
        task = get_task(task_id, app_id=mstatus['app_id'])
    except TaskNotFound:
        raise ApiFailure("Task with id {} not found".format(task_id), 404)
    except Exception:
        error_message = traceback.format_exc()
        raise ApiFailure(error_message, 500)
    if verbose:
        task = add_slave_info(task)
        task = add_executor_info(task)
    return task._Task__items
Ejemplo n.º 4
0
def instance_task(request):
    status = instance_status(request)
    task_id = request.swagger_data.get('task_id', None)
    verbose = request.swagger_data.get('verbose', False)
    try:
        mstatus = status['marathon']
    except KeyError:
        raise ApiFailure("Only marathon tasks supported", 400)
    try:
        task = get_task(task_id, app_id=mstatus['app_id'])
    except TaskNotFound:
        raise ApiFailure("Task with id {0} not found".format(task_id), 404)
    except Exception:
        error_message = traceback.format_exc()
        raise ApiFailure(error_message, 500)
    if verbose:
        task = add_slave_info(task)
        task = add_executor_info(task)
    return task._Task__items