From: Rishabh Dave Date: Wed, 17 Jun 2020 10:08:59 +0000 (+0530) Subject: qa/cephfs: don't pass cmd args from run_as_user as str X-Git-Tag: v16.1.0~1941^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F35540%2Fhead;p=ceph.git qa/cephfs: don't pass cmd args from run_as_user as str Passing command arguments from run_as_user() to run_shell() as string can be problematic since command argument to be passed to -c option of sudo should be a single argument (i.e. 'ls dir' instead of ['ls', 'dir']). Fixes: https://tracker.ceph.com/issues/46057 Signed-off-by: Rishabh Dave --- diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 769058fa05b..511ccebe3fb 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -516,23 +516,27 @@ class CephFSMount(object): stdout=StringIO(), stderr=StringIO(), cwd=cwd, check_status=check_status) - def run_as_user(self, args, user, wait=True, stdin=None, - check_status=True, cwd=None): + def run_as_user(self, **kwargs): + """ + Besides the arguments defined for run_shell() this method also + accepts argument 'user'. + """ + args = kwargs.pop('args') + user = kwargs.pop('user') if isinstance(args, str): - args = 'sudo -u %s -s /bin/bash -c %s' % (user, args) + args = ['sudo', '-u', user, '-s', '/bin/bash', '-c', args] elif isinstance(args, list): cmdlist = args cmd = '' for i in cmdlist: cmd = cmd + i + ' ' - args = ['sudo', '-u', user, '-s', '/bin/bash', '-c'] - args.append(cmd) - if not cwd: - cwd = self.mountpoint + # get rid of extra space at the end. + cmd = cmd[:-1] - return self.client_remote.run(args=args, wait=wait, stdin=stdin, - stdout=StringIO(), stderr=StringIO(), - check_status=check_status, cwd=cwd) + args = ['sudo', '-u', user, '-s', '/bin/bash', '-c', cmd] + + kwargs['args'] = args + return self.run_shell(**kwargs) def run_as_root(self, **kwargs): """