qa/cephfs: don't expect "file exists" error for "mkdir -p"

Get rid of try-except block in _create_mntpt() since "mkdir -p" doesn't
raise any error when the directory to be created already exists. Also,
use chmod command instead of mkdir command to set the permission mode on
directory since mkdir command would have no effect on the directory's
permission mode if the directory already exists.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
This commit is contained in:
Rishabh Dave 2021-03-10 10:30:32 +05:30
parent 1b34665741
commit 60d5d7cf9c
2 changed files with 8 additions and 15 deletions

View File

@ -176,16 +176,12 @@ class CephFSMount(object):
log.info('Ready to start {}...'.format(type(self).__name__))
def _create_mntpt(self):
stderr = StringIO()
self.client_remote.run(args=f'mkdir -p -v {self.hostfs_mntpt}',
timeout=60)
# Use 0000 mode to prevent undesired modifications to the mountpoint on
# the local file system.
script = f'mkdir -m 0000 -p -v {self.hostfs_mntpt}'.split()
try:
self.client_remote.run(args=script, timeout=(15*60),
stderr=stderr)
except CommandFailedError:
if 'file exists' not in stderr.getvalue().lower():
raise
self.client_remote.run(args=f'chmod 0000 {self.hostfs_mntpt}',
timeout=60)
@property
def _nsenter_args(self):

View File

@ -707,14 +707,11 @@ class LocalFuseMount(LocalCephFSMount, FuseMount):
self._mount_cmd_cwd, self._mount_cmd_logger, \
self._mount_cmd_stdin = None, None, None
# XXX: CephFSMount._create_mntpt() sets mountpoint's permission mode to
# 0000 which doesn't work for vstart_runner since superuser privileges are
# not used for mounting Ceph FS with FUSE.
def _create_mntpt(self):
stderr = StringIO()
script = f'mkdir -p -v {self.hostfs_mntpt}'.split()
try:
self.client_remote.run(args=script, stderr=stderr)
except CommandFailedError:
if 'file exists' not in stderr.getvalue().lower():
raise
self.client_remote.run(args=f'mkdir -p -v {self.hostfs_mntpt}')
def _run_mount_cmd(self, mntopts, check_status):
super(type(self), self)._run_mount_cmd(mntopts, check_status)