Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ipam_driver): do not pass --ipam-driver option when value set to … #851

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
44 changes: 40 additions & 4 deletions pytests/test_get_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"]