From a646925cb79a11e280d10656a559bc1504a5b9a6 Mon Sep 17 00:00:00 2001 From: avran Date: Thu, 2 Nov 2023 23:31:06 +0530 Subject: [PATCH 1/2] returns the context when using context.use (#488) --- python_on_whales/components/context/cli_wrapper.py | 1 + tests/python_on_whales/components/test_context.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/python_on_whales/components/context/cli_wrapper.py b/python_on_whales/components/context/cli_wrapper.py index 625510cf..9f2af125 100644 --- a/python_on_whales/components/context/cli_wrapper.py +++ b/python_on_whales/components/context/cli_wrapper.py @@ -231,3 +231,4 @@ def use(self, context: ValidContext): """ full_cmd = self.docker_cmd + ["context", "use", context] run(full_cmd) + return self.inspect(context) diff --git a/tests/python_on_whales/components/test_context.py b/tests/python_on_whales/components/test_context.py index e85fcf49..0160885d 100644 --- a/tests/python_on_whales/components/test_context.py +++ b/tests/python_on_whales/components/test_context.py @@ -48,6 +48,10 @@ def test_use_context(): docker.context.use("default") +def test_use_context_returns(): + assert docker.context.use("default") == docker.context.inspect("default") + + def test_remove_empty_context_list(): all_contexts = set(docker.context.list()) docker.context.remove([]) From 83a41c939e892c38d9697b5862b8389bab67bba6 Mon Sep 17 00:00:00 2001 From: avran Date: Fri, 3 Nov 2023 00:12:30 +0530 Subject: [PATCH 2/2] adds support for --renew-anon-volumes (#487) --- .../components/compose/cli_wrapper.py | 4 +++ .../components/compose_anon_volumes.yml | 8 +++++ .../components/test_compose.py | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/python_on_whales/components/compose_anon_volumes.yml diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py index 43cebac0..f68466bb 100644 --- a/python_on_whales/components/compose/cli_wrapper.py +++ b/python_on_whales/components/compose/cli_wrapper.py @@ -669,6 +669,7 @@ def up( recreate: bool = True, no_build: bool = False, remove_orphans: bool = False, + renew_anon_volumes: bool = False, color: bool = True, log_prefix: bool = True, start: bool = True, @@ -704,6 +705,8 @@ def up( `recreate=False` and `force_recreate=True` are incompatible. no_build: Don't build an image, even if it's missing. remove_orphans: Remove containers for services not defined in the Compose file. + renew_anon_volumes: Recreate anonymous volumes instead of retrieving + data from the previous containers. color: If `False`, it will produce monochrome output. log_prefix: If `False`, will not display the prefix in the logs. start: Start the service after creating them. @@ -733,6 +736,7 @@ def up( full_cmd.add_flag("--no-log-prefix", not log_prefix) full_cmd.add_flag("--no-start", not start) full_cmd.add_flag("--remove-orphans", remove_orphans) + full_cmd.add_flag("--renew-anon-volumes", renew_anon_volumes) full_cmd.add_simple_arg("--pull", pull) if no_attach_services is not None: diff --git a/tests/python_on_whales/components/compose_anon_volumes.yml b/tests/python_on_whales/components/compose_anon_volumes.yml new file mode 100644 index 00000000..0b121fcc --- /dev/null +++ b/tests/python_on_whales/components/compose_anon_volumes.yml @@ -0,0 +1,8 @@ +version: "3.9" + +services: + busybox: + image: busybox:latest + command: sleep infinity + volumes: + - /hello-volume diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py index 7e09b6a8..5b8b0a33 100644 --- a/tests/python_on_whales/components/test_compose.py +++ b/tests/python_on_whales/components/test_compose.py @@ -740,6 +740,42 @@ def test_compose_multiple_profiles(): docker.compose.down(timeout=1) +def test_compose_anon_volumes_recreate_not_enabled(): + docker = DockerClient( + compose_files=[ + PROJECT_ROOT / "tests/python_on_whales/components/compose_anon_volumes.yml" + ], + ) + docker.compose.up(detach=True) + + volume_name_before_recreate = docker.compose.ps()[0].mounts[0].name + + docker.compose.up(detach=True, force_recreate=True) + volumes_name_after_recreate = docker.compose.ps()[0].mounts[0].name + + assert volume_name_before_recreate == volumes_name_after_recreate + + docker.compose.down(timeout=1) + + +def test_compose_anon_volumes_recreate_enabled(): + docker = DockerClient( + compose_files=[ + PROJECT_ROOT / "tests/python_on_whales/components/compose_anon_volumes.yml" + ], + ) + docker.compose.up(detach=True) + + volume_name_before_recreate = docker.compose.ps()[0].mounts[0].name + + docker.compose.up(detach=True, force_recreate=True, renew_anon_volumes=True) + volumes_name_after_recreate = docker.compose.ps()[0].mounts[0].name + + assert volume_name_before_recreate != volumes_name_after_recreate + + docker.compose.down(timeout=1) + + def test_compose_port(): d = DockerClient( compose_files=[