From 0b4315b96f001f8cf876df15c710286a1279d7f2 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Tue, 5 May 2015 00:07:18 +0800 Subject: [PATCH] pycephfs: add tests for open call Signed-off-by: Haomai Wang --- src/pybind/cephfs.py | 8 +++----- src/test/pybind/test_cephfs.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py index decd7cf36d2..7aad54e2444 100644 --- a/src/pybind/cephfs.py +++ b/src/pybind/cephfs.py @@ -342,9 +342,6 @@ class LibCephFS(object): if ret < 0: raise make_ex(ret, "chdir failed") - def isdir(self, dirent): - return dirent['d_type'] == 0x4 - def opendir(self, path): self.require_state("mounted") if not isinstance(path, basestring): @@ -419,10 +416,11 @@ class LibCephFS(object): cephfs_flags |= os.O_RDONLY elif c == 'w': cephfs_flags |= os.O_WRONLY | os.O_TRUNC | os.O_CREAT - elif c == 'a': - cephfs_flags |= os.O_APPEND | os.O_CREAT elif c == '+': cephfs_flags |= os.O_RDWR + else: + raise OperationNotSupported( + "open flags doesn't support %s" % c) ret = self.libcephfs.ceph_open(self.cluster, c_char_p(path), c_int(cephfs_flags), c_int(mode)) diff --git a/src/test/pybind/test_cephfs.py b/src/test/pybind/test_cephfs.py index add586b5ab6..faa4d77595b 100644 --- a/src/test/pybind/test_cephfs.py +++ b/src/test/pybind/test_cephfs.py @@ -65,10 +65,19 @@ def test_open(): assert_raises(libcephfs.ObjectNotFound, cephfs.open, 'file-1', 'r') assert_raises(libcephfs.ObjectNotFound, cephfs.open, 'file-1', 'r+') fd = cephfs.open('file-1', 'w') + cephfs.write(fd, "asdf", 0) cephfs.close(fd) fd = cephfs.open('file-1', 'r') + assert_equal(cephfs.read(fd, 0, 4), "asdf") cephfs.close(fd) - fd = cephfs.open('file-2', 'a') + fd = cephfs.open('file-1', 'r+') + cephfs.write(fd, "zxcv", 4) + assert_equal(cephfs.read(fd, 4, 8), "zxcv") cephfs.close(fd) + fd = cephfs.open('file-1', 'w+') + assert_equal(cephfs.read(fd, 0, 4), "") + cephfs.write(fd, "zxcv", 4) + assert_equal(cephfs.read(fd, 4, 8), "zxcv") + cephfs.close(fd) + assert_raises(libcephfs.OperationNotSupported, cephfs.open, 'file-1', 'a') cephfs.unlink('file-1') - cephfs.unlink('file-2')