From f023c669fe4bca8475cd5a25e6a81ad51273df9c Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Thu, 7 Oct 2021 10:49:25 +0200 Subject: [PATCH] cephadm: shell --mount shouldnt enforce ':z' option cephadm shouldn't enforce this option. For instance, it can be an issue when you try to bindmount a file in /usr Fixes: https://tracker.ceph.com/issues/52853 Signed-off-by: Guillaume Abrioux (cherry picked from commit aeae360e2595f348f10ddc36cdb270b018f7eb02) --- src/cephadm/cephadm | 6 ++++-- src/cephadm/tests/test_cephadm.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 7e367993ec70e..20627916844c1 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -4638,10 +4638,12 @@ def command_shell(ctx): mount = pathify(split_src_dst[0]) filename = os.path.basename(split_src_dst[0]) if len(split_src_dst) > 1: - dst = split_src_dst[1] + ':z' if len(split_src_dst) == 3 else split_src_dst[1] + dst = split_src_dst[1] + if len(split_src_dst) == 3: + dst = '{}:{}'.format(dst, split_src_dst[2]) mounts[mount] = dst else: - mounts[mount] = '/mnt/{}:z'.format(filename) + mounts[mount] = '/mnt/{}'.format(filename) if ctx.command: command = ctx.command else: diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 4c8f573d0f6bf..c4c902a68b5df 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1384,6 +1384,29 @@ class TestShell(object): assert retval == 0 assert ctx.keyring == 'foo' + @mock.patch('cephadm.CephContainer') + def test_mount_no_dst(self, m_ceph_container, cephadm_fs): + cmd = ['shell', '--mount', '/etc/foo'] + with with_cephadm_ctx(cmd) as ctx: + retval = cd.command_shell(ctx) + assert retval == 0 + assert m_ceph_container.call_args.kwargs['volume_mounts']['/etc/foo'] == '/mnt/foo' + + @mock.patch('cephadm.CephContainer') + def test_mount_with_dst_no_opt(self, m_ceph_container, cephadm_fs): + cmd = ['shell', '--mount', '/etc/foo:/opt/foo/bar'] + with with_cephadm_ctx(cmd) as ctx: + retval = cd.command_shell(ctx) + assert retval == 0 + assert m_ceph_container.call_args.kwargs['volume_mounts']['/etc/foo'] == '/opt/foo/bar' + + @mock.patch('cephadm.CephContainer') + def test_mount_with_dst_and_opt(self, m_ceph_container, cephadm_fs): + cmd = ['shell', '--mount', '/etc/foo:/opt/foo/bar:Z'] + with with_cephadm_ctx(cmd) as ctx: + retval = cd.command_shell(ctx) + assert retval == 0 + assert m_ceph_container.call_args.kwargs['volume_mounts']['/etc/foo'] == '/opt/foo/bar:Z' class TestCephVolume(object): -- 2.39.5