Merge "Add Keystone v3 compatibility"

This commit is contained in:
Jenkins 2016-01-28 09:01:54 +00:00 committed by Gerrit Code Review
commit 84d9888d82
4 changed files with 80 additions and 6 deletions

View File

@ -276,6 +276,26 @@ class OpenStackMagnumShell(object):
default=cliutils.env('OS_TENANT_ID'),
help='Defaults to env[OS_TENANT_ID].')
parser.add_argument('--os-user-domain-id',
metavar='<auth-user-domain-id>',
default=cliutils.env('OS_USER_DOMAIN_ID'),
help='Defaults to env[OS_USER_DOMAIN_ID].')
parser.add_argument('--os-user-domain-name',
metavar='<auth-user-domain-name>',
default=cliutils.env('OS_USER_DOMAIN_NAME'),
help='Defaults to env[OS_USER_DOMAIN_NAME].')
parser.add_argument('--os-project-domain-id',
metavar='<auth-project-domain-id>',
default=cliutils.env('OS_PROJECT_DOMAIN_ID'),
help='Defaults to env[OS_PROJECT_DOMAIN_ID].')
parser.add_argument('--os-project-domain-name',
metavar='<auth-project-domain-name>',
default=cliutils.env('OS_PROJECT_DOMAIN_NAME'),
help='Defaults to env[OS_PROJECT_DOMAIN_NAME].')
parser.add_argument('--service-type',
metavar='<service-type>',
help='Defaults to container for all '
@ -440,9 +460,13 @@ class OpenStackMagnumShell(object):
return 0
(os_username, os_tenant_name, os_tenant_id,
os_user_domain_id, os_user_domain_name,
os_project_domain_id, os_project_domain_name,
os_auth_url, os_auth_system, endpoint_type,
service_type, bypass_url, insecure) = (
(args.os_username, args.os_tenant_name, args.os_tenant_id,
args.os_user_domain_id, args.os_user_domain_name,
args.os_project_domain_id, args.os_project_domain_name,
args.os_auth_url, args.os_auth_system, args.endpoint_type,
args.service_type, args.bypass_url, args.insecure)
)
@ -530,6 +554,10 @@ class OpenStackMagnumShell(object):
api_key=os_password,
project_id=os_tenant_id,
project_name=os_tenant_name,
user_domain_id=os_user_domain_id,
user_domain_name=os_user_domain_name,
project_domain_id=os_project_domain_id,
project_domain_name=os_project_domain_name,
auth_url=os_auth_url,
service_type=service_type,
region_name=args.os_region_name,

View File

@ -40,6 +40,13 @@ FAKE_ENV3 = {'OS_USERNAME': 'username',
'OS_TENANT_ID': 'tenant_id',
'OS_AUTH_URL': 'http://no.where/v2.0'}
FAKE_ENV4 = {'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_ID': 'tenant_id',
'OS_USER_DOMAIN_NAME': 'Default',
'OS_PROJECT_DOMAIN_NAME': 'Default',
'OS_AUTH_URL': 'http://no.where/v3'}
def _create_ver_list(versions):
return {'versions': {'values': versions}}
@ -233,6 +240,8 @@ class ShellTest(utils.TestCase):
endpoint_type='publicURL', project_id='',
project_name='tenant_name', auth_url=self.AUTH_URL,
service_type='container', region_name=expected_region_name,
project_domain_id='', project_domain_name='',
user_domain_id='', user_domain_name='',
magnum_url=None, insecure=False)
def test_main_option_region(self):
@ -258,6 +267,8 @@ class ShellTest(utils.TestCase):
endpoint_type='publicURL', project_id='',
project_name='tenant_name', auth_url=self.AUTH_URL,
service_type='container', region_name=None,
project_domain_id='', project_domain_name='',
user_domain_id='', user_domain_name='',
magnum_url=None, insecure=False)
@mock.patch('magnumclient.v1.client.Client')
@ -269,6 +280,8 @@ class ShellTest(utils.TestCase):
endpoint_type='internalURL', project_id='',
project_name='tenant_name', auth_url=self.AUTH_URL,
service_type='container', region_name=None,
project_domain_id='', project_domain_name='',
user_domain_id='', user_domain_name='',
magnum_url=None, insecure=False)
@ -287,3 +300,16 @@ class ShellTestKeystoneV3(ShellTest):
mreq.register_uri(
'GET', v3_url, json=_create_ver_list([v3_version]),
status_code=200)
@mock.patch('magnumclient.v1.client.Client')
def test_main_endpoint_public(self, mock_client):
self.make_env(fake_env=FAKE_ENV4)
self.shell('--endpoint-type publicURL bay-list')
mock_client.assert_called_once_with(
username='username', api_key='password',
endpoint_type='publicURL', project_id='tenant_id',
project_name='', auth_url=self.AUTH_URL,
service_type='container', region_name=None,
project_domain_id='', project_domain_name='Default',
user_domain_id='', user_domain_name='Default',
magnum_url=None, insecure=False)

View File

@ -66,6 +66,10 @@ class ClientTest(testtools.TestCase):
auth_url='authurl',
project_id=None,
project_name=None,
project_domain_id=None,
project_domain_name=None,
user_domain_id=None,
user_domain_name=None,
token='mytoken')
http_client.assert_called_once_with(
interface='public',
@ -87,6 +91,10 @@ class ClientTest(testtools.TestCase):
auth_url='authurl',
username='myuser',
password=None,
project_domain_id=None,
project_domain_name=None,
user_domain_id=None,
user_domain_name=None,
project_id=None,
project_name=None)
http_client.assert_called_once_with(
@ -114,6 +122,10 @@ class ClientTest(testtools.TestCase):
auth_url='authurl',
username='myuser',
password=None,
project_domain_id=None,
project_domain_name=None,
user_domain_id=None,
user_domain_name=None,
project_id=None,
project_name=None)
http_client.assert_not_called()

View File

@ -34,7 +34,9 @@ class Client(object):
endpoint_type=None, service_type='container',
region_name=None, input_auth_token=None,
session=None, password=None, auth_type='password',
interface='public', service_name=None, insecure=False):
interface='public', service_name=None, insecure=False,
user_domain_id=None, user_domain_name=None,
project_domain_id=None, project_domain_name=None):
# We have to keep the api_key are for backwards compat, but let's
# remove it from the rest of our code since it's not a keystone
@ -57,22 +59,28 @@ class Client(object):
token=input_auth_token,
auth_url=auth_url,
project_id=project_id,
project_name=project_name)
project_name=project_name,
user_domain_id=user_domain_id,
user_domain_name=user_domain_name,
project_domain_id=project_domain_id,
project_domain_name=project_domain_name)
else:
loader_kwargs = dict(
username=username,
password=password,
auth_url=auth_url,
project_id=project_id,
project_name=project_name)
project_name=project_name,
user_domain_id=user_domain_id,
user_domain_name=user_domain_name,
project_domain_id=project_domain_id,
project_domain_name=project_domain_name)
# Backwards compatability for people not passing in Session
if session is None:
loader = loading.get_plugin_loader(auth_type)
# This only supports keystone v2 password auth - but we can
# support other auth by passing in a Session, which is the
# right thing to do anyway
# This should be able to handle v2 and v3 Keystone Auth
auth_plugin = loader.load_from_options(**loader_kwargs)
session = ksa_session.Session(
auth=auth_plugin, verify=(not insecure))