From 91b09efae14983754cc2ea6716e681726f2bc4b9 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 8 Sep 2021 16:58:14 +0200 Subject: [PATCH] mgr/cephadm: test_cephadm: Add some more tests for OrchestratorEvent Signed-off-by: Sebastian Wagner (cherry picked from commit 7d1bea2bb8777ac6c4d08b9042af1f6597ed2906) --- src/pybind/mgr/cephadm/module.py | 11 +++++++--- src/pybind/mgr/cephadm/tests/test_cephadm.py | 21 +++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 235b16682c784..6ca92478c4acd 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2436,9 +2436,14 @@ Then run the following: @handle_orch_error def add_daemon(self, spec: ServiceSpec) -> List[str]: ret: List[str] = [] - for d_type in service_to_daemon_types(spec.service_type): - ret.extend(self._add_daemon(d_type, spec)) - return ret + try: + with orchestrator.set_exception_subject('service', spec.service_name(), overwrite=True): + for d_type in service_to_daemon_types(spec.service_type): + ret.extend(self._add_daemon(d_type, spec)) + return ret + except OrchestratorError as e: + self.events.from_orch_error(e) + raise @handle_orch_error def apply_mon(self, spec: ServiceSpec) -> str: diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 368b79f55c733..22113eebd5547 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -299,14 +299,16 @@ class TestCephadm(object): with with_service(cephadm_module, RGWSpec(service_id='myrgw.foobar', unmanaged=True)) as _, \ with_daemon(cephadm_module, RGWSpec(service_id='myrgw.foobar'), 'test') as daemon_id: - c = cephadm_module.daemon_action('redeploy', 'rgw.' + daemon_id) + d_name = 'rgw.' + daemon_id + + c = cephadm_module.daemon_action('redeploy', d_name) assert wait(cephadm_module, c) == f"Scheduled to redeploy rgw.{daemon_id} on host 'test'" for what in ('start', 'stop', 'restart'): - c = cephadm_module.daemon_action(what, 'rgw.' + daemon_id) + c = cephadm_module.daemon_action(what, d_name) assert wait(cephadm_module, - c) == F"Scheduled to {what} rgw.{daemon_id} on host 'test'" + c) == F"Scheduled to {what} {d_name} on host 'test'" # Make sure, _check_daemons does a redeploy due to monmap change: cephadm_module._store['_ceph_get/mon_map'] = { @@ -317,6 +319,13 @@ class TestCephadm(object): CephadmServe(cephadm_module)._check_daemons() + assert cephadm_module.events.get_for_daemon(d_name) == [ + OrchestratorEvent(mock.ANY, 'daemon', d_name, 'INFO', + f"Deployed {d_name} on host \'test\'"), + OrchestratorEvent(mock.ANY, 'daemon', d_name, 'INFO', + f"stop {d_name} from host \'test\'"), + ] + @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]')) def test_daemon_action_fail(self, cephadm_module: CephadmOrchestrator): cephadm_module.service_cache_timeout = 10 @@ -1002,6 +1011,12 @@ class TestCephadm(object): 'prefix': 'auth rm', 'entity': entity, }) + assert cephadm_module.events.get_for_service(spec.service_name()) == [ + OrchestratorEvent(mock.ANY, 'service', spec.service_name(), 'INFO', + "service was created"), + OrchestratorEvent(mock.ANY, 'service', spec.service_name(), 'ERROR', + "fail"), + ] @mock.patch("cephadm.serve.CephadmServe._run_cephadm") def test_daemon_place_fail_health_warning(self, _run_cephadm, cephadm_module): -- 2.39.5