]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: allow keeping sudo in command arguments
authorRishabh Dave <ridave@redhat.com>
Wed, 20 Feb 2019 16:36:41 +0000 (22:06 +0530)
committerRamana Raja <rraja@redhat.com>
Mon, 16 Mar 2020 09:48:58 +0000 (15:18 +0530)
sudo cannot be omitted from the given command's arguments, when running
passwd, chown and, specially, when sudo is used for running the given
command as different user.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
(cherry picked from commit 3e0a1361f78452d79c283f70b5dc2b865d62cb61)

qa/tasks/cephfs/mount.py
qa/tasks/vstart_runner.py

index c3d58c86180cecc695dc91976f618d1a18735ec6..f0129b84ae47a6b83a65e9cc199525afcbdb1094 100644 (file)
@@ -155,11 +155,12 @@ class CephFSMount(object):
         p.wait()
         return p.stdout.getvalue().strip()
 
-    def run_shell(self, args, wait=True, check_status=True):
+    def run_shell(self, args, wait=True, check_status=True, omit_sudo=True):
         args = ["cd", self.mountpoint, run.Raw('&&'), "sudo"] + args
         return self.client_remote.run(args=args, stdout=StringIO(),
                                       stderr=StringIO(), wait=wait,
-                                      check_status=check_status)
+                                      check_status=check_status,
+                                      omit_sudo=omit_sudo)
 
     def open_no_data(self, basename):
         """
index 0d2247ccbdb719078ac5fbc9243b9205e8f41d29..808b7e5cc322fdbab07a998a9b90230caadb4f77 100644 (file)
@@ -236,10 +236,16 @@ class LocalRemote(object):
 
     def run(self, args, check_status=True, wait=True,
             stdout=None, stderr=None, cwd=None, stdin=None,
-            logger=None, label=None, env=None, timeout=None):
+            logger=None, label=None, env=None, timeout=None, omit_sudo=True):
+        try:
+            if args[args.index('sudo') + 1] in ['-u', 'passwd', 'chown']:
+                omit_sudo = False
+        except ValueError:
+            pass
 
         # We don't need no stinkin' sudo
-        args = [a for a in args if a != "sudo"]
+        if omit_sudo:
+            args = [a for a in args if a != "sudo"]
 
         # We have to use shell=True if any run.Raw was present, e.g. &&
         shell = any([a for a in args if isinstance(a, Raw)])
@@ -418,12 +424,13 @@ class LocalFuseMount(FuseMount):
         # to avoid assumptions about daemons' pwd
         return os.path.abspath("./client.{0}.keyring".format(self.client_id))
 
-    def run_shell(self, args, wait=True, check_status=True):
+    def run_shell(self, args, wait=True, check_status=True, omit_sudo=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
         return self.client_remote.run(args, wait=wait, cwd=self.mountpoint,
-                                      check_status=check_status)
+                                      check_status=check_status,
+                                      omit_sudo=omit_sudo)
 
     def setupfs(self, name=None):
         if name is None and self.fs is not None: