From 852bd45c94df4a5c5ccb1e42077ec4f2d1a57272 Mon Sep 17 00:00:00 2001 From: Mark Hamzy Date: Mon, 5 Mar 2018 15:18:31 -0600 Subject: [PATCH] Fix formatting of ImportError Fix formatting of ImportError when using a driver not found in the list of token providers. Change-Id: I0ac8ac199aeebd20960ad0654461f1f81c4d7da0 Closes-bug: 1753584 --- keystone/common/manager.py | 2 +- keystone/tests/unit/token/test_common.py | 14 ++++++++++++++ .../notes/bug-1753584-e052bc7805f001b4.yaml | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-1753584-e052bc7805f001b4.yaml diff --git a/keystone/common/manager.py b/keystone/common/manager.py index 4a60e8566f..9934fd8af9 100644 --- a/keystone/common/manager.py +++ b/keystone/common/manager.py @@ -78,7 +78,7 @@ def load_driver(namespace, driver_name, *args): return driver_manager.driver except stevedore.exception.NoMatches: msg = (_('Unable to find %(name)r driver in %(namespace)r.')) - raise ImportError(msg, {'name': driver_name, 'namespace': namespace}) + raise ImportError(msg % {'name': driver_name, 'namespace': namespace}) class _TraceMeta(type): diff --git a/keystone/tests/unit/token/test_common.py b/keystone/tests/unit/token/test_common.py index 4f028c6cd0..ac835b9dcc 100644 --- a/keystone/tests/unit/token/test_common.py +++ b/keystone/tests/unit/token/test_common.py @@ -10,9 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + from six.moves import urllib from keystone.tests import unit +from keystone.token import provider from keystone.token.providers import common @@ -20,3 +23,14 @@ class TestTokenProvidersCommon(unit.TestCase): def test_strings_are_url_safe(self): s = common.random_urlsafe_str() self.assertEqual(s, urllib.parse.quote_plus(s)) + + def test_unsupported_provider_raises_import_error(self): + namespace = "keystone.token.provider" + # Generate a random name + driver = uuid.uuid4().hex + self.config_fixture.config(group='token', provider=driver) + msg = "Unable to find '%(driver)s' driver in '%(namespace)s'." % { + 'namespace': namespace, 'driver': driver + } + + self.assertRaisesRegex(ImportError, msg, provider.Manager) diff --git a/releasenotes/notes/bug-1753584-e052bc7805f001b4.yaml b/releasenotes/notes/bug-1753584-e052bc7805f001b4.yaml new file mode 100644 index 0000000000..c431f980e5 --- /dev/null +++ b/releasenotes/notes/bug-1753584-e052bc7805f001b4.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + [`bug 1753584 `_] + Fix formatting of ImportError when using a driver not found in the list + of token providers.