From 24687e694cd8174c77c02800ae4a10d84bf8a177 Mon Sep 17 00:00:00 2001 From: Joseph Sawaya Date: Wed, 11 Aug 2021 11:01:25 -0400 Subject: [PATCH] mgr/rook: fix convert_size method in DefaultFetcher 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 --- src/pybind/mgr/rook/rook_cluster.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/rook/rook_cluster.py b/src/pybind/mgr/rook/rook_cluster.py index 876f1ab1c0e92..3215f258c3682 100644 --- a/src/pybind/mgr/rook/rook_cluster.py +++ b/src/pybind/mgr/rook/rook_cluster.py @@ -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 -- 2.39.5