From 9b4a62a8358ee293b0851e45b38c2857b7bc8c46 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) --- qa/tasks/ceph_test_case.py | 42 ++++++++++++++++++++++++++++- qa/tasks/cephfs/cephfs_test_case.py | 41 +--------------------------- qa/tasks/cephfs/filesystem.py | 2 +- 3 files changed, 43 insertions(+), 42 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 7c9cb6aae472e..f26b598aa09e9 100644 --- a/qa/tasks/cephfs/cephfs_test_case.py +++ b/qa/tasks/cephfs/cephfs_test_case.py @@ -2,7 +2,6 @@ import json import logging import os import re -from io import StringIO from tasks.ceph_test_case import CephTestCase @@ -54,32 +53,7 @@ class MountDetails(): mntobj.hostfs_mntpt = self.hostfs_mntpt -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 CephFSTestCase(CephTestCase, RunCephCmd): +class CephFSTestCase(CephTestCase): """ Test case for Ceph FS, requires caller to populate Filesystem and Mounts, into the fs, mount_a, mount_b class attributes (setting mount_b is optional) @@ -137,21 +111,8 @@ class CephFSTestCase(CephTestCase, RunCephCmd): for addr, blocklisted_at in blacklist.items(): self.run_ceph_cmd("osd", "blacklist", "rm", addr) - 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): super(CephFSTestCase, self).setUp() - self._init_mon_manager() - self.admin_remote = self.ceph_cluster.admin_remote self.config_set('mon', 'mon_allow_pool_delete', True) diff --git a/qa/tasks/cephfs/filesystem.py b/qa/tasks/cephfs/filesystem.py index 7104866b08d92..dc314efa8f0ab 100644 --- a/qa/tasks/cephfs/filesystem.py +++ b/qa/tasks/cephfs/filesystem.py @@ -20,7 +20,7 @@ from teuthology import contextutil from tasks.ceph_manager import write_conf from tasks.ceph_manager import CephManager -from tasks.cephfs.cephfs_test_case import RunCephCmd +from tasks.ceph_test_case import RunCephCmd log = logging.getLogger(__name__) -- 2.39.5