From: Sebastian Wagner Date: Sat, 6 Jun 2020 22:54:35 +0000 (+0200) Subject: mgr/cephadm: Add event when deploying a daemon X-Git-Tag: v15.2.5~105^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9af917613687cfed26b17d46594fa90b5e234eb1;p=ceph.git mgr/cephadm: Add event when deploying a daemon Signed-off-by: Sebastian Wagner (cherry picked from commit 960f6bfac0d18eb92a017ea21ca97efa1a12b7cf) --- diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index 5ae52342d436..3bb8c81d54e9 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -347,16 +347,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] @@ -499,7 +499,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 e679947d1bb7..caa6de4b4c8b 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 f39761a0493a..d4b387ca03e8 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',