From e6883d24d0a6928678e560a1a20bb05f5046aa7f Mon Sep 17 00:00:00 2001 From: yatin karel Date: Tue, 24 Feb 2015 23:20:08 +0530 Subject: [PATCH] allow --endpoint-type internal|admin|public other openstack clients like glance, cinder use --endpoint-type (internal|admin|public). This allows users to use the same arguments with the nova cli. Partial-bug: #1367389 Change-Id: Ia55cad797ac0dca7fa60f55c1f2dfba0b64d0fd3 --- novaclient/shell.py | 5 +++++ novaclient/tests/unit/test_shell.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/novaclient/shell.py b/novaclient/shell.py index 42376de55..2b979cb82 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -651,6 +651,11 @@ class OpenStackComputeShell(object): if not endpoint_type: endpoint_type = DEFAULT_NOVA_ENDPOINT_TYPE + # This allow users to use endpoint_type as (internal, public or admin) + # just like other openstack clients (glance, cinder etc) + if endpoint_type in ['internal', 'public', 'admin']: + endpoint_type += 'URL' + if not service_type: os_compute_api_version = (options.os_compute_api_version or DEFAULT_OS_COMPUTE_API_VERSION) diff --git a/novaclient/tests/unit/test_shell.py b/novaclient/tests/unit/test_shell.py index 9e9079637..e0995113b 100644 --- a/novaclient/tests/unit/test_shell.py +++ b/novaclient/tests/unit/test_shell.py @@ -45,6 +45,13 @@ FAKE_ENV3 = {'OS_USER_ID': 'user_id', 'NOVA_ENDPOINT_TYPE': 'novaURL', 'OS_ENDPOINT_TYPE': 'osURL'} +FAKE_ENV4 = {'OS_USER_ID': 'user_id', + 'OS_PASSWORD': 'password', + 'OS_TENANT_ID': 'tenant_id', + 'OS_AUTH_URL': 'http://no.where/v2.0', + 'NOVA_ENDPOINT_TYPE': 'internal', + 'OS_ENDPOINT_TYPE': 'osURL'} + def _create_ver_list(versions): return {'versions': {'values': versions}} @@ -248,6 +255,15 @@ class ShellTest(utils.TestCase): client_kwargs = mock_client.call_args_list[0][1] self.assertEqual(client_kwargs['endpoint_type'], 'novaURL') + @mock.patch('novaclient.client.Client') + @requests_mock.Mocker() + def test_endpoint_type_like_other_clients(self, mock_client, m_requests): + self.make_env(fake_env=FAKE_ENV4) + self.register_keystone_discovery_fixture(m_requests) + self.shell('list') + client_kwargs = mock_client.call_args_list[0][1] + self.assertEqual(client_kwargs['endpoint_type'], 'internalURL') + @mock.patch('novaclient.client.Client') @requests_mock.Mocker() def test_os_endpoint_type(self, mock_client, m_requests):