]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: upgrade is_mounted() in mount.py 45036/head
authorRishabh Dave <ridave@redhat.com>
Tue, 7 Dec 2021 10:34:00 +0000 (16:04 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 20 Jul 2022 17:06:18 +0000 (22:36 +0530)
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 <ridave@redhat.com>
qa/tasks/cephfs/fuse_mount.py
qa/tasks/cephfs/kernel_mount.py
qa/tasks/cephfs/mount.py

index 6f04967132e1e92290d5efee25e933dcf9a4fc97..fa0d84b842b3bf4722eb569ac14dca207e63424b 100644 (file)
@@ -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)
 
index ae7bceb7cfc8333a9a452975ee647b93391843d4..9d69b81aeba47c94875e14d2cec518d61847145c 100644 (file)
@@ -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()
 
index 9e53c983abc05ed5a681c79139edc76e2bad82c6..014972e6d0e1c2dadfd68bd3e9490535b511adc2 100644 (file)
@@ -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)