From: Ernesto Puerta Date: Thu, 10 Oct 2019 09:16:13 +0000 (+0200) Subject: mgr/dashboard: add Mixins and @final to plugins X-Git-Tag: v15.1.0~1274^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fc899d04899f35efc3689f70bd08688b03428547;p=ceph.git mgr/dashboard: add Mixins and @final to plugins Fixes: https://tracker.ceph.com/issues/41990 Signed-off-by: Ernesto Puerta --- diff --git a/src/pybind/mgr/dashboard/plugins/__init__.py b/src/pybind/mgr/dashboard/plugins/__init__.py index 2a4ded2b6d1c..897365477027 100644 --- a/src/pybind/mgr/dashboard/plugins/__init__.py +++ b/src/pybind/mgr/dashboard/plugins/__init__.py @@ -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"