From 530982129ec131ef78e2f9989abfaeddb0959c65 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Mon, 17 Aug 2020 15:28:12 +0530 Subject: [PATCH] qa: add method run ceph cluster command with better interface This new method should allow better control on the process launched by the passed command. This is achieved by allowing arguments provided by teuthology.orchestra.run.run(). Signed-off-by: Rishabh Dave --- qa/tasks/ceph_manager.py | 72 +++++++++++++++------------------------ qa/tasks/vstart_runner.py | 23 +++++++++---- 2 files changed, 43 insertions(+), 52 deletions(-) diff --git a/qa/tasks/ceph_manager.py b/qa/tasks/ceph_manager.py index 4f1cbca93c85..0ea99210b653 100644 --- a/qa/tasks/ceph_manager.py +++ b/qa/tasks/ceph_manager.py @@ -1329,61 +1329,43 @@ class CephManager: except CommandFailedError: self.log('Failed to get pg_num from pool %s, ignoring' % pool) + def run_cluster_cmd(self, **kwargs): + """ + Run a Ceph command and return the object representing the process + for the command. + + Accepts arguments same as that of teuthology.orchestra.run.run() + """ + if self.cephadm: + return shell(self.ctx, self.cluster, self.controller, + args=['ceph'] + list(kwargs['args']), + stdout=StringIO(), + check_status=kwargs.get('check_status', True)) + + testdir = teuthology.get_testdir(self.ctx) + prefix = ['sudo', 'adjust-ulimits', 'ceph-coverage', + f'{testdir}/archive/coverage', 'timeout', '120', 'ceph', + '--cluster', self.cluster, '--log-early'] + kwargs['args'] = prefix + list(kwargs['args']) + return self.controller.run(**kwargs) + def raw_cluster_cmd(self, *args): """ Start ceph on a raw cluster. Return count """ - if self.cephadm: - proc = shell(self.ctx, self.cluster, self.controller, - args=['ceph'] + list(args), - stdout=StringIO()) - else: - testdir = teuthology.get_testdir(self.ctx) - ceph_args = [ - 'sudo', - 'adjust-ulimits', - 'ceph-coverage', - '{tdir}/archive/coverage'.format(tdir=testdir), - 'timeout', - '120', - 'ceph', - '--cluster', - self.cluster, - '--log-early', - ] - ceph_args.extend(args) - proc = self.controller.run( - args=ceph_args, - stdout=StringIO(), - ) - return proc.stdout.getvalue() + return self.run_cluster_cmd(**{'args': args, + 'stdout': StringIO()}).stdout.getvalue() def raw_cluster_cmd_result(self, *args, **kwargs): """ Start ceph on a cluster. Return success or failure information. """ if self.cephadm: - proc = shell(self.ctx, self.cluster, self.controller, - args=['ceph'] + list(args), - check_status=False) - else: - testdir = teuthology.get_testdir(self.ctx) - ceph_args = [ - 'sudo', - 'adjust-ulimits', - 'ceph-coverage', - '{tdir}/archive/coverage'.format(tdir=testdir), - 'timeout', - '120', - 'ceph', - '--cluster', - self.cluster, - ] - ceph_args.extend(args) - kwargs['args'] = ceph_args - kwargs['check_status'] = False - proc = self.controller.run(**kwargs) - return proc.exitstatus + return shell(self.ctx, self.cluster, self.controller, args=args, + check_status=False).existatus + + kwargs['args'], kwargs['check_status'] = args, False + return self.run_cluster_cmd(**kwargs).exitstatus def run_ceph_w(self, watch_channel=None): """ diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index 7c59491f4a4f..262fe65454a9 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -865,23 +865,32 @@ class LocalCephManager(CephManager): proc = self.controller.run(args=args, wait=False, stdout=StringIO()) return proc + def run_cluster_cmd(self, **kwargs): + """ + Run a Ceph command and the object representing the process for the + command. + + Accepts arguments same as teuthology.orchestra.remote.run(). + """ + kwargs['args'] = [os.path.join(BIN_PREFIX,'ceph')]+list(kwargs['args']) + return self.controller.run(**kwargs) + def raw_cluster_cmd(self, *args, **kwargs): """ args like ["osd", "dump"} return stdout string """ - proc = self.controller.run(args=[os.path.join(BIN_PREFIX, "ceph")] +\ - list(args), **kwargs, stdout=StringIO()) - return proc.stdout.getvalue() + kwargs['args'] = args + if kwargs.get('stdout') is None: + kwargs['stdout'] = StringIO() + return self.run_cluster_cmd(**kwargs).stdout.getvalue() def raw_cluster_cmd_result(self, *args, **kwargs): """ like raw_cluster_cmd but don't check status, just return rc """ - kwargs['check_status'] = False - proc = self.controller.run(args=[os.path.join(BIN_PREFIX, "ceph")] + \ - list(args), **kwargs) - return proc.exitstatus + kwargs['args'], kwargs['check_status'] = args, False + return self.run_cluster_cmd(**kwargs).exitstatus def admin_socket(self, daemon_type, daemon_id, command, check_status=True, timeout=None, stdout=None): -- 2.47.3