summaryrefslogtreecommitdiffstats
path: root/src/ceph-volume/ceph_volume/tests/util
diff options
context:
space:
mode:
authorGuillaume Abrioux <gabrioux@redhat.com>2021-11-16 20:32:38 +0100
committerGuillaume Abrioux <gabrioux@redhat.com>2021-11-17 09:22:28 +0100
commit6940856f233f4d365a119eed90ff88fd918f6916 (patch)
tree2486a045b6119e75956ae03fb9c6426ecd7b705e /src/ceph-volume/ceph_volume/tests/util
parentMerge pull request #43746 from kamoltat/wip-fix-autoscale-typo (diff)
downloadceph-6940856f233f4d365a119eed90ff88fd918f6916.tar.xz
ceph-6940856f233f4d365a119eed90ff88fd918f6916.zip
ceph-volume: human_readable_size() refactor
This commit refactors the `human_readable_size()` function. The current implementation has a couple of issues: in a 'human readable' mindset, I would expect `human_readable_size(1024)` to return '1.00 KB' instead of '1024.00 KB'. ``` In [1]: from ceph_volume.util.disk import human_readable_size In [2]: human_readable_size(1024) Out[2]: '1024.00 B' In [3]: human_readable_size(1024*1024) Out[3]: '1024.00 KB' ``` Also, it doesn't support PB unit: ``` In [4]: human_readable_size(1024*1024*1024*1024*1024) Out[4]: '1024.00 TB' In [5]: human_readable_size(1024*1024*1024*1024*1024*1024) --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-31-0859861661dc> in <module> ----> 1 human_readable_size(1024*1024*1024*1024*1024*1024) ~/GIT/ceph/src/ceph-volume/ceph_volume/util/disk.py in human_readable_size(size) 640 return "{size:.2f} {suffix}".format( 641 size=size, --> 642 suffix=suffixes[suffix_index]) 643 644 IndexError: list index out of range ``` This commit fixes this. Fixes: https://tracker.ceph.com/issues/48492 Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
Diffstat (limited to 'src/ceph-volume/ceph_volume/tests/util')
-rw-r--r--src/ceph-volume/ceph_volume/tests/util/test_disk.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/ceph-volume/ceph_volume/tests/util/test_disk.py b/src/ceph-volume/ceph_volume/tests/util/test_disk.py
index 5f4d57343e4..44f19e036fa 100644
--- a/src/ceph-volume/ceph_volume/tests/util/test_disk.py
+++ b/src/ceph-volume/ceph_volume/tests/util/test_disk.py
@@ -124,6 +124,9 @@ class TestHumanReadableSize(object):
result = disk.human_readable_size(81.2*1024*1024*1024*1024)
assert result == '81.20 TB'
+ def test_petabytes(self):
+ result = disk.human_readable_size(9.23*1024*1024*1024*1024*1024)
+ assert result == '9.23 PB'
class TestSizeFromHumanReadable(object):
@@ -143,10 +146,14 @@ class TestSizeFromHumanReadable(object):
result = disk.size_from_human_readable('2 G')
assert result == disk.Size(gb=2)
- def test_terrabytes(self):
+ def test_terabytes(self):
result = disk.size_from_human_readable('2 T')
assert result == disk.Size(tb=2)
+ def test_petabytes(self):
+ result = disk.size_from_human_readable('2 P')
+ assert result == disk.Size(pb=2)
+
def test_case(self):
result = disk.size_from_human_readable('2 t')
assert result == disk.Size(tb=2)
@@ -182,10 +189,14 @@ class TestSizeParse(object):
result = disk.Size.parse('2G')
assert result == disk.Size(gb=2)
- def test_terrabytes(self):
+ def test_terabytes(self):
result = disk.Size.parse('2T')
assert result == disk.Size(tb=2)
+ def test_petabytes(self):
+ result = disk.Size.parse('2P')
+ assert result == disk.Size(pb=2)
+
def test_tb(self):
result = disk.Size.parse('2Tb')
assert result == disk.Size(tb=2)