summaryrefslogtreecommitdiffstats
path: root/test/functional
diff options
context:
space:
mode:
authorThiago da Silva <thiago@redhat.com>2014-01-21 14:21:40 -0500
committerThiago da Silva <thiago@redhat.com>2014-01-22 11:15:11 -0500
commit5be3fc07eb54bedf441f358ccb2ac62152de2a78 (patch)
tree29757f73b51bf20cd0318229e7e7824d12c06c95 /test/functional
parentacef148b02c5ab0204e1820457cb058f08be5db2 (diff)
first libgfapi-python functional tests
adding a few functional tests and removing old tests from source code Change-Id: Iefcb091d614f2825592943cfb42847b5865322c6 Signed-off-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/__init__.py0
-rw-r--r--test/functional/libgfapi-python-tests.py127
2 files changed, 127 insertions, 0 deletions
diff --git a/test/functional/__init__.py b/test/functional/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/functional/__init__.py
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
new file mode 100644
index 0000000..30a1732
--- /dev/null
+++ b/test/functional/libgfapi-python-tests.py
@@ -0,0 +1,127 @@
+import unittest
+import os
+import types
+import loremipsum
+
+from nose import SkipTest
+from gluster import gfapi
+
+
+class FileOpsTest(unittest.TestCase):
+
+ vol = None
+ path = None
+ data = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.vol = gfapi.Volume("gfshost", "test")
+ cls.vol.set_logging("/dev/null", 7)
+ cls.vol.mount()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.vol = None
+
+ def setUp(self):
+ self.data = loremipsum.get_sentence()
+ self.path = self._testMethodName + ".io"
+ with self.vol.creat(self.path, os.O_WRONLY | os.O_EXCL, 0644) as fd:
+ rc = fd.write(self.data)
+
+ def tearDown(self):
+ self.path = None
+ self.data = None
+
+ def test_open_and_read(self):
+ with self.vol.open(self.path, os.O_RDONLY) as fd:
+ self.assertTrue(isinstance(fd, gfapi.File))
+ buf = fd.read(len(self.data))
+ self.assertFalse(isinstance(buf, types.IntType))
+ self.assertEqual(buf, self.data)
+
+ def test_lstat(self):
+ sb = self.vol.lstat(self.path)
+ self.assertFalse(isinstance(sb, types.IntType))
+ self.assertEqual(sb.st_size, len(self.data))
+
+ def test_rename(self):
+ newpath = self.path + ".rename"
+ ret = self.vol.rename(self.path, newpath)
+ self.assertEqual(ret, 0)
+ self.assertRaises(OSError, self.vol.lstat, self.path)
+
+ def test_unlink(self):
+ ret = self.vol.unlink(self.path)
+ self.assertEqual(ret, 0)
+ self.assertRaises(OSError, self.vol.lstat, self.path)
+
+ def test_xattr(self):
+ key1, key2 = "hello", "world"
+ ret1 = self.vol.setxattr(self.path, "trusted.key1", key1, len(key1))
+ self.assertEqual(0, ret1)
+ ret2 = self.vol.setxattr(self.path, "trusted.key2", key2, len(key2))
+ self.assertEqual(0, ret2)
+
+ xattrs = self.vol.listxattr(self.path)
+ self.assertFalse(isinstance(xattrs, types.IntType))
+ self.assertEqual(xattrs, ["trusted.key1", "trusted.key2"])
+
+ buf = self.vol.getxattr(self.path, "trusted.key1", 32)
+ self.assertFalse(isinstance(buf, types.IntType))
+ self.assertEqual(buf, "hello")
+
+
+class DirOpsTest(unittest.TestCase):
+
+ data = None
+ dir_path = None
+ file_path = None
+ testfile = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.vol = gfapi.Volume("gfshost", "test")
+ cls.vol.set_logging("/dev/null", 7)
+ cls.vol.mount()
+ cls.testfile = "testfile.io"
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.vol = None
+ cls.testfile = None
+
+ def setUp(self):
+ self.data = loremipsum.get_sentence()
+ self.dir_path = self._testMethodName + "_dir"
+ self.vol.mkdir(self.dir_path)
+ self.file_path = self.dir_path + "/" + self.testfile
+ with self.vol.creat(
+ self.file_path, os.O_WRONLY | os.O_EXCL, 0644) as fd:
+ rc = fd.write(self.data)
+
+ def tearDown(self):
+ self.dir_path = None
+ self.file_path = None
+ self.data = None
+
+ def test_dir_listing(self):
+ fd = self.vol.opendir(self.dir_path)
+ self.assertTrue(isinstance(fd, gfapi.Dir))
+ files = []
+ while True:
+ ent = fd.next()
+ if not isinstance(ent, gfapi.Dirent):
+ break
+ name = ent.d_name[:ent.d_reclen]
+ files.append(name)
+ self.assertEqual(files, [".", "..", self.testfile])
+
+ def test_delete_file_and_dir(self):
+ ret = self.vol.unlink(self.file_path)
+ self.assertEqual(ret, 0)
+ self.assertRaises(OSError, self.vol.lstat, self.file_path)
+
+ ret = self.vol.rmdir(self.dir_path)
+ self.assertEqual(ret, 0)
+ self.assertRaises(OSError, self.vol.lstat, self.dir_path)