]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: add a custom warning message when enabling feature
authorNizamudeen A <nia@redhat.com>
Fri, 15 Nov 2024 07:20:07 +0000 (12:50 +0530)
committerNizamudeen A <nia@redhat.com>
Wed, 11 Dec 2024 09:58:30 +0000 (15:28 +0530)
would be helpful if we want to notify user about certain issues when
enabling something.

```
[root@ceph ceph]# ceph dashboard feature enable iscsi

WARNING: iscsi warning message
Feature 'iscsi': enabled
```

Fixes: https://tracker.ceph.com/issues/68969
Signed-off-by: Nizamudeen A <nia@redhat.com>
(cherry picked from commit 14855b306c4e9fdb837c46f1d8d68f43cc9b07e1)

src/pybind/mgr/dashboard/plugins/feature_toggles.py
src/pybind/mgr/mgr_util.py

index f16b2e68c4d692c3b06f7d97d97105251ebd2de8..63b1d762c3417b1421dcfab150b4c381bd9af585 100644 (file)
@@ -1,10 +1,11 @@
 # -*- coding: utf-8 -*-
 
 from enum import Enum
-from typing import List, Optional, Set, no_type_check
+from typing import Dict, List, Optional, Set, no_type_check
 
 import cherrypy
 from mgr_module import CLICommand, Option
+from mgr_util import CLIWarning
 
 from ..controllers.cephfs import CephFS
 from ..controllers.iscsi import Iscsi, IscsiTarget
@@ -27,6 +28,14 @@ class Features(Enum):
     NFS = 'nfs'
     DASHBOARD = 'dashboard'
 
+    # if we want to add any custom warning message when enabling a feature
+    # we can add it here as key-value pair in warn_msg.
+    # eg: Features.ISCSI.value: 'iscsi warning message'
+    @property
+    def warning(self):
+        warn_msg: Dict[str, str] = {}
+        return warn_msg.get(self.value, None)
+
 
 PREDISABLED_FEATURES = set()  # type: Set[str]
 
@@ -91,6 +100,8 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions,
                         mgr.set_module_option(
                             self.OPTION_FMT.format(feature),
                             action == Actions.ENABLE)
+                        if action == Actions.ENABLE and feature.warning:
+                            msg += [CLIWarning(feature.warning)]
                         msg += ["Feature '{.value}': {}".format(
                             feature,
                             'enabled' if action == Actions.ENABLE else
index 05ec6496682f4dd7a9f24826100c4cd46df9b2ba..8d71dd69128840928a64e8cb551d72583d49ba1b 100644 (file)
@@ -59,6 +59,13 @@ class PortAlreadyInUse(Exception):
     pass
 
 
+# helper function for showing a warning text in
+# the terminal
+class CLIWarning(str):
+    def __new__(cls, content: str) -> "CLIWarning":
+        return super().__new__(cls, f"WARNING: {content}")
+
+
 class CephfsConnectionException(Exception):
     def __init__(self, error_code: int, error_message: str):
         self.errno = error_code