summaryrefslogtreecommitdiffstats
path: root/test/functional/libgfapi-python-tests.py
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2014-04-10 16:49:05 +0530
committerGerrit Code Review <review@dev.gluster.org>2014-05-19 18:34:48 -0700
commit8acb5a7585a8e155cf0c9d0a60d76e75cdd725f7 (patch)
tree45ffd1ca45cce932b2916a71d94e150fe770db08 /test/functional/libgfapi-python-tests.py
parentda5a33d206431f885a4dc029d79f693a27ef293a (diff)
Fix functional tests
* The order of elements in list returned by listdir() can vary and may not be sorted. This caused assertEqual in "test_listdir" to fail. * Also, some systems may have xattrs belonging to selinux. So, a listxattr can list them too. * Allow hostname/ip and volume name to be configured easily by setting it in test.conf. This enables functional tests to use a non-local volume. * Cleanup volume before and after running functional tests. * Added MANIFEST.in and LICENSE file Change-Id: Icfa6eb60e8d8e7ed4d6ab8190a2a2c80688999a3 Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/functional/libgfapi-python-tests.py')
-rw-r--r--test/functional/libgfapi-python-tests.py53
1 files changed, 46 insertions, 7 deletions
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
index 3ef2401..5af7d70 100644
--- a/test/functional/libgfapi-python-tests.py
+++ b/test/functional/libgfapi-python-tests.py
@@ -20,6 +20,22 @@ import loremipsum
import errno
from glusterfs import gfapi
+from test import get_test_config
+from ConfigParser import NoSectionError, NoOptionError
+
+config = get_test_config()
+if config:
+ try:
+ HOST = config.get('func_test', 'gfs_host')
+ except (NoSectionError, NoOptionError):
+ HOST = 'gfshost'
+ try:
+ VOLNAME = config.get('func_test', 'gfs_volname')
+ except (NoSectionError, NoOptionError):
+ VOLNAME = 'test'
+else:
+ HOST = 'gfshost'
+ VOLNAME = 'test'
class BinFileOpsTest(unittest.TestCase):
@@ -30,12 +46,19 @@ class BinFileOpsTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
- cls.vol = gfapi.Volume("gfshost", "test")
+ cls.vol = gfapi.Volume(HOST, VOLNAME)
cls.vol.set_logging("/dev/null", 7)
- cls.vol.mount()
+ ret = cls.vol.mount()
+ if ret == 0:
+ # Cleanup volume
+ cls.vol.rmtree("/", ignore_errors=True)
+ else:
+ raise Exception("Initializing volume %s:%s failed." %
+ (HOST, VOLNAME))
@classmethod
def tearDownClass(cls):
+ cls.vol.rmtree("/", ignore_errors=True)
cls.vol = None
def setUp(self):
@@ -61,12 +84,19 @@ class FileOpsTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
- cls.vol = gfapi.Volume("gfshost", "test")
+ cls.vol = gfapi.Volume(HOST, VOLNAME)
cls.vol.set_logging("/dev/null", 7)
- cls.vol.mount()
+ ret = cls.vol.mount()
+ if ret == 0:
+ # Cleanup volume
+ cls.vol.rmtree("/", ignore_errors=True)
+ else:
+ raise Exception("Initializing volume %s:%s failed." %
+ (HOST, VOLNAME))
@classmethod
def tearDownClass(cls):
+ cls.vol.rmtree("/", ignore_errors=True)
cls.vol = None
def setUp(self):
@@ -195,7 +225,7 @@ class FileOpsTest(unittest.TestCase):
xattrs = self.vol.listxattr(self.path)
self.assertFalse(isinstance(xattrs, types.IntType))
- self.assertEqual(xattrs, ["trusted.key1", "trusted.key2"])
+ self.assertTrue(set(["trusted.key1", "trusted.key2"]) <= set(xattrs))
buf = self.vol.getxattr(self.path, "trusted.key1", 32)
self.assertFalse(isinstance(buf, types.IntType))
@@ -206,7 +236,7 @@ class FileOpsTest(unittest.TestCase):
xattrs = self.vol.listxattr(self.path)
self.assertFalse(isinstance(xattrs, types.IntType))
- self.assertEqual(xattrs, ["trusted.key2"])
+ self.assertTrue(["trusted.key1"] not in xattrs)
class DirOpsTest(unittest.TestCase):
@@ -217,13 +247,21 @@ class DirOpsTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
- cls.vol = gfapi.Volume("gfshost", "test")
+ cls.vol = gfapi.Volume(HOST, VOLNAME)
cls.vol.set_logging("/dev/null", 7)
cls.vol.mount()
+ ret = cls.vol.mount()
+ if ret == 0:
+ # Cleanup volume
+ cls.vol.rmtree("/", ignore_errors=True)
+ else:
+ raise Exception("Initializing volume %s:%s failed." %
+ (HOST, VOLNAME))
cls.testfile = "testfile"
@classmethod
def tearDownClass(cls):
+ cls.vol.rmtree("/", ignore_errors=True)
cls.vol = None
cls.testfile = None
@@ -254,6 +292,7 @@ class DirOpsTest(unittest.TestCase):
def test_listdir(self):
dir_list = self.vol.listdir(self.dir_path)
+ dir_list.sort()
self.assertEqual(dir_list, ["testfile0", "testfile1", "testfile2"])
def test_makedirs(self):