From 1d972ef174ce48cd6aae5a9bd948d0962be8a13d Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Fri, 11 Feb 2022 01:15:02 +0100 Subject: [PATCH] Propagate all bind-type mount options Before this commit, adding multiple options to a bind-type mount (e.g. /foo/bar:/baz:Z,U) would result in a podman command in which only the last option would be used (e.g. U). This is because when parsing the mount string, a loop would go over each mount option and assign it to mount_opt_dict, this meant that this dict was overridden for each option, thus only the last option in the mount string would be kept and passed onto podman. This commit solves this by appending to a temporary list and then converting it to a comma-separated string and assigning it to the mount_opt_dict. Fixes #412 Signed-off-by: Adrian Torres --- podman_compose.py | 5 ++++- test_volumes.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test_volumes.py diff --git a/podman_compose.py b/podman_compose.py index df2de31..8915119 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -116,15 +116,18 @@ def parse_short_mount(mount_str, basedir): # - datavolume:/var/lib/mysql mount_type = "volume" mount_opts = filteri((mount_opt or '').split(',')) + propagation_opts = [] for opt in mount_opts: if opt == 'ro': mount_opt_dict["read_only"] = True elif opt == 'rw': mount_opt_dict["read_only"] = False elif opt in ('consistent', 'delegated', 'cached'): mount_opt_dict["consistency"] = opt - elif propagation_re.match(opt): mount_opt_dict["bind"] = dict(propagation=opt) + elif propagation_re.match(opt): + propagation_opts.append(opt) else: # TODO: ignore raise ValueError("unknown mount option "+opt) + mount_opt_dict["bind"] = dict(propagation=','.join(propagation_opts)) return dict(type=mount_type, source=mount_src, target=mount_dst, **mount_opt_dict) # NOTE: if a named volume is used but not defined it diff --git a/test_volumes.py b/test_volumes.py new file mode 100644 index 0000000..810ede3 --- /dev/null +++ b/test_volumes.py @@ -0,0 +1,19 @@ +import pytest + +from podman_compose import parse_short_mount + +@pytest.fixture +def multi_propagation_mount_str(): + return "/foo/bar:/baz:U,Z" + + +def test_parse_short_mount_multi_propagation(multi_propagation_mount_str): + expected = { + "type": "bind", + "source": "/foo/bar", + "target": "/baz", + "bind": { + "propagation": "U,Z", + }, + } + assert parse_short_mount(multi_propagation_mount_str, "/") == expected