diff options
-rw-r--r-- | src/pybind/mgr/cephadm/module.py | 10 | ||||
-rw-r--r-- | src/pybind/mgr/dashboard/module.py | 6 | ||||
-rw-r--r-- | src/pybind/mgr/insights/module.py | 6 | ||||
-rw-r--r-- | src/pybind/mgr/k8sevents/module.py | 6 | ||||
-rw-r--r-- | src/pybind/mgr/localpool/module.py | 6 | ||||
-rw-r--r-- | src/pybind/mgr/mds_autoscaler/module.py | 6 | ||||
-rw-r--r-- | src/pybind/mgr/mgr_module.py | 21 | ||||
-rw-r--r-- | src/pybind/mgr/mirroring/fs/snapshot_mirror.py | 5 | ||||
-rw-r--r-- | src/pybind/mgr/mirroring/module.py | 4 | ||||
-rw-r--r-- | src/pybind/mgr/restful/module.py | 8 | ||||
-rw-r--r-- | src/pybind/mgr/stats/module.py | 6 |
11 files changed, 51 insertions, 33 deletions
diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index bbd37e80ab8..d0653c2a8ed 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -31,7 +31,7 @@ from cephadm.services.cephadmservice import CephadmDaemonDeploySpec from cephadm.agent import CherryPyThread, CephadmAgentHelpers -from mgr_module import MgrModule, HandleCommandResult, Option +from mgr_module import MgrModule, HandleCommandResult, Option, NotifyType import orchestrator from orchestrator.module import to_format, Format @@ -434,7 +434,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, self.apply_spec_fails: List[Tuple[str, str]] = [] self.max_osd_draining_count = 10 - self.notify('mon_map', None) + self.notify(NotifyType.mon_map, None) self.config_notify() path = self.get_ceph_option('cephadm_path') @@ -580,8 +580,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, self.event.set() - def notify(self, notify_type: str, notify_id: Optional[str]) -> None: - if notify_type == "mon_map": + def notify(self, notify_type: NotifyType, notify_id: Optional[str]) -> None: + if notify_type == NotifyType.mon_map: # get monmap mtime so we can refresh configs when mons change monmap = self.get('mon_map') self.last_monmap = str_to_datetime(monmap['modified']) @@ -590,7 +590,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, if getattr(self, 'manage_etc_ceph_ceph_conf', False): # getattr, due to notify() being called before config_notify() self._kick_serve_loop() - if notify_type == "pg_summary": + if notify_type == NotifyType.pg_summary: self._trigger_osd_removal() def _trigger_osd_removal(self) -> None: diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 9b9e028d694..2963af3a089 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: from typing_extensions import Literal from mgr_module import CLICommand, CLIWriteCommand, HandleCommandResult, \ - MgrModule, MgrStandbyModule, Option, _get_localized_key + MgrModule, MgrStandbyModule, NotifyType, Option, _get_localized_key from mgr_util import ServerConfigException, build_url, \ create_self_signed_cert, get_default_addr, verify_tls_files @@ -478,8 +478,8 @@ class Module(MgrModule, CherryPyConfig): return (-errno.EINVAL, '', 'Command not found \'{0}\'' .format(cmd['prefix'])) - def notify(self, notify_type, notify_id): - NotificationQueue.new_notification(notify_type, notify_id) + def notify(self, notify_type: NotifyType, notify_id): + NotificationQueue.new_notification(str(notify_type), notify_id) def get_updated_pool_stats(self): df = self.get('df') diff --git a/src/pybind/mgr/insights/module.py b/src/pybind/mgr/insights/module.py index 4c7fd98cdae..c20ada65729 100644 --- a/src/pybind/mgr/insights/module.py +++ b/src/pybind/mgr/insights/module.py @@ -4,7 +4,7 @@ import re import threading from mgr_module import CLICommand, CLIReadCommand, HandleCommandResult -from mgr_module import MgrModule, CommandResult +from mgr_module import MgrModule, CommandResult, NotifyType from . import health as health_util # hours of crash history to report @@ -50,9 +50,9 @@ class Module(MgrModule): return { k: v for k, v in self._store.items() if k.startswith(prefix) } - def notify(self, ttype, ident): + def notify(self, ttype: NotifyType, ident): """Queue updates for processing""" - if ttype == "health": + if ttype == NotifyType.health: self.log.info("Received health check update {} pending".format( len(self._pending_health))) health = json.loads(self.get("health")["json"]) diff --git a/src/pybind/mgr/k8sevents/module.py b/src/pybind/mgr/k8sevents/module.py index 1e12d1f27a2..8c1521bfbda 100644 --- a/src/pybind/mgr/k8sevents/module.py +++ b/src/pybind/mgr/k8sevents/module.py @@ -40,7 +40,7 @@ from urllib3.exceptions import MaxRetryError,ProtocolError from collections import OrderedDict import rados -from mgr_module import MgrModule +from mgr_module import MgrModule, NotifyType from mgr_util import verify_cacrt, ServerConfigException try: @@ -1138,7 +1138,7 @@ class Module(MgrModule): else: self.log.warning("Unexpected clog message format received - skipped: {}".format(log_message)) - def notify(self, notify_type, notify_id): + def notify(self, notify_type: NotifyType, notify_id): """ Called by the ceph-mgr service to notify the Python plugin that new state is available. @@ -1153,7 +1153,7 @@ class Module(MgrModule): """ # only interested in cluster log (clog) messages for now - if notify_type == 'clog': + if notify_type == NotifyType.clog: self.log.debug("received a clog entry from mgr.notify") if isinstance(notify_id, dict): # create a log object to process diff --git a/src/pybind/mgr/localpool/module.py b/src/pybind/mgr/localpool/module.py index ce7cb1af2a6..907c7026b7d 100644 --- a/src/pybind/mgr/localpool/module.py +++ b/src/pybind/mgr/localpool/module.py @@ -1,4 +1,4 @@ -from mgr_module import MgrModule, CommandResult, Option +from mgr_module import MgrModule, CommandResult, Option, NotifyType import json import threading from typing import cast, Any @@ -51,8 +51,8 @@ class Module(MgrModule): super(Module, self).__init__(*args, **kwargs) self.serve_event = threading.Event() - def notify(self, notify_type: str, notify_id: str) -> None: - if notify_type == 'osd_map': + def notify(self, notify_type: NotifyType, notify_id: str) -> None: + if notify_type == NotifyType.osd_map: self.handle_osd_map() def handle_osd_map(self) -> None: diff --git a/src/pybind/mgr/mds_autoscaler/module.py b/src/pybind/mgr/mds_autoscaler/module.py index 006d8547c95..66b026bd706 100644 --- a/src/pybind/mgr/mds_autoscaler/module.py +++ b/src/pybind/mgr/mds_autoscaler/module.py @@ -4,7 +4,7 @@ Automatically scale MDSs based on status of the file-system using the FSMap import logging from typing import Any, Optional -from mgr_module import MgrModule +from mgr_module import MgrModule, NotifyType from ceph.deployment.service_spec import ServiceSpec import orchestrator import copy @@ -84,8 +84,8 @@ class MDSAutoscaler(orchestrator.OrchestratorClientMixin, MgrModule): self.log.exception(f"fs {fs_name}: exception while updating service: {e}") pass - def notify(self, notify_type: str, notify_id: str) -> None: - if notify_type != 'fs_map': + def notify(self, notify_type: NotifyType, notify_id: str) -> None: + if notify_type != NotifyType.fs_map: return fs_map = self.get('fs_map') if not fs_map: diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 0f6a19263d2..66382fb3bea 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -17,7 +17,7 @@ import json import subprocess import threading from collections import defaultdict -from enum import IntEnum +from enum import IntEnum, Enum import rados import re import socket @@ -84,6 +84,23 @@ NFS_GANESHA_SUPPORTED_FSALS = ['CEPH', 'RGW'] NFS_POOL_NAME = '.nfs' +class NotifyType(str, Enum): + mon_map = 'mon_map' + pg_summary = 'pg_summary' + health = 'health' + clog = 'clog' + osd_map = 'osd_map' + fs_map = 'fs_map' + command = 'command' + + # these are disabled because there are no users. + # see Mgr.cc: + # service_map = 'service_map' + # mon_status = 'mon_status' + # see DaemonServer.cc: + # perf_schema_update = 'perf_schema_update' + + class CommandResult(object): """ Use with MgrModule.send_command @@ -1169,7 +1186,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): """ return self._ceph_get_context() - def notify(self, notify_type: str, notify_id: str) -> None: + def notify(self, notify_type: NotifyType, notify_id: str) -> None: """ Called by the ceph-mgr service to notify the Python plugin that new state is available. diff --git a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py index ad9e550435d..6fa8d0c4c53 100644 --- a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py +++ b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py @@ -15,6 +15,7 @@ import rados from mgr_util import RTimer, CephfsClient, open_filesystem,\ CephfsConnectionException +from mgr_module import NotifyType from .blocklist import blocklist from .notify import Notifier, InstanceWatcher from .utils import INSTANCE_ID_PREFIX, MIRROR_OBJECT_NAME, Finisher, \ @@ -288,9 +289,9 @@ class FSSnapshotMirror: self.refresh_pool_policy() self.local_fs = CephfsClient(mgr) - def notify(self, notify_type): + def notify(self, notify_type: NotifyType): log.debug(f'got notify type {notify_type}') - if notify_type == 'fs_map': + if notify_type == NotifyType.fs_map: with self.lock: self.fs_map = self.mgr.get('fs_map') self.refresh_pool_policy_locked() diff --git a/src/pybind/mgr/mirroring/module.py b/src/pybind/mgr/mirroring/module.py index b9223111ae9..196cb8e6c09 100644 --- a/src/pybind/mgr/mirroring/module.py +++ b/src/pybind/mgr/mirroring/module.py @@ -1,6 +1,6 @@ from typing import List, Optional -from mgr_module import MgrModule, CLIReadCommand, CLIWriteCommand, Option +from mgr_module import MgrModule, CLIReadCommand, CLIWriteCommand, Option, NotifyType from .fs.snapshot_mirror import FSSnapshotMirror @@ -11,7 +11,7 @@ class Module(MgrModule): super().__init__(*args, **kwargs) self.fs_snapshot_mirror = FSSnapshotMirror(self) - def notify(self, notify_type, notify_id): + def notify(self, notify_type: NotifyType, notify_id): self.fs_snapshot_mirror.notify(notify_type) @CLIWriteCommand('fs snapshot mirror enable') diff --git a/src/pybind/mgr/restful/module.py b/src/pybind/mgr/restful/module.py index b76464e76fa..97f99059931 100644 --- a/src/pybind/mgr/restful/module.py +++ b/src/pybind/mgr/restful/module.py @@ -23,7 +23,7 @@ from pecan.rest import RestController from werkzeug.serving import make_server, make_ssl_devcert from .hooks import ErrorHook -from mgr_module import MgrModule, CommandResult +from mgr_module import MgrModule, CommandResult, NotifyType from mgr_util import build_url @@ -360,15 +360,15 @@ class Module(MgrModule): self.log.error(str(traceback.format_exc())) - def notify(self, notify_type, tag): + def notify(self, notify_type: NotifyType, tag: str): try: self._notify(notify_type, tag) except: self.log.error(str(traceback.format_exc())) - def _notify(self, notify_type, tag): - if notify_type != "command": + def _notify(self, notify_type: NotifyType, tag): + if notify_type != NotifyType.command: self.log.debug("Unhandled notification type '%s'", notify_type) return # we can safely skip all the sequential commands diff --git a/src/pybind/mgr/stats/module.py b/src/pybind/mgr/stats/module.py index a4bc44630d6..5d74aeb1d81 100644 --- a/src/pybind/mgr/stats/module.py +++ b/src/pybind/mgr/stats/module.py @@ -5,7 +5,7 @@ performance stats for ceph filesystem (for now...) import json from typing import List, Dict -from mgr_module import MgrModule, Option +from mgr_module import MgrModule, Option, NotifyType from .fs.perf_stats import FSPerfStats @@ -26,8 +26,8 @@ class Module(MgrModule): super(Module, self).__init__(*args, **kwargs) self.fs_perf_stats = FSPerfStats(self) - def notify(self, notify_type, notify_id): - if notify_type == "command": + def notify(self, notify_type: NotifyType, notify_id): + if notify_type == NotifyType.command: self.fs_perf_stats.notify(notify_id) def handle_command(self, inbuf, cmd): |