summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhchiramm <hchiramm@redhat.com>2014-04-09 18:48:28 +0530
committerhchiramm <hchiramm@redhat.com>2014-05-02 18:05:29 +0530
commitda5a33d206431f885a4dc029d79f693a27ef293a (patch)
treee4804568c053d3e08adcab54320a614f38a3c285
parentbd683d93cb8d967f761d53f7a6b4243eb8eaedea (diff)
Add statvfs support
This support will help other consumers to get the statvfs details. Change-Id: Iee4e84a515ff80f24add812ad6fcf84c992bf356 Signed-off-by: hchiramm <hchiramm@redhat.com>
-rwxr-xr-x[-rw-r--r--]glusterfs/gfapi.py29
-rw-r--r--test/functional/libgfapi-python-tests.py10
-rw-r--r--test/unit/gluster/test_gfapi.py15
3 files changed, 54 insertions, 0 deletions
diff --git a/glusterfs/gfapi.py b/glusterfs/gfapi.py
index 80418a1..974aac5 100644..100755
--- a/glusterfs/gfapi.py
+++ b/glusterfs/gfapi.py
@@ -60,6 +60,23 @@ class Stat (ctypes.Structure):
]
+class Statvfs (ctypes.Structure):
+ _fields_ = [
+ ("f_bsize", ctypes.c_ulong),
+ ("f_frsize", ctypes.c_ulong),
+ ("f_blocks", ctypes.c_ulong),
+ ("f_bfree", ctypes.c_ulong),
+ ("f_bavail", ctypes.c_ulong),
+ ("f_files", ctypes.c_ulong),
+ ("f_ffree", ctypes.c_ulong),
+ ("f_favail", ctypes.c_ulong),
+ ("f_fsid", ctypes.c_ulong),
+ ("f_flag", ctypes.c_ulong),
+ ("f_namemax", ctypes.c_ulong),
+ ("__f_spare", ctypes.c_int * 6),
+ ]
+
+
class Dirent (ctypes.Structure):
_fields_ = [
("d_ino", ctypes.c_ulong),
@@ -518,6 +535,18 @@ class Volume(object):
raise OSError(err, os.strerror(err))
return s
+ def statvfs(self, path):
+ """
+ To get status information about the file system that contains the file
+ named by the path argument.
+ """
+ s = Statvfs()
+ rc = api.glfs_statvfs(self.fs, path, ctypes.byref(s))
+ if rc < 0:
+ err = ctypes.get_errno()
+ raise OSError(err, os.strerror(err))
+ return s
+
def symlink(self, source, link_name):
"""
Create a symbolic link 'link_name' which points to 'source'
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
index baad035..3ef2401 100644
--- a/test/functional/libgfapi-python-tests.py
+++ b/test/functional/libgfapi-python-tests.py
@@ -261,6 +261,16 @@ class DirOpsTest(unittest.TestCase):
self.vol.makedirs(name, 0755)
self.assertTrue(self.vol.isdir(name))
+ def test_statvfs(self):
+ sb = self.vol.statvfs("/")
+ self.assertFalse(isinstance(sb, types.IntType))
+ self.assertEqual(sb.f_namemax, 255L)
+ # creating a dir, checking Total number of free inodes
+ # is reduced
+ self.vol.makedirs("statvfs_dir1", 0755)
+ sb2 = self.vol.statvfs("/")
+ self.assertTrue(sb2.f_ffree < sb.f_ffree)
+
def test_rmtree(self):
"""
by testing rmtree, we are also testing unlink and rmdir
diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py
index e0308f7..c7627b1 100644
--- a/test/unit/gluster/test_gfapi.py
+++ b/test/unit/gluster/test_gfapi.py
@@ -498,6 +498,21 @@ class TestVolume(unittest.TestCase):
with patch("glusterfs.gfapi.api.glfs_stat", mock_glfs_stat):
self.assertRaises(OSError, self.vol.stat, "file.txt")
+ def test_statvfs_success(self):
+ mock_glfs_statvfs = Mock()
+ mock_glfs_statvfs.return_value = 0
+
+ with patch("glusterfs.gfapi.api.glfs_statvfs", mock_glfs_statvfs):
+ s = self.vol.statvfs("/")
+ self.assertTrue(isinstance(s, gfapi.Statvfs))
+
+ def test_statvfs_fail_exception(self):
+ mock_glfs_statvfs = Mock()
+ mock_glfs_statvfs.return_value = -1
+
+ with patch("glusterfs.gfapi.api.glfs_statvfs", mock_glfs_statvfs):
+ self.assertRaises(OSError, self.vol.statvfs, "/")
+
def test_makedirs_success(self):
mock_glfs_mkdir = Mock()
mock_glfs_mkdir.side_effect = [0, 0]