From: Kefu Chai Date: Sat, 16 Jan 2021 15:30:30 +0000 (+0800) Subject: pybind/mgr: define CLUSTER_LOG_PRIO* using enum.IntEnum X-Git-Tag: v16.2.0~230^2~38 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=74b30425ba448cd6789993473c8a1f92ddda09e1;p=ceph.git pybind/mgr: define CLUSTER_LOG_PRIO* using enum.IntEnum so the clog type / prio can be typed. Signed-off-by: Kefu Chai (cherry picked from commit 141969d7c428698df2e4534ebdc935311163ee82) --- diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index b428efe7ab532..a6f14e82d0084 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -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) diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 93da6045c8e1b..5d1ed2afb1157 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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): diff --git a/src/pybind/mgr/selftest/module.py b/src/pybind/mgr/selftest/module.py index 6603a603e7e1f..d63e4cc24ab69 100644 --- a/src/pybind/mgr/selftest/module.py +++ b/src/pybind/mgr/selftest/module.py @@ -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']], diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index af7ebaaa5130a..97cd4171c3268 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -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):