Beispiel #1
0
def receiver(sock, stdout_stream, stderr_stream):
    from docker.utils.socket import next_frame_header
    from docker.utils.socket import read_exactly
    while True:
        stream, length = next_frame_header(sock)
        if stream == -1:
            break
        received = read_exactly(sock, length)
        if stream == 1:
            stdout_stream.write(received)
        else:
            INFO("stderr: %s" % received.decode('utf-8'))
            stderr_stream.write(received)
Beispiel #2
0
    def _internal_recv(self, n):
        if len(self._buf) == 0:
            (stream, size) = docker_socket.next_frame_header(self.sock)
            while size > 0:
                result = docker_socket.read(self.sock, size)
                if result is None:
                    continue
                data_length = len(result)
                if data_length == 0:
                    raise EOFError
                size -= data_length
                self._buf += result

        end = min(len(self._buf), n)
        ret = self._buf[:end]
        self._buf = self._buf[end:]
        return ret
Beispiel #3
0
    def test_exec_start_socket(self):
        container = self.client.create_container(BUSYBOX, 'cat',
                                                 detach=True, stdin_open=True)
        container_id = container['Id']
        self.client.start(container_id)
        self.tmp_containers.append(container_id)

        line = 'yay, interactive exec!'
        # `echo` appends CRLF, `printf` doesn't
        exec_id = self.client.exec_create(
            container_id, ['printf', line], tty=True)
        assert 'Id' in exec_id

        socket = self.client.exec_start(exec_id, socket=True)
        self.addCleanup(socket.close)

        (stream, next_size) = next_frame_header(socket)
        assert stream == 1  # stdout (0 = stdin, 1 = stdout, 2 = stderr)
        assert next_size == len(line)
        data = read_exactly(socket, next_size)
        assert data.decode('utf-8') == line