]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_cephfs.py: add tests for utimensat()
authorRishabh Dave <ridave@redhat.com>
Wed, 12 Nov 2025 16:50:59 +0000 (22:20 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 16 Apr 2026 12:41:08 +0000 (18:11 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/test/pybind/test_cephfs.py

index d5af032c6db17762b56a2d87f085e2a3d3347239..e68353cf3c7a3db638d9f2054f51fa53deee24ed 100644 (file)
@@ -1225,6 +1225,56 @@ class TestChmodat:
         cephfs.close(fd)
 
 
+class TestUtimensat:
+
+    def test_utimensat_for_regfile(self, testdir):
+        cephfs.mkdir('dir1', 0o755)
+        fd = cephfs.open('dir1/file1', 'w')
+        cephfs.write(fd, b'abcd', 0)
+        cephfs.close(fd)
+        st1 = cephfs.stat(b'dir1/file1')
+
+        dirfd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755)
+        time.sleep(2)
+        x = datetime.now()
+        timestamps = (time.mktime(x.timetuple()), time.mktime(x.timetuple()))
+        cephfs.utimensat(dirfd, 'file1', timestamps, 0)
+
+        st2 = cephfs.stat(b'dir1/file1')
+        assert_greater(st2.st_atime, st1.st_atime)
+
+    def test_utimensat_for_dir(self, testdir):
+        cephfs.mkdir('dir1', 0o755)
+        cephfs.mkdir('dir1/dir2', 0o755)
+        st1 = cephfs.stat(b'dir1/dir2')
+
+        dirfd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755)
+        time.sleep(2)
+        x = datetime.now()
+        timestamps = (time.mktime(x.timetuple()), time.mktime(x.timetuple()))
+        cephfs.utimensat(dirfd, 'dir2', timestamps, 0)
+
+        st2 = cephfs.stat(b'dir1/dir2')
+        assert_greater(st2.st_atime, st1.st_atime)
+
+    def test_utimensat_for_symlink(self, testdir):
+        cephfs.mkdir('dir1', 0o755)
+        fd = cephfs.open('dir1/file1', 'w', 0o644)
+        cephfs.write(fd, b'abcd', 0)
+        cephfs.close(fd)
+        cephfs.symlink('file1', 'dir1/slink1')
+        st1 = cephfs.stat(b'dir1/slink1')
+
+        dirfd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755)
+        time.sleep(2)
+        x = datetime.now()
+        timestamps = (time.mktime(x.timetuple()), time.mktime(x.timetuple()))
+        cephfs.utimensat(dirfd, 'file1', timestamps, libcephfs.AT_SYMLINK_NOFOLLOW)
+
+        st2 = cephfs.stat(b'dir1/slink1')
+        assert_greater(st2.st_atime, st1.st_atime)
+
+
 class TestWithRootUser:
 
     def setup_method(self):