Skip to content

Commit

Permalink
fixes #852: do not pass --ipam-driver option when value set to default
Browse files Browse the repository at this point in the history
  • Loading branch information
fccagou committed Mar 9, 2024
1 parent 121b5f6 commit 7b8cebc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,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):
Expand Down
44 changes: 40 additions & 4 deletions pytests/test_network_create_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_bridge(self):
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,
Expand All @@ -96,14 +96,50 @@ def test_ipam_driver(self):
}
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",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
"--ipam-driver",
"default",
"someipamdriver",
"--subnet",
"192.168.0.0/24",
"--ip-range",
Expand All @@ -122,7 +158,7 @@ def test_complete(self):
"driver": "bridge",
"driver_opts": {"opt1": "value1", "opt2": "value2"},
"ipam": {
"driver": "default",
"driver": "someipamdriver",
"config": [
{
"subnet": "192.168.0.0/24",
Expand Down Expand Up @@ -153,7 +189,7 @@ def test_complete(self):
"--opt",
"opt2=value2",
"--ipam-driver",
"default",
"someipamdriver",
"--ipv6",
"--subnet",
"192.168.0.0/24",
Expand Down
15 changes: 15 additions & 0 deletions tests/ipam_default/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 7b8cebc

Please sign in to comment.