From 960f6bfac0d18eb92a017ea21ca97efa1a12b7cf Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Sun, 7 Jun 2020 00:54:35 +0200 Subject: [PATCH] mgr/cephadm: Add event when deploying a daemon Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/inventory.py | 20 ++++++++++---------- src/pybind/mgr/cephadm/module.py | 10 ++++++++-- src/pybind/mgr/cephadm/tests/test_cephadm.py | 5 +++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index 1f059186b32..8966813fd65 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -345,16 +345,16 @@ class HostCache(): return r def get_daemons_with_volatile_status(self) -> Iterator[Tuple[str, Dict[str, orchestrator.DaemonDescription]]]: - for host, dm in self.daemons.items(): + def alter(host, dd_orig: orchestrator.DaemonDescription) -> orchestrator.DaemonDescription: + dd = copy(dd_orig) if host in self.mgr.offline_hosts: - def set_offline(dd: orchestrator.DaemonDescription) -> orchestrator.DaemonDescription: - ret = copy(dd) - ret.status = -1 - ret.status_desc = 'host is offline' - return ret - yield host, {name: set_offline(d) for name, d in dm.items()} - else: - yield host, dm + dd.status = -1 + dd.status_desc = 'host is offline' + dd.events = self.mgr.events.get_for_daemon(dd.name()) + return dd + + for host, dm in self.daemons.items(): + yield host, {name: alter(host, d) for name, d in dm.items()} def get_daemons_by_service(self, service_name): # type: (str) -> List[orchestrator.DaemonDescription] @@ -497,7 +497,7 @@ class EventStore(): unknowns: List[str] = [] daemons = self.mgr.cache.get_daemon_names() specs = self.mgr.spec_store.specs.keys() - for k_s, v in self.events.keys(): + for k_s, v in self.events.items(): kind, subject = k_s.split(':') if kind == 'service': if subject not in specs: diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index e679947d1bb..caa6de4b4c8 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -29,7 +29,7 @@ from cephadm.services.cephadmservice import CephadmDaemonSpec from mgr_module import MgrModule, HandleCommandResult import orchestrator from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpec, \ - CLICommandMeta + CLICommandMeta, OrchestratorEvent from orchestrator._interface import GenericSpec from . import remotes @@ -1772,8 +1772,14 @@ you may want to run: self.cache.invalidate_host_daemons(daemon_spec.host) self.cache.update_daemon_config_deps(daemon_spec.host, daemon_spec.name(), deps, start_time) self.cache.save_host(daemon_spec.host) - return "{} {} on host '{}'".format( + msg = "{} {} on host '{}'".format( 'Reconfigured' if reconfig else 'Deployed', daemon_spec.name(), daemon_spec.host) + if not code: + self.events.for_daemon(daemon_spec.name(), OrchestratorEvent.INFO, msg) + else: + what = 'reconfigure' if reconfig else 'deploy' + self.events.for_daemon(daemon_spec.name(), OrchestratorEvent.ERROR, f'Failed to {what}: {err}') + return msg @forall_hosts def _remove_daemons(self, name, host) -> str: diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index aaa2a86fedf..b6ca68c1c77 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -92,12 +92,13 @@ class TestCephadm(object): c = cephadm_module.list_daemons() - def remove_id(dd): + def remove_id_events(dd): out = dd.to_json() del out['daemon_id'] + del out['events'] return out - assert [remove_id(dd) for dd in wait(cephadm_module, c)] == [ + assert [remove_id_events(dd) for dd in wait(cephadm_module, c)] == [ { 'daemon_type': 'mds', 'hostname': 'test', -- 2.39.5