From: Joseph Sawaya Date: Wed, 11 Aug 2021 15:01:25 +0000 (-0400) Subject: mgr/rook: fix convert_size method in DefaultFetcher X-Git-Tag: v17.1.0~1071^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=24687e694cd8174c77c02800ae4a10d84bf8a177;p=ceph.git 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 --- 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