mirror of
https://github.com/containers/podman-compose.git
synced 2025-06-20 11:47:50 +02:00
use preferred format of podman command line options
Specifically: - use "--network=foo" instead of "--network foo" - specify "--network-alias" multiple times instead of concatenating values Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
This commit is contained in:
parent
bdff78dcba
commit
9baea704d7
@ -786,18 +786,18 @@ def get_net_args(compose, cnt):
|
|||||||
if net == "none":
|
if net == "none":
|
||||||
is_bridge = False
|
is_bridge = False
|
||||||
elif net == "host":
|
elif net == "host":
|
||||||
net_args.extend(["--network", net])
|
net_args.append(f"--network={net}")
|
||||||
elif net.startswith("slirp4netns:"):
|
elif net.startswith("slirp4netns:"):
|
||||||
net_args.extend(["--network", net])
|
net_args.append(f"--network={net}")
|
||||||
elif net.startswith("ns:"):
|
elif net.startswith("ns:"):
|
||||||
net_args.extend(["--network", net])
|
net_args.append(f"--network={net}")
|
||||||
elif net.startswith("service:"):
|
elif net.startswith("service:"):
|
||||||
other_srv = net.split(":", 1)[1].strip()
|
other_srv = net.split(":", 1)[1].strip()
|
||||||
other_cnt = compose.container_names_by_service[other_srv][0]
|
other_cnt = compose.container_names_by_service[other_srv][0]
|
||||||
net_args.extend(["--network", f"container:{other_cnt}"])
|
net_args.append(f"--network=container:{other_cnt}")
|
||||||
elif net.startswith("container:"):
|
elif net.startswith("container:"):
|
||||||
other_cnt = net.split(":", 1)[1].strip()
|
other_cnt = net.split(":", 1)[1].strip()
|
||||||
net_args.extend(["--network", f"container:{other_cnt}"])
|
net_args.append(f"--network=container:{other_cnt}")
|
||||||
elif net.startswith("bridge"):
|
elif net.startswith("bridge"):
|
||||||
is_bridge = True
|
is_bridge = True
|
||||||
else:
|
else:
|
||||||
@ -905,12 +905,15 @@ def get_net_args(compose, cnt):
|
|||||||
net_options.append(f"mac={mac}")
|
net_options.append(f"mac={mac}")
|
||||||
|
|
||||||
if net_options:
|
if net_options:
|
||||||
net_args.extend(["--network", f"{net_name}:" + ",".join(net_options)])
|
net_args.append(f"--network={net_name}:" + ",".join(net_options))
|
||||||
else:
|
else:
|
||||||
net_args.extend(["--network", f"{net_name}"])
|
net_args.append(f"--network={net_name}")
|
||||||
else:
|
else:
|
||||||
if is_bridge:
|
if is_bridge:
|
||||||
net_args.extend(["--network", net_names_str])
|
if net_names_str:
|
||||||
|
net_args.append(f"--network={net_names_str}")
|
||||||
|
else:
|
||||||
|
net_args.append("--network=bridge")
|
||||||
if ip:
|
if ip:
|
||||||
net_args.append(f"--ip={ip}")
|
net_args.append(f"--ip={ip}")
|
||||||
if ip6:
|
if ip6:
|
||||||
@ -919,7 +922,8 @@ def get_net_args(compose, cnt):
|
|||||||
net_args.append(f"--mac-address={mac_address}")
|
net_args.append(f"--mac-address={mac_address}")
|
||||||
|
|
||||||
if is_bridge:
|
if is_bridge:
|
||||||
net_args.extend(["--network-alias", ",".join(aliases)])
|
for alias in aliases:
|
||||||
|
net_args.extend([f"--network-alias={alias}"])
|
||||||
|
|
||||||
return net_args
|
return net_args
|
||||||
|
|
||||||
|
@ -37,10 +37,8 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||||||
[
|
[
|
||||||
"--name=project_name_service_name1",
|
"--name=project_name_service_name1",
|
||||||
"-d",
|
"-d",
|
||||||
"--network",
|
"--network=bridge",
|
||||||
"",
|
"--network-alias=service_name",
|
||||||
"--network-alias",
|
|
||||||
"service_name",
|
|
||||||
"busybox",
|
"busybox",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -57,10 +55,8 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||||||
[
|
[
|
||||||
"--name=project_name_service_name1",
|
"--name=project_name_service_name1",
|
||||||
"-d",
|
"-d",
|
||||||
"--network",
|
"--network=bridge",
|
||||||
"",
|
"--network-alias=service_name",
|
||||||
"--network-alias",
|
|
||||||
"service_name",
|
|
||||||
"--runtime",
|
"--runtime",
|
||||||
"runsc",
|
"runsc",
|
||||||
"busybox",
|
"busybox",
|
||||||
@ -82,10 +78,8 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||||||
[
|
[
|
||||||
"--name=project_name_service_name1",
|
"--name=project_name_service_name1",
|
||||||
"-d",
|
"-d",
|
||||||
"--network",
|
"--network=bridge",
|
||||||
"",
|
"--network-alias=service_name",
|
||||||
"--network-alias",
|
|
||||||
"service_name",
|
|
||||||
"--sysctl",
|
"--sysctl",
|
||||||
"net.core.somaxconn=1024",
|
"net.core.somaxconn=1024",
|
||||||
"--sysctl",
|
"--sysctl",
|
||||||
@ -109,10 +103,8 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||||||
[
|
[
|
||||||
"--name=project_name_service_name1",
|
"--name=project_name_service_name1",
|
||||||
"-d",
|
"-d",
|
||||||
"--network",
|
"--network=bridge",
|
||||||
"",
|
"--network-alias=service_name",
|
||||||
"--network-alias",
|
|
||||||
"service_name",
|
|
||||||
"--sysctl",
|
"--sysctl",
|
||||||
"net.core.somaxconn=1024",
|
"net.core.somaxconn=1024",
|
||||||
"--sysctl",
|
"--sysctl",
|
||||||
@ -143,10 +135,8 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||||||
[
|
[
|
||||||
"--name=project_name_service_name1",
|
"--name=project_name_service_name1",
|
||||||
"-d",
|
"-d",
|
||||||
"--network",
|
"--network=bridge",
|
||||||
"",
|
"--network-alias=service_name",
|
||||||
"--network-alias",
|
|
||||||
"service_name",
|
|
||||||
"--pid",
|
"--pid",
|
||||||
"host",
|
"host",
|
||||||
"busybox",
|
"busybox",
|
||||||
@ -166,10 +156,8 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||||||
"--name=project_name_service_name1",
|
"--name=project_name_service_name1",
|
||||||
"-d",
|
"-d",
|
||||||
"--http-proxy=false",
|
"--http-proxy=false",
|
||||||
"--network",
|
"--network=bridge",
|
||||||
"",
|
"--network-alias=service_name",
|
||||||
"--network-alias",
|
|
||||||
"service_name",
|
|
||||||
"busybox",
|
"busybox",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -38,13 +38,22 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
def test_minimal(self):
|
def test_minimal(self):
|
||||||
compose = get_networked_compose()
|
compose = get_networked_compose()
|
||||||
container = get_minimal_container()
|
container = get_minimal_container()
|
||||||
|
|
||||||
|
expected_args = [
|
||||||
|
"--network=bridge",
|
||||||
|
f"--network-alias={SERVICE_NAME}",
|
||||||
|
]
|
||||||
|
args = get_net_args(compose, container)
|
||||||
|
self.assertListEqual(expected_args, args)
|
||||||
|
|
||||||
|
def test_one_net(self):
|
||||||
|
compose = get_networked_compose()
|
||||||
|
container = get_minimal_container()
|
||||||
container["networks"] = {"net0": {}}
|
container["networks"] = {"net0": {}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -56,10 +65,10 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["_aliases"] = ["alias1", "alias2"]
|
container["_aliases"] = ["alias1", "alias2"]
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
"--network-alias",
|
"--network-alias=alias1",
|
||||||
f"{SERVICE_NAME},alias1,alias2",
|
"--network-alias=alias2",
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -71,11 +80,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["networks"] = {"net0": {"ipv4_address": ip}}
|
container["networks"] = {"net0": {"ipv4_address": ip}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--ip={ip}",
|
||||||
"--ip=" + ip,
|
f"--network-alias={SERVICE_NAME}",
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertEqual(expected_args, args)
|
self.assertEqual(expected_args, args)
|
||||||
@ -87,11 +94,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["networks"] = {"net0": {"ipv6_address": ipv6_address}}
|
container["networks"] = {"net0": {"ipv6_address": ipv6_address}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--ip6={ipv6_address}",
|
||||||
"--ip6=" + ipv6_address,
|
f"--network-alias={SERVICE_NAME}",
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -104,11 +109,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["mac_address"] = mac
|
container["mac_address"] = mac
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--mac-address={mac}",
|
||||||
"--mac-address=" + mac,
|
f"--network-alias={SERVICE_NAME}",
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -121,12 +124,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["mac_address"] = mac
|
container["mac_address"] = mac
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0:mac={mac}",
|
||||||
f"{PROJECT_NAME}_net0:mac={mac}",
|
f"--network={PROJECT_NAME}_net1",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net1",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -137,12 +137,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["networks"] = {"net0": {}, "net1": {}}
|
container["networks"] = {"net0": {}, "net1": {}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--network={PROJECT_NAME}_net1",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net1",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -153,12 +150,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["networks"] = ["net0", "net1"]
|
container["networks"] = ["net0", "net1"]
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0",
|
||||||
f"{PROJECT_NAME}_net0",
|
f"--network={PROJECT_NAME}_net1",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net1",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -171,12 +165,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["networks"] = {"net0": {"ipv4_address": ip0}, "net1": {"ipv4_address": ip1}}
|
container["networks"] = {"net0": {"ipv4_address": ip0}, "net1": {"ipv4_address": ip1}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0:ip={ip0}",
|
||||||
f"{PROJECT_NAME}_net0:ip={ip0}",
|
f"--network={PROJECT_NAME}_net1:ip={ip1}",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net1:ip={ip1}",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -189,12 +180,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["networks"] = {"net0": {"ipv6_address": ip0}, "net1": {"ipv6_address": ip1}}
|
container["networks"] = {"net0": {"ipv6_address": ip0}, "net1": {"ipv6_address": ip1}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0:ip={ip0}",
|
||||||
f"{PROJECT_NAME}_net0:ip={ip0}",
|
f"--network={PROJECT_NAME}_net1:ip={ip1}",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net1:ip={ip1}",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -211,12 +199,9 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0:mac={mac0}",
|
||||||
f"{PROJECT_NAME}_net0:mac={mac0}",
|
f"--network={PROJECT_NAME}_net1:mac={mac1}",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net1:mac={mac1}",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
@ -259,16 +244,11 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
container["mac_address"] = mac
|
container["mac_address"] = mac
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net0:ip={ip4_0},ip={ip6_0},mac={mac}",
|
||||||
f"{PROJECT_NAME}_net0:ip={ip4_0},ip={ip6_0},mac={mac}",
|
f"--network={PROJECT_NAME}_net1:ip={ip4_1}",
|
||||||
"--network",
|
f"--network={PROJECT_NAME}_net2:ip={ip6_2}",
|
||||||
f"{PROJECT_NAME}_net1:ip={ip4_1}",
|
f"--network={PROJECT_NAME}_net3",
|
||||||
"--network",
|
f"--network-alias={SERVICE_NAME}",
|
||||||
f"{PROJECT_NAME}_net2:ip={ip6_2}",
|
|
||||||
"--network",
|
|
||||||
f"{PROJECT_NAME}_net3",
|
|
||||||
"--network-alias",
|
|
||||||
SERVICE_NAME,
|
|
||||||
]
|
]
|
||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user