From c57e562d2b941c47abdfea46fbe45e8f8cdf431b Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Mon, 8 Dec 2014 13:12:53 +1000 Subject: [PATCH] Add name parameter to NoMatchingPlugin exception If you want to handle a NoMatchingPlugin exception rather than simply exit then the name of the missing plugin is generally more useful than the message. The exception is specific enough that you can know what went wrong, but you cannot determine the name of the missing plugin if you want to do your own logging - only use the message that is generated. We should keep the message but expose the plugin name as well. Closes-Bug: #1410391 Change-Id: Ic93ec6583b8d7797529d36d63995ef0d8db754f1 --- keystoneclient/auth/base.py | 4 +--- keystoneclient/exceptions.py | 11 +++++++++++ keystoneclient/tests/auth/test_conf.py | 13 ++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/keystoneclient/auth/base.py b/keystoneclient/auth/base.py index 9da90b74c..5b622e797 100644 --- a/keystoneclient/auth/base.py +++ b/keystoneclient/auth/base.py @@ -17,7 +17,6 @@ import six import stevedore from keystoneclient import exceptions -from keystoneclient.i18n import _ # NOTE(jamielennox): The AUTH_INTERFACE is a special value that can be @@ -44,8 +43,7 @@ def get_plugin_class(name): name=name, invoke_on_load=False) except RuntimeError: - msg = _('The plugin %s could not be found') % name - raise exceptions.NoMatchingPlugin(msg) + raise exceptions.NoMatchingPlugin(name) return mgr.driver diff --git a/keystoneclient/exceptions.py b/keystoneclient/exceptions.py index 241d27b30..a76aa3287 100644 --- a/keystoneclient/exceptions.py +++ b/keystoneclient/exceptions.py @@ -81,8 +81,19 @@ class MissingAuthPlugin(ClientException): class NoMatchingPlugin(ClientException): """There were no auth plugins that could be created from the parameters provided. + + :param str name: The name of the plugin that was attempted to load. + + .. py:attribute:: name + + The name of the plugin that was attempted to load. """ + def __init__(self, name): + self.name = name + msg = _('The plugin %s could not be found') % name + super(NoMatchingPlugin, self).__init__(msg) + class InvalidResponse(ClientException): """The response from the server is not valid for this request.""" diff --git a/keystoneclient/tests/auth/test_conf.py b/keystoneclient/tests/auth/test_conf.py index 342333f35..4945b3fc6 100644 --- a/keystoneclient/tests/auth/test_conf.py +++ b/keystoneclient/tests/auth/test_conf.py @@ -92,13 +92,16 @@ class ConfTests(utils.TestCase): self.assertEqual(project_domain_name, a.project_domain_name) def test_loading_invalid_plugin(self): - self.conf_fixture.config(auth_plugin=uuid.uuid4().hex, + auth_plugin = uuid.uuid4().hex + self.conf_fixture.config(auth_plugin=auth_plugin, group=self.GROUP) - self.assertRaises(exceptions.NoMatchingPlugin, - conf.load_from_conf_options, - self.conf_fixture.conf, - self.GROUP) + e = self.assertRaises(exceptions.NoMatchingPlugin, + conf.load_from_conf_options, + self.conf_fixture.conf, + self.GROUP) + + self.assertEqual(auth_plugin, e.name) def test_loading_with_no_data(self): self.assertIsNone(conf.load_from_conf_options(self.conf_fixture.conf,