]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tasks: add test case for readonly MDS
authorYan, Zheng <zyan@redhat.com>
Fri, 5 Dec 2014 14:01:13 +0000 (22:01 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 10 Dec 2014 01:48:02 +0000 (09:48 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
tasks/cephfs/mount.py
tasks/mds_auto_repair.py

index b977c1e233aa89c12cedcf9c0596f25f4fcc4ae0..a45b639e6adcd18004d33acea78b5e33b5ae5625 100644 (file)
@@ -211,7 +211,7 @@ class CephFSMount(object):
             'sudo', 'python', '-c', pyscript
         ])
 
-    def write_background(self, basename="background_file"):
+    def write_background(self, basename="background_file", loop=False):
         """
         Open a file for writing, complete as soon as you can
         :param basename:
@@ -222,12 +222,20 @@ class CephFSMount(object):
         path = os.path.join(self.mountpoint, basename)
 
         pyscript = dedent("""
+            import os
             import time
 
-            f = open("{path}", 'w')
-            f.write('content')
-            f.close()
-            """).format(path=path)
+            fd = os.open("{path}", os.O_RDWR | os.O_CREAT, 0644)
+            try:
+                while True:
+                    os.write(fd, 'content')
+                    time.sleep(1)
+                    if not {loop}:
+                        break
+            except IOError, e:
+                pass
+            os.close(fd)
+            """).format(path=path, loop=str(loop))
 
         rproc = self._run_python(pyscript)
         self.background_procs.append(rproc)
index 4f01d5a900138359e93b1243580329f0050a0e82..1c9f44e68908ec4adb0da2ff49c3559a68f8f09a 100644 (file)
@@ -98,6 +98,36 @@ class TestMDSAutoRepair(CephFSTestCase):
         proc = self.mount_a.run_shell(["sudo", "rados", "-p", "metadata", "getxattr", objname, "parent"])
         self.assertEqual(proc.exitstatus, 0)
 
+    def test_mds_readonly(self):
+        """
+        test if MDS behave correct when it's readonly
+        """
+        # operation should successd when MDS is not readonly
+        self.mount_a.run_shell(["sudo", "touch", "test_file1"])
+        writer = self.mount_a.write_background(loop=True)
+
+        time.sleep(10)
+        self.assertFalse(writer.finished)
+
+        # force MDS to read-only mode
+        self.fs.mds_asok(['force_readonly'])
+        time.sleep(10)
+
+        # touching test file should fail
+        try:
+            self.mount_a.run_shell(["sudo", "touch", "test_file1"])
+        except CommandFailedError, e:
+            pass
+        else:
+            self.assertTrue(False)
+
+        # background writer also should fail
+        self.assertTrue(writer.finished)
+
+        # restart mds to make it writable
+        self.fs.mds_restart()
+        self.fs.wait_for_daemons()
+
 @contextlib.contextmanager
 def task(ctx, config):
     fs = Filesystem(ctx, config)