Conditionally validate KeystoneAuthV2 credentials

Don't validate the presence of KeystoneAuthV2 credential info if a
keystone client is given.

Co-Authored-By: Anderson Mesquita <andersonvom@gmail.com>
Change-Id: I5d928efda843d8a6310103bf07c375d716908031
This commit is contained in:
Richard Lee
2014-03-06 17:30:28 -06:00
committed by Anderson Mesquita
parent ecc4f2eb7b
commit 3f120f6ba2
2 changed files with 17 additions and 8 deletions

View File

@@ -51,20 +51,23 @@ class AuthPluginBase(object):
class KeystoneAuthV2(AuthPluginBase):
def __init__(self, auth_url='', username='', password='',
tenant_name='', tenant_id='', insecure=False, keystone=None):
if not all([auth_url, username, password, tenant_name or tenant_id]):
raise ValueError('Please provide auth_url, username, password,'
' and tenant_id or tenant_name.')
if not keystone:
tenant_info = tenant_name or tenant_id
if not all([auth_url, username, password, tenant_info]):
raise ValueError('Please provide auth_url, username, password,'
' and tenant_id or tenant_name.')
self._barbican_url = None
#TODO(dmend): make these configurable
self._service_type = 'keystore'
self._endpoint_type = 'publicURL'
self._keystone = keystone or ksclient.Client(username=username,
password=password,
tenant_name=tenant_name,
tenant_id=tenant_id,
auth_url=auth_url,
insecure=insecure)
self._barbican_url = None
#TODO(dmend): make these configurable
self._service_type = 'keystore'
self._endpoint_type = 'publicURL'
self.tenant_name = self._keystone.tenant_name
self.tenant_id = self._keystone.tenant_id

View File

@@ -44,6 +44,12 @@ class WhenTestingKeystoneAuthentication(unittest.TestCase):
with self.assertRaises(ValueError):
keystone = auth.KeystoneAuthV2()
def test_nothing_is_required_if_keystone_is_present(self):
fake_keystone = mock.Mock(tenant_name='foo', tenant_id='bar')
keystone_auth = auth.KeystoneAuthV2(keystone=fake_keystone)
self.assertEqual('foo', keystone_auth.tenant_name)
self.assertEqual('bar', keystone_auth.tenant_id)
def test_get_barbican_url(self):
barbican_url = 'https://www.barbican.com'
self.keystone_auth._barbican_url = barbican_url