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,13 +256,19 @@ class CeilometerShell(object):
self.do_help(args)
return 0
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 env[OS_USERNAME]")
"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]")
"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 "

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()