From 537412cc96be40bc4ab920eb5625f7d1338f4569 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Mon, 27 Jul 2020 12:09:30 +0200 Subject: [PATCH] mgr/cephadm: Add test verifying the initializaiton order Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/tests/fixtures.py | 13 ++++++++++--- src/pybind/mgr/cephadm/tests/test_cephadm.py | 9 +++++++-- src/pybind/mgr/tests/__init__.py | 10 +++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 330dbcecca34c..354eeab2134a2 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -33,20 +33,27 @@ def match_glob(val, pat): 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]) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 1e46134f508ed..4a551776f40a4 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -22,7 +22,8 @@ from ceph.deployment.inventory import Devices, Device 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 """ @@ -662,7 +663,11 @@ class TestCephadm(object): 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): diff --git a/src/pybind/mgr/tests/__init__.py b/src/pybind/mgr/tests/__init__.py index f87ffe1d60f66..4b024ce1c987a 100644 --- a/src/pybind/mgr/tests/__init__.py +++ b/src/pybind/mgr/tests/__init__.py @@ -20,9 +20,13 @@ if 'UNITTEST' in os.environ: 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] @@ -30,6 +34,8 @@ if 'UNITTEST' in os.environ: 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) @@ -56,7 +62,9 @@ if 'UNITTEST' in os.environ: 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. -- 2.39.5