From 2bb8c6abaf34c72b27e68a397d228dc2293aa349 Mon Sep 17 00:00:00 2001 From: Roman Vasilets Date: Fri, 11 Dec 2015 19:23:13 +0200 Subject: [PATCH] Make PluginWithSuchNameExists more informative To find out where are already imported modules of existing plugin and the new one. We need to provide to the user places of allocations of this modules. Change-Id: Ic9e072dfb7f183c2d935b514d2b8df1bd42d3976 --- rally/common/plugin/plugin.py | 12 +++++++++--- rally/exceptions.py | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rally/common/plugin/plugin.py b/rally/common/plugin/plugin.py index 3605307a96..43df1d63c3 100644 --- a/rally/common/plugin/plugin.py +++ b/rally/common/plugin/plugin.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + from rally.common.plugin import discover from rally.common.plugin import info from rally.common.plugin import meta @@ -142,13 +144,17 @@ class Plugin(meta.MetaMixin, info.InfoMixin): @classmethod def _set_name_and_namespace(cls, name, namespace): try: - Plugin.get(name, namespace=namespace) + existing_plugin = Plugin.get(name, namespace=namespace) except exceptions.PluginNotFound: cls._meta_set("name", name) cls._meta_set("namespace", namespace) else: - raise exceptions.PluginWithSuchNameExists(name=name, - namespace=namespace) + raise exceptions.PluginWithSuchNameExists( + name=name, namespace=namespace, + existing_path=( + sys.modules[existing_plugin.__module__].__file__), + new_path=sys.modules[cls.__module__].__file__ + ) @classmethod def _set_deprecated(cls, reason, rally_version): diff --git a/rally/exceptions.py b/rally/exceptions.py index 006ff964c7..f957242642 100644 --- a/rally/exceptions.py +++ b/rally/exceptions.py @@ -86,7 +86,9 @@ class PluginNotFound(NotFoundException): class PluginWithSuchNameExists(RallyException): msg_fmt = _("Plugin with such name: %(name)s already exists in " - "%(namespace)s namespace") + "%(namespace)s namespace. It's module allocates at " + "%(existing_path)s. You are trying to add plugin whose module " + "allocates at %(new_path)s.") class NoSuchConfigField(NotFoundException):