From 6bd226a3b4d37627bf9f039133de7792af3e9710 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 22 Feb 2018 13:47:11 -0500 Subject: [PATCH] ceph-volume util.prepare normalize mount flags for CLI Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/util/prepare.py | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index da9375fb7b3..3e1a77f90ad 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -144,6 +144,34 @@ def format_device(device): process.run(command) +def _normalize_mount_flags(flags): + """ + Mount flag options have to be a single string, separated by a comma. If the + flags are separated by spaces, or with commas and spaces in ceph.conf, the + mount options will be passed incorrectly. + + This will help when parsing ceph.conf values return something like:: + + ["rw,", "exec,"] + + Or:: + + [" rw ,", "exec"] + + :param flags: A list of flags, or a single string of mount flags + """ + if isinstance(flags, list): + # ensure that spaces and commas are removed so that they can join + # correctly + return ','.join([f.strip().strip(',') for f in flags if f]) + + # split them, clean them, and join them back again + flags = flags.strip().split(' ') + return ','.join( + [f.strip().strip(',') for f in flags if f] + ) + + def mount_osd(device, osd_id): destination = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id) command = ['mount', '-t', 'xfs', '-o'] @@ -153,7 +181,7 @@ def mount_osd(device, osd_id): default=constants.mount.get('xfs'), split=' ', ) - command.extend(flags) + command.append(_normalize_mount_flags(flags)) command.append(device) command.append(destination) process.run(command) -- 2.39.5