From 09b82e2bd909746836589c5249b1f5458d3e5947 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Fri, 5 Dec 2014 22:01:13 +0800 Subject: [PATCH] tasks: add test case for readonly MDS Signed-off-by: Yan, Zheng --- tasks/cephfs/mount.py | 18 +++++++++++++----- tasks/mds_auto_repair.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tasks/cephfs/mount.py b/tasks/cephfs/mount.py index b977c1e233a..a45b639e6ad 100644 --- a/tasks/cephfs/mount.py +++ b/tasks/cephfs/mount.py @@ -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) diff --git a/tasks/mds_auto_repair.py b/tasks/mds_auto_repair.py index 4f01d5a9001..1c9f44e6890 100644 --- a/tasks/mds_auto_repair.py +++ b/tasks/mds_auto_repair.py @@ -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)