diff --git a/python/binharness/bootstrap/docker.py b/python/binharness/bootstrap/docker.py index 3b6ab06..c6f4bfe 100644 --- a/python/binharness/bootstrap/docker.py +++ b/python/binharness/bootstrap/docker.py @@ -17,15 +17,15 @@ class DockerAgent(AgentConnection): it allows managing the agent in a docker container. """ - _client: docker.DockerClient + _docker_client: docker.DockerClient _container_id: str def __init__(self: DockerAgent, container_id: str, port: int) -> None: """Initialize a DockerAgent.""" - self._client = docker.from_env() + self._docker_client = docker.from_env() self._container_id = container_id - container = self._client.containers.get(container_id) + container = self._docker_client.containers.get(container_id) ip_address = container.attrs["NetworkSettings"]["IPAddress"] super().__init__(ip_address, port) @@ -34,12 +34,12 @@ def __del__(self: DockerAgent) -> None: if self.container.status == "running": self.container.stop() self.container.remove() - self._client.close() + self._docker_client.close() @property def container(self: DockerAgent) -> docker.models.containers.Container: """Return the docker container.""" - return self._client.containers.get(self._container_id) + return self._docker_client.containers.get(self._container_id) def _create_in_memory_tarfile(files: dict[str, str]) -> BinaryIO: diff --git a/python/tests/bootstrap/test_docker.py b/python/tests/bootstrap/test_docker.py index efe5e2a..a2be5d4 100644 --- a/python/tests/bootstrap/test_docker.py +++ b/python/tests/bootstrap/test_docker.py @@ -9,14 +9,16 @@ def test_bootstrap_env_from_image(agent_binary_linux_host_arch: str) -> None: agent = bootstrap_env_from_image(agent_binary_linux_host_arch, "ubuntu:22.04") + try: + assert isinstance(agent, DockerAgent) + assert agent.get_environment_ids() == [0] - assert isinstance(agent, DockerAgent) - assert agent.get_environment_ids() == [0] + env = agent.get_environment(0) + target = Target(env, Path("/usr/bin/echo"), args=["hello world"]) + proc = NullExecutor().run_target(target) - env = agent.get_environment(0) - target = Target(env, Path("/usr/bin/echo"), args=["hello world"]) - proc = NullExecutor().run_target(target) - - proc.wait() - assert proc.returncode == 0 - assert proc.stdout.read() == b"hello world\n" + proc.wait() + assert proc.returncode == 0 + assert proc.stdout.read() == b"hello world\n" + finally: + agent.container.stop()