From 346d88388c50c3fd7cab2035dc6305127b3b834c Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 8 Sep 2021 16:23:32 +0200 Subject: [PATCH] mgr/cephadm: check_for_moved_osds: Add OrchEvent Signed-off-by: Sebastian Wagner (cherry picked from commit 25d27fb6c1bd3520564e624965fa3b6f81a21ac0) --- src/pybind/mgr/cephadm/serve.py | 2 ++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 11 ++++++++++- src/pybind/mgr/orchestrator/_interface.py | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index cc8bd1307846f..e50c0070f8082 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -566,6 +566,8 @@ class CephadmServe: assert e.hostname try: self._remove_daemon(e.name(), e.hostname) + self.mgr.events.for_daemon( + e.name(), 'INFO', f"Removed duplicated daemon on host '{e.hostname}'") except OrchestratorError as ex: self.mgr.events.from_orch_error(ex) logger.exception(f'failed to remove duplicated daemon {e}') diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 6acd3938956dc..368b79f55c733 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -20,7 +20,7 @@ from ceph.deployment.drive_selection.selector import DriveSelection from ceph.deployment.inventory import Devices, Device from ceph.utils import datetime_to_str, datetime_now from orchestrator import DaemonDescription, InventoryHost, \ - HostSpec, OrchestratorError, DaemonDescriptionStatus + HostSpec, OrchestratorError, DaemonDescriptionStatus, OrchestratorEvent from tests import mock from .fixtures import wait, _run_cephadm, match_glob, with_host, \ with_cephadm_module, with_service, _deploy_cephadm_binary @@ -917,6 +917,15 @@ class TestCephadm(object): assert len(cephadm_module.cache.get_daemons()) == 1 + assert cephadm_module.events.get_for_daemon('osd.1') == [ + OrchestratorEvent(mock.ANY, 'daemon', 'osd.1', 'INFO', + "Deployed osd.1 on host 'host1'"), + OrchestratorEvent(mock.ANY, 'daemon', 'osd.1', 'INFO', + "Deployed osd.1 on host 'host2'"), + OrchestratorEvent(mock.ANY, 'daemon', 'osd.1', 'INFO', + "Removed duplicated daemon on host 'host2'"), + ] + @pytest.mark.parametrize( "spec", [ diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index f6031edd1e961..efaa7dfc3d3c7 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1380,6 +1380,9 @@ class OrchestratorEvent: return self.created == other.created and self.kind == other.kind \ and self.subject == other.subject and self.message == other.message + def __repr__(self) -> str: + return f'OrchestratorEvent.from_json({self.to_json()!r})' + def _mk_orch_methods(cls: Any) -> Any: # Needs to be defined outside of for. -- 2.39.5