From 23f279d7a9ec2578779e06b4775b3f440a04340e Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 17 Jun 2020 15:38:59 +0530 Subject: [PATCH] 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 --- qa/tasks/cephfs/mount.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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): """ -- 2.39.5