From e5f30052f96b50faadcc2731eda5603918504957 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Tue, 18 Jun 2019 16:09:04 +0530 Subject: [PATCH] test_cephfs_shell: copy humanize() from cephfs-shell 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 --- qa/tasks/cephfs/test_cephfs_shell.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qa/tasks/cephfs/test_cephfs_shell.py b/qa/tasks/cephfs/test_cephfs_shell.py index 049c516afc0..7d1d84f8536 100644 --- a/qa/tasks/cephfs/test_cephfs_shell.py +++ b/qa/tasks/cephfs/test_cephfs_shell.py @@ -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 -- 2.47.3