]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: Add test verifying the initializaiton order
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 27 Jul 2020 10:09:30 +0000 (12:09 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 28 Jul 2020 10:18:56 +0000 (12:18 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/tests/fixtures.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/tests/__init__.py

index 330dbcecca34c3bb8fb6e73c9d0ed9f32ab96c58..354eeab2134a2624c06cbef632d7dffaa89cc17a 100644 (file)
@@ -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])
index 1e46134f508ed73bc1add5427661d0c865b39817..4a551776f40a471429a4449cb86cb7c1cd410fc9 100644 (file)
@@ -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):
index f87ffe1d60f6615a9e28c5c7c41f6b912ee5d29a..4b024ce1c987a7440c4ad0a6b3343e13a836d12b 100644 (file)
@@ -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.