]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/tasks/ceph_manager.py: always use self.logger
authorKefu Chai <kchai@redhat.com>
Wed, 24 Jul 2019 02:22:40 +0000 (10:22 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 24 Jul 2019 02:28:00 +0000 (10:28 +0800)
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 <kchai@redhat.com>
qa/tasks/ceph_manager.py

index b1f41eb38d1157d6a722e9746e30afd7eeb18d55..4d9ac33a9022818afe414f9d2c1b8f92b8f27c34 100644 (file)
@@ -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()