From 14a25863dfc491aaa40b1e036eb6f7577766fc99 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Thu, 15 Oct 2015 12:09:19 +1100 Subject: [PATCH] Return None from generic plugin if failure The create_plugin method can be called multiple times with different version values and the generic plugin should return an object if it is suitable. By raising an error here when you have invalid parameters it prevents the generic handler attempting additional version options. Change-Id: I3391c6607fc53a154e10bee7e741bf73afeae5fa --- keystoneauth1/identity/generic/password.py | 4 +--- .../tests/unit/loading/test_generic.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/keystoneauth1/identity/generic/password.py b/keystoneauth1/identity/generic/password.py index a24fde22..967fcc3a 100644 --- a/keystoneauth1/identity/generic/password.py +++ b/keystoneauth1/identity/generic/password.py @@ -12,7 +12,6 @@ from keystoneauth1 import _utils as utils from keystoneauth1 import discover -from keystoneauth1 import exceptions from keystoneauth1.identity.generic import base from keystoneauth1.identity import v2 from keystoneauth1.identity import v3 @@ -45,8 +44,7 @@ class Password(base.BaseGenericPlugin): def create_plugin(self, session, version, url, raw_status=None): if discover.version_match((2,), version): if self._user_domain_id or self._user_domain_name: - raise exceptions.DiscoveryFailure( - 'Cannot use v2 authentication with domain scope') + return None return v2.Password(auth_url=url, user_id=self._user_id, diff --git a/keystoneauth1/tests/unit/loading/test_generic.py b/keystoneauth1/tests/unit/loading/test_generic.py index d4bcdeaf..cbaca240 100644 --- a/keystoneauth1/tests/unit/loading/test_generic.py +++ b/keystoneauth1/tests/unit/loading/test_generic.py @@ -10,7 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + +from keystoneauth1 import fixture +from keystoneauth1 import identity from keystoneauth1.loading._plugins.identity import generic +from keystoneauth1 import session from keystoneauth1.tests.unit.loading import utils @@ -37,6 +42,24 @@ class PasswordTests(utils.TestCase): self.assertEqual(set(allowed_opts), set(opts)) self.assertEqual(len(allowed_opts), len(opts)) + def test_loads_v3_with_user_domain(self): + auth_url = 'http://keystone.test:5000' + disc = fixture.DiscoveryList(href=auth_url) + sess = session.Session() + self.requests_mock.get(auth_url, json=disc) + + plugin = generic.Password().load_from_options( + auth_url=auth_url, + user_id=uuid.uuid4().hex, + password=uuid.uuid4().hex, + project_id=uuid.uuid4().hex, + user_domain_id=uuid.uuid4().hex) + + inner_plugin = plugin._do_create_plugin(sess) + + self.assertIsInstance(inner_plugin, identity.V3Password) + self.assertEqual(inner_plugin.auth_url, auth_url + '/v3') + class TokenTests(utils.TestCase):