Support --os-auth-token.

Fixed bug #1130286.

Change-Id: Ia0a8884f2738c31c3d91d6679622ebd3ec9b86b5
This commit is contained in:
Lianhao Lu
2013-02-20 17:30:58 +08:00
parent d740e37672
commit 17204a4dcd
2 changed files with 49 additions and 28 deletions

View File

@@ -256,38 +256,44 @@ class CeilometerShell(object):
self.do_help(args)
return 0
if not args.os_username:
raise exc.CommandError("You must provide a username via"
" either --os-username or env[OS_USERNAME]")
if args.os_auth_token and args.ceilometer_url:
token = args.os_auth_token
endpoint = args.ceilometer_url
else:
if not args.os_username:
raise exc.CommandError("You must provide a username via "
"either --os-username or via "
"env[OS_USERNAME]")
if not args.os_password:
raise exc.CommandError("You must provide a password via"
" either --os-password or env[OS_PASSWORD]")
if not args.os_password:
raise exc.CommandError("You must provide a password via "
"either --os-password or via "
"env[OS_PASSWORD]")
if not (args.os_tenant_id or args.os_tenant_name):
raise exc.CommandError("You must provide a tenant_id via"
" either --os-tenant-id or via "
"env[OS_TENANT_ID]")
if not (args.os_tenant_id or args.os_tenant_name):
raise exc.CommandError("You must provide a tenant_id via "
"either --os-tenant-id or via "
"env[OS_TENANT_ID]")
if not args.os_auth_url:
raise exc.CommandError("You must provide an auth url via"
" either --os-auth-url or via "
"env[OS_AUTH_URL]")
kwargs = {
'username': args.os_username,
'password': args.os_password,
'tenant_id': args.os_tenant_id,
'tenant_name': args.os_tenant_name,
'auth_url': args.os_auth_url,
'service_type': args.os_service_type,
'endpoint_type': args.os_endpoint_type,
'insecure': args.insecure
}
_ksclient = self._get_ksclient(**kwargs)
token = args.os_auth_token or _ksclient.auth_token
if not args.os_auth_url:
raise exc.CommandError("You must provide an auth url via "
"either --os-auth-url or via "
"env[OS_AUTH_URL]")
kwargs = {
'username': args.os_username,
'password': args.os_password,
'tenant_id': args.os_tenant_id,
'tenant_name': args.os_tenant_name,
'auth_url': args.os_auth_url,
'service_type': args.os_service_type,
'endpoint_type': args.os_endpoint_type,
'insecure': args.insecure
}
_ksclient = self._get_ksclient(**kwargs)
token = args.os_auth_token or _ksclient.auth_token
endpoint = args.ceilometer_url or \
self._get_endpoint(_ksclient, **kwargs)
endpoint = args.ceilometer_url or \
self._get_endpoint(_ksclient, **kwargs)
kwargs = {
'token': token,

View File

@@ -105,3 +105,18 @@ class ShellTest(unittest2.TestCase):
help_text = self.shell(argstr)
for r in required:
self.assertRegexpMatches(help_text, r)
def test_auth_param(self):
class TokenContext(object):
def __enter__(self):
fake_env = {
'OS_AUTH_TOKEN': 'token',
'CEILOMETER_URL': 'http://no.where'
}
self.old_env, os.environ = os.environ, fake_env.copy()
def __exit__(self, exc_type, exc_value, traceback):
os.environ = self.old_env
with TokenContext():
self.test_help()