]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/cephfs: move run_shell and related methods to mount.py
authorRishabh Dave <ridave@redhat.com>
Fri, 24 Jan 2020 10:40:58 +0000 (16:10 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 16 Apr 2020 18:57:41 +0000 (00:27 +0530)
LocalFuseMount and LocalKernelMount can directly inherit these methods
from CephFSMount via FuseMount and KernelMount respectively. Moving
would avoid duplication and would make these methods more accessible
for reusing via inheritance.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/mount.py
qa/tasks/vstart_runner.py

index d3cb0a429edd3fb0cdda33b961ab9015eb15a240..03fb38cf60edf72f3fdf421672055e619b8ebe60 100644 (file)
@@ -194,15 +194,49 @@ class CephFSMount(object):
         return six.ensure_str(p.stdout.getvalue().strip())
 
     def run_shell(self, args, wait=True, stdin=None, check_status=True,
-                  omit_sudo=True):
+                  cwd=None, omit_sudo=True):
+        args = args.split() if isinstance(args, str) else args
+        # XXX: all commands ran with CephFS mount as CWD must be executed with
+        #  superuser privileges when tests are being run using teuthology.
+        if args[0] != 'sudo':
+            args.insert(0, 'sudo')
+        if not cwd:
+            cwd = self.mountpoint
+
+        return self.client_remote.run(args=args, stdin=stdin, wait=wait,
+                                      stdout=BytesIO(), stderr=BytesIO(),
+                                      cwd=cwd, check_status=check_status)
+
+    def run_as_user(self, args, user, wait=True, stdin=None,
+                    check_status=True, cwd=None):
         if isinstance(args, str):
-            args = args.split()
-
-        args = ["cd", self.mountpoint, run.Raw('&&'), "sudo"] + args
-        return self.client_remote.run(args=args, stdout=StringIO(),
-                                      stderr=StringIO(), wait=wait,
-                                      stdin=stdin, check_status=check_status,
-                                      omit_sudo=omit_sudo)
+            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)
+        if not cwd:
+            cwd = self.mountpoint
+
+        return self.client_remote.run(args=args, wait=wait, stdin=stdin,
+                                      stdout=BytesIO(), stderr=BytesIO(),
+                                      check_status=check_status, cwd=cwd)
+
+    def run_as_root(self, args, wait=True, stdin=None, check_status=True,
+                    cwd=None):
+        if isinstance(args, str):
+            args = 'sudo ' + args
+        if isinstance(args, list):
+            args.insert(0, 'sudo')
+        if not cwd:
+            cwd = self.mountpoint
+
+        return self.client_remote.run(args=args, wait=wait, stdin=stdin,
+                                      stdout=BytesIO(), stderr=BytesIO(),
+                                      check_status=check_status, cwd=cwd)
 
     def open_no_data(self, basename):
         """
index 919ac92c58b4fe47cd44e58d68041a22ad3980c9..f19cd112aa5f847f2dc5f75019c4c6d10c4fb367 100644 (file)
@@ -512,7 +512,6 @@ def safe_kill(pid):
         else:
             raise
 
-
 class LocalKernelMount(KernelMount):
     def __init__(self, ctx, test_dir, client_id):
         super(LocalKernelMount, self).__init__(ctx, test_dir, client_id, LocalRemote(), None, None, None)
@@ -532,67 +531,6 @@ class LocalKernelMount(KernelMount):
         else:
             return keyring_path
 
-    def run_shell(self, args, wait=True, stdin=None, check_status=True,
-                  omit_sudo=False):
-        # 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=args, wait=wait, cwd=self.mountpoint,
-                                      stdin=stdin, 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=args, wait=wait, cwd=self.mountpoint,
-                                      check_status=check_status, stdin=stdin,
-                                      omit_sudo=False)
-
-    def run_as_root(self, args, 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 ' + args
-        if isinstance(args, list):
-            args.insert(0, 'sudo')
-
-        return self.client_remote.run(args=args, wait=wait, cwd=self.mountpoint,
-                                      check_status=check_status,
-                                      omit_sudo=False)
-
-    def testcmd(self, args, wait=True, stdin=None, omit_sudo=False):
-        # 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.run_shell(args, wait=wait, stdin=stdin, check_status=False,
-                              omit_sudo=omit_sudo)
-
-    def testcmd_as_user(self, args, user, wait=True, stdin=None):
-        # 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.run_as_user(args, user=user, wait=wait, stdin=stdin,
-                                check_status=False)
-
-    def testcmd_as_root(self, args, wait=True, stdin=None):
-        # 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.run_as_root(args, wait=wait, stdin=stdin,
-                                check_status=False)
-
     def setupfs(self, name=None):
         if name is None and self.fs is not None:
             # Previous mount existed, reuse the old name
@@ -721,66 +659,6 @@ 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, stdin=None, 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=args, wait=wait, cwd=self.mountpoint,
-                                      stdin=stdin, 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=args, wait=wait, cwd=self.mountpoint,
-                                      check_status=check_status, stdin=stdin,
-                                      omit_sudo=False)
-
-    def run_as_root(self, args, 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 ' + args
-        if isinstance(args, list):
-            args.insert(0, 'sudo')
-
-        return self.client_remote.run(args=args, wait=wait, cwd=self.mountpoint,
-                                      check_status=check_status,
-                                      omit_sudo=False)
-
-    def testcmd(self, args, wait=True, stdin=None, 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.run_shell(args, wait=wait, stdin=stdin, check_status=False,
-                              omit_sudo=omit_sudo)
-
-    def testcmd_as_user(self, args, user, wait=True, stdin=None):
-        # 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.run_as_user(args, user=user, wait=wait, stdin=stdin,
-                                check_status=False)
-
-    def testcmd_as_root(self, args, wait=True, stdin=None):
-        # 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.run_as_root(args, wait=wait, stdin=stdin,
-                                check_status=False)
-
     def setupfs(self, name=None):
         if name is None and self.fs is not None:
             # Previous mount existed, reuse the old name