]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: Add 'KB' to supported suffixes in SizeMatcher 48184/head
authorTim Serong <tserong@suse.com>
Tue, 20 Sep 2022 05:42:51 +0000 (15:42 +1000)
committerTim Serong <tserong@suse.com>
Tue, 20 Sep 2022 05:42:54 +0000 (15:42 +1000)
Fixes: https://tracker.ceph.com/issues/57609
Signed-off-by: Tim Serong <tserong@suse.com>
src/python-common/ceph/deployment/drive_selection/matchers.py
src/python-common/ceph/tests/test_disk_selector.py

index 8203796659b3cad5bcf06e15269c13a2329a82f2..f423c2f43eea86dd4025a4232fa065276d41cdd5 100644 (file)
@@ -175,9 +175,9 @@ class SizeMatcher(Matcher):
     """
 
     SUFFIXES = (
-        ["MB", "GB", "TB"],
-        ["M", "G", "T"],
-        [1e+6, 1e+9, 1e+12]
+        ["KB", "MB", "GB", "TB"],
+        ["K", "M", "G", "T"],
+        [1e+3, 1e+6, 1e+9, 1e+12]
     )
 
     supported_suffixes = SUFFIXES[0] + SUFFIXES[1]
index 0b7826c4b0697793ce7285c62a539b8278424038..b08236130e0666e89ef1da201daafa29218ff8fd 100644 (file)
@@ -122,6 +122,12 @@ class TestSizeMatcher(object):
         assert matcher.low[0] == '50'
         assert matcher.low[1] == 'GB'
 
+    def test_to_byte_KB(self):
+        """ I doubt anyone ever thought we'd need to understand KB """
+
+        ret = drive_selection.SizeMatcher('size', '4K').to_byte(('4', 'KB'))
+        assert ret == 4 * 1e+3
+
     def test_to_byte_GB(self):
         """ Pretty nonesense test.."""