]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: define CLUSTER_LOG_PRIO* using enum.IntEnum
authorKefu Chai <kchai@redhat.com>
Sat, 16 Jan 2021 15:30:30 +0000 (23:30 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 24 Jan 2021 14:16:36 +0000 (22:16 +0800)
so the clog type / prio can be typed.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/dashboard/tools.py
src/pybind/mgr/mgr_module.py
src/pybind/mgr/selftest/module.py
src/pybind/mgr/volumes/fs/volume.py

index b428efe7ab5324fb0eeed714c72a608387069212..a6f14e82d00845a2a14b8ba27cde3c14b0a49003 100644 (file)
@@ -66,7 +66,7 @@ class RequestLoggingTool(cherrypy.Tool):
                 for key in keys:
                     params[key] = '***'
                 msg = '{} params=\'{}\''.format(msg, json.dumps(params))
-            mgr.cluster_log('audit', mgr.CLUSTER_LOG_PRIO_INFO, msg)
+            mgr.cluster_log('audit', mgr.ClusterLogPrio.INFO, msg)
 
     def request_error(self):
         self._request_log(self.logger.error)
index 93da6045c8e1bdef0d39783c8aded5a495a9d2c0..5d1ed2afb1157633598492e07d29b0ecb214cd5d 100644 (file)
@@ -16,6 +16,7 @@ import functools
 import json
 import threading
 from collections import defaultdict, namedtuple
+from enum import IntEnum
 import rados
 import re
 import sys
@@ -523,11 +524,11 @@ class ClusterLogHandler(logging.Handler):
 
     def emit(self, record):
         levelmap = {
-            'DEBUG': MgrModule.CLUSTER_LOG_PRIO_DEBUG,
-            'INFO': MgrModule.CLUSTER_LOG_PRIO_INFO,
-            'WARNING': MgrModule.CLUSTER_LOG_PRIO_WARN,
-            'ERROR': MgrModule.CLUSTER_LOG_PRIO_ERROR,
-            'CRITICAL': MgrModule.CLUSTER_LOG_PRIO_ERROR,
+            'DEBUG': MgrModule.ClusterLogPrio.DEBUG,
+            'INFO': MgrModule.ClusterLogPrio.INFO,
+            'WARNING': MgrModule.ClusterLogPrio.WARN,
+            'ERROR': MgrModule.ClusterLogPrio.ERROR,
+            'CRITICAL': MgrModule.ClusterLogPrio.ERROR,
         }
         level = levelmap[record.levelname]
         if record.levelno >= self.level:
@@ -799,11 +800,12 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
     NONE = 1
 
     # Cluster log priorities
-    CLUSTER_LOG_PRIO_DEBUG = 0
-    CLUSTER_LOG_PRIO_INFO = 1
-    CLUSTER_LOG_PRIO_SEC = 2
-    CLUSTER_LOG_PRIO_WARN = 3
-    CLUSTER_LOG_PRIO_ERROR = 4
+    class ClusterLogPrio(IntEnum):
+        DEBUG = 0
+        INFO = 1
+        SEC = 2
+        WARN = 3
+        ERROR = 4
 
     def __init__(self, module_name, py_modules_ptr, this_ptr):
         self.module_name = module_name
@@ -871,16 +873,10 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
     def cluster_log(self, channel, priority, message):
         """
         :param channel: The log channel. This can be 'cluster', 'audit', ...
-        :type channel: str
-        :param priority: The log message priority. This can be
-                         CLUSTER_LOG_PRIO_DEBUG, CLUSTER_LOG_PRIO_INFO,
-                         CLUSTER_LOG_PRIO_SEC, CLUSTER_LOG_PRIO_WARN or
-                         CLUSTER_LOG_PRIO_ERROR.
-        :type priority: int
+        :param priority: The log message priority.
         :param message: The message to log.
-        :type message: str
         """
-        self._ceph_cluster_log(channel, priority, message)
+        self._ceph_cluster_log(channel, priority.value, message)
 
     @property
     def version(self):
index 6603a603e7e1fb70e0ad81c3d203eed289db92e9..d63e4cc24ab69c84721fb9f3e149baa82c9d955b 100644 (file)
@@ -152,10 +152,10 @@ class Module(MgrModule):
             return self._insights_set_now_offset(inbuf, command)
         elif command['prefix'] == 'mgr self-test cluster-log':
             priority_map = {
-                'info': self.CLUSTER_LOG_PRIO_INFO,
-                'security': self.CLUSTER_LOG_PRIO_SEC,
-                'warning': self.CLUSTER_LOG_PRIO_WARN,
-                'error': self.CLUSTER_LOG_PRIO_ERROR
+                'info': self.ClusterLogPrio.INFO,
+                'security': self.ClusterLogPrio.SEC,
+                'warning': self.ClusterLogPrio.WARN,
+                'error': self.ClusterLogPrio.ERROR
             }
             self.cluster_log(command['channel'],
                              priority_map[command['priority']],
index af7ebaaa5130aa9a7b863c8bb48ae391521da3cd..97cd4171c3268aee7b9721083e4e3e44757ec4fe 100644 (file)
@@ -78,7 +78,7 @@ class VolumeClient(CephfsClient["Module"]):
         log to cluster log with default log level as WARN.
         """
         if not lvl:
-            lvl = self.mgr.CLUSTER_LOG_PRIO_WARN
+            lvl = self.mgr.ClusterLogPrio.WARN
         self.mgr.cluster_log("cluster", lvl, msg)
 
     def volume_exception_to_retval(self, ve):