From c2248233a7bb631cdd307fa5d0dbae720418ea59 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 24 Apr 2020 11:22:28 +0200 Subject: [PATCH] mgr/dashboard: Add dashboard to mon_command reference docs Signed-off-by: Sebastian Wagner (cherry picked from commit 6b029c09951d002fa6bf04390920f1232390fb2f) --- src/pybind/mgr/dashboard/__init__.py | 9 ++++--- src/pybind/mgr/dashboard/conftest.py | 39 ---------------------------- src/pybind/mgr/tests/__init__.py | 19 ++++++++++++++ 3 files changed, 25 insertions(+), 42 deletions(-) delete mode 100644 src/pybind/mgr/dashboard/conftest.py diff --git a/src/pybind/mgr/dashboard/__init__.py b/src/pybind/mgr/dashboard/__init__.py index 78879986398..25a7f19f3c6 100644 --- a/src/pybind/mgr/dashboard/__init__.py +++ b/src/pybind/mgr/dashboard/__init__.py @@ -23,8 +23,6 @@ if 'UNITTEST' not in os.environ: mgr = _ModuleProxy() - # DO NOT REMOVE: required for ceph-mgr to load a module - from .module import Module, StandbyModule # noqa: F401 else: import logging logging.basicConfig(level=logging.DEBUG) @@ -32,7 +30,12 @@ else: os.environ['PATH'] = '{}:{}'.format(os.path.abspath('../../../../build/bin'), os.environ['PATH']) - from tests import mock # type: ignore + from tests import mock, mock_ceph_modules # type: ignore mgr = mock.Mock() mgr.get_frontend_path.side_effect = lambda: os.path.abspath("./frontend/dist") + + mock_ceph_modules() + +# DO NOT REMOVE: required for ceph-mgr to load a module +from .module import Module, StandbyModule # noqa: F401 diff --git a/src/pybind/mgr/dashboard/conftest.py b/src/pybind/mgr/dashboard/conftest.py deleted file mode 100644 index 8b5e9ac9c36..00000000000 --- a/src/pybind/mgr/dashboard/conftest.py +++ /dev/null @@ -1,39 +0,0 @@ -import sys - -try: - from mock import Mock, patch -except ImportError: - from unittest.mock import Mock, patch - - -class MockRadosError(Exception): - def __init__(self, message, errno=None): - super(MockRadosError, self).__init__(message) - self.errno = errno - - def __str__(self): - msg = super(MockRadosError, self).__str__() - if self.errno is None: - return msg - return '[errno {0}] {1}'.format(self.errno, msg) - - -def pytest_configure(config): - sys.modules.update({ - 'rados': Mock(Error=MockRadosError, OSError=MockRadosError), - 'rbd': Mock(), - 'cephfs': Mock(), - }) - - # we need the following patches to fix the issue of multiple inheritance when - # one of the base classes is being mocked. - # Error example: - # TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) \ - # subclass of the metaclasses of all its bases - class _BaseMgrModule: - pass - - patcher = patch("ceph_module.BaseMgrStandbyModule", new=_BaseMgrModule) - patcher.start() - patcher = patch("ceph_module.BaseMgrModule", new=_BaseMgrModule) - patcher.start() diff --git a/src/pybind/mgr/tests/__init__.py b/src/pybind/mgr/tests/__init__.py index d3b10393e8f..7bccfc79970 100644 --- a/src/pybind/mgr/tests/__init__.py +++ b/src/pybind/mgr/tests/__init__.py @@ -66,3 +66,22 @@ if 'UNITTEST' in os.environ: cm.BaseMgrModule = M cm.BaseMgrStandbyModule = M sys.modules['ceph_module'] = cm + + def mock_ceph_modules(): + class MockRadosError(Exception): + def __init__(self, message, errno=None): + super(MockRadosError, self).__init__(message) + self.errno = errno + + def __str__(self): + msg = super(MockRadosError, self).__str__() + if self.errno is None: + return msg + return '[errno {0}] {1}'.format(self.errno, msg) + + + sys.modules.update({ + 'rados': mock.Mock(Error=MockRadosError, OSError=MockRadosError), + 'rbd': mock.Mock(), + 'cephfs': mock.Mock(), + }) \ No newline at end of file -- 2.47.3