Change CLI options to use dashes

Change documented options to use dashes instead of underscores
in option names.  Continue to support old underscore names for
backward compatibility for a release or two (TBD).

Blueprint: command-options

Change-Id: Ied0d325a9fdd32f80bf8c993887e1975aa6adf16
This commit is contained in:
Dean Troyer
2012-06-28 11:53:44 -05:00
parent 3ed4007e11
commit 1fa29109c2
5 changed files with 188 additions and 48 deletions

View File

@@ -42,14 +42,14 @@ Installing this package gets you a shell command, ``keystone``, that you
can use to interact with Keystone's Identity API. can use to interact with Keystone's Identity API.
You'll need to provide your OpenStack tenant, username and password. You can You'll need to provide your OpenStack tenant, username and password. You can
do this with the ``--os_tenant_name``, ``--os_username`` and ``--os_password`` do this with the ``--os-tenant-name``, ``--os-username`` and ``--os-password``
params, but it's easier to just set them as environment variables:: params, but it's easier to just set them as environment variables::
export OS_TENANT_NAME=project export OS_TENANT_NAME=project
export OS_USERNAME=user export OS_USERNAME=user
export OS_PASSWORD=pass export OS_PASSWORD=pass
You will also need to define the authentication url with ``--os_auth_url`` and the You will also need to define the authentication url with ``--os-auth-url`` and the
version of the API with ``--identity_api_version``. Or set them as an environment version of the API with ``--identity_api_version``. Or set them as an environment
variables as well:: variables as well::
@@ -73,12 +73,13 @@ can specify the one you want with ``--region_name`` (or
You'll find complete documentation on the shell by running You'll find complete documentation on the shell by running
``keystone help``:: ``keystone help``::
usage: keystone [--os_username OS_USERNAME] [--os_password OS_PASSWORD] usage: keystone [--os-username <auth-user-name>]
[--os_tenant_name OS_TENANT_NAME] [--os-password <auth-password>]
[--os_tenant_id OS_TENANT_ID] [--os_auth_url OS_AUTH_URL] [--os-tenant-name <auth-tenant-name>]
[--os_region_name OS_REGION_NAME] [--os-tenant-id <tenant-id>] [--os-auth-url <auth-url>]
[--identity_api_version IDENTITY_API_VERSION] [--token TOKEN] [--os-region-name <region-name>]
[--endpoint ENDPOINT] [--os-identity-api-version <identity-api-version>]
[--token <service-token>] [--endpoint <service-endpoint>]
<subcommand> ... <subcommand> ...
Command-line interface to the OpenStack Identity API. Command-line interface to the OpenStack Identity API.
@@ -128,21 +129,23 @@ You'll find complete documentation on the shell by running
subcommands. subcommands.
Optional arguments: Optional arguments:
--os_username OS_USERNAME --os-username <auth-user-name>
Defaults to env[OS_USERNAME] Defaults to env[OS_USERNAME]
--os_password OS_PASSWORD --os-password <auth-password>
Defaults to env[OS_PASSWORD] Defaults to env[OS_PASSWORD]
--os_tenant_name OS_TENANT_NAME --os-tenant-name <auth-tenant-name>
Defaults to env[OS_TENANT_NAME] Defaults to env[OS_TENANT_NAME]
--os_tenant_id OS_TENANT_ID --os-tenant-id <tenant-id>
Defaults to env[OS_TENANT_ID] Defaults to env[OS_TENANT_ID]
--os_auth_url OS_AUTH_URL --os-auth-url <auth-url>
Defaults to env[OS_AUTH_URL] Defaults to env[OS_AUTH_URL]
--os_region_name OS_REGION_NAME --os-region-name <region-name>
Defaults to env[OS_REGION_NAME] Defaults to env[OS_REGION_NAME]
--identity_api_version IDENTITY_API_VERSION --os-identity-api-version <identity-api-version>
Defaults to env[OS_IDENTITY_API_VERSION] or 2.0 Defaults to env[OS_IDENTITY_API_VERSION] or 2.0
--token TOKEN Defaults to env[SERVICE_TOKEN] --token <service-token>
--endpoint ENDPOINT Defaults to env[SERVICE_ENDPOINT] Defaults to env[SERVICE_TOKEN]
--endpoint <service-endpoint>
Defaults to env[SERVICE_ENDPOINT]
See "keystone help COMMAND" for help on a specific command. See "keystone help COMMAND" for help on a specific command.

View File

@@ -12,8 +12,8 @@ First, you'll need an OpenStack Keystone account. You get this by using the
`keystone-manage` command in OpenStack Keystone. `keystone-manage` command in OpenStack Keystone.
You'll need to provide :program:`keystone` with your OpenStack username and You'll need to provide :program:`keystone` with your OpenStack username and
password. You can do this with the :option:`--os_username`, :option:`--os_password`. password. You can do this with the :option:`--os-username`, :option:`--os-password`.
You can optionally specify a :option:`--os_tenant_id` or :option:`--os_tenant_name`, You can optionally specify a :option:`--os-tenant-id` or :option:`--os-tenant-name`,
to scope your token to a specific tenant. If you don't specify a tenant, you to scope your token to a specific tenant. If you don't specify a tenant, you
will be scoped to your default tenant if you have one. Instead of using will be scoped to your default tenant if you have one. Instead of using
options, it is easier to just set them as environment variables: options, it is easier to just set them as environment variables:

View File

@@ -66,42 +66,56 @@ class OpenStackIdentityShell(object):
action='store_true', action='store_true',
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
parser.add_argument('--os_username', parser.add_argument('--os-username',
metavar='<auth-user-name>', metavar='<auth-user-name>',
default=env('OS_USERNAME'), default=env('OS_USERNAME'),
help='Defaults to env[OS_USERNAME]') help='Defaults to env[OS_USERNAME]')
parser.add_argument('--os_username',
help=argparse.SUPPRESS)
parser.add_argument('--os_password', parser.add_argument('--os-password',
metavar='<auth-password>', metavar='<auth-password>',
default=env('OS_PASSWORD'), default=env('OS_PASSWORD'),
help='Defaults to env[OS_PASSWORD]') help='Defaults to env[OS_PASSWORD]')
parser.add_argument('--os_password',
help=argparse.SUPPRESS)
parser.add_argument('--os_tenant_name', parser.add_argument('--os-tenant-name',
metavar='<auth-tenant-name>', metavar='<auth-tenant-name>',
default=env('OS_TENANT_NAME'), default=env('OS_TENANT_NAME'),
help='Defaults to env[OS_TENANT_NAME]') help='Defaults to env[OS_TENANT_NAME]')
parser.add_argument('--os_tenant_name',
help=argparse.SUPPRESS)
parser.add_argument('--os_tenant_id', parser.add_argument('--os-tenant-id',
metavar='<tenant-id>', metavar='<tenant-id>',
default=env('OS_TENANT_ID'), default=env('OS_TENANT_ID'),
help='Defaults to env[OS_TENANT_ID]') help='Defaults to env[OS_TENANT_ID]')
parser.add_argument('--os_tenant_id',
help=argparse.SUPPRESS)
parser.add_argument('--os_auth_url', parser.add_argument('--os-auth-url',
metavar='<auth-url>', metavar='<auth-url>',
default=env('OS_AUTH_URL'), default=env('OS_AUTH_URL'),
help='Defaults to env[OS_AUTH_URL]') help='Defaults to env[OS_AUTH_URL]')
parser.add_argument('--os_auth_url',
help=argparse.SUPPRESS)
parser.add_argument('--os_region_name', parser.add_argument('--os-region-name',
metavar='<region-name>', metavar='<region-name>',
default=env('OS_REGION_NAME'), default=env('OS_REGION_NAME'),
help='Defaults to env[OS_REGION_NAME]') help='Defaults to env[OS_REGION_NAME]')
parser.add_argument('--os_region_name',
help=argparse.SUPPRESS)
parser.add_argument('--os_identity_api_version', parser.add_argument('--os-identity-api-version',
metavar='<identity-api-version>', metavar='<identity-api-version>',
default=env('OS_IDENTITY_API_VERSION', default=env('OS_IDENTITY_API_VERSION',
'KEYSTONE_VERSION'), 'KEYSTONE_VERSION'),
help='Defaults to env[OS_IDENTITY_API_VERSION]' help='Defaults to env[OS_IDENTITY_API_VERSION]'
' or 2.0') ' or 2.0')
parser.add_argument('--os_identity_api_version',
help=argparse.SUPPRESS)
parser.add_argument('--token', parser.add_argument('--token',
metavar='<service-token>', metavar='<service-token>',
@@ -195,7 +209,7 @@ class OpenStackIdentityShell(object):
' either a service token, ' ' either a service token, '
'--token or env[SERVICE_TOKEN], \n' '--token or env[SERVICE_TOKEN], \n'
' or credentials, ' ' or credentials, '
'--os_username or env[OS_USERNAME].') '--os-username or env[OS_USERNAME].')
# if it looks like the user wants to provide a service token # if it looks like the user wants to provide a service token
# but is missing something # but is missing something
@@ -219,16 +233,16 @@ class OpenStackIdentityShell(object):
if not args.os_username: if not args.os_username:
raise exc.CommandError( raise exc.CommandError(
'Expecting a username provided via either ' 'Expecting a username provided via either '
'--os_username or env[OS_USERNAME]') '--os-username or env[OS_USERNAME]')
if not args.os_password: if not args.os_password:
raise exc.CommandError( raise exc.CommandError(
'Expecting a password provided via either ' 'Expecting a password provided via either '
'--os_password or env[OS_PASSWORD]') '--os-password or env[OS_PASSWORD]')
if not args.os_auth_url: if not args.os_auth_url:
raise exc.CommandError( raise exc.CommandError(
'Expecting an auth URL via either --os_auth_url or ' 'Expecting an auth URL via either --os-auth-url or '
'env[OS_AUTH_URL]') 'env[OS_AUTH_URL]')
if utils.isunauthenticated(args.func): if utils.isunauthenticated(args.func):

View File

@@ -15,14 +15,17 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import argparse
from keystoneclient.v2_0 import client from keystoneclient.v2_0 import client
from keystoneclient import utils from keystoneclient import utils
CLIENT_CLASS = client.Client CLIENT_CLASS = client.Client
@utils.arg('--tenant_id', metavar='<tenant-id>', @utils.arg('--tenant-id', metavar='<tenant-id>',
help='Tenant ID; lists all users if not specified') help='Tenant ID; lists all users if not specified')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
def do_user_list(kc, args): def do_user_list(kc, args):
"""List users""" """List users"""
users = kc.users.list(tenant_id=args.tenant_id) users = kc.users.list(tenant_id=args.tenant_id)
@@ -38,8 +41,9 @@ def do_user_get(kc, args):
@utils.arg('--name', metavar='<user-name>', required=True, @utils.arg('--name', metavar='<user-name>', required=True,
help='New user name (must be unique)') help='New user name (must be unique)')
@utils.arg('--tenant_id', metavar='<tenant-id>', @utils.arg('--tenant-id', metavar='<tenant-id>',
help='New user default tenant') help='New user default tenant')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
@utils.arg('--pass', metavar='<pass>', dest='passwd', @utils.arg('--pass', metavar='<pass>', dest='passwd',
help='New user password') help='New user password')
@utils.arg('--email', metavar='<email>', @utils.arg('--email', metavar='<email>',
@@ -215,27 +219,35 @@ def do_role_delete(kc, args):
# TODO(jakedahn): refactor this to allow role, user, and tenant names. # TODO(jakedahn): refactor this to allow role, user, and tenant names.
@utils.arg('--user_id', metavar='<user-id>', required=True, help='User ID') @utils.arg('--user-id', '--user_id', metavar='<user-id>', required=True,
@utils.arg('--role_id', metavar='<role-id>', required=True, help='Role ID') help='User ID')
@utils.arg('--tenant_id', metavar='<tenant-id>', help='Tenant ID') @utils.arg('--role-id', '--role_id', metavar='<role-id>', required=True,
help='Role ID')
@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
def do_user_role_add(kc, args): def do_user_role_add(kc, args):
"""Add role to user""" """Add role to user"""
kc.roles.add_user_role(args.user_id, args.role_id, args.tenant_id) kc.roles.add_user_role(args.user_id, args.role_id, args.tenant_id)
# TODO(jakedahn): refactor this to allow role, user, and tenant names. # TODO(jakedahn): refactor this to allow role, user, and tenant names.
@utils.arg('--user_id', metavar='<user-id>', required=True, help='User ID') @utils.arg('--user-id', '--user_id', metavar='<user-id>', required=True,
@utils.arg('--role_id', metavar='<role-id>', required=True, help='Role ID') help='User ID')
@utils.arg('--tenant_id', metavar='<tenant-id>', help='Tenant ID') @utils.arg('--role-id', '--role_id', metavar='<role-id>', required=True,
help='Role ID')
@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
def do_user_role_remove(kc, args): def do_user_role_remove(kc, args):
"""Remove role from user""" """Remove role from user"""
kc.roles.remove_user_role(args.user_id, args.role_id, args.tenant_id) kc.roles.remove_user_role(args.user_id, args.role_id, args.tenant_id)
@utils.arg('--user_id', metavar='<user-id>', @utils.arg('--user-id', metavar='<user-id>',
help='List roles granted to a user') help='List roles granted to a user')
@utils.arg('--tenant_id', metavar='<tenant-id>', @utils.arg('--user_id', help=argparse.SUPPRESS)
@utils.arg('--tenant-id', metavar='<tenant-id>',
help='List roles granted on a tenant') help='List roles granted on a tenant')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
def do_user_role_list(kc, args): def do_user_role_list(kc, args):
"""List roles granted to a user""" """List roles granted to a user"""
if not args.tenant_id: if not args.tenant_id:
@@ -254,8 +266,10 @@ def do_user_role_list(kc, args):
utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id']) utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id'])
@utils.arg('--user_id', metavar='<user-id>', help='User ID') @utils.arg('--user-id', metavar='<user-id>', help='User ID')
@utils.arg('--tenant_id', metavar='<tenant-id>', help='Tenant ID') @utils.arg('--user_id', help=argparse.SUPPRESS)
@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID')
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
def do_ec2_credentials_create(kc, args): def do_ec2_credentials_create(kc, args):
"""Create EC2-compatibile credentials for user per tenant""" """Create EC2-compatibile credentials for user per tenant"""
if not args.tenant_id: if not args.tenant_id:
@@ -268,7 +282,8 @@ def do_ec2_credentials_create(kc, args):
utils.print_dict(credentials._info) utils.print_dict(credentials._info)
@utils.arg('--user_id', metavar='<user-id>', help='User ID') @utils.arg('--user-id', metavar='<user-id>', help='User ID')
@utils.arg('--user_id', help=argparse.SUPPRESS)
@utils.arg('--access', metavar='<access-key>', required=True, @utils.arg('--access', metavar='<access-key>', required=True,
help='Access Key') help='Access Key')
def do_ec2_credentials_get(kc, args): def do_ec2_credentials_get(kc, args):
@@ -281,7 +296,8 @@ def do_ec2_credentials_get(kc, args):
utils.print_dict(cred._info) utils.print_dict(cred._info)
@utils.arg('--user_id', metavar='<user-id>', help='User ID') @utils.arg('--user-id', metavar='<user-id>', help='User ID')
@utils.arg('--user_id', help=argparse.SUPPRESS)
def do_ec2_credentials_list(kc, args): def do_ec2_credentials_list(kc, args):
"""List EC2-compatibile credentials for a user""" """List EC2-compatibile credentials for a user"""
if not args.user_id: if not args.user_id:
@@ -298,7 +314,8 @@ def do_ec2_credentials_list(kc, args):
utils.print_list(credentials, ['tenant', 'access', 'secret']) utils.print_list(credentials, ['tenant', 'access', 'secret'])
@utils.arg('--user_id', metavar='<user-id>', help='User ID') @utils.arg('--user-id', metavar='<user-id>', help='User ID')
@utils.arg('--user_id', help=argparse.SUPPRESS)
@utils.arg('--access', metavar='<access-key>', required=True, @utils.arg('--access', metavar='<access-key>', required=True,
help='Access Key') help='Access Key')
def do_ec2_credentials_delete(kc, args): def do_ec2_credentials_delete(kc, args):
@@ -327,8 +344,10 @@ def do_catalog(kc, args):
@utils.arg('--service', metavar='<service-type>', required=True, @utils.arg('--service', metavar='<service-type>', required=True,
help='Service type to select') help='Service type to select')
@utils.arg('--endpoint_type', metavar='<endpoint-type>', default='publicURL', @utils.arg('--endpoint-type', metavar='<endpoint-type>', default='publicURL',
help='Endpoint type to select') help='Endpoint type to select')
@utils.arg('--endpoint_type', default='publicURL',
help=argparse.SUPPRESS)
@utils.arg('--attr', metavar='<service-attribute>', @utils.arg('--attr', metavar='<service-attribute>',
help='Service attribute to match for selection') help='Service attribute to match for selection')
@utils.arg('--value', metavar='<value>', @utils.arg('--value', metavar='<value>',
@@ -359,8 +378,8 @@ def do_endpoint_list(kc, args):
@utils.arg('--region', metavar='<endpoint-region>', @utils.arg('--region', metavar='<endpoint-region>',
help='Endpoint region', default='regionOne') help='Endpoint region', default='regionOne')
@utils.arg('--service_id', metavar='<service-id>', required=True, @utils.arg('--service-id', '--service_id', metavar='<service-id>',
help='ID of service associated with Endpoint') required=True, help='ID of service associated with Endpoint')
@utils.arg('--publicurl', metavar='<public-url>', @utils.arg('--publicurl', metavar='<public-url>',
help='Public URL endpoint') help='Public URL endpoint')
@utils.arg('--adminurl', metavar='<admin-url>', @utils.arg('--adminurl', metavar='<admin-url>',

View File

@@ -60,6 +60,8 @@ class ShellTest(utils.TestCase):
expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# Old_style options
shell('--os_auth_url http://0.0.0.0:5000/ --os_password xyzpdq ' shell('--os_auth_url http://0.0.0.0:5000/ --os_password xyzpdq '
'--os_tenant_id 1234 --os_tenant_name fred ' '--os_tenant_id 1234 --os_tenant_name fred '
'--os_username barney ' '--os_username barney '
@@ -73,6 +75,20 @@ class ShellTest(utils.TestCase):
'fred', 'barney', '2.0') 'fred', 'barney', '2.0')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
shell('--os-auth-url http://1.1.1.1:5000/ --os-password xyzpdq '
'--os-tenant-id 4321 --os-tenant-name wilma '
'--os-username betty '
'--os-identity-api-version 2.0 user-list')
assert do_tenant_mock.called
((a, b), c) = do_tenant_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 = ('http://1.1.1.1:5000/', 'xyzpdq', '4321',
'wilma', 'betty', '2.0')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
def test_shell_user_create_args(self): def test_shell_user_create_args(self):
"""Test user-create args""" """Test user-create args"""
do_uc_mock = mock.MagicMock() do_uc_mock = mock.MagicMock()
@@ -82,6 +98,7 @@ class ShellTest(utils.TestCase):
with mock.patch('keystoneclient.v2_0.shell.do_user_create', with mock.patch('keystoneclient.v2_0.shell.do_user_create',
do_uc_mock): do_uc_mock):
# Old_style options
# Test case with one --tenant_id args present: ec2 creds # Test case with one --tenant_id args present: ec2 creds
shell('user-create --name=FOO ' shell('user-create --name=FOO '
'--pass=secrete --tenant_id=barrr --enabled=true') '--pass=secrete --tenant_id=barrr --enabled=true')
@@ -97,6 +114,23 @@ class ShellTest(utils.TestCase):
expect = ('barrr', 'FOO', 'secrete', 'true') expect = ('barrr', 'FOO', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) 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 '
'--pass=secrete --tenant-id=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_id, b.name, b.passwd, b.enabled)
expect = ('BARRR', 'foo', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# Old_style options
# Test case with --os_tenant_id and --tenant_id args present # Test case with --os_tenant_id and --tenant_id args present
shell('--os_tenant_id=os-tenant user-create --name=FOO ' shell('--os_tenant_id=os-tenant user-create --name=FOO '
'--pass=secrete --tenant_id=barrr --enabled=true') '--pass=secrete --tenant_id=barrr --enabled=true')
@@ -112,6 +146,22 @@ class ShellTest(utils.TestCase):
expect = ('barrr', 'FOO', 'secrete', 'true') expect = ('barrr', 'FOO', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
# Test case with --os-tenant-id and --tenant-id args present
shell('--os-tenant-id=ostenant user-create --name=foo '
'--pass=secrete --tenant-id=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, '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)
expect = ('BARRR', 'foo', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
def test_do_tenant_create(self): def test_do_tenant_create(self):
do_tenant_mock = mock.MagicMock() do_tenant_mock = mock.MagicMock()
with mock.patch('keystoneclient.v2_0.shell.do_tenant_create', with mock.patch('keystoneclient.v2_0.shell.do_tenant_create',
@@ -140,6 +190,7 @@ class ShellTest(utils.TestCase):
with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_create', with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_create',
do_ec2_mock): do_ec2_mock):
# Old_style options
# Test case with one --tenant_id args present: ec2 creds # Test case with one --tenant_id args present: ec2 creds
shell('ec2-credentials-create ' shell('ec2-credentials-create '
'--tenant_id=ec2-tenant --user_id=ec2-user') '--tenant_id=ec2-tenant --user_id=ec2-user')
@@ -155,6 +206,23 @@ class ShellTest(utils.TestCase):
expect = ('ec2-tenant', 'ec2-user') expect = ('ec2-tenant', 'ec2-user')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) 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('ec2-credentials-create '
'--tenant-id=dash-tenant --user-id=dash-user')
assert do_ec2_mock.called
((a, b), c) = do_ec2_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_id, b.user_id)
expect = ('dash-tenant', 'dash-user')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# Old_style options
# Test case with two --tenant_id args present # Test case with two --tenant_id args present
shell('--os_tenant_id=os-tenant ec2-credentials-create ' shell('--os_tenant_id=os-tenant ec2-credentials-create '
'--tenant_id=ec2-tenant --user_id=ec2-user') '--tenant_id=ec2-tenant --user_id=ec2-user')
@@ -170,6 +238,22 @@ class ShellTest(utils.TestCase):
expect = ('ec2-tenant', 'ec2-user') expect = ('ec2-tenant', 'ec2-user')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
# Test case with two --tenant-id args present
shell('--os-tenant-id=ostenant ec2-credentials-create '
'--tenant-id=dash-tenant --user-id=dash-user')
assert do_ec2_mock.called
((a, b), c) = do_ec2_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, 'ostenant',
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.tenant_id, b.user_id)
expect = ('dash-tenant', 'dash-user')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
def test_do_ec2_get(self): def test_do_ec2_get(self):
do_shell_mock = mock.MagicMock() do_shell_mock = mock.MagicMock()
@@ -201,6 +285,7 @@ class ShellTest(utils.TestCase):
with mock.patch('keystoneclient.v2_0.shell.do_endpoint_create', with mock.patch('keystoneclient.v2_0.shell.do_endpoint_create',
do_shell_mock): do_shell_mock):
# Old_style options
# Test create args # Test create args
shell('endpoint-create ' shell('endpoint-create '
'--service_id=2 --publicurl=http://example.com:1234/go ' '--service_id=2 --publicurl=http://example.com:1234/go '
@@ -218,3 +303,22 @@ class ShellTest(utils.TestCase):
'http://example.com:1234/go', 'http://example.com:1234/go',
'http://example.com:9876/adm') 'http://example.com:9876/adm')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# New-style options
# Test create args
shell('endpoint-create '
'--service-id=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_id, 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)]))