]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add Mixins and @final to plugins
authorErnesto Puerta <epuertat@redhat.com>
Thu, 10 Oct 2019 09:16:13 +0000 (11:16 +0200)
committerErnesto Puerta <epuertat@redhat.com>
Thu, 10 Oct 2019 10:58:52 +0000 (12:58 +0200)
Fixes: https://tracker.ceph.com/issues/41990
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
src/pybind/mgr/dashboard/plugins/__init__.py

index 2a4ded2b6d1c3729efc92e87235411016d5ee6ab..8973654770278f8bcd1296a6f1e6853c6461f141 100644 (file)
@@ -12,6 +12,10 @@ class Interface(object):
     pass
 
 
+class Mixin(object):
+    pass
+
+
 class DashboardPluginManager(object):
     def __init__(self, project_name):
         self.__pm = PluginManager(project_name)
@@ -32,6 +36,11 @@ class DashboardPluginManager(object):
         self.pm.add_hookspecs(cls)
         return cls
 
+    @staticmethod
+    def final(func):
+        setattr(func, '__final__', True)
+        return func
+
     def add_plugin(self, plugin):
         """ Provides decorator interface for PluginManager.register():
             @PLUGIN_MANAGER.add_plugin
@@ -45,6 +54,9 @@ class DashboardPluginManager(object):
         from inspect import getmembers, ismethod
         for interface in plugin.__bases__:
             for method_name, _ in getmembers(interface, predicate=ismethod):
+                if hasattr(getattr(interface, method_name), '__final__'):
+                    continue
+
                 if self.pm.parse_hookimpl_opts(plugin, method_name) is None:
                     raise NotImplementedError(
                         "Plugin '{}' implements interface '{}' but existing"