From c0632f6bd528e47a2be8d828ba56458b3a393f09 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Tue, 16 Feb 2021 04:22:06 -0500 Subject: [PATCH] test: add test for validating cephfs-mirror daemon service status Fixes: http://tracker.ceph.com/issues/48943 Signed-off-by: Venky Shankar --- qa/tasks/cephfs/test_mirroring.py | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/qa/tasks/cephfs/test_mirroring.py b/qa/tasks/cephfs/test_mirroring.py index 2994f1ccc23..45ef59d7ea1 100644 --- a/qa/tasks/cephfs/test_mirroring.py +++ b/qa/tasks/cephfs/test_mirroring.py @@ -219,6 +219,28 @@ class TestMirroring(CephFSTestCase): log.debug(f'command returned={res}') return json.loads(res) + def get_mirror_daemon_id(self): + ceph_status = json.loads(self.fs.mon_manager.raw_cluster_cmd("status", "--format=json")) + log.debug(f'ceph_status: {ceph_status}') + daemon_id = None + for k in ceph_status['servicemap']['services']['cephfs-mirror']['daemons']: + try: + daemon_id = int(k) + break #nit, only a single mirror daemon is expected -- bail out. + except ValueError: + pass + + log.debug(f'daemon_id: {daemon_id}') + self.assertTrue(daemon_id is not None) + return daemon_id + + def get_mirror_daemon_status(self, daemon_id, fs_name, fs_id): + daemon_status = json.loads(self.mgr_cluster.mon_manager.raw_cluster_cmd("fs", "snapshot", "mirror", "daemon", "status", fs_name)) + log.debug(f'daemon_status: {daemon_status}') + status = daemon_status[str(daemon_id)][str(fs_id)] + log.debug(f'status: {status}') + return status + def test_basic_mirror_commands(self): self.enable_mirroring(self.primary_fs_name, self.primary_fs_id) self.disable_mirroring(self.primary_fs_name, self.primary_fs_id) @@ -625,3 +647,46 @@ class TestMirroring(CephFSTestCase): self.check_peer_status(self.primary_fs_name, self.primary_fs_id, "client.mirror_remote@ceph", '/d0', 'snap0', 1) self.disable_mirroring(self.primary_fs_name, self.primary_fs_id) + + def test_cephfs_mirror_service_daemon_status(self): + self.enable_mirroring(self.primary_fs_name, self.primary_fs_id) + self.peer_add(self.primary_fs_name, self.primary_fs_id, "client.mirror_remote@ceph", self.secondary_fs_name) + peer_uuid = self.get_peer_uuid("client.mirror_remote@ceph") + + daemon_id = self.get_mirror_daemon_id() + + time.sleep(30) + status = self.get_mirror_daemon_status(daemon_id, self.primary_fs_name, self.primary_fs_id) + + # we have not added any directories + self.assertEquals(status['directory_count'], 0) + + peer_stats = status['peers'][peer_uuid]['stats'] + self.assertEquals(peer_stats['failure_count'], 0) + self.assertEquals(peer_stats['recovery_count'], 0) + + # add a non-existent directory for synchronization -- check if its reported + # in daemon stats + self.add_directory(self.primary_fs_name, self.primary_fs_id, '/d0') + + time.sleep(120) + status = self.get_mirror_daemon_status(daemon_id, self.primary_fs_name, self.primary_fs_id) + # we added one + self.assertEquals(status['directory_count'], 1) + peer_stats = status['peers'][peer_uuid]['stats'] + # failure count should be reflected + self.assertEquals(peer_stats['failure_count'], 1) + self.assertEquals(peer_stats['recovery_count'], 0) + + # create the directory, mirror daemon would recover + self.mount_a.run_shell(["mkdir", "d0"]) + + time.sleep(120) + status = self.get_mirror_daemon_status(daemon_id, self.primary_fs_name, self.primary_fs_id) + self.assertEquals(status['directory_count'], 1) + peer_stats = status['peers'][peer_uuid]['stats'] + # failure and recovery count should be reflected + self.assertEquals(peer_stats['failure_count'], 1) + self.assertEquals(peer_stats['recovery_count'], 1) + + self.disable_mirroring(self.primary_fs_name, self.primary_fs_id) -- 2.39.5