]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util normalize comma with dot for str-to-int conversion
authorAlfredo Deza <adeza@redhat.com>
Fri, 21 Dec 2018 20:24:25 +0000 (15:24 -0500)
committerAlfredo Deza <adeza@redhat.com>
Thu, 3 Jan 2019 18:45:00 +0000 (13:45 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit aa5323fbcfdc6c21177cb800884712b0252b84a0)

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

index cdcf3a5b0d9cb1d85dde52c3214a281aa1fa11c7..db6e8c72451dc0a8bf1aa331c01f511b64676194 100644 (file)
@@ -31,10 +31,21 @@ def str_to_int(string, round_down=True):
     """
     Parses a string number into an integer, optionally converting to a float
     and rounding down.
+
+    Some LVM values may come with a comma instead of a dot to define decimals.
+    This function normalizes a comma into a dot
     """
     error_msg = "Unable to convert to integer: '%s'" % str(string)
     try:
-        integer = float(string)
+        integer = float(string.replace(',', '.'))
+    except AttributeError:
+        # this might be a integer already, so try to use it, otherwise raise
+        # the original exception
+        if isinstance(string, (int, float)):
+            integer = string
+        else:
+            logger.exception(error_msg)
+            raise RuntimeError(error_msg)
     except (TypeError, ValueError):
         logger.exception(error_msg)
         raise RuntimeError(error_msg)