Skip to content

Commit 1d1bae9

Browse files
committed
Add fake "podman network exists" command
Motivation: podman-compose uses the "podman network exists" command to avoid creating the same network twice. This command was added with podman v3.1.0. Debian stable has an older version of podman (v3.0.1) that doesn't support the "podman network exists" command. A symptom of this problem is podman-compose failing with lines like: subprocess.CalledProcessError: Command '['podman', 'network', 'exists', 'scicatlive_default']' returned non-zero exit status 125. During handling of the above exception, another exception occurred: [...] subprocess.CalledProcessError: Command '['podman', 'network', 'create', '--labelect=scicatlive', 'scicatlive_default']' returned non-zero exit status 125. Modification: Abstract the two places where podman-compose checks if a network already exists. This is now handled by a specific method. Check the podman version. If the podman version is earlier than v3.1.0 then simulate the "podman network exists" command by parsing the output from "podman network ls", otherwise simply call the "podman network exists" command directly. Result: podman-compose is now able to create a network with versions of podman before v3.1.0. Signed-off-by: Paul Millar <paul.millar@desy.de>
1 parent 08ffcf6 commit 1d1bae9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

podman_compose.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from threading import Thread
2727

2828
import shlex
29+
import semantic_version as sv
2930

3031
try:
3132
from shlex import quote as cmd_quote
@@ -669,6 +670,22 @@ def norm_ports(ports_in):
669670
ports_out.append(port)
670671
return ports_out
671672

673+
def assert_network_exists(compose, net_name):
674+
podman_version = sv.Version(compose.podman_version)
675+
if sv.SimpleSpec('<3.1.0').match(podman_version):
676+
output = compose.podman.output([], "network", ["ls"])
677+
offset = None
678+
for raw_line in output.splitlines():
679+
line = raw_line.decode("utf-8")
680+
if not offset:
681+
offset = line.find("VERSION")
682+
else:
683+
this_net_name = line[:offset].rstrip()
684+
if (this_net_name == net_name):
685+
return ''
686+
raise subprocess.CalledProcessError(1, "docker network exists " + net_name)
687+
else:
688+
return compose.podman.output([], "network", ["exists", net_name])
672689

673690
def assert_cnt_nets(compose, cnt):
674691
"""
@@ -693,7 +710,7 @@ def assert_cnt_nets(compose, cnt):
693710
ext_desc.get("name", None) or net_desc.get("name", None) or default_net_name
694711
)
695712
try:
696-
compose.podman.output([], "network", ["exists", net_name])
713+
assert_network_exists(compose, net_name)
697714
except subprocess.CalledProcessError as e:
698715
if is_ext:
699716
raise RuntimeError(
@@ -735,7 +752,7 @@ def assert_cnt_nets(compose, cnt):
735752
args.extend(("--gateway", gateway))
736753
args.append(net_name)
737754
compose.podman.output([], "network", args)
738-
compose.podman.output([], "network", ["exists", net_name])
755+
assert_network_exists(compose, net_name)
739756

740757

741758
def get_net_args(compose, cnt):

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
pyyaml
66
python-dotenv
7+
semantic-version
78

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
install_requires=[
3535
"pyyaml",
3636
"python-dotenv",
37+
"semantic-version",
3738
],
3839
# test_suite='tests',
3940
# tests_require=[

0 commit comments

Comments
 (0)