From fef0180c93393b4890093b782cc113494fa6d236 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Thu, 27 Jun 2019 19:10:28 +0530 Subject: [PATCH] test_cephfs_shell: allow running CephFS shell script 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 --- qa/tasks/cephfs/test_cephfs_shell.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/qa/tasks/cephfs/test_cephfs_shell.py b/qa/tasks/cephfs/test_cephfs_shell.py index 31f16b44a25..ab267e52184 100644 --- a/qa/tasks/cephfs/test_cephfs_shell.py +++ b/qa/tasks/cephfs/test_cephfs_shell.py @@ -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. -- 2.39.5