]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test_cephfs_shell: allow running CephFS shell script
authorRishabh Dave <ridave@redhat.com>
Thu, 27 Jun 2019 13:40:28 +0000 (19:10 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 25 Jul 2019 05:21:11 +0000 (10:51 +0530)
Add a method to test_cephfs_shell.py that allows running CephFS shell
script using option "-b" of cephfs-shell.

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

index 31f16b44a257057b4e9db8e01f2c80a4fc617074..ab267e521847416b82e470cc475758943a155f0b 100644 (file)
@@ -1,6 +1,7 @@
 import os
 import crypt
 import logging
+from tempfile import mkstemp as tempfile_mkstemp
 from StringIO import StringIO
 from tasks.cephfs.cephfs_test_case import CephFSTestCase
 from tasks.cephfs.fuse_mount import FuseMount
@@ -23,6 +24,22 @@ class TestCephFSShell(CephFSTestCase):
                                                 stdin=stdin)
         return status.stdout.getvalue().strip()
 
+    def run_cephfs_shell_script(self, script, mount_x=None, stdin=None):
+        if mount_x is None:
+            mount_x = self.mount_a
+
+        scriptpath = tempfile_mkstemp(prefix='test-cephfs', text=True)[1]
+        with open(scriptpath, 'w') as scriptfile:
+            scriptfile.write(script)
+        # copy script to the machine running cephfs-shell.
+        mount_x.client_remote.put_file(scriptpath, scriptpath)
+        mount_x.run_shell('chmod 755 ' + scriptpath)
+
+        args = ["cephfs-shell", "-c", mount_x.config_path, '-b', scriptpath]
+        log.info('Running script \"' + scriptpath + '\"')
+        return mount_x.client_remote.run(args=args, stdout=StringIO(),
+                                         stderr=StringIO(), stdin=stdin)
+
     def test_help(self):
         """
         Test that help outputs commands.