From c803df13359da387e9eb541a730b568c4d3045f5 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Fri, 2 Feb 2018 15:33:44 +0000 Subject: [PATCH] mgr/dashboard_v2: mocking of rados and rbd modules Signed-off-by: Ricardo Dias --- src/pybind/mgr/dashboard_v2/.pylintrc | 2 +- src/pybind/mgr/dashboard_v2/__init__.py | 4 ++- .../mgr/dashboard_v2/cephmock/__init__.py | 0 .../{ => cephmock}/ceph_module_mock.py | 3 ++ .../mgr/dashboard_v2/cephmock/rados_mock.py | 12 +++++++ .../mgr/dashboard_v2/cephmock/rbd_mock.py | 31 +++++++++++++++++++ src/pybind/mgr/dashboard_v2/tox.ini | 7 ++++- 7 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/pybind/mgr/dashboard_v2/cephmock/__init__.py rename src/pybind/mgr/dashboard_v2/{ => cephmock}/ceph_module_mock.py (92%) create mode 100644 src/pybind/mgr/dashboard_v2/cephmock/rados_mock.py create mode 100644 src/pybind/mgr/dashboard_v2/cephmock/rbd_mock.py diff --git a/src/pybind/mgr/dashboard_v2/.pylintrc b/src/pybind/mgr/dashboard_v2/.pylintrc index f43d157e452..ab5d1f8a777 100644 --- a/src/pybind/mgr/dashboard_v2/.pylintrc +++ b/src/pybind/mgr/dashboard_v2/.pylintrc @@ -3,7 +3,7 @@ # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code -extension-pkg-whitelist= +extension-pkg-whitelist=rados,rbd # Add files or directories to the blacklist. They should be base names, not # paths. diff --git a/src/pybind/mgr/dashboard_v2/__init__.py b/src/pybind/mgr/dashboard_v2/__init__.py index 5102e244e22..51e53764ee8 100644 --- a/src/pybind/mgr/dashboard_v2/__init__.py +++ b/src/pybind/mgr/dashboard_v2/__init__.py @@ -26,8 +26,10 @@ else: import logging import sys # pylint: disable=W0403 - from . import ceph_module_mock + from .cephmock import ceph_module_mock, rados_mock, rbd_mock sys.modules['ceph_module'] = ceph_module_mock + sys.modules['rados'] = rados_mock + sys.modules['rbd'] = rbd_mock logging.basicConfig(level=logging.WARNING) logger = logging.getLogger(__name__) logging.root.handlers[0].setLevel(logging.WARNING) diff --git a/src/pybind/mgr/dashboard_v2/cephmock/__init__.py b/src/pybind/mgr/dashboard_v2/cephmock/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pybind/mgr/dashboard_v2/ceph_module_mock.py b/src/pybind/mgr/dashboard_v2/cephmock/ceph_module_mock.py similarity index 92% rename from src/pybind/mgr/dashboard_v2/ceph_module_mock.py rename to src/pybind/mgr/dashboard_v2/cephmock/ceph_module_mock.py index 254b1d90376..edb3c341cf7 100644 --- a/src/pybind/mgr/dashboard_v2/ceph_module_mock.py +++ b/src/pybind/mgr/dashboard_v2/cephmock/ceph_module_mock.py @@ -36,3 +36,6 @@ class BaseMgrModule(object): def _ceph_log(self, *args): pass + + def _ceph_get_context(self): + return None diff --git a/src/pybind/mgr/dashboard_v2/cephmock/rados_mock.py b/src/pybind/mgr/dashboard_v2/cephmock/rados_mock.py new file mode 100644 index 00000000000..3e51f4038cd --- /dev/null +++ b/src/pybind/mgr/dashboard_v2/cephmock/rados_mock.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + + +class Rados(object): + def __init__(self, *args, **kwargs): + pass + + def connect(self): + pass + + def open_ioctx(self, pool_name): + pass diff --git a/src/pybind/mgr/dashboard_v2/cephmock/rbd_mock.py b/src/pybind/mgr/dashboard_v2/cephmock/rbd_mock.py new file mode 100644 index 00000000000..3b433ed5d74 --- /dev/null +++ b/src/pybind/mgr/dashboard_v2/cephmock/rbd_mock.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + + +RBD_FEATURE_LAYERING = "RBD_FEATURE_LAYERING" +RBD_FEATURE_STRIPINGV2 = "RBD_FEATURE_STRIPINGV2" +RBD_FEATURE_EXCLUSIVE_LOCK = "RBD_FEATURE_EXCLUSIVE_LOCK" +RBD_FEATURE_OBJECT_MAP = "RBD_FEATURE_OBJECT_MAP" +RBD_FEATURE_FAST_DIFF = "RBD_FEATURE_FAST_DIFF" +RBD_FEATURE_DEEP_FLATTEN = "RBD_FEATURE_DEEP_FLATTEN" +RBD_FEATURE_JOURNALING = "RBD_FEATURE_JOURNALING" +RBD_FEATURE_DATA_POOL = "RBD_FEATURE_DATA_POOL" +RBD_FEATURE_OPERATIONS = "RBD_FEATURE_OPERATIONS" + + +class RBD(object): + def __init__(self, *args, **kwargs): + pass + + def list(self, ioctx): + pass + + +class Image(object): + def __init__(self, *args, **kwargs): + pass + + def stat(self): + pass + + def features(self): + pass diff --git a/src/pybind/mgr/dashboard_v2/tox.ini b/src/pybind/mgr/dashboard_v2/tox.ini index 7afc92647a7..6fcfcdacef7 100644 --- a/src/pybind/mgr/dashboard_v2/tox.ini +++ b/src/pybind/mgr/dashboard_v2/tox.ini @@ -8,6 +8,8 @@ setenv= UNITTEST=true WEBTEST_INTERACTIVE=false COVERAGE_FILE= .coverage.{envname} + PYTHONPATH = {toxinidir}/../../../../build/lib/cython_modules/lib.3:{toxinidir}/../../../../build/lib/cython_modules/lib.2 + LD_LIBRARY_PATH = {toxinidir}/../../../../build/lib commands= {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml tests/ @@ -28,7 +30,10 @@ commands = coverage xml [testenv:lint] +setenv = + PYTHONPATH = {toxinidir}/../../../../build/lib/cython_modules/lib.3:{toxinidir}/../../../../build/lib/cython_modules/lib.2 + LD_LIBRARY_PATH = {toxinidir}/../../../../build/lib deps=-r{toxinidir}/requirements.txt commands= - pylint --rcfile=.pylintrc --jobs=5 . module.py tools.py ceph_module_mock.py controllers tests + pylint --rcfile=.pylintrc --jobs=5 . module.py tools.py controllers tests cephmock pycodestyle --max-line-length=100 --exclude=python2.7,.tox,venv,frontend .