From f96031b9202b2169e2d81746d14daa702864857c Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Tue, 7 Dec 2021 16:04:00 +0530 Subject: [PATCH] qa/cephfs: upgrade is_mounted() in mount.py Instead of relying on value of a mutable variable, actually check if the CephFS is mounted on the system. This will prevent bugs due to stale and incorrect values. Fixes: https://tracker.ceph.com/issues/54283 Signed-off-by: Rishabh Dave --- qa/tasks/cephfs/fuse_mount.py | 8 -------- qa/tasks/cephfs/kernel_mount.py | 10 +++------- qa/tasks/cephfs/mount.py | 6 +++--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/qa/tasks/cephfs/fuse_mount.py b/qa/tasks/cephfs/fuse_mount.py index 6f04967132e1e..fa0d84b842b3b 100644 --- a/qa/tasks/cephfs/fuse_mount.py +++ b/qa/tasks/cephfs/fuse_mount.py @@ -71,8 +71,6 @@ class FuseMount(CephFSMount): self.gather_mount_info() - self.mounted = True - def _run_mount_cmd(self, mntopts, check_status): mount_cmd = self._get_mount_cmd(mntopts) mountcmd_stdout, mountcmd_stderr = StringIO(), StringIO() @@ -281,8 +279,6 @@ class FuseMount(CephFSMount): time.sleep(5) - self.mounted = True - # Now that we're mounted, set permissions so that the rest of the test # will have unrestricted access to the filesystem mount. for retry in range(10): @@ -358,7 +354,6 @@ class FuseMount(CephFSMount): if self.is_mounted(): raise - self.mounted = False self._fuse_conn = None self.id = None self.inst = None @@ -407,7 +402,6 @@ class FuseMount(CephFSMount): if require_clean: raise - self.mounted = False self.cleanup() def teardown(self): @@ -425,8 +419,6 @@ class FuseMount(CephFSMount): except CommandFailedError: pass - self.mounted = False - def _asok_path(self): return "/var/run/ceph/ceph-client.{0}.*.asok".format(self.client_id) diff --git a/qa/tasks/cephfs/kernel_mount.py b/qa/tasks/cephfs/kernel_mount.py index ae7bceb7cfc83..9d69b81aeba47 100644 --- a/qa/tasks/cephfs/kernel_mount.py +++ b/qa/tasks/cephfs/kernel_mount.py @@ -61,8 +61,6 @@ class KernelMount(CephFSMount): self.enable_dynamic_debug() self.ctx[f'kmount_count.{self.client_remote.hostname}'] = kmount_count + 1 - self.mounted = True - def _run_mount_cmd(self, mntopts, check_status): mount_cmd = self._get_mount_cmd(mntopts) mountcmd_stdout, mountcmd_stderr = StringIO(), StringIO() @@ -154,7 +152,6 @@ class KernelMount(CephFSMount): self.disable_dynamic_debug() self.ctx[f'kmount_count.{self.client_remote.hostname}'] = kmount_count - 1 - self.mounted = False self.cleanup() def umount_wait(self, force=False, require_clean=False, @@ -178,7 +175,6 @@ class KernelMount(CephFSMount): self.mountpoint], timeout=timeout, omit_sudo=False) - self.mounted = False self.cleanup() def wait_until_mounted(self): @@ -186,11 +182,11 @@ class KernelMount(CephFSMount): Unlike the fuse client, the kernel client is up and running as soon as the initial mount() function returns. """ - assert self.mounted + assert self.is_mounted() def teardown(self): super(KernelMount, self).teardown() - if self.mounted: + if self.is_mounted(): self.umount() def _get_debug_dir(self): @@ -300,7 +296,7 @@ echo '{fdata}' | sudo tee /sys/kernel/debug/dynamic_debug/control Look up the CephFS client ID for this mount, using debugfs. """ - assert self.mounted + assert self.is_mounted() return self._get_global_id() diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 9e53c983abc05..014972e6d0e1c 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -41,7 +41,6 @@ class CephFSMount(object): :param cephfs_mntpt: Path to directory inside Ceph FS that will be mounted as root """ - self.mounted = False self.ctx = ctx self.test_dir = test_dir @@ -170,7 +169,8 @@ class CephFSMount(object): sudo=True).decode()) def is_mounted(self): - return self.mounted + return self.hostfs_mntpt in \ + self.client_remote.read_file('/proc/self/mounts',stdout=StringIO()) def setupfs(self, name=None): if name is None and self.fs is not None: @@ -518,7 +518,7 @@ class CephFSMount(object): exception: wait accepted too which can be True or False. """ self.umount_wait() - assert not self.mounted + assert not self.is_mounted() mntopts = kwargs.pop('mntopts', []) check_status = kwargs.pop('check_status', True) -- 2.39.5