]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: add a method to run a command as a different user
authorRishabh Dave <ridave@redhat.com>
Wed, 20 Feb 2019 16:40:04 +0000 (22:10 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 12 Apr 2019 09:30:57 +0000 (15:00 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/vstart_runner.py

index f4b6bb400f1135c59882948e3d91c0203143ee10..d1c628df72241815e2abb4ba96c71ea4574fe2f1 100644 (file)
@@ -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