Merge "No auth when token and endpoint are passed"

This commit is contained in:
Jenkins 2015-09-25 17:12:18 +00:00 committed by Gerrit Code Review
commit 5eaa52eae4
2 changed files with 25 additions and 11 deletions

View File

@ -443,18 +443,13 @@ class OpenStackImagesShell(object):
return ks_session
def _get_endpoint_and_token(self, args):
image_url = self._get_image_url(args)
endpoint = self._get_image_url(args)
auth_token = args.os_auth_token
auth_reqd = (not (auth_token and image_url) or
(hasattr(args, 'func') and
utils.is_authentication_required(args.func)))
if not auth_reqd:
endpoint = image_url
token = args.os_auth_token
else:
auth_req = (hasattr(args, 'func') and
utils.is_authentication_required(args.func))
if auth_req and not (endpoint and auth_token):
if not args.os_username:
raise exc.CommandError(
_("You must provide a username via"
@ -527,7 +522,7 @@ class OpenStackImagesShell(object):
'key': args.os_key
}
ks_session = self._get_keystone_session(**kwargs)
token = args.os_auth_token or ks_session.get_token()
auth_token = args.os_auth_token or ks_session.get_token()
endpoint_type = args.os_endpoint_type or 'public'
service_type = args.os_service_type or 'image'
@ -536,7 +531,7 @@ class OpenStackImagesShell(object):
interface=endpoint_type,
region_name=args.os_region_name)
return endpoint, token
return endpoint, auth_token
def _get_versioned_client(self, api_version, args):
endpoint, token = self._get_endpoint_and_token(args)

View File

@ -295,6 +295,25 @@ class ShellTest(testutils.TestCase):
glance_shell.main(args.split())
self._assert_auth_plugin_args()
@mock.patch('glanceclient.Client')
def test_endpoint_token_no_auth_req(self, mock_client):
def verify_input(version=None, endpoint=None, *args, **kwargs):
self.assertIn('token', kwargs)
self.assertEqual(TOKEN_ID, kwargs['token'])
self.assertEqual(DEFAULT_IMAGE_URL, endpoint)
return mock.MagicMock()
mock_client.side_effect = verify_input
glance_shell = openstack_shell.OpenStackImagesShell()
args = ['--os-image-api-version', '2',
'--os-auth-token', TOKEN_ID,
'--os-image-url', DEFAULT_IMAGE_URL,
'image-list']
glance_shell.main(args)
self.assertEqual(1, mock_client.call_count)
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
@mock.patch('getpass.getpass', return_value='password')
@mock.patch('glanceclient.v2.client.Client')