From 310ccd9f9f7b16c276d18a6cc109a76d22467ee8 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 24 Jul 2019 10:22:40 +0800 Subject: [PATCH] qa/tasks/ceph_manager.py: always use self.logger in fbd4836d, a regression is introduced: self.log("failed to read erasure_code_profile. %s was likely removed", pool) because `self.log` is actually a lambda which just do self.logger.info(x) in this change * `Thrasher.log()` is added for three reasons: - in PEP-8, > Always use a def statement instead of an assignment statement that > binds a lambda expression directly to an identifier so a better way is to define a method using `def` - and i think it helps with the readability * `logger` parameter is now mandatory now in the constructor of `Thrasher` class. because the instance of this class is only created by `qa/tasks/thrashosds.py`, like: thrash_proc = ceph_manager.Thrasher( cluster_manager, config, logger=log.getChild('thrasher') ) and `log.getChild()` does not return `None`, so there is no need to handle that case. Signed-off-by: Kefu Chai --- qa/tasks/ceph_manager.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/qa/tasks/ceph_manager.py b/qa/tasks/ceph_manager.py index b1f41eb38d1..4d9ac33a902 100644 --- a/qa/tasks/ceph_manager.py +++ b/qa/tasks/ceph_manager.py @@ -104,7 +104,7 @@ class Thrasher: """ Object used to thrash Ceph """ - def __init__(self, manager, config, logger=None): + def __init__(self, manager, config, logger): self.ceph_manager = manager self.cluster = manager.cluster self.ceph_manager.wait_for_clean() @@ -136,15 +136,6 @@ class Thrasher: num_osds = self.in_osds + self.out_osds self.max_pgs = self.config.get("max_pgs_per_pool_osd", 1200) * len(num_osds) self.min_pgs = self.config.get("min_pgs_per_pool_osd", 1) * len(num_osds) - if self.logger is not None: - self.log = lambda x: self.logger.info(x) - else: - def tmp(x): - """ - Implement log behavior - """ - print x - self.log = tmp if self.config is None: self.config = dict() # prevent monitor from auto-marking things out while thrasher runs @@ -187,6 +178,9 @@ class Thrasher: if self.noscrub_toggle_delay: self.noscrub_toggle_thread = gevent.spawn(self.do_noscrub_toggle) + def log(self, msg, *args, **kwargs): + self.logger.info(msg, *args, **kwargs) + def cmd_exists_on_osds(self, cmd): allremotes = self.ceph_manager.ctx.cluster.only(\ teuthology.is_type('osd', self.cluster)).remotes.keys() -- 2.39.5