]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: don't pass cmd args from run_as_user as str 35540/head
authorRishabh Dave <ridave@redhat.com>
Wed, 17 Jun 2020 10:08:59 +0000 (15:38 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 17 Jun 2020 17:43:05 +0000 (23:13 +0530)
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 <ridave@redhat.com>
qa/tasks/cephfs/mount.py

index 769058fa05b5112b10e5de5e851552d1119f5405..511ccebe3fb59980cbea466450a1b20e27183d23 100644 (file)
@@ -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):
         """