Add name arguments to keystone command.

Fixes #Bug 1183655

This patch adds name arguments to the following subcommands:
  * user-list
  * user-create
  * endpoint-create

Change-Id: I056e87de78f88f6fcf76baa4c820622c42f74f39
This commit is contained in:
Ken'ichi Ohmichi
2013-05-24 09:10:56 +09:00
parent 9ee038fc65
commit 793b3e9682
2 changed files with 59 additions and 12 deletions

View File

@@ -42,12 +42,16 @@ def require_service_catalog(f):
return wrapped
@utils.arg('--tenant-id', metavar='<tenant-id>',
help='Tenant ID; lists all users if not specified')
@utils.arg('--tenant', '--tenant-id', metavar='<tenant>',
help='Tenant; lists all users if not specified')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
def do_user_list(kc, args):
"""List users"""
users = kc.users.list(tenant_id=args.tenant_id)
if args.tenant:
tenant_id = utils.find_resource(kc.tenants, args.tenant).id
else:
tenant_id = None
users = kc.users.list(tenant_id=tenant_id)
utils.print_list(users, ['id', 'name', 'enabled', 'email'],
order_by='name')
@@ -61,7 +65,7 @@ def do_user_get(kc, args):
@utils.arg('--name', metavar='<user-name>', required=True,
help='New user name (must be unique)')
@utils.arg('--tenant-id', metavar='<tenant-id>',
@utils.arg('--tenant', '--tenant-id', metavar='<tenant>',
help='New user default tenant')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
@utils.arg('--pass', metavar='<pass>', dest='passwd',
@@ -72,8 +76,14 @@ def do_user_get(kc, args):
help='Initial user enabled status (default true)')
def do_user_create(kc, args):
"""Create new user"""
if args.tenant:
tenant_id = utils.find_resource(kc.tenants, args.tenant).id
elif args.tenant_id:
tenant_id = args.tenant_id
else:
tenant_id = None
user = kc.users.create(args.name, args.passwd, args.email,
tenant_id=args.tenant_id,
tenant_id=tenant_id,
enabled=utils.string_to_bool(args.enabled))
utils.print_dict(user._info)
@@ -475,8 +485,9 @@ def do_endpoint_list(kc, args):
@utils.arg('--region', metavar='<endpoint-region>',
help='Endpoint region', default='regionOne')
@utils.arg('--service-id', '--service_id', metavar='<service-id>',
required=True, help='ID of service associated with Endpoint')
@utils.arg('--service', '--service-id', '--service_id',
metavar='<service>', required=True,
help='Name or ID of service associated with Endpoint')
@utils.arg('--publicurl', metavar='<public-url>',
help='Public URL endpoint')
@utils.arg('--adminurl', metavar='<admin-url>',
@@ -485,8 +496,9 @@ def do_endpoint_list(kc, args):
help='Internal URL endpoint')
def do_endpoint_create(kc, args):
"""Create a new endpoint associated with a service"""
service_id = utils.find_resource(kc.services, args.service).id
endpoint = kc.endpoints.create(args.region,
args.service_id,
service_id,
args.publicurl,
args.adminurl,
args.internalurl)

View File

@@ -209,6 +209,22 @@ class ShellTest(utils.TestCase):
expect = ('barrr', 'FOO', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
# Test case with one --tenant args present: ec2 creds
shell('user-create --name=foo '
'--pass=secrete --tenant=BARRR --enabled=true')
assert do_uc_mock.called
((a, b), c) = do_uc_mock.call_args
actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username,
b.os_identity_api_version)
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.tenant, b.name, b.passwd, b.enabled)
expect = ('BARRR', 'foo', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
# Test case with one --tenant-id args present: ec2 creds
shell('user-create --name=foo '
@@ -221,7 +237,7 @@ class ShellTest(utils.TestCase):
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.tenant_id, b.name, b.passwd, b.enabled)
actual = (b.tenant, b.name, b.passwd, b.enabled)
expect = ('BARRR', 'foo', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
@@ -253,7 +269,7 @@ class ShellTest(utils.TestCase):
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'ostenant',
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.tenant_id, b.name, b.passwd, b.enabled)
actual = (b.tenant, b.name, b.passwd, b.enabled)
expect = ('BARRR', 'foo', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
@@ -420,7 +436,7 @@ class ShellTest(utils.TestCase):
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.service_id, b.publicurl, b.adminurl)
actual = (b.service, b.publicurl, b.adminurl)
expect = ('2',
'http://example.com:1234/go',
'http://example.com:9876/adm')
@@ -439,7 +455,26 @@ class ShellTest(utils.TestCase):
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.service_id, b.publicurl, b.adminurl)
actual = (b.service, b.publicurl, b.adminurl)
expect = ('3',
'http://example.com:4321/go',
'http://example.com:9876/adm')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
# Test create args
shell('endpoint-create '
'--service=3 --publicurl=http://example.com:4321/go '
'--adminurl=http://example.com:9876/adm')
assert do_shell_mock.called
((a, b), c) = do_shell_mock.call_args
actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username,
b.os_identity_api_version)
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.service, b.publicurl, b.adminurl)
expect = ('3',
'http://example.com:4321/go',
'http://example.com:9876/adm')