Skip to content

Commit

Permalink
Add support for disable_dns, dns and ignore on network creation
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Guterres Jeffman <[email protected]>
  • Loading branch information
rjeffman committed Jan 11, 2025
1 parent 84f1fbd commit 19ce283
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions newsfragments/network-creation-fields-support.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for disable_dns, dns and ignore on network creation.
6 changes: 6 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,12 @@ def get_network_create_args(net_desc, proj_name, net_name):
ipam_config_ls = ipam.get("config", [])
if net_desc.get("enable_ipv6"):
args.append("--ipv6")
if net_desc.get("ignore"):
args.append("--ignore")
if net_desc.get("disable_dns"):
args.append("--disable-dns")
if net_desc.get("dns"):
args.extend(("--dns", ",".join(norm_as_list(net_desc.get("dns")))))

if isinstance(ipam_config_ls, dict):
ipam_config_ls = [ipam_config_ls]
Expand Down
98 changes: 98 additions & 0 deletions tests/unit/test_get_network_create_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,101 @@ def test_complete(self):
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

def test_ignore(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": False,
"ignore": True,
}
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}",
"--ignore",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

def test_disable_dns(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": False,
"disable_dns": True,
}
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}",
"--disable-dns",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

def test_dns_string(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": False,
"dns": "192.168.1.2",
}
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}",
"--dns",
"192.168.1.2",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

def test_dns_list(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": False,
"dns": ["192.168.1.2", "192.168.1.3"],
}
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}",
"--dns",
"192.168.1.2,192.168.1.3",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

0 comments on commit 19ce283

Please sign in to comment.