def mon_command(*args, **kwargs):
return 0, '', ''
-
-@pytest.yield_fixture()
-def cephadm_module():
+@contextmanager
+def with_cephadm_module(module_options):
with mock.patch("cephadm.module.CephadmOrchestrator.get_ceph_option", get_ceph_option),\
mock.patch("cephadm.module.CephadmOrchestrator.remote"),\
mock.patch("cephadm.module.CephadmOrchestrator.send_command"), \
mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command):
m = CephadmOrchestrator.__new__ (CephadmOrchestrator)
+ for k, v in module_options.items():
+ m._ceph_set_module_option('cephadm', k, v)
m.__init__('cephadm', 0, 0)
m._cluster_fsid = "fsid"
yield m
+@pytest.yield_fixture()
+def cephadm_module():
+ with with_cephadm_module({}) as m:
+ yield m
+
+
def wait(m, c):
# type: (CephadmOrchestrator, Completion) -> Any
m.process([c])
from orchestrator import ServiceDescription, DaemonDescription, InventoryHost, \
HostSpec, OrchestratorError
from tests import mock
-from .fixtures import cephadm_module, wait, _run_cephadm, mon_command, match_glob, with_host
+from .fixtures import cephadm_module, wait, _run_cephadm, mon_command, match_glob, with_host, \
+ with_cephadm_module
from cephadm.module import CephadmOrchestrator, CEPH_DATEFMT
"""
cephadm_module.notify('mon_map', mock.MagicMock())
assert cephadm_module.cache.host_needs_new_etc_ceph_ceph_conf('test')
-
+
+ def test_etc_ceph_init(self):
+ with with_cephadm_module({'manage_etc_ceph_ceph_conf': True}) as m:
+ assert m.manage_etc_ceph_ceph_conf == True
+
@mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm")
def test_registry_login(self, _run_cephadm, cephadm_module: CephadmOrchestrator):
def check_registry_credentials(url, username, password):
class M(object):
def _ceph_get_store(self, k):
+ if not hasattr(self, '_store'):
+ self._store = {}
return self._store.get(k, None)
def _ceph_set_store(self, k, v):
+ if not hasattr(self, '_store'):
+ self._store = {}
if v is None:
if k in self._store:
del self._store[k]
self._store[k] = v
def _ceph_get_store_prefix(self, prefix):
+ if not hasattr(self, '_store'):
+ self._store = {}
return {
k: v for k, v in self._store.items()
if k.startswith(prefix)
def __init__(self, *args):
- self._store = {}
+ if not hasattr(self, '_store'):
+ self._store = {}
+
if self.__class__.__name__ not in M_classes:
# call those only once.