From b46451d02d2660cdf46338b2e535467bf39e5164 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Mon, 13 Jun 2016 15:55:49 +0530 Subject: Expose glfs_readdirplus_r This patch does the following: * Implements Volume.listdir_with_stat() API which internally invokes glfs_readdirplus_r to return directory entries along with stat for each entry. * Implements Volume.scandir() which is similar to os.scandir() present in Python 3.5 * Makes Dir class iterable. * Enables Dir class to raise OSError when glfs_readdir* calls fail. Previously, these failures were silently being ignored and treated as a case of EOF. Change-Id: Id918c39a7ef3882553e9bcd3fbf9455ee1c25a83 Signed-off-by: Prashanth Pai --- test/functional/libgfapi-python-tests.py | 35 +++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py index 7dab995..1e6db3e 100644 --- a/test/functional/libgfapi-python-tests.py +++ b/test/functional/libgfapi-python-tests.py @@ -10,17 +10,19 @@ import unittest import os +import stat import types import errno import hashlib import threading - -from gluster.gfapi import File, Volume -from gluster.exceptions import LibgfapiException, Error from test import get_test_config from ConfigParser import NoSectionError, NoOptionError from uuid import uuid4 +from gluster.api import Stat +from gluster.gfapi import File, Volume, DirEntry +from gluster.exceptions import LibgfapiException, Error + config = get_test_config() if config: try: @@ -845,6 +847,33 @@ class DirOpsTest(unittest.TestCase): dir_list.sort() self.assertEqual(dir_list, ["testfile0", "testfile1", "testfile2"]) + def test_listdir_with_stat(self): + dir_list = self.vol.listdir_with_stat(self.dir_path) + dir_list_sorted = sorted(dir_list, key=lambda tup: tup[0]) + for index, (name, stat_info) in enumerate(dir_list_sorted): + self.assertEqual(name, 'testfile%s' % (index)) + self.assertTrue(isinstance(stat_info, Stat)) + self.assertTrue(stat.S_ISREG(stat_info.st_mode)) + self.assertEqual(stat_info.st_size, len(self.data)) + + # Error - path does not exist + self.assertRaises(OSError, + self.vol.listdir_with_stat, 'non-existent-dir') + + def test_scandir(self): + entries = [] + for entry in self.vol.scandir(self.dir_path): + self.assertTrue(isinstance(entry, DirEntry)) + entries.append(entry) + + entries_sorted = sorted(entries, key=lambda e: e.name) + for index, entry in enumerate(entries_sorted): + self.assertEqual(entry.name, 'testfile%s' % (index)) + self.assertTrue(entry.is_file()) + self.assertFalse(entry.is_dir()) + self.assertTrue(isinstance(entry.stat(), Stat)) + self.assertEqual(entry.stat().st_size, len(self.data)) + def test_makedirs(self): name = self.dir_path + "/subd1/subd2/subd3" self.vol.makedirs(name, 0755) -- cgit