From: Jos Collin Date: Mon, 6 May 2024 12:47:29 +0000 (+0530) Subject: pybind/mgr/mirroring: Fix KeyError: 'directory_count' in daemon status X-Git-Tag: v19.1.1~258^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e4651edcfa76bc7e715bdbe83ced8d74c6ca5314;p=ceph.git pybind/mgr/mirroring: Fix KeyError: 'directory_count' in daemon status The directory_count key is missing in self.mgr.get_daemon_status() output json, intermittently when there is a delay caused by m_listener.handle_mirroring_enabled() to update the directory_count, which results in ServiceDaemon::update_status() creates a json with out 'directory_count' key/value. But the mgr/mirroring -> daemon_status() always expects the 'directory_count' key to be present in the json returned by self.mgr.get_daemon_status(). This issue occurs intermittently when we enable/disable mirroring and check the 'daemon status' in between. This patch fixes this issue by setting a default value 0 for 'directory_count' in doemon_status(). Fixes: https://tracker.ceph.com/issues/65795 Signed-off-by: Jos Collin (cherry picked from commit b78baa23e562742b8bdc5a75f82e3b6fbf55a8a5) --- diff --git a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py index 89da37920312..2bfb6482674e 100644 --- a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py +++ b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py @@ -766,13 +766,13 @@ class FSSnapshotMirror: } # type: Dict[str, Any] daemon_status = self.mgr.get_daemon_status('cephfs-mirror', daemon_key) if not daemon_status: - log.debug(f'daemon status not yet availble for cephfs-mirror daemon: {daemon_key}') + log.debug(f'daemon status not yet available for cephfs-mirror daemon: {daemon_key}') continue status = json.loads(daemon_status['status_json']) for fs_id, fs_desc in status.items(): fs = {'filesystem_id' : int(fs_id), 'name' : fs_desc['name'], - 'directory_count' : fs_desc['directory_count'], + 'directory_count' : fs_desc.get('directory_count', 0), 'peers' : [] } # type: Dict[str, Any] for peer_uuid, peer_desc in fs_desc['peers'].items():