コード例 #1
0
def setup_module():
    # create a completed task
    with app(SLEEP_COMPLETED, 'test-app-completed'):
        pass

    for app_ in INIT_APPS:
        add_app(app_[0])
コード例 #2
0
def test_log_completed():
    """ Test `dcos task log --completed` """
    with app(SLEEP_COMPLETED1, 'test-app-completed1'):
        task_id_completed = _get_task_id('test-app-completed1')

    # create a completed task
    # ensure that tail lists nothing
    # ensure that tail --completed lists a completed task
    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'log', task_id_completed])

    assert returncode == 1
    assert stdout == b''
    assert stderr.startswith(
        b"Error: no task ID found containing 'test-app-completed1")

    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'log', '--completed', task_id_completed, 'stderr'])
    assert returncode == 0
    assert stderr == b''
    assert len(stdout.decode('utf-8').split('\n')) >= 3

    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'log', '--all', task_id_completed, 'stderr'])
    assert returncode == 0
    assert stderr == b''
    assert len(stdout.decode('utf-8').split('\n')) >= 3
コード例 #3
0
def test_ls_completed():
    with app(SLEEP_COMPLETED1, 'test-app-completed1'):
        task_id_completed = _get_task_id('test-app-completed1')

    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'ls', task_id_completed])

    assert returncode == 1
    assert stdout == b''

    err = b"Error: no task ID found containing 'test-app-completed1"
    assert stderr.startswith(err)

    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'ls', '--completed', task_id_completed])

    assert returncode == 0
    assert stderr == b''

    ls_line = '.*stderr.*stdout.*'
    lines = stdout.decode('utf-8').rstrip().split('\n')
    num_expected_lines = 1

    assert len(lines) == num_expected_lines
    assert re.match(ls_line, lines[0])
コード例 #4
0
def test_log_task():
    with app(HELLO_STDERR, 'test-hello-stderr'):
        returncode, stdout, stderr = exec_command([
            'dcos', 'task', 'log', 'test-hello-stderr', 'stderr', '--lines=-1'
        ])

        assert returncode == 0
        assert not stderr
        assert stdout == b'hello\n'
コード例 #5
0
ファイル: test_marathon.py プロジェクト: ksauzz/dcos-cli
def test_app_locked_error():
    with app('tests/data/marathon/apps/sleep_many_instances.json',
             '/sleep-many-instances',
             wait=False):
        stderr = b'Changes blocked: deployment already in progress for app.\n'
        assert_command(
            ['dcos', 'marathon', 'app', 'stop', 'sleep-many-instances'],
            returncode=1,
            stderr=stderr)
コード例 #6
0
def test_restarting_app():
    app_id = 'zero-instance-app'
    with app(_ZERO_INSTANCE_APP, app_id):
        start_app(app_id, 3)
        watch_all_deployments()
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'app', 'restart', app_id])

        assert returncode == 0
        assert stdout.decode().startswith('Created deployment ')
        assert stderr == b''
コード例 #7
0
def test_log_follow():
    """ Test --follow """
    # verify output
    with app(FOLLOW, 'follow'):
        proc = subprocess.Popen(['dcos', 'task', 'log', 'follow', '--follow'],
                                stdout=subprocess.PIPE)

        # mark stdout as non-blocking, so we can read all available data
        # before EOF
        _mark_non_blocking(proc.stdout)

        time.sleep(10)
        assert len(_read_lines(proc.stdout)) >= 1

        proc.kill()
コード例 #8
0
def test_log_task():
    with app(HELLO_STDERR, 'test-hello-stderr'):

        # We've seen flakiness here where the command below doesn't return the
        # expected "hello" line. This happens since the Go subcommand is much
        # faster than the former Python one, so it is possible that
        # "dcos task log" happens before the task writes to stderr.
        time.sleep(5)

        returncode, stdout, stderr = exec_command(
            ['dcos', 'task', 'log', 'test-hello-stderr', 'stderr',
             '--lines=-1'])

        assert returncode == 0
        assert not stderr
        assert stdout == b'hello\n'
コード例 #9
0
ファイル: test_task.py プロジェクト: insighty/dcos-cli
def test_log_two_tasks_follow():
    """ Test tailing a single file on two separate tasks with --follow """
    with app(TWO_TASKS_FOLLOW, 'two-tasks-follow'):
        proc = subprocess.Popen(
            ['dcos', 'task', 'log', 'two-tasks-follow', '--follow'],
            stdout=subprocess.PIPE)

        # mark stdout as non-blocking, so we can read all available data
        # before EOF
        _mark_non_blocking(proc.stdout)

        time.sleep(5)
        first_lines = _read_lines(proc.stdout)
        time.sleep(3)
        second_lines = _read_lines(proc.stdout)

        assert len(first_lines) >= 1
        # assert there are more lines after sleeping
        assert len(second_lines) >= 1

        proc.kill()
コード例 #10
0
ファイル: test_marathon.py プロジェクト: ksauzz/dcos-cli
def _zero_instance_app_through_http():
    class JSONRequestHandler(BaseHTTPRequestHandler):
        def do_GET(self):  # noqa: N802
            self.send_response(200)
            self.send_header("Content-type", "application/json")
            self.end_headers()
            self.wfile.write(
                open('tests/data/marathon/apps/zero_instance_sleep.json',
                     'rb').read())

    host = 'localhost'
    port = 12345
    server = HTTPServer((host, port), JSONRequestHandler)
    thread = threading.Thread(target=server.serve_forever)
    thread.setDaemon(True)
    thread.start()

    with app('http://{}:{}'.format(host, port), 'zero-instance-app'):
        try:
            yield
        finally:
            server.shutdown()
コード例 #11
0
ファイル: test_task.py プロジェクト: insighty/dcos-cli
def test_ls_completed():
    with app(SLEEP_COMPLETED1, 'test-app-completed1'):
        task_id_completed = _get_task_id('test-app-completed1')

    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'ls', task_id_completed])

    assert returncode == 1
    assert stdout == b''

    err = b'Cannot find a task with ID containing "test-app-completed1'
    assert stderr.startswith(err)

    returncode, stdout, stderr = exec_command(
        ['dcos', 'task', 'ls', '--completed', task_id_completed])

    assert returncode == 0
    assert stderr == b''

    ls_line = '\.ssl.*stderr.*stdout.*'
    lines = stdout.decode('utf-8').split('\n')
    assert len(lines) == 2
    assert re.match(ls_line, lines[0])
コード例 #12
0
ファイル: test_marathon.py プロジェクト: ksauzz/dcos-cli
def _zero_instance_app():
    with app('tests/data/marathon/apps/zero_instance_sleep.json',
             'zero-instance-app'):
        yield
コード例 #13
0
def test_add_app():
    app_id = 'zero-instance-app'
    with app(_ZERO_INSTANCE_APP, app_id):
        show_app('zero-instance-app')
コード例 #14
0
def _stuck_app(max_count=300):
    with app('tests/data/marathon/apps/stuck_sleep.json',
             'stuck-sleep', False):
        watch_for_overdue(max_count)
        yield