Example #1
0
def test_log_files_single_mesos_file(mock_util_stream, mock_get_master_state):
    ctx = MockLogger()
    _file = MesosFile("TestFile", dcos_client=MesosClient(""))

    # mock out the parts of `dcos` that make remote API calls.
    mock_util_stream.return_value = [(MockFuture(), _file)]
    mock_get_master_state.return_value = None

    log_files(ctx, [_file], False, 10)
    assert ctx.buffer.getvalue() == "AAAAA\n" + \
                                    "BBBBB\n" + \
                                    "CCCCC\n"
Example #2
0
def test_log_files_unreachable_mesos_file(mock_util_stream, mock_get_master_state):
    ctx = MockLogger()
    _file_1 = MesosFile("TestFile_1", dcos_client=MesosClient(""))
    _file_2 = MesosFile("TestFile_2", dcos_client=MesosClient(""))

    # mock out the parts of `dcos` that make remote API calls.
    mock_util_stream.return_value = [(MockFutureException(), _file_1), (MockFuture(), _file_2)]
    mock_get_master_state.return_value = None

    log_files(ctx, [_file_1, _file_2], False, 10)
    assert ctx.buffer.getvalue() == "[2] AAAAA\n" + \
                                    "[2] BBBBB\n" + \
                                    "[2] CCCCC\n"
Example #3
0
def cli(logger, mesos_client, follow, completed, lines, stream, application_id):
    """ Tail a file in a mesos task's sandbox.
    """

    # get tasks from mesos. We add a "." to the application ID to ensure that
    # we only get back tasks from the application we ask for. Mesos matching
    # for the fltr arg is greedy so this is necessary to restrict the output.
    tasks = mesos_client.get_tasks(application_id + ".", completed=completed)

    # If we couldn't find any running tasks for our app we tell the user.
    if not tasks:
        raise click.UsageError('No matching tasks. Exiting.')

    # for each of our found tasks, check the mesos sandbox of each one and get
    # a MesosFile object for each of the files we want to inspect.
    mesos_files = mesos._mesos_files(tasks, stream, mesos_client)
    if not mesos_files:
        raise click.UsageError('No matching files. Exiting.')

    log_files(logger, mesos_files, follow, lines)
Example #4
0
def test_log_files_no_mesos_files():
    ctx = MockLogger()
    with pytest.raises(DCOSException):
        log_files(ctx, [], False, 10)