From 4a53eb72f3b1a1613b86cfa17de1329265e449f5 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Thu, 18 Jun 2020 14:07:54 +0200 Subject: [PATCH] mgr/cephadm: Add test for _check_daemons() Signed-off-by: Sebastian Wagner (cherry picked from commit 1aeb0be49b3dc26f456da5d0d850b1d68aec88cf) --- src/pybind/mgr/cephadm/tests/test_cephadm.py | 12 +++++++++--- src/pybind/mgr/tests/__init__.py | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 79da52aaa6b3e..0203e070abe7a 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -23,8 +23,7 @@ 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 cephadm.module import CephadmOrchestrator - +from cephadm.module import CephadmOrchestrator, CEPH_DATEFMT """ TODOs: @@ -161,7 +160,9 @@ class TestCephadm(object): ) ]) )) - def test_daemon_action(self, cephadm_module): + #@mock.patch("mgr_module.MgrModule._ceph_get") + @mock.patch("ceph_module.BaseMgrModule._ceph_get") + def test_daemon_action(self, _ceph_get, cephadm_module: CephadmOrchestrator): cephadm_module.service_cache_timeout = 10 with with_host(cephadm_module, 'test'): c = cephadm_module.list_daemons(refresh=True) @@ -173,6 +174,11 @@ class TestCephadm(object): c = cephadm_module.daemon_action(what, 'rgw', 'myrgw.foobar') assert wait(cephadm_module, c) == [what + " rgw.myrgw.foobar from host 'test'"] + now = datetime.datetime.utcnow().strftime(CEPH_DATEFMT) + _ceph_get.return_value = {'modified': now} + + cephadm_module._check_daemons() + assert_rm_daemon(cephadm_module, 'rgw.myrgw.foobar', 'test') @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]')) diff --git a/src/pybind/mgr/tests/__init__.py b/src/pybind/mgr/tests/__init__.py index 46f6728225108..f87ffe1d60f66 100644 --- a/src/pybind/mgr/tests/__init__.py +++ b/src/pybind/mgr/tests/__init__.py @@ -51,6 +51,10 @@ if 'UNITTEST' in os.environ: def _ceph_set_module_option(self, module, key, val): return self._ceph_set_store(f'{module}/{key}', val) + def _ceph_get(self, *args): + return mock.MagicMock() + + def __init__(self, *args): self._store = {} @@ -62,7 +66,6 @@ if 'UNITTEST' in os.environ: super(M, self).__init__() self._ceph_get_version = mock.Mock() - self._ceph_get = mock.MagicMock() self._ceph_get_option = mock.MagicMock() self._ceph_get_context = mock.MagicMock() self._ceph_register_client = mock.MagicMock() -- 2.39.5