]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/rook: fix convert_size method in DefaultFetcher
authorJoseph Sawaya <jsawaya@redhat.com>
Wed, 11 Aug 2021 15:01:25 +0000 (11:01 -0400)
committerJoseph Sawaya <jsawaya@redhat.com>
Tue, 17 Aug 2021 14:50:27 +0000 (10:50 -0400)
This commit fixes the convert_size method by getting it
to use the re python module to split the digits and letters
to support all units a PV could be expressed in.

Signed-off-by: Joseph Sawaya <jsawaya@redhat.com>
src/pybind/mgr/rook/rook_cluster.py

index 876f1ab1c0e92d1de4eabb8f36ba5512144e3085..3215f258c36826a47535c0be921032f0b4fdface 100644 (file)
@@ -99,14 +99,16 @@ class DefaultFetcher():
         self.pvs_in_sc = [i for i in self.inventory.items if i.spec.storage_class_name == self.storage_class]
 
     def convert_size(self, size_str: str) -> int:
-        units = ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei")
-        unit = size_str[-2:]
-        try:
-            factor = units.index(unit)
+        units = ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "", "K", "M", "G", "T", "P", "E")
+        coeff_and_unit = re.search('(\d+)(\D+)', size_str)
+        assert coeff_and_unit is not None
+        coeff = int(coeff_and_unit[1])
+        unit = coeff_and_unit[2]
+        try: 
+            factor = units.index(unit) % 7
         except ValueError:
             log.error("PV size format invalid")
             raise
-        coeff = int(size_str[:-2])
         size = coeff * (2 ** (10 * factor))
         return size