cephfs.close(fd)
cephfs.unlink(b'/file-fchmod')
+def test_chown(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+ cephfs.close(fd)
+
+ uid = 1012
+ gid = 1012
+ cephfs.chown('file1', uid, gid)
+ st = cephfs.stat(b'/file1')
+ assert_equal(st.st_uid, uid)
+ assert_equal(st.st_gid, gid)
+
+def test_chown_change_uid_but_not_gid(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+ cephfs.close(fd)
+
+ st1 = cephfs.stat(b'/file1')
+
+ uid = 1012
+ cephfs.chown('file1', uid, -1)
+ st2 = cephfs.stat(b'/file1')
+ assert_equal(st2.st_uid, uid)
+
+ # ensure that gid is unchaged.
+ assert_equal(st1.st_gid, st2.st_gid)
+
+def test_chown_change_gid_but_not_uid(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+ cephfs.close(fd)
+
+ st1 = cephfs.stat(b'/file1')
+
+ gid = 1012
+ cephfs.chown('file1', -1, gid)
+ st2 = cephfs.stat(b'/file1')
+ assert_equal(st2.st_gid, gid)
+
+ # ensure that uid is unchaged.
+ assert_equal(st1.st_uid, st2.st_uid)
+
+def test_lchown(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+ cephfs.close(fd)
+ cephfs.symlink('file1', 'slink1')
+
+ uid = 1012
+ gid = 1012
+ cephfs.lchown('slink1', uid, gid)
+ st = cephfs.lstat(b'/slink1')
+ assert_equal(st.st_uid, uid)
+ assert_equal(st.st_gid, gid)
+
+def test_lchown_change_uid_but_not_gid(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+ cephfs.close(fd)
+ cephfs.symlink('file1', 'slink1')
+
+ st1 = cephfs.lstat(b'slink1')
+
+ uid = 1012
+ cephfs.lchown('slink1', uid, -1)
+ st2 = cephfs.lstat(b'/slink1')
+ assert_equal(st2.st_uid, uid)
+
+ # ensure that gid is unchaged.
+ assert_equal(st1.st_gid, st2.st_gid)
+
+def test_lchown_change_gid_but_not_uid(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+ cephfs.close(fd)
+ cephfs.symlink('file1', 'slink1')
+
+ st1 = cephfs.lstat(b'slink1')
+
+ gid = 1012
+ cephfs.lchown('slink1', -1, gid)
+ st2 = cephfs.lstat(b'/slink1')
+ assert_equal(st2.st_gid, gid)
+
+ # ensure that uid is unchaged.
+ assert_equal(st1.st_uid, st2.st_uid)
+
def test_fchown(testdir):
fd = cephfs.open(b'/file-fchown', 'w', 0o655)
uid = os.getuid()
cephfs.close(fd)
cephfs.unlink(b'/file-fchown')
+def test_fchown_change_uid_but_not_gid(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+
+ st1 = cephfs.stat(b'/file1')
+
+ uid = 1012
+ cephfs.fchown(fd, uid, -1)
+ st2 = cephfs.stat(b'/file1')
+ assert_equal(st2.st_uid, uid)
+
+ # ensure that uid is unchanged.
+ assert_equal(st1.st_gid, st2.st_gid)
+
+ cephfs.close(fd)
+
+def test_fchown_change_gid_but_not_uid(testdir):
+ fd = cephfs.open('file1', 'w', 0o755)
+ cephfs.write(fd, b'abcd', 0)
+
+ st1 = cephfs.stat(b'/file1')
+
+ gid = 1012
+ cephfs.chown('file1', -1, gid)
+ st2 = cephfs.stat(b'/file1')
+ assert_equal(st2.st_gid, gid)
+
+ # ensure that gid is unchanged.
+ assert_equal(st1.st_uid, st2.st_uid)
+
+ cephfs.close(fd)
+
def test_truncate(testdir):
fd = cephfs.open(b'/file-truncate', 'w', 0o755)
cephfs.write(fd, b"1111", 0)