Exemple #1
0
def test_attach_no_tty():
    task_id = _get_task_id('ls-app')

    proc, master = popen_tty('dcos task attach ' + task_id)
    master = os.fdopen(master, 'w')
    tty.setraw(master, when=termios.TCSANOW)

    stdout, stderr = proc.communicate()
    assert stderr == b'Unable to attach to a task launched without a TTY.\n'

    assert proc.wait() != 0
    master.close()
def test_attach_no_tty():
    task_id = _get_task_id('ls-app')

    proc, master = popen_tty('dcos task attach ' + task_id)
    master = os.fdopen(master, 'w')
    tty.setraw(master, when=termios.TCSANOW)

    stdout, stderr = proc.communicate()
    assert stderr == (b'Error: : I/O switchboard server '
                      b'was disabled for this container\n')

    assert proc.wait() != 0
    master.close()
Exemple #3
0
def test_app_add_no_tty():
    proc, master = popen_tty('dcos marathon app add')

    stdout, stderr = proc.communicate()
    os.close(master)

    print(stdout)
    print(stderr)

    assert proc.wait() == 1
    assert stdout == b''
    assert stderr == (b"We currently don't support reading from the TTY. "
                      b"Please specify an application JSON.\n"
                      b"E.g.: dcos marathon app add < app_resource.json\n")
def test_attach_custom_escape_sequence():
    task_id = _get_task_id('cat-app')

    env = os.environ.copy()
    env["DCOS_TASK_ESCAPE_SEQUENCE"] = "ctrl-p,ctrl-r,ctrl-s"

    proc, master = popen_tty('dcos task attach ' + task_id, env=env)
    master = os.fdopen(master, 'w')
    tty.setraw(master, when=termios.TCSANOW)

    master.buffer.write(b'\x10\x12\x13')
    master.flush()

    assert proc.wait() == 0
    master.close()
Exemple #5
0
def test_attach():
    task_id = _get_task_id('sh-app')

    proc, master = popen_tty('dcos task attach ' + task_id)
    master = os.fdopen(master, 'w')
    tty.setraw(master, when=termios.TCSANOW)

    master.write("echo 'Hello World!'\r\n")
    master.flush()

    echo = proc.stdout.read(33).decode("utf-8")
    assert echo == "echo 'Hello World!'\r\nHello World!"

    master.buffer.write(b'\x10\x11')
    master.flush()

    assert proc.wait() == 0
    master.close()
def test_attach():
    task_id = _get_task_id('cat-app')

    proc, master = popen_tty('dcos task attach ' + task_id)
    master = os.fdopen(master, 'w')
    tty.setraw(master, when=termios.TCSANOW)

    msg = "Hello World!\n"
    expected_output = "Hello World!\r\nHello World!\r\n"
    master.write(msg)
    master.flush()

    assert proc.stdout.read(len(expected_output)).decode() == expected_output

    master.buffer.write(b'\x10\x11')
    master.flush()

    assert proc.wait() == 0
    master.close()
def test_attach_partial_escape_sequence():
    task_id = _get_task_id('cat-app')

    proc, master = popen_tty('dcos task attach ' + task_id)
    master = os.fdopen(master, 'w')
    tty.setraw(master, when=termios.TCSANOW)

    master.write('\x10B')
    master.flush()

    assert proc.stdout.read(3).decode() == '^PB'

    # Flush ctrl-p and ctrl-q individually,
    # this is closer to how a real tty behaves.
    master.buffer.write(b'\x10')
    master.flush()
    master.buffer.write(b'\x11')
    master.flush()

    assert proc.wait() == 0
    master.close()