From 226c9d623dada6de17611dea844bc7a412493da6 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Fri, 29 Nov 2024 10:48:29 -0500 Subject: [PATCH] docker compat: use hyphens to join container names docker-compose uses - not _ to join container names to project. not a huge thing, but for services making assumptions based on this it can catch off guard, and is easy to make the same. Signed-off-by: Matt Phillips --- podman_compose.py | 2 +- tests/integration/test_podman_compose_deps.py | 2 +- .../test_podman_compose_extends_w_file.py | 4 ++-- .../test_podman_compose_extends_w_file_subdir.py | 2 +- .../integration/test_podman_compose_ipam_default.py | 4 ++-- .../integration/test_podman_compose_multicompose.py | 12 ++++++------ tests/integration/test_podman_compose_nets_test1.py | 6 +++--- tests/integration/test_podman_compose_nets_test2.py | 12 ++++++------ tests/integration/test_podman_compose_networks.py | 4 ++-- tests/integration/test_podman_compose_tests.py | 4 ++-- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index db6dc58e..3fdfe699 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1979,7 +1979,7 @@ def _parse_compose_file(self): container_names_by_service[service_name] = [] for num in range(1, replicas + 1): - name0 = f"{project_name}_{service_name}_{num}" + name0 = f"{project_name}-{service_name}-{num}" if num == 1: name = service_desc.get("container_name", name0) else: diff --git a/tests/integration/test_podman_compose_deps.py b/tests/integration/test_podman_compose_deps.py index 1c468121..1fed93bc 100644 --- a/tests/integration/test_podman_compose_deps.py +++ b/tests/integration/test_podman_compose_deps.py @@ -26,7 +26,7 @@ def test_deps(self): "wget -O - http://web:8000/hosts", ]) self.assertIn(b"HTTP request sent, awaiting response... 200 OK", output) - self.assertIn(b"deps_web_1", output) + self.assertIn(b"deps-web-1", output) finally: self.run_subprocess_assert_returncode([ podman_compose_path(), diff --git a/tests/integration/test_podman_compose_extends_w_file.py b/tests/integration/test_podman_compose_extends_w_file.py index a57f51cb..825abed3 100644 --- a/tests/integration/test_podman_compose_extends_w_file.py +++ b/tests/integration/test_podman_compose_extends_w_file.py @@ -29,8 +29,8 @@ def test_extends_w_file(self): # when file is Dockerfile for building the image compose_yaml_path(), "ps", ]) - self.assertIn("extends_w_file_web_1", str(output)) - self.assertIn("extends_w_file_important_web_1", str(output)) + self.assertIn("extends_w_file-web-1", str(output)) + self.assertIn("extends_w_file-important_web-1", str(output)) finally: self.run_subprocess_assert_returncode([ podman_compose_path(), diff --git a/tests/integration/test_podman_compose_extends_w_file_subdir.py b/tests/integration/test_podman_compose_extends_w_file_subdir.py index 4a8dfa3e..f0d1df01 100644 --- a/tests/integration/test_podman_compose_extends_w_file_subdir.py +++ b/tests/integration/test_podman_compose_extends_w_file_subdir.py @@ -29,7 +29,7 @@ def test_extends_w_file_subdir(self): # when file is Dockerfile for building th compose_yaml_path(), "ps", ]) - self.assertIn("extends_w_file_subdir_web_1", str(output)) + self.assertIn("extends_w_file_subdir-web-1", str(output)) finally: self.run_subprocess_assert_returncode([ podman_compose_path(), diff --git a/tests/integration/test_podman_compose_ipam_default.py b/tests/integration/test_podman_compose_ipam_default.py index 1cafb7a0..7534e91c 100644 --- a/tests/integration/test_podman_compose_ipam_default.py +++ b/tests/integration/test_podman_compose_ipam_default.py @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDt-License-Identifier: GPL-2.0 import json import os @@ -34,7 +34,7 @@ def test_ipam_default(self): [ "podman", "inspect", - "ipam_default_testipam_1", + "ipam_default-testipam-1", ], ) network_info = json.loads(output.decode('utf-8'))[0] diff --git a/tests/integration/test_podman_compose_multicompose.py b/tests/integration/test_podman_compose_multicompose.py index 339292a8..aacecfcf 100644 --- a/tests/integration/test_podman_compose_multicompose.py +++ b/tests/integration/test_podman_compose_multicompose.py @@ -38,14 +38,14 @@ def test_multicompose(self): os.path.join(os.path.join(test_path(), "multicompose"), "d2/docker-compose.yml"), "ps", ]) - self.assertIn(b"d1_web1_1", output) - self.assertIn(b"d1_web2_1", output) + self.assertIn(b"d1-web1-1", output) + self.assertIn(b"d1-web2-1", output) output, _ = self.run_subprocess_assert_returncode([ "podman", "exec", "-ti", - "d1_web1_1", + "d1-web1-1", "sh", "-c", "set", @@ -58,7 +58,7 @@ def test_multicompose(self): "podman", "exec", "-ti", - "d1_web2_1", + "d1-web2-1", "sh", "-c", "set", @@ -70,7 +70,7 @@ def test_multicompose(self): "podman", "exec", "-ti", - "d1_web1_1", + "d1-web1-1", "sh", "-c", "cat /var/www/html/index.txt", @@ -82,7 +82,7 @@ def test_multicompose(self): "podman", "exec", "-ti", - "d1_web2_1", + "d1-web2-1", "sh", "-c", "cat /var/www/html/index.txt", diff --git a/tests/integration/test_podman_compose_nets_test1.py b/tests/integration/test_podman_compose_nets_test1.py index 652ebce7..91df3ea0 100644 --- a/tests/integration/test_podman_compose_nets_test1.py +++ b/tests/integration/test_podman_compose_nets_test1.py @@ -34,8 +34,8 @@ def test_nets_test1(self): compose_yaml_path(), "ps", ]) - self.assertIn(b"nets_test1_web1_1", output) - self.assertIn(b"nets_test1_web2_1", output) + self.assertIn(b"nets_test1-web1-1", output) + self.assertIn(b"nets_test1-web2-1", output) response = requests.get('http://localhost:8001/index.txt') self.assertTrue(response.ok) @@ -49,7 +49,7 @@ def test_nets_test1(self): output, _ = self.run_subprocess_assert_returncode([ "podman", "inspect", - "nets_test1_web1_1", + "nets_test1-web1-1", ]) container_info = json.loads(output.decode('utf-8'))[0] diff --git a/tests/integration/test_podman_compose_nets_test2.py b/tests/integration/test_podman_compose_nets_test2.py index e9b0a8a5..774efc4a 100644 --- a/tests/integration/test_podman_compose_nets_test2.py +++ b/tests/integration/test_podman_compose_nets_test2.py @@ -34,8 +34,8 @@ def test_nets_test2(self): compose_yaml_path(), "ps", ]) - self.assertIn(b"nets_test2_web1_1", output) - self.assertIn(b"nets_test2_web2_1", output) + self.assertIn(b"nets_test2-web1-1", output) + self.assertIn(b"nets_test2-web2-1", output) response = requests.get('http://localhost:8001/index.txt') self.assertTrue(response.ok) @@ -49,13 +49,13 @@ def test_nets_test2(self): output, _ = self.run_subprocess_assert_returncode([ "podman", "inspect", - "nets_test2_web1_1", + "nets_test2-web1-1", ]) container_info = json.loads(output.decode('utf-8'))[0] # check if network got specific name from networks top-level element self.assertEqual( - list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2_mystack" + list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2-mystack" ) # check if Host port is the same as prodvided by the service port @@ -70,12 +70,12 @@ def test_nets_test2(self): output, _ = self.run_subprocess_assert_returncode([ "podman", "inspect", - "nets_test2_web2_1", + "nets_test2-web2-1", ]) container_info = json.loads(output.decode('utf-8'))[0] self.assertEqual( - list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2_mystack" + list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2-mystack" ) self.assertEqual( diff --git a/tests/integration/test_podman_compose_networks.py b/tests/integration/test_podman_compose_networks.py index de3982bc..a07363cc 100644 --- a/tests/integration/test_podman_compose_networks.py +++ b/tests/integration/test_podman_compose_networks.py @@ -63,8 +63,8 @@ def test_networks(self): '"{{.Names}}"', ] out, _ = self.run_subprocess_assert_returncode(check_cmd) - self.assertIn(b"nets_test_ip_web1_1", out) - self.assertIn(b"nets_test_ip_web2_1", out) + self.assertIn(b"nets_test_ip-web1-1", out) + self.assertIn(b"nets_test_ip-web2-1", out) expected_wget = { "172.19.1.10": "test1", diff --git a/tests/integration/test_podman_compose_tests.py b/tests/integration/test_podman_compose_tests.py index f5ac152e..8af5af32 100644 --- a/tests/integration/test_podman_compose_tests.py +++ b/tests/integration/test_podman_compose_tests.py @@ -200,7 +200,7 @@ def test_down_with_network(self): "-d", ]) output, _, _ = self.run_subprocess(["podman", "network", "ls"]) - self.assertIn("network_mystack", output.decode()) + self.assertIn("network-mystack", output.decode()) finally: self.run_subprocess_assert_returncode([ "coverage", @@ -211,4 +211,4 @@ def test_down_with_network(self): "down", ]) output, _, _ = self.run_subprocess(["podman", "network", "ls"]) - self.assertNotIn("network_mystack", output.decode()) + self.assertNotIn("network-mystack", output.decode())