summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/libgfapi-python-tests.py48
-rw-r--r--test/unit/gluster/test_gfapi.py22
2 files changed, 50 insertions, 20 deletions
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
index 776390d..7eb4cd2 100644
--- a/test/functional/libgfapi-python-tests.py
+++ b/test/functional/libgfapi-python-tests.py
@@ -13,6 +13,7 @@ import unittest
import os
import types
import errno
+import threading
from gluster.gfapi import File, Volume
from gluster.exceptions import LibgfapiException
@@ -132,7 +133,13 @@ class FileOpsTest(unittest.TestCase):
# invalid mode
self.assertRaises(ValueError, self.vol.fopen, "file", 'x+')
# file does not exist
- self.assertRaises(OSError, self.vol.fopen, "file", 'r')
+ try:
+ self.vol.fopen("file", "r")
+ except OSError as err:
+ if err.errno != errno.ENOENT:
+ self.fail("Expecting ENOENT")
+ else:
+ self.fail("Expecting ENOENT")
def test_fopen(self):
# Default permission should be 0666
@@ -197,6 +204,17 @@ class FileOpsTest(unittest.TestCase):
f.lseek(0, os.SEEK_SET)
self.assertEqual(f.read(), data + "hello world")
+ def test_fopen_in_thread(self):
+ def gluster_fopen():
+ name = uuid4().hex
+ with self.vol.fopen(name, 'w') as f:
+ f.write('hello world')
+
+ # the following caused segfault before the fix
+ thread = threading.Thread(target=gluster_fopen)
+ thread.start()
+ thread.join()
+
def test_create_file_already_exists(self):
try:
f = File(self.vol.open("newfile", os.O_CREAT))
@@ -278,7 +296,13 @@ class FileOpsTest(unittest.TestCase):
def test_rename(self):
newpath = self.path + ".rename"
self.vol.rename(self.path, newpath)
- self.assertRaises(OSError, self.vol.lstat, self.path)
+ try:
+ self.vol.lstat(self.path)
+ except OSError as err:
+ if err.errno != errno.ENOENT:
+ self.fail("Expecting ENOENT")
+ else:
+ self.fail("Expecting ENOENT")
def test_stat(self):
sb = self.vol.stat(self.path)
@@ -287,7 +311,13 @@ class FileOpsTest(unittest.TestCase):
def test_unlink(self):
self.vol.unlink(self.path)
- self.assertRaises(OSError, self.vol.lstat, self.path)
+ try:
+ self.vol.lstat(self.path)
+ except OSError as err:
+ if err.errno != errno.ENOENT:
+ self.fail("Expecting ENOENT")
+ else:
+ self.fail("Expecting ENOENT")
def test_setxattr(self):
value = "hello world"
@@ -548,7 +578,7 @@ class DirOpsTest(unittest.TestCase):
class TestVolumeInit(unittest.TestCase):
- def test_mount_unmount_default(self):
+ def test_mount_umount_default(self):
# Create volume object instance
vol = Volume(HOST, VOLNAME)
# Check attribute init
@@ -563,18 +593,18 @@ class TestVolumeInit(unittest.TestCase):
# Check mounted property
self.assertTrue(vol.mounted)
# Unmount the volume
- vol.unmount()
+ vol.umount()
# Check mounted property again
self.assertFalse(vol.mounted)
- # Do a double unmount - should not crash or raise exception
- vol.unmount()
+ # Do a double umount - should not crash or raise exception
+ vol.umount()
self.assertFalse(vol.mounted)
# Do a double mount - should not crash or raise exception
vol.mount()
vol.mount()
self.assertTrue(vol.mounted)
# Unmount the volume
- vol.unmount()
+ vol.umount()
self.assertFalse(vol.mounted)
def test_mount_err(self):
@@ -608,5 +638,5 @@ class TestVolumeInit(unittest.TestCase):
vol.set_logging(log_file2, 7)
self.assertEqual(vol.log_file, log_file2)
# Unmount the volume
- vol.unmount()
+ vol.umount()
self.assertFalse(vol.mounted)
diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py
index f850f0f..d07ec67 100644
--- a/test/unit/gluster/test_gfapi.py
+++ b/test/unit/gluster/test_gfapi.py
@@ -329,12 +329,12 @@ class TestVolume(unittest.TestCase):
self.assertEqual(v.port, 9876)
self.assertFalse(v.mounted)
- def test_mount_unmount_success(self):
+ def test_mount_umount_success(self):
v = Volume("host", "vol")
v.mount()
self.assertTrue(v.mounted)
self.assertTrue(v.fs)
- v.unmount()
+ v.umount()
self.assertFalse(v.mounted)
self.assertFalse(v.fs)
@@ -377,16 +377,16 @@ class TestVolume(unittest.TestCase):
with patch("gluster.gfapi.api.glfs_init", _m_glfs_init):
self.assertRaises(LibgfapiException, v.mount)
self.assertFalse(v.mounted)
- _m_glfs_init.assert_caled_once_with(v.fs)
+ _m_glfs_init.assert_called_once_with(v.fs)
- def test_unmount_error(self):
+ def test_umount_error(self):
v = Volume("host", "vol")
v.mount()
_m_glfs_fini = Mock(return_value=-1)
with patch("gluster.gfapi.api.glfs_fini", _m_glfs_fini):
- self.assertRaises(LibgfapiException, v.unmount)
+ self.assertRaises(LibgfapiException, v.umount)
_m_glfs_fini.assert_called_once_with(v.fs)
- # Should still be mounted as unmount failed.
+ # Should still be mounted as umount failed.
self.assertTrue(v.mounted)
def test_set_logging(self):
@@ -440,7 +440,7 @@ class TestVolume(unittest.TestCase):
mock_glfs_creat = Mock()
mock_glfs_creat.return_value = 2
- with patch("gluster.api.client.glfs_creat", mock_glfs_creat):
+ with patch("gluster.api.glfs_creat", mock_glfs_creat):
with File(self.vol.open("file.txt", os.O_CREAT, 0644)) as f:
self.assertTrue(isinstance(f, File))
self.assertEqual(mock_glfs_creat.call_count, 1)
@@ -716,7 +716,7 @@ class TestVolume(unittest.TestCase):
mock_glfs_open = Mock()
mock_glfs_open.return_value = 2
- with patch("gluster.api.client.glfs_open", mock_glfs_open):
+ with patch("gluster.api.glfs_open", mock_glfs_open):
with File(self.vol.open("file.txt", os.O_WRONLY)) as f:
self.assertTrue(isinstance(f, File))
self.assertEqual(mock_glfs_open.call_count, 1)
@@ -731,14 +731,14 @@ class TestVolume(unittest.TestCase):
with self.vol.open("file.txt", os.O_WRONLY) as fd:
self.assertEqual(fd, None)
- with patch("gluster.api.client.glfs_open", mock_glfs_open):
+ with patch("gluster.api.glfs_open", mock_glfs_open):
self.assertRaises(OSError, assert_open)
def test_open_direct_success(self):
mock_glfs_open = Mock()
mock_glfs_open.return_value = 2
- with patch("gluster.api.client.glfs_open", mock_glfs_open):
+ with patch("gluster.api.glfs_open", mock_glfs_open):
f = File(self.vol.open("file.txt", os.O_WRONLY))
self.assertTrue(isinstance(f, File))
self.assertEqual(mock_glfs_open.call_count, 1)
@@ -749,7 +749,7 @@ class TestVolume(unittest.TestCase):
mock_glfs_open = Mock()
mock_glfs_open.return_value = None
- with patch("gluster.api.client.glfs_open", mock_glfs_open):
+ with patch("gluster.api.glfs_open", mock_glfs_open):
self.assertRaises(OSError, self.vol.open, "file.txt", os.O_RDONLY)
def test_opendir_success(self):