]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/tests/__init__.py
7bccfc79970887b7eec6339db736909aafe9be24
2 from __future__
import absolute_import
7 if 'UNITTEST' in os
.environ
:
9 # Mock ceph_module. Otherwise every module that is involved in a testcase and imports it will
10 # raise an ImportError
15 from unittest
import mock
22 def _ceph_get_store(self
, k
):
23 return self
._store
.get(k
, None)
25 def _ceph_set_store(self
, k
, v
):
32 def _ceph_get_store_prefix(self
, prefix
):
34 k
: v
for k
, v
in self
._store
.items()
35 if k
.startswith(prefix
)
38 def _ceph_get_module_option(self
, module
, key
, localized_prefix
: None):
39 return self
._ceph
_get
_store
(f
'{module}/{key}')
41 def _ceph_set_module_option(self
, module
, key
, val
):
42 return self
._ceph
_set
_store
(f
'{module}/{key}', val
)
44 def __init__(self
, *args
):
47 if self
.__class
__.__name
__ not in M_classes
:
48 # call those only once.
49 self
._register
_commands
('')
50 self
._register
_options
('')
51 M_classes
.add(self
.__class
__.__name
__)
53 super(M
, self
).__init
__()
54 self
._ceph
_get
_version
= mock
.Mock()
55 self
._ceph
_get
= mock
.MagicMock()
56 self
._ceph
_get
_option
= mock
.MagicMock()
57 self
._ceph
_get
_context
= mock
.MagicMock()
58 self
._ceph
_register
_client
= mock
.MagicMock()
59 self
._configure
_logging
= lambda *_
: None
60 self
._unconfigure
_logging
= mock
.MagicMock()
61 self
._ceph
_log
= mock
.MagicMock()
62 self
._ceph
_dispatch
_remote
= lambda *_
: None
67 cm
.BaseMgrStandbyModule
= M
68 sys
.modules
['ceph_module'] = cm
70 def mock_ceph_modules():
71 class MockRadosError(Exception):
72 def __init__(self
, message
, errno
=None):
73 super(MockRadosError
, self
).__init
__(message
)
77 msg
= super(MockRadosError
, self
).__str
__()
78 if self
.errno
is None:
80 return '[errno {0}] {1}'.format(self
.errno
, msg
)
84 'rados': mock
.Mock(Error
=MockRadosError
, OSError=MockRadosError
),
86 'cephfs': mock
.Mock(),