From 56cb3e5e616c6abe72b8f739ca374426c48bf9dc Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 9 Aug 2023 18:10:32 +0530 Subject: [PATCH] qa: inherit RunCephCmd in CephTestCase instead of CephFSTestCase MgrTestCase also needs RunCephCmd. If RunCephCmd is inherited by CephTestCase, instead of CephFSTestCase, MgrTestCase will automatically inherit RunCephCmd because it inhertis CephTestCase. Fixes: https://tracker.ceph.com/issues/62084 Signed-off-by: Rishabh Dave (cherry picked from commit 4b369cf18ed1391a426ab4ae86da834e9c074f81) Conflicts: qa/tasks/cephfs/cephfs_test_case.py qa/tasks/cephfs/filesystem.py Minor conflicts related to missing backports. --- qa/tasks/ceph_test_case.py | 42 ++++++++++++++++++++++++++++- qa/tasks/cephfs/cephfs_test_case.py | 2 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/qa/tasks/ceph_test_case.py b/qa/tasks/ceph_test_case.py index 3f355825c6f38..a8371089e2f30 100644 --- a/qa/tasks/ceph_test_case.py +++ b/qa/tasks/ceph_test_case.py @@ -2,6 +2,7 @@ from typing import Optional, TYPE_CHECKING import unittest import time import logging +from io import StringIO from teuthology.exceptions import CommandFailedError @@ -13,7 +14,32 @@ log = logging.getLogger(__name__) class TestTimeoutError(RuntimeError): pass -class CephTestCase(unittest.TestCase): +class RunCephCmd: + + def run_ceph_cmd(self, *args, **kwargs): + if kwargs.get('args') is None and args: + if len(args) == 1: + args = args[0] + kwargs['args'] = args + return self.mon_manager.run_cluster_cmd(**kwargs) + + def get_ceph_cmd_result(self, *args, **kwargs): + if kwargs.get('args') is None and args: + if len(args) == 1: + args = args[0] + kwargs['args'] = args + return self.run_ceph_cmd(**kwargs).exitstatus + + def get_ceph_cmd_stdout(self, *args, **kwargs): + if kwargs.get('args') is None and args: + if len(args) == 1: + args = args[0] + kwargs['args'] = args + kwargs['stdout'] = kwargs.pop('stdout', StringIO()) + return self.run_ceph_cmd(**kwargs).stdout.getvalue() + + +class CephTestCase(unittest.TestCase, RunCephCmd): """ For test tasks that want to define a structured set of tests implemented in python. Subclass this with appropriate @@ -36,9 +62,23 @@ class CephTestCase(unittest.TestCase): # their special needs. If not met, tests will be skipped. REQUIRE_MEMSTORE = False + def _init_mon_manager(self): + # if vstart_runner.py has invoked this code + if 'Local' in str(type(self.ceph_cluster)): + from tasks.vstart_runner import LocalCephManager + self.mon_manager = LocalCephManager(ctx=self.ctx) + # else teuthology has invoked this code + else: + from tasks.ceph_manager import CephManager + self.mon_manager = CephManager(self.ceph_cluster.admin_remote, + ctx=self.ctx, logger=log.getChild('ceph_manager')) + def setUp(self): self._mon_configs_set = set() + self._init_mon_manager() + self.admin_remote = self.ceph_cluster.admin_remote + self.ceph_cluster.mon_manager.raw_cluster_cmd("log", "Starting test {0}".format(self.id())) diff --git a/qa/tasks/cephfs/cephfs_test_case.py b/qa/tasks/cephfs/cephfs_test_case.py index d2688929cc37f..aead68108ab50 100644 --- a/qa/tasks/cephfs/cephfs_test_case.py +++ b/qa/tasks/cephfs/cephfs_test_case.py @@ -111,7 +111,7 @@ class CephFSTestCase(CephTestCase): "dump", "--format=json-pretty"))['blacklist'] log.info(f"Removing {len(blacklist)} blacklist entries") for addr, blocklisted_at in blacklist.items(): - self.mds_cluster.mon_manager.raw_cluster_cmd("osd", "blacklist", "rm", addr) + self.run_ceph_cmd("osd", "blacklist", "rm", addr) def setUp(self): super(CephFSTestCase, self).setUp() -- 2.39.5