From: Sebastian Wagner Date: Fri, 21 Aug 2020 15:38:33 +0000 (+0200) Subject: mgr/cephadm: add test_daemon_check X-Git-Tag: v16.1.0~1283^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F36753%2Fhead;p=ceph.git mgr/cephadm: add test_daemon_check Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 9f7864ccebed..b70469cbbefd 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -7,7 +7,7 @@ from ceph.deployment.service_spec import PlacementSpec, ServiceSpec from cephadm.module import CEPH_DATEFMT try: - from typing import Any + from typing import Any, Iterator, List except ImportError: pass import pytest @@ -127,7 +127,7 @@ def assert_rm_service(cephadm, srv_name): @contextmanager -def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str): +def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str) -> Iterator[List[str]]: if spec.placement.is_empty(): spec.placement = PlacementSpec(hosts=[host], count=1) c = meth(cephadm_module, spec) @@ -138,9 +138,9 @@ def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, h cephadm_module._apply_all_services() dds = wait(cephadm_module, cephadm_module.list_daemons()) - names = {dd.service_name() for dd in dds} - assert spec.service_name() in names, dds + own_dds = [dd for dd in dds if dd.service_name() == spec.service_name()] + assert own_dds - yield + yield [dd.name() for dd in own_dds] assert_rm_service(cephadm_module, spec.service_name()) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 5d53a5f13c4e..ebddee226cb4 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -225,6 +225,31 @@ class TestCephadm(object): assert 'myerror' in ''.join(evs) + @pytest.mark.parametrize( + "action", + [ + 'start', + 'stop', + 'restart', + 'reconfig', + 'redeploy' + ] + ) + @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) + def test_daemon_check(self, cephadm_module: CephadmOrchestrator, action): + with with_host(cephadm_module, 'test'): + with with_service(cephadm_module, ServiceSpec(service_type='grafana'), CephadmOrchestrator.apply_grafana, 'test') as d_names: + [daemon_name] = d_names + + cephadm_module._schedule_daemon_action(daemon_name, action) + + assert cephadm_module.cache.get_scheduled_daemon_action( + 'test', daemon_name) == action + + cephadm_module._check_daemons() + + assert cephadm_module.cache.get_scheduled_daemon_action('test', daemon_name) is None + @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) def test_daemon_check_post(self, cephadm_module: CephadmOrchestrator): with with_host(cephadm_module, 'test'):