]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_cephfs_shell: copy humanize() from cephfs-shell
authorRishabh Dave <ridave@redhat.com>
Tue, 18 Jun 2019 10:39:04 +0000 (16:09 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 13 Sep 2019 05:13:55 +0000 (10:43 +0530)
Copy the method named humanize from cephfs-shell so that output can be
compared. Unfortunately, importing this method isn't possible since the
dash in "cephfs-shell" leads to an syntax error.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/test_cephfs_shell.py

index 049c516afc0f2fc569ead87c4fc7988316eec2f5..7d1d84f85368f290b0509e0094a64d19da5ac629 100644 (file)
@@ -2,6 +2,7 @@ import os
 import crypt
 import logging
 from tempfile import mkstemp as tempfile_mkstemp
+import math
 from StringIO import StringIO
 from tasks.cephfs.cephfs_test_case import CephFSTestCase
 from tasks.cephfs.fuse_mount import FuseMount
@@ -9,6 +10,15 @@ from teuthology.exceptions import CommandFailedError
 
 log = logging.getLogger(__name__)
 
+def humansize(nbytes):
+    suffixes = ['B', 'K', 'M', 'G', 'T', 'P']
+    i = 0
+    while nbytes >= 1024 and i < len(suffixes)-1:
+        nbytes /= 1024.
+        i += 1
+    nbytes = math.ceil(nbytes)
+    f = ('%d' % nbytes).rstrip('.')
+    return '%s%s' % (f, suffixes[i])
 
 class TestCephFSShell(CephFSTestCase):
     CLIENTS_REQUIRED = 1