From c23a8b2cbdd961ab2975d93803351eb2281ba2e8 Mon Sep 17 00:00:00 2001 From: fccagou Date: Sat, 9 Mar 2024 12:36:43 +0100 Subject: [PATCH] Do not pass --ipam-driver option when value set to default fixes #852. Signed-off-by: fccagou --- podman_compose.py | 2 +- pytests/test_get_network_create_args.py | 44 ++++++++++++++++++++++--- tests/ipam_default/docker-compose.yaml | 15 +++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 tests/ipam_default/docker-compose.yaml diff --git a/podman_compose.py b/podman_compose.py index daba7fb..1f9b48e 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -734,7 +734,7 @@ def get_network_create_args(net_desc, proj_name, net_name): args.extend(("--opt", f"{key}={value}")) ipam = net_desc.get("ipam", None) or {} ipam_driver = ipam.get("driver", None) - if ipam_driver: + if ipam_driver and ipam_driver != "default": args.extend(("--ipam-driver", ipam_driver)) ipam_config_ls = ipam.get("config", None) or [] if net_desc.get("enable_ipv6", None): diff --git a/pytests/test_get_network_create_args.py b/pytests/test_get_network_create_args.py index c2ab119..55d3021 100644 --- a/pytests/test_get_network_create_args.py +++ b/pytests/test_get_network_create_args.py @@ -77,7 +77,7 @@ class TestGetNetworkCreateArgs(unittest.TestCase): args = get_network_create_args(net_desc, proj_name, net_name) self.assertEqual(args, expected_args) - def test_ipam_driver(self): + def test_ipam_driver_default(self): net_desc = { "labels": [], "internal": False, @@ -96,6 +96,42 @@ class TestGetNetworkCreateArgs(unittest.TestCase): } proj_name = "test_project" net_name = "test_network" + expected_args = [ + "create", + "--label", + f"io.podman.compose.project={proj_name}", + "--label", + f"com.docker.compose.project={proj_name}", + "--subnet", + "192.168.0.0/24", + "--ip-range", + "192.168.0.2/24", + "--gateway", + "192.168.0.1", + net_name, + ] + args = get_network_create_args(net_desc, proj_name, net_name) + self.assertEqual(args, expected_args) + + def test_ipam_driver(self): + net_desc = { + "labels": [], + "internal": False, + "driver": None, + "driver_opts": {}, + "ipam": { + "driver": "someipamdriver", + "config": [ + { + "subnet": "192.168.0.0/24", + "ip_range": "192.168.0.2/24", + "gateway": "192.168.0.1", + } + ], + }, + } + proj_name = "test_project" + net_name = "test_network" expected_args = [ "create", "--label", @@ -103,7 +139,7 @@ class TestGetNetworkCreateArgs(unittest.TestCase): "--label", f"com.docker.compose.project={proj_name}", "--ipam-driver", - "default", + "someipamdriver", "--subnet", "192.168.0.0/24", "--ip-range", @@ -122,7 +158,7 @@ class TestGetNetworkCreateArgs(unittest.TestCase): "driver": "bridge", "driver_opts": {"opt1": "value1", "opt2": "value2"}, "ipam": { - "driver": "default", + "driver": "someipamdriver", "config": [ { "subnet": "192.168.0.0/24", @@ -153,7 +189,7 @@ class TestGetNetworkCreateArgs(unittest.TestCase): "--opt", "opt2=value2", "--ipam-driver", - "default", + "someipamdriver", "--ipv6", "--subnet", "192.168.0.0/24", diff --git a/tests/ipam_default/docker-compose.yaml b/tests/ipam_default/docker-compose.yaml new file mode 100644 index 0000000..311c41b --- /dev/null +++ b/tests/ipam_default/docker-compose.yaml @@ -0,0 +1,15 @@ +version: '3' + +# --ipam-driver must not be pass when driver is "default" +networks: + ipam_test_default: + ipam: + driver: default + config: + - subnet: 172.19.0.0/24 + +services: + testipam: + image: busybox + command: ["echo", "ipamtest"] +