From 36af3dc08d553c3aa02799aa450378d36ad7a9d0 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 3 Mar 2021 17:14:22 +0530 Subject: [PATCH] qa/cephfs: move is_blocklisted() to filesystem.CephCluster Using self.fs.mon_manager in mount.py can lead to a crash since self.fs can be None. Move is_blocklisted() to tasks.filesystem.CephCluster where it can get access to mon_manager without depending on objects representing Ceph FSs. Fixes: https://tracker.ceph.com/issues/49511 Signed-off-by: Rishabh Dave (cherry picked from commit 4d0f56fcc524cfe328d89d0b3706ca22a68a268f) --- qa/tasks/cephfs/filesystem.py | 14 ++++++++++++++ qa/tasks/cephfs/mount.py | 12 ------------ qa/tasks/cephfs/test_misc.py | 3 ++- qa/tasks/cephfs/test_sessionmap.py | 6 ++++-- qa/tasks/fs.py | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/qa/tasks/cephfs/filesystem.py b/qa/tasks/cephfs/filesystem.py index 3bb6a926cd750..b8e25a48bd189 100644 --- a/qa/tasks/cephfs/filesystem.py +++ b/qa/tasks/cephfs/filesystem.py @@ -255,6 +255,20 @@ class CephCluster(object): log.debug("_json_asok output empty") return None + def is_addr_blocklisted(self, addr=None): + if addr is None: + log.warn("Couldn't get the client address, so the blocklisted " + "status undetermined") + return False + + blocklist = json.loads(self.mon_manager.run_cluster_cmd( + args=["osd", "blocklist", "ls", "--format=json"], + stdout=StringIO()).stdout.getvalue()) + for b in blocklist: + if addr == b["addr"]: + return True + return False + class MDSCluster(CephCluster): """ diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 6b6090c8c20fd..d7e775f64e022 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -562,18 +562,6 @@ class CephFSMount(object): finally: self.umount_wait() - def is_blocklisted(self): - addr = self.get_global_addr() - if addr is None: - log.warn("Couldn't get the client address, so the blocklisted status undetermined") - return False - - blocklist = json.loads(self.fs.mon_manager.raw_cluster_cmd("osd", "blocklist", "ls", "--format=json")) - for b in blocklist: - if addr == b["addr"]: - return True - return False - def create_file(self, filename='testfile', dirname=None, user=None, check_status=True): assert(self.is_mounted()) diff --git a/qa/tasks/cephfs/test_misc.py b/qa/tasks/cephfs/test_misc.py index 6a295bbfdf1ac..47c3af75a425a 100644 --- a/qa/tasks/cephfs/test_misc.py +++ b/qa/tasks/cephfs/test_misc.py @@ -165,7 +165,8 @@ class TestMisc(CephFSTestCase): cap_waited, session_timeout )) - self.assertTrue(self.mount_a.is_blocklisted()) + self.assertTrue(self.mds_cluster.is_addr_blocklisted( + self.mount_a.get_global_addr())) self.mount_a._kill_background(cap_holder) finally: self.mount_a.resume_netns() diff --git a/qa/tasks/cephfs/test_sessionmap.py b/qa/tasks/cephfs/test_sessionmap.py index 6d37879277f8a..79f1fb45e243a 100644 --- a/qa/tasks/cephfs/test_sessionmap.py +++ b/qa/tasks/cephfs/test_sessionmap.py @@ -192,7 +192,8 @@ class TestSessionMap(CephFSTestCase): Check that mds evicts blocklisted client """ if not isinstance(self.mount_a, FuseMount): - self.skipTest("Requires FUSE client to use is_blocklisted()") + self.skipTest("Requires FUSE client to use " + "mds_cluster.is_addr_blocklisted()") self.fs.set_max_mds(2) status = self.fs.wait_for_daemons() @@ -213,7 +214,8 @@ class TestSessionMap(CephFSTestCase): mount_a_client_id = self.mount_a.get_global_id() self.fs.mds_asok(['session', 'evict', "%s" % mount_a_client_id], mds_id=self.fs.get_rank(rank=0, status=status)['name']) - self.wait_until_true(lambda: self.mount_a.is_blocklisted(), timeout=30) + self.wait_until_true(lambda: self.mds_cluster.is_addr_blocklisted( + self.mount_a.get_global_addr()), timeout=30) # 10 seconds should be enough for evicting client time.sleep(10) diff --git a/qa/tasks/fs.py b/qa/tasks/fs.py index 4f7a3e2060b6c..b4f3e3a16071a 100644 --- a/qa/tasks/fs.py +++ b/qa/tasks/fs.py @@ -56,10 +56,10 @@ def clients_evicted(ctx, config): if mount is not None: if evicted: log.info("confirming client {} is blocklisted".format(client)) - assert mount.is_blocklisted() + assert fs.is_addr_blocklisted(mount.get_global_addr()) elif client in no_session: log.info("client {} should not be evicted but has no session with an MDS".format(client)) - mount.is_blocklisted() # for debugging + fs.is_addr_blocklisted(mount.get_global_addr()) # for debugging should_assert = True if should_assert: raise RuntimeError("some clients which should not be evicted have no session with an MDS?") -- 2.39.5