def restart(self, timeout=10):
        self._container.restart(timeout=timeout)

        try:
            wait_for_callable('Waiting for container to be ready after restart', self.ready)
        except TimeoutError:
            raise ContainerNotReady(self, 'Timeout while waiting for container to be ready after restart')
Example #2
0
def test_container_ipv6(ipv6):
    addr = ipv6.get_addr('1234/udp')
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto(b'msg', addr)

    wait_for_callable('Waiting for delivery confirmation',
                      lambda: 'msg' in ipv6.logs())
Example #3
0
def test_container_ipv6(ipv6):
    addr = ipv6.get_addr("1234/udp")
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto(b"msg", addr)

    wait_for_callable("Waiting for delivery confirmation",
                      lambda: "msg" in ipv6.logs())
def container(request, docker_client, wrapper_class, **kwargs):
    """ Docker container: image={image} """

    wrapper_class = wrapper_class or Container

    kwargs.update({"detach": True})
    set_reusable_labels(kwargs, request)

    signature = hash_params(kwargs)
    set_signature(kwargs, signature)

    if request.config.option.reuse_containers:
        if "name" not in kwargs.keys():
            pytest.fail(
                "Tried to use '--reuse-containers' command line argument without "
                "setting 'name' attribute on container"
            )

        name = kwargs["name"]

        try:
            current = docker_client.containers.get(name)
        except NotFound:
            pass
        else:
            # Found a container with the right name, but it doesn't have pytest-docker-tools labels
            # We shouldn't just clobber it, its not ours. Bail out.
            if not is_reusable_container(current):
                pytest.fail(
                    f"Tried to reuse {name} but it does not appear to be a reusable container"
                )

            # It's ours, and its not stale. Reuse it!
            if check_signature(current.labels, signature):
                return wrapper_class(current)

            # It's ours and it is stale. Clobber it.
            print(f"Removing stale reusable container: {name}")
            current.remove(force=True)

    timeout = kwargs.pop("timeout", 30)

    raw_container = docker_client.containers.run(**kwargs)
    if not request.config.option.reuse_containers:
        request.addfinalizer(
            lambda: raw_container.remove(force=True) and raw_container.wait(timeout=10)
        )

    container = wrapper_class(raw_container)

    try:
        wait_for_callable("Waiting for container to be ready", container.ready, timeout)
    except TimeoutError:
        raise ContainerNotReady(
            container, "Timeout while waiting for container to be ready"
        )

    return container
Example #5
0
def __start_docker():
    docker_client = docker.from_env()

    image = __get_image(docker_client)

    docker_container = docker_client.containers.run(image=image.id,
                                                    detach=True)

    my_clai = Container(docker_container)

    wait_for_callable('Waiting for container to be ready', my_clai.ready)

    print(f"container run {my_clai.status} {my_clai.name}")

    return my_clai
def container(request, docker_client, wrapper_class, **kwargs):
    ''' Docker container: image={image} '''

    kwargs.update({'detach': True})

    raw_container = docker_client.containers.run(**kwargs)
    request.addfinalizer(lambda: raw_container.remove(force=True) and raw_container.wait(timeout=10))

    wrapper_class = wrapper_class or Container
    container = wrapper_class(raw_container)

    try:
        wait_for_callable('Waiting for container to be ready', container.ready, kwargs.pop('timeout', 30))
    except TimeoutError:
        raise ContainerNotReady(container, 'Timeout while waiting for container to be ready')

    return container
Example #7
0
    def _run_server(self):
        self.server_running = True
        self.on_server_running()

        docker_client = docker.from_env()

        image = self.__get_image(docker_client)

        docker_container = docker_client.containers.run(image=image.id,
                                                        detach=True)

        self.my_clai = Container(docker_container)

        wait_for_callable('Waiting for container to be ready',
                          self.my_clai.ready)

        print(f"container run {self.my_clai.status}")

        self.request_skills()
Example #8
0
def container(request, docker_client, wrapper_class, **kwargs):
    """ Docker container: image={image} """

    timeout = kwargs.pop("timeout", 30)

    kwargs.update({"detach": True})

    raw_container = docker_client.containers.run(**kwargs)
    request.addfinalizer(lambda: raw_container.remove(force=True) and
                         raw_container.wait(timeout=10))

    wrapper_class = wrapper_class or Container
    container = wrapper_class(raw_container)

    try:
        wait_for_callable("Waiting for container to be ready", container.ready,
                          timeout)
    except TimeoutError:
        raise ContainerNotReady(
            container, "Timeout while waiting for container to be ready")

    return container
Example #9
0
def container(request, docker_client, wrapper_class, **kwargs):
    """
    A temporary solution for this
    `issue <https://github.com/Jc2k/pytest-docker-tools/issues/9#issuecomment-634311572>`_
    until a new version of
    `pytest-docker-tools <https://github.com/Jc2k/pytest-docker-tools>`_
    is released.
    """
    timeout = kwargs.pop('timeout', 30)
    kwargs.update({'detach': True})

    raw_container = docker_client.containers.run(**kwargs)
    request.addfinalizer(lambda: raw_container.remove(force=True) and raw_container.wait(timeout=10))

    wrapper_class = wrapper_class or Container
    container = wrapper_class(raw_container)

    try:
        wait_for_callable('Waiting for container to be ready', container.ready, timeout)
    except TimeoutError:
        raise ContainerNotReady(container, 'Timeout while waiting for container to be ready')

    return container