]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-volume: data_allocate_fraction: new validation class
authorJonas Pfefferle <pepperjo@japf.ch>
Thu, 3 Jun 2021 07:44:16 +0000 (09:44 +0200)
committerJonas Pfefferle <pepperjo@japf.ch>
Thu, 3 Jun 2021 07:44:16 +0000 (09:44 +0200)
Move validator for data_allocate_fraction to utils.arg_validators

Signed-off-by: Jonas Pfefferle <pepperjo@japf.ch>
src/ceph-volume/ceph_volume/devices/lvm/batch.py
src/ceph-volume/ceph_volume/util/arg_validators.py

index 94ab26888ea67d571573798f52d5b220f73e22ee..d953b1ac599bc09d0ca0900404138d0f85d53c08 100644 (file)
@@ -1,7 +1,6 @@
 import argparse
 from collections import namedtuple
 import json
-import math
 import logging
 from textwrap import dedent
 from ceph_volume import terminal, decorators
@@ -270,14 +269,9 @@ class Batch(object):
                   ' if more slots then osds-per-device are specified, slots'
                   'will stay unoccupied'),
         )
-        def data_allocate_fraction(pct):
-            pct_float = float(pct)
-            if math.isnan(pct_float) or pct_float == 0.0  or pct_float < 0.0 or pct_float > 1.0:
-                raise argparse.ArgumentTypeError('Percentage not in (0,1.0]')
-            return pct_float
         parser.add_argument(
             '--data-allocate-fraction',
-            type=data_allocate_fraction,
+            type=arg_validators.ValidFraction(),
             help='Fraction to allocate from data device (0,1.0]',
             default=1.0
         )
index 94cb4f691dbee180a0f095b95c989a32f8f1945f..e04e2018834e53793e590cb943b25b199aade5a3 100644 (file)
@@ -1,5 +1,6 @@
 import argparse
 import os
+import math
 from ceph_volume import terminal
 from ceph_volume import decorators
 from ceph_volume.util import disk
@@ -148,3 +149,14 @@ def exclude_group_options(parser, groups, argv=None):
                     terminal.warning(msg)
             last_group = group_name
         last_flag = flag
+
+class ValidFraction(object):
+    """
+    Validate fraction is in (0, 1.0]
+    """
+
+    def __call__(self, fraction):
+        fraction_float = float(fraction)
+        if math.isnan(fraction_float) or fraction_float <= 0.0 or fraction_float > 1.0:
+            raise argparse.ArgumentTypeError('Fraction not in (0,1.0]')
+        return fraction_float