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
This commit is contained in:
parent
3ccc37410d
commit
14a25863df
@ -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,
|
||||
|
@ -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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user