support OS_ENDPOINT_TYPE in nova client

This change makes the handling of the endpoint_type setting in the nova
client more consistent while keeping backwards compatibility. The
NOVA_ENDPOINT_TYPE environment variable is checked first, and if it is
not set then the more generic OS_ENDPOINT_TYPE variable is checked. A
--os-endpoint-type command line option was added as well.

Change-Id: I0d96f9f87106fc41a9853920f557ffad724859e7
Closes-Bug: 1382249
This commit is contained in:
Miguel Grinberg 2014-10-17 19:03:23 +00:00
parent ae6c39397e
commit 607ac48e6c
2 changed files with 38 additions and 4 deletions

View File

@ -351,12 +351,18 @@ class OpenStackComputeShell(object):
parser.add_argument('--volume_service_name',
help=argparse.SUPPRESS)
parser.add_argument('--endpoint-type',
parser.add_argument('--os-endpoint-type',
metavar='<endpoint-type>',
dest='endpoint_type',
default=utils.env('NOVA_ENDPOINT_TYPE',
default=DEFAULT_NOVA_ENDPOINT_TYPE),
help=(_('Defaults to env[NOVA_ENDPOINT_TYPE] or ')
+ DEFAULT_NOVA_ENDPOINT_TYPE + '.'))
default=utils.env('OS_ENDPOINT_TYPE',
default=DEFAULT_NOVA_ENDPOINT_TYPE)),
help=_('Defaults to env[NOVA_ENDPOINT_TYPE], '
'env[OS_ENDPOINT_TYPE] or ')
+ DEFAULT_NOVA_ENDPOINT_TYPE + '.')
parser.add_argument('--endpoint-type',
help=argparse.SUPPRESS)
# NOTE(dtroyer): We can't add --endpoint_type here due to argparse
# thinking usage-list --end is ambiguous; but it
# works fine with only --endpoint-type present

View File

@ -36,6 +36,13 @@ FAKE_ENV2 = {'OS_USER_ID': 'user_id',
'OS_TENANT_ID': 'tenant_id',
'OS_AUTH_URL': 'http://no.where'}
FAKE_ENV3 = {'OS_USER_ID': 'user_id',
'OS_PASSWORD': 'password',
'OS_TENANT_ID': 'tenant_id',
'OS_AUTH_URL': 'http://no.where',
'NOVA_ENDPOINT_TYPE': 'novaURL',
'OS_ENDPOINT_TYPE': 'osURL'}
class ShellTest(utils.TestCase):
@ -192,6 +199,27 @@ class ShellTest(utils.TestCase):
else:
self.fail('CommandError not raised')
@mock.patch('novaclient.client.Client')
def test_nova_endpoint_type(self, mock_client):
self.make_env(fake_env=FAKE_ENV3)
self.shell('list')
client_kwargs = mock_client.call_args_list[0][1]
self.assertEqual(client_kwargs['endpoint_type'], 'novaURL')
@mock.patch('novaclient.client.Client')
def test_os_endpoint_type(self, mock_client):
self.make_env(exclude='NOVA_ENDPOINT_TYPE', fake_env=FAKE_ENV3)
self.shell('list')
client_kwargs = mock_client.call_args_list[0][1]
self.assertEqual(client_kwargs['endpoint_type'], 'osURL')
@mock.patch('novaclient.client.Client')
def test_default_endpoint_type(self, mock_client):
self.make_env()
self.shell('list')
client_kwargs = mock_client.call_args_list[0][1]
self.assertEqual(client_kwargs['endpoint_type'], 'publicURL')
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
@mock.patch('getpass.getpass', return_value='password')
def test_password(self, mock_getpass, mock_stdin):