]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: introduce NotifyType enum
authorSage Weil <sage@newdream.net>
Thu, 2 Dec 2021 15:22:48 +0000 (10:22 -0500)
committerNeha Ojha <nojha@redhat.com>
Wed, 16 Feb 2022 17:20:47 +0000 (17:20 +0000)
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 <sage@newdream.net>
(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

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/dashboard/module.py
src/pybind/mgr/insights/module.py
src/pybind/mgr/k8sevents/module.py
src/pybind/mgr/localpool/module.py
src/pybind/mgr/mds_autoscaler/module.py
src/pybind/mgr/mgr_module.py
src/pybind/mgr/mirroring/fs/snapshot_mirror.py
src/pybind/mgr/mirroring/module.py
src/pybind/mgr/restful/module.py
src/pybind/mgr/stats/module.py

index 9facf7c36582e3a2e89b1f315204e1a68dedf7e1..a9ef41cb81ed147dcd6a2a0a1a255017215393fc 100644 (file)
@@ -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:
index 47afe2e25042d45df1e574e26077cc3cd3367eed..37f39e24ff0b5109cf40f57e7930e57579050128 100644 (file)
@@ -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')
index eb0752717158739ad0a863b0eab3497679bb2e99..ce3fadc2af70ae5fddf4b30e2548fc40817234dc 100644 (file)
@@ -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"])
index 1e12d1f27a25c07959ed0d01ca5c1709fc40a606..8c1521bfbda3fb22e71a286bcfc55fde0c2f739e 100644 (file)
@@ -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
index 23ffeaa12de1f6aaabd5d693dea34b56f20d95e6..55bdd4ffc7593b16bf2642d010f08ec4d034f73b 100644 (file)
@@ -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):
index 01a9df2f4a89283d500fa1975b69dafdff2f801e..b95bf35fbb7bf724f21593aab31eaa13d7c550e8 100644 (file)
@@ -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:
index 2b1c7d1b8db5127ed78928b06586af85a3069093..8b12cd29791eef44a10639746a31d7b52a1cf19a 100644 (file)
@@ -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.
index ad9e550435d801eb36eaa6317a695061d1b76436..6fa8d0c4c53382b635c27d1fff0516d2354dc1c5 100644 (file)
@@ -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()
index b9223111ae902507aa3f52ea374d1adce0ae0cf7..196cb8e6c099aa26ca7c1af7a9b6539728e4e4b2 100644 (file)
@@ -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')
index 4d3f1355286b13998acd375ebd2defac1a02e2e1..4c2f1d68e6e9cb4362b3dcc87caf7e6ccc4e2941 100644 (file)
@@ -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
index a4bc44630d637168eb8a6f6d94f926520bde7a43..5d74aeb1d81ee684b56b912181d4e95b23bdbcbe 100644 (file)
@@ -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):