From: Sage Weil Date: Thu, 2 Dec 2021 15:22:48 +0000 (-0500) Subject: pybind/mgr: introduce NotifyType enum X-Git-Tag: v16.2.8~156^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=900c502a996a13b00634e3753fb964bbbab3c01b;p=ceph.git pybind/mgr: introduce NotifyType enum Note that we don't annotate the dashboard NotificationQueue because it is used internally by the dashboard with other events. Signed-off-by: Sage Weil (cherry picked from commit 1ac480df45058e103a2f4954950b8a4edb23610a) Conflicts: src/pybind/mgr/cephadm/module.py - trivial resolution src/pybind/mgr/dashboard/module.py - trivial resolution src/pybind/mgr/localpool/module.py - trivial resolution src/pybind/mgr/mds_autoscaler/module.py - trivial resolution --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 9facf7c3658..a9ef41cb81e 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -30,7 +30,7 @@ from ceph.utils import str_to_datetime, datetime_to_str, datetime_now from cephadm.serve import CephadmServe from cephadm.services.cephadmservice import CephadmDaemonDeploySpec -from mgr_module import MgrModule, HandleCommandResult, Option +from mgr_module import MgrModule, HandleCommandResult, Option, NotifyType from mgr_util import create_self_signed_cert import secrets import orchestrator @@ -421,7 +421,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, self._cons: Dict[str, Tuple[remoto.backends.BaseConnection, remoto.backends.LegacyModuleExecute]] = {} - self.notify('mon_map', None) + self.notify(NotifyType.mon_map, None) self.config_notify() path = self.get_ceph_option('cephadm_path') @@ -554,8 +554,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']) @@ -564,7 +564,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 47afe2e2504..37f39e24ff0 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -22,7 +22,7 @@ if TYPE_CHECKING: from typing_extensions import Literal from mgr_module import CLIWriteCommand, HandleCommandResult, MgrModule, \ - MgrStandbyModule, Option, _get_localized_key + MgrStandbyModule, NotifyType, Option, _get_localized_key from mgr_util import ServerConfigException, build_url, \ create_self_signed_cert, get_default_addr, verify_tls_files @@ -430,8 +430,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 eb075271715..ce3fadc2af7 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 23ffeaa12de..55bdd4ffc75 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 +from mgr_module import MgrModule, CommandResult, NotifyType import json import threading @@ -53,7 +53,7 @@ class Module(MgrModule): self.serve_event = threading.Event() def notify(self, notify_type, notify_id): - if notify_type == 'osd_map': + if notify_type == NotifyType.osd_map: self.handle_osd_map() def handle_osd_map(self): diff --git a/src/pybind/mgr/mds_autoscaler/module.py b/src/pybind/mgr/mds_autoscaler/module.py index 01a9df2f4a8..b95bf35fbb7 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 Optional, List, Set -from mgr_module import MgrModule +from mgr_module import MgrModule, NotifyType from ceph.deployment.service_spec import ServiceSpec import orchestrator import copy @@ -85,7 +85,7 @@ class MDSAutoscaler(orchestrator.OrchestratorClientMixin, MgrModule): pass def notify(self, notify_type, notify_id): - if notify_type != 'fs_map': + 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 2b1c7d1b8db..8b12cd29791 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 @@ -83,6 +83,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 @@ -985,7 +1002,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 4d3f1355286..4c2f1d68e6e 100644 --- a/src/pybind/mgr/restful/module.py +++ b/src/pybind/mgr/restful/module.py @@ -24,7 +24,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 @@ -361,15 +361,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):