]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pycephfs: add tests for open call 4460/head
authorHaomai Wang <haomaiwang@gmail.com>
Mon, 4 May 2015 16:07:18 +0000 (00:07 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Mon, 4 May 2015 16:31:49 +0000 (00:31 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/pybind/cephfs.py
src/test/pybind/test_cephfs.py

index decd7cf36d21adcb9595f4f96acc2a2abe0107cc..7aad54e24445021a396727ce17deed97f3b2c821 100644 (file)
@@ -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))
index add586b5ab664cfcd655747920ab894648b837c5..faa4d77595b5d8f2e2c8c5ecd206cc01387505d0 100644 (file)
@@ -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')