diff options
author | Peter Portante <peter.portante@redhat.com> | 2013-10-24 16:15:25 -0400 |
---|---|---|
committer | Luis Pabon <lpabon@redhat.com> | 2013-10-28 11:51:51 -0700 |
commit | 286a1308db72c5cfdd6ce16aff3f291ebce257c2 (patch) | |
tree | aabb3c54a29d6236f5ade0a229c477378a6c832c /test/unit/common/test_fs_utils.py | |
parent | 6b8d7c59195327484ac0f14bd1c29e4f75415e3b (diff) |
Rebase to OpenStack Swift Havana (1.10.0)
Change-Id: I90821230a1a7100c74d97cccc9c445251d0f65e7
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/6157
Reviewed-by: Luis Pabon <lpabon@redhat.com>
Tested-by: Luis Pabon <lpabon@redhat.com>
Diffstat (limited to 'test/unit/common/test_fs_utils.py')
-rw-r--r-- | test/unit/common/test_fs_utils.py | 73 |
1 files changed, 59 insertions, 14 deletions
diff --git a/test/unit/common/test_fs_utils.py b/test/unit/common/test_fs_utils.py index 02c6ecb..19fc2df 100644 --- a/test/unit/common/test_fs_utils.py +++ b/test/unit/common/test_fs_utils.py @@ -30,8 +30,22 @@ from gluster.swift.common.exceptions import NotDirectoryError, \ def mock_os_fsync(fd): return True -def mock_tpool_execute(func, *args, **kwargs): - func(*args, **kwargs) +def mock_os_fdatasync(fd): + return True + + +class TestFakefile(unittest.TestCase): + """ Tests for common.fs_utils.Fake_file """ + + def test_Fake_file(self): + path = "/tmp/bar" + ff = fs.Fake_file(path) + self.assertEqual(path, ff.path) + self.assertEqual(0, ff.tell()) + self.assertEqual(None, ff.read(50)) + self.assertEqual(-1, ff.fileno()) + self.assertEqual(None, ff.close()) + class TestFsUtils(unittest.TestCase): """ Tests for common.fs_utils """ @@ -688,9 +702,8 @@ class TestFsUtils(unittest.TestCase): fd, tmpfile = mkstemp(dir=tmpdir) try: os.write(fd, 'test') - with patch('eventlet.tpool.execute', mock_tpool_execute): - with patch('os.fsync', mock_os_fsync): - assert fs.do_fsync(fd) is None + with patch('os.fsync', mock_os_fsync): + assert fs.do_fsync(fd) is None except GlusterFileSystemOSError as ose: self.fail('Opening a temporary file failed with %s' %ose.strerror) else: @@ -704,15 +717,47 @@ class TestFsUtils(unittest.TestCase): try: fd, tmpfile = mkstemp(dir=tmpdir) os.write(fd, 'test') - with patch('eventlet.tpool.execute', mock_tpool_execute): - with patch('os.fsync', mock_os_fsync): - assert fs.do_fsync(fd) is None + with patch('os.fsync', mock_os_fsync): + assert fs.do_fsync(fd) is None + os.close(fd) + try: + fs.do_fsync(fd) + except GlusterFileSystemOSError: + pass + else: + self.fail("Expected GlusterFileSystemOSError") + finally: + shutil.rmtree(tmpdir) + + def test_do_fdatasync(self): + tmpdir = mkdtemp() + try: + fd, tmpfile = mkstemp(dir=tmpdir) + try: + os.write(fd, 'test') + with patch('os.fdatasync', mock_os_fdatasync): + assert fs.do_fdatasync(fd) is None + except GlusterFileSystemOSError as ose: + self.fail('Opening a temporary file failed with %s' %ose.strerror) + else: os.close(fd) - try: - fs.do_fsync(fd) - except GlusterFileSystemOSError: - pass - else: - self.fail("Expected GlusterFileSystemOSError") + finally: + shutil.rmtree(tmpdir) + + + def test_do_fdatasync_err(self): + tmpdir = mkdtemp() + try: + fd, tmpfile = mkstemp(dir=tmpdir) + os.write(fd, 'test') + with patch('os.fdatasync', mock_os_fdatasync): + assert fs.do_fdatasync(fd) is None + os.close(fd) + try: + fs.do_fdatasync(fd) + except GlusterFileSystemOSError: + pass + else: + self.fail("Expected GlusterFileSystemOSError") finally: shutil.rmtree(tmpdir) |