From 714363941720b52f96e3dff19209be0a4bd1da7e Mon Sep 17 00:00:00 2001 From: Adam King Date: Wed, 18 Oct 2023 14:00:05 -0400 Subject: [PATCH] mgr/cephadm: update timestamp on repeat daemon/service events If you have a daemon/service event and then an identical event happens later (e.g. the same daemon is redeployed multiple times) the events are not updated on the repeat instances. In cases like this I think it makes more sense to update the timestamp so users can see the most recent time the event happened. Fixes: https://tracker.ceph.com/issues/63238 Signed-off-by: Adam King (cherry picked from commit 13512cc202c90abd6c5f1e2747d121cc07689d1b) --- src/pybind/mgr/cephadm/inventory.py | 2 ++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 38 +++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index f83e687031c87..03a3f1218567c 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -1469,6 +1469,8 @@ class EventStore(): for e in self.events[event.kind_subject()]: if e.message == event.message: + # if subject and message match, just update the timestamp + e.created = event.created return self.events[event.kind_subject()].append(event) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 8e09eb9400116..a9795c8980aa3 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -21,7 +21,7 @@ from ceph.deployment.service_spec import ServiceSpec, PlacementSpec, RGWSpec, \ CustomConfig, PrometheusSpec 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 ceph.utils import datetime_to_str, datetime_now, str_to_datetime from orchestrator import DaemonDescription, InventoryHost, \ HostSpec, OrchestratorError, DaemonDescriptionStatus, OrchestratorEvent from tests import mock @@ -394,6 +394,42 @@ class TestCephadm(object): assert 'myerror' in ''.join(evs) + @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]')) + def test_daemon_action_event_timestamp_update(self, cephadm_module: CephadmOrchestrator): + # Test to make sure if a new daemon event is created with the same subject + # and message that the timestamp of the event is updated to let users know + # when it most recently occurred. + cephadm_module.service_cache_timeout = 10 + with with_host(cephadm_module, 'test'): + 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: + + d_name = 'rgw.' + daemon_id + + now = str_to_datetime('2023-10-18T22:45:29.119250Z') + with mock.patch("cephadm.inventory.datetime_now", lambda: now): + c = cephadm_module.daemon_action('redeploy', d_name) + assert wait(cephadm_module, + c) == f"Scheduled to redeploy rgw.{daemon_id} on host 'test'" + + CephadmServe(cephadm_module)._check_daemons() + + d_events = cephadm_module.events.get_for_daemon(d_name) + assert len(d_events) == 1 + assert d_events[0].created == now + + later = str_to_datetime('2023-10-18T23:46:37.119250Z') + with mock.patch("cephadm.inventory.datetime_now", lambda: later): + c = cephadm_module.daemon_action('redeploy', d_name) + assert wait(cephadm_module, + c) == f"Scheduled to redeploy rgw.{daemon_id} on host 'test'" + + CephadmServe(cephadm_module)._check_daemons() + + d_events = cephadm_module.events.get_for_daemon(d_name) + assert len(d_events) == 1 + assert d_events[0].created == later + @pytest.mark.parametrize( "action", [ -- 2.39.5