]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util add an OSDPath argument validator
authorAlfredo Deza <adeza@redhat.com>
Fri, 3 Nov 2017 18:35:03 +0000 (14:35 -0400)
committerAlfredo Deza <adeza@redhat.com>
Mon, 13 Nov 2017 15:20:10 +0000 (10:20 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit a826fdf4a2ed9ff704fb823d05d3cb706ba89e38)

src/ceph-volume/ceph_volume/util/arg_validators.py

index 75ba5579e0befad5bd72e9a30c377cc0d84b4157..6a2ff956e8586bee32a890d77fc372090b28733a 100644 (file)
@@ -1,5 +1,7 @@
 import argparse
 import os
+from ceph_volume import terminal
+from ceph_volume.util import disk
 
 
 class LVPath(object):
@@ -36,3 +38,34 @@ class LVPath(object):
         if error:
             raise argparse.ArgumentError(None, error)
         return string
+
+
+class OSDPath(object):
+    """
+    Validate path exists and it looks like an OSD directory.
+    """
+
+    def __call__(self, string):
+        if not os.path.exists(string):
+            error = "Path does not exist: %s" % string
+            raise argparse.ArgumentError(None, error)
+
+        arg_is_partition = disk.is_partition(string)
+        if arg_is_partition:
+            return string
+        absolute_path = os.path.abspath(string)
+        if not os.path.isdir(absolute_path):
+            error = "Argument is not a directory or device which is required to scan"
+            raise argparse.ArgumentError(None, error)
+        key_files = ['ceph_fsid', 'fsid', 'keyring', 'ready', 'type', 'whoami']
+        dir_files = os.listdir(absolute_path)
+        for key_file in key_files:
+            if key_file not in dir_files:
+                terminal.error('All following files must exist in path: %s' % ' '.join(key_files))
+                error = "Required file (%s) was not found in OSD dir path: %s" % (
+                    key_file,
+                    absolute_path
+                )
+                raise argparse.ArgumentError(None, error)
+
+        return string