From: Rishabh Dave Date: Wed, 20 Feb 2019 16:40:04 +0000 (+0530) Subject: qa: add a method to run a command as a different user X-Git-Tag: v15.1.0~2911^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8ca094ff997bc1432413768b3fbe976d7482fe30;p=ceph.git qa: add a method to run a command as a different user Signed-off-by: Rishabh Dave --- diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index f4b6bb400f1..d1c628df722 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -432,6 +432,24 @@ class LocalFuseMount(FuseMount): check_status=check_status, omit_sudo=omit_sudo) + def run_as_user(self, args, user, wait=True, stdin=None, check_status=True): + # FIXME maybe should add a pwd arg to teuthology.orchestra so that + # the "cd foo && bar" shenanigans isn't needed to begin with and + # then we wouldn't have to special case this + if isinstance(args, str): + args = 'sudo -u %s -s /bin/bash -c %s' % (user, 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) + + return self.client_remote.run(args, wait=wait, cwd=self.mountpoint, + check_status=check_status, stdin=stdin, + omit_sudo=False) + def setupfs(self, name=None): if name is None and self.fs is not None: # Previous mount existed, reuse the old name