]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: combine the LVPath arg validator with ValidDevice
authorAndrew Schoen <aschoen@redhat.com>
Tue, 13 Nov 2018 18:28:23 +0000 (12:28 -0600)
committerAlfredo Deza <adeza@redhat.com>
Wed, 14 Nov 2018 20:06:16 +0000 (15:06 -0500)
This combines the two arg validators and makes both batch and
prepare/active both use ValidDevice.

This will also allow us to use lvs with a full path, like
/dev/vg/lv instead of always enforcing vg/lv.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
Resolves: rm#27062
(cherry picked from commit d6a5a7606c3a0c1f1624c5784abb02bb1a4e1620)

src/ceph-volume/ceph_volume/devices/lvm/common.py
src/ceph-volume/ceph_volume/util/arg_validators.py

index 0253ce1b2a583d538016ce4480df9de5b6815b0c..f9f475e96c4838ed064ba463b2fdf3996f50ff0c 100644 (file)
@@ -52,7 +52,7 @@ def common_parser(prog, description):
     required_group.add_argument(
         '--data',
         required=True,
-        type=arg_validators.LVPath(),
+        type=arg_validators.ValidDevice(as_string=True),
         help='OSD data path. A physical device or logical volume',
     )
 
index d0144fc58de30d7301143acff5c740e58d057cc4..d13ed878048747d2bc271d058b618c6864cf8a9c 100644 (file)
@@ -6,51 +6,24 @@ from ceph_volume.util import disk
 from ceph_volume.util.device import Device
 
 
-class LVPath(object):
-    """
-    A simple validator to ensure that a logical volume is specified like::
-
-        <vg name>/<lv name>
-
-    Or a full path to a device, like ``/dev/sda``
+class ValidDevice(object):
 
-    Because for LVM it is better to be specific on what group does an lv
-    belongs to.
-    """
+    def __init__(self, as_string=False):
+        self.as_string = as_string
 
     def __call__(self, string):
+        device = Device(string)
         error = None
-        if string.startswith('/'):
-            if not os.path.exists(string):
-                error = "Argument (device) does not exist: %s" % string
-                raise argparse.ArgumentError(None, error)
-            else:
-                return string
-        try:
-            vg, lv = string.split('/')
-        except ValueError:
-            error = "Logical volume must be specified as 'volume_group/logical_volume' but got: %s" % string
-            raise argparse.ArgumentError(None, error)
-
-        if not vg:
-            error = "Didn't specify a volume group like 'volume_group/logical_volume', got: %s" % string
-        if not lv:
-            error = "Didn't specify a logical volume like 'volume_group/logical_volume', got: %s" % string
+        if not device.exists:
+            error = "Unable to proceed with non-existing device: %s" % string
+        elif device.has_gpt_headers:
+            error = "GPT headers found, they must be removed on: %s" % string
 
         if error:
             raise argparse.ArgumentError(None, error)
-        return string
-
-
-class ValidDevice(object):
-
-    def __call__(self, string):
-        device = Device(string)
-        if not device.exists:
-            raise argparse.ArgumentError(
-                None, "Unable to proceed with non-existing device: %s" % string
-            )
 
+        if self.as_string:
+            return string
         return device