From 06d153824429c4e85814d8f783ac2032c0938127 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Tue, 20 Sep 2022 15:42:51 +1000 Subject: [PATCH] python-common: Add 'KB' to supported suffixes in SizeMatcher Fixes: https://tracker.ceph.com/issues/57609 Signed-off-by: Tim Serong --- .../ceph/deployment/drive_selection/matchers.py | 6 +++--- src/python-common/ceph/tests/test_disk_selector.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/python-common/ceph/deployment/drive_selection/matchers.py b/src/python-common/ceph/deployment/drive_selection/matchers.py index 8203796659b3..f423c2f43eea 100644 --- a/src/python-common/ceph/deployment/drive_selection/matchers.py +++ b/src/python-common/ceph/deployment/drive_selection/matchers.py @@ -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] diff --git a/src/python-common/ceph/tests/test_disk_selector.py b/src/python-common/ceph/tests/test_disk_selector.py index 0b7826c4b069..b08236130e06 100644 --- a/src/python-common/ceph/tests/test_disk_selector.py +++ b/src/python-common/ceph/tests/test_disk_selector.py @@ -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..""" -- 2.47.3