]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util.prepare normalize mount flags for CLI
authorAlfredo Deza <adeza@redhat.com>
Thu, 22 Feb 2018 18:47:11 +0000 (13:47 -0500)
committerAlfredo Deza <adeza@redhat.com>
Thu, 22 Feb 2018 21:19:54 +0000 (16:19 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/util/prepare.py

index da9375fb7b322c133720c3dad1d97e0ba871ae80..3e1a77f90add0e6776a252c05e3bf1fa5d7154aa 100644 (file)
@@ -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)