Relax requirement for tenant_name in get_auth()

get_auth() in client.py raises an exception if
tenant_name is not included in the os_options
dict. This is overly constrained since tenant_id
is equally sufficient. This patch modifies
get_auth to require either tenant_name
or tenant_id.

Change-Id: Ibbcda1704637eb887efa5895579d260a1e072327
This commit is contained in:
anc 2014-05-20 13:35:03 +01:00
parent 3d0de79e26
commit 916f5cbd61
2 changed files with 21 additions and 3 deletions

View File

@ -361,7 +361,7 @@ def get_auth(auth_url, user, key, **kwargs):
if kwargs.get('tenant_name'):
os_options['tenant_name'] = kwargs['tenant_name']
if ('tenant_name' not in os_options):
if not (os_options.get('tenant_name') or os_options.get('tenant_id')):
raise ClientException('No tenant specified')
cacert = kwargs.get('cacert', None)

View File

@ -285,7 +285,7 @@ class TestGetAuth(MockHttpTest):
'asdf', 'asdf',
auth_version='1.0')
def test_auth_v2(self):
def test_auth_v2_with_tenant_name(self):
os_options = {'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
@ -294,13 +294,31 @@ class TestGetAuth(MockHttpTest):
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
def test_auth_v2_no_tenant_name(self):
def test_auth_v2_with_tenant_id(self):
os_options = {'tenant_id': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options,
auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
def test_auth_v2_no_tenant_name_or_tenant_id(self):
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0({})
self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf',
os_options={},
auth_version='2.0')
def test_auth_v2_with_tenant_name_none_and_tenant_id_none(self):
os_options = {'tenant_name': None,
'tenant_id': None}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf',
os_options=os_options,
auth_version='2.0')
def test_auth_v2_with_tenant_user_in_user(self):
tenant_option = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option)