mirror of
https://github.com/ceph/ceph
synced 2025-01-31 07:22:56 +00:00
pycephfs: add tests for open call
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
This commit is contained in:
parent
6b81d5cbc6
commit
0b4315b96f
@ -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))
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user