From 8ca094ff997bc1432413768b3fbe976d7482fe30 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 20 Feb 2019 22:10:04 +0530 Subject: [PATCH] qa: add a method to run a command as a different user Signed-off-by: Rishabh Dave --- qa/tasks/vstart_runner.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index f4b6bb400f113..d1c628df72241 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 -- 2.39.5