From: Alfonso Martínez Date: Tue, 6 Apr 2021 10:34:02 +0000 (+0200) Subject: nautilus: mgr/dashboard: decouple unit tests from build artifacts X-Git-Tag: v14.2.22~27^2~3^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3069af7903f2d7a7086a0fea1d4f65b1c7240960;p=ceph.git nautilus: mgr/dashboard: decouple unit tests from build artifacts Signed-off-by: Alfonso Martínez --- diff --git a/src/pybind/mgr/dashboard/__init__.py b/src/pybind/mgr/dashboard/__init__.py index 798ed37e3ab..fc8fbc20adb 100644 --- a/src/pybind/mgr/dashboard/__init__.py +++ b/src/pybind/mgr/dashboard/__init__.py @@ -48,7 +48,38 @@ else: # raise an ImportError import sys import mock - sys.modules['ceph_module'] = mock.Mock() mgr = mock.Mock() mgr.get_frontend_path.side_effect = lambda: os.path.abspath("./frontend/dist") + + 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) + + rbd = mock.Mock() + rbd.RBD_FEATURE_LAYERING = 1 + rbd.RBD_FEATURE_STRIPINGV2 = 2 + rbd.RBD_FEATURE_EXCLUSIVE_LOCK = 4 + rbd.RBD_FEATURE_OBJECT_MAP = 8 + rbd.RBD_FEATURE_FAST_DIFF = 16 + rbd.RBD_FEATURE_DEEP_FLATTEN = 32 + rbd.RBD_FEATURE_JOURNALING = 64 + rbd.RBD_FEATURE_DATA_POOL = 128 + rbd.RBD_FEATURE_OPERATIONS = 256 + + sys.modules.update({ + 'rados': mock.Mock(Error=MockRadosError, OSError=MockRadosError), + 'rbd': rbd, + 'cephfs': mock.Mock(), + 'ceph_module': mock.Mock(), + }) + + mock_ceph_modules() diff --git a/src/pybind/mgr/dashboard/controllers/iscsi.py b/src/pybind/mgr/dashboard/controllers/iscsi.py index af7532055d4..0a353841fc1 100644 --- a/src/pybind/mgr/dashboard/controllers/iscsi.py +++ b/src/pybind/mgr/dashboard/controllers/iscsi.py @@ -8,8 +8,8 @@ import re import json import cherrypy -import rados -import rbd +import rados # pylint: disable=import-error +import rbd # pylint: disable=import-error from . import ApiController, UiApiController, RESTController, BaseController, Endpoint,\ ReadPermission, UpdatePermission, Task diff --git a/src/pybind/mgr/dashboard/controllers/nfsganesha.py b/src/pybind/mgr/dashboard/controllers/nfsganesha.py index b9599d72b48..e98b17e6aeb 100644 --- a/src/pybind/mgr/dashboard/controllers/nfsganesha.py +++ b/src/pybind/mgr/dashboard/controllers/nfsganesha.py @@ -4,7 +4,7 @@ from __future__ import absolute_import from functools import partial import cherrypy -import cephfs +import cephfs # pylint: disable=import-error from . import ApiController, RESTController, UiApiController, BaseController, \ Endpoint, Task, ReadPermission, ControllerDoc, EndpointDoc diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 52dca087044..ea5714a6b72 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -9,7 +9,7 @@ from datetime import datetime import cherrypy -import rbd +import rbd # pylint: disable=import-error from . import ApiController, RESTController, Task, UpdatePermission, \ DeletePermission, CreatePermission, ReadPermission, allow_empty_body diff --git a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py index 0f6574a4667..405c068b0ff 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py @@ -8,7 +8,7 @@ from functools import partial import cherrypy -import rbd +import rbd # pylint: disable=import-error from . import ApiController, Endpoint, Task, BaseController, ReadPermission, \ RESTController diff --git a/src/pybind/mgr/dashboard/exceptions.py b/src/pybind/mgr/dashboard/exceptions.py index b44a3f15b03..83de90f0619 100644 --- a/src/pybind/mgr/dashboard/exceptions.py +++ b/src/pybind/mgr/dashboard/exceptions.py @@ -42,7 +42,7 @@ class DashboardException(Exception): def code(self): if self._code: return str(self._code) - return str(abs(self.errno)) + return str(abs(self.errno)) if self.errno is not None else 'Error' # access control module exceptions diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 224b05cab22..1a521d00b59 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -14,12 +14,14 @@ import sys import tempfile import threading import time + from uuid import uuid4 from OpenSSL import crypto -import _strptime # pylint: disable=unused-import from mgr_module import MgrModule, MgrStandbyModule, Option, CLIWriteCommand from mgr_util import get_default_addr, ServerConfigException, verify_tls_files +import _strptime # pylint: disable=unused-import + try: import cherrypy from cherrypy._cptools import HandlerWrapperTool diff --git a/src/pybind/mgr/dashboard/services/ceph_service.py b/src/pybind/mgr/dashboard/services/ceph_service.py index 6d38fa41079..dc02b2967d4 100644 --- a/src/pybind/mgr/dashboard/services/ceph_service.py +++ b/src/pybind/mgr/dashboard/services/ceph_service.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import json -import rados +import rados # pylint: disable=import-error from mgr_module import CommandResult from mgr_util import get_time_series_rates, get_most_recent_rate diff --git a/src/pybind/mgr/dashboard/services/cephfs.py b/src/pybind/mgr/dashboard/services/cephfs.py index bb75b4e2573..2c596c57b9e 100644 --- a/src/pybind/mgr/dashboard/services/cephfs.py +++ b/src/pybind/mgr/dashboard/services/cephfs.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from contextlib import contextmanager -import cephfs +import cephfs # pylint: disable=import-error from .. import mgr, logger diff --git a/src/pybind/mgr/dashboard/services/exception.py b/src/pybind/mgr/dashboard/services/exception.py index b5c0bd58a17..ff51b973e65 100644 --- a/src/pybind/mgr/dashboard/services/exception.py +++ b/src/pybind/mgr/dashboard/services/exception.py @@ -7,8 +7,8 @@ from contextlib import contextmanager import cherrypy -import rbd -import rados +import rbd # pylint: disable=import-error +import rados # pylint: disable=import-error from .. import logger from ..services.ceph_service import SendCommandError diff --git a/src/pybind/mgr/dashboard/services/rbd.py b/src/pybind/mgr/dashboard/services/rbd.py index 55c6f542c0a..d0ac20917db 100644 --- a/src/pybind/mgr/dashboard/services/rbd.py +++ b/src/pybind/mgr/dashboard/services/rbd.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import six -import rbd +import rbd # pylint: disable=import-error from .. import mgr from .ceph_service import CephService diff --git a/src/pybind/mgr/dashboard/tests/test_exceptions.py b/src/pybind/mgr/dashboard/tests/test_exceptions.py index 5607f1dd029..83845921797 100644 --- a/src/pybind/mgr/dashboard/tests/test_exceptions.py +++ b/src/pybind/mgr/dashboard/tests/test_exceptions.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import time -import rados +import rados # pylint: disable=import-error from . import ControllerTestCase from ..services.ceph_service import SendCommandError