From 4cda08d91c6344770819df48d5be855590e592f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Mon, 16 Feb 2015 21:33:15 +0100 Subject: [PATCH] Fix non-working endpoint type argument Whatever the endpoint type passed with --os-endpoint-type or OS_ENDPOINT_TYPE, the publicURL is always used (instead of, for instance, adminURL or internalURL). This patch passes the user-defined endpoint type to keystoneclient's get_endpoint() so that the correct endpoint is chosen from the catalog. Change-Id: Iee9f0e576d5fba3b4bf1dd267dfee233b0a7ea8f Closes-Bug: #1422487 --- heatclient/shell.py | 4 +- heatclient/tests/test_shell.py | 81 +++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/heatclient/shell.py b/heatclient/shell.py index eeaaeb23..007818df 100644 --- a/heatclient/shell.py +++ b/heatclient/shell.py @@ -612,6 +612,7 @@ class HeatShell(object): keystone_session = self._get_keystone_session(**kwargs) project_id = args.os_project_id or args.os_tenant_id project_name = args.os_project_name or args.os_tenant_name + endpoint_type = args.os_endpoint_type or 'publicURL' kwargs = { 'username': args.os_username, 'user_id': args.os_user_id, @@ -632,9 +633,8 @@ class HeatShell(object): region_name = args.os_region_name endpoint = keystone_auth.get_endpoint(keystone_session, service_type=svc_type, + interface=endpoint_type, region_name=region_name) - - endpoint_type = args.os_endpoint_type or 'publicURL' kwargs = { 'auth_url': args.os_auth_url, 'session': keystone_session, diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py index 86729397..9cea755b 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -39,6 +39,7 @@ from heatclient.common import utils from heatclient import exc import heatclient.shell from heatclient.tests import fakes +import heatclient.v1.shell load_tests = testscenarios.load_tests_apply_scenarios TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), @@ -123,13 +124,18 @@ class TestCase(testtools.TestCase): def register_keystone_v2_token_fixture(self): v2_token = keystone_fixture.V2Token(token_id=self.tokenid) service = v2_token.add_service('orchestration') - service.add_endpoint('http://heat.example.com', region='RegionOne') + service.add_endpoint('http://heat.example.com', + admin='http://heat-admin.localdomain', + internal='http://heat.localdomain', + region='RegionOne') self.requests.post('%s/tokens' % V2_URL, json=v2_token) def register_keystone_v3_token_fixture(self): v3_token = keystone_fixture.V3Token() service = v3_token.add_service('orchestration') - service.add_standard_endpoints(public='http://heat.example.com') + service.add_standard_endpoints(public='http://heat.example.com', + admin='http://heat-admin.localdomain', + internal='http://heat.localdomain') self.requests.post('%s/auth/tokens' % V3_URL, json=v3_token, headers={'X-Subject-Token': self.tokenid}) @@ -425,6 +431,77 @@ class ShellTestNoMoxV3(ShellTestNoMox): self.set_fake_env(FAKE_ENV_KEYSTONE_V3) +class ShellTestEndpointType(TestCase): + + def setUp(self): + super(ShellTestEndpointType, self).setUp() + self.m = mox.Mox() + self.m.StubOutWithMock(http, '_construct_http_client') + self.m.StubOutWithMock(heatclient.v1.shell, 'do_stack_list') + self.addCleanup(self.m.VerifyAll) + self.addCleanup(self.m.UnsetStubs) + self.set_fake_env(FAKE_ENV_KEYSTONE_V2) + + def test_endpoint_type_public_url(self): + self.register_keystone_auth_fixture() + kwargs = { + 'auth_url': 'http://keystone.example.com:5000/', + 'session': mox.IgnoreArg(), + 'auth': mox.IgnoreArg(), + 'service_type': 'orchestration', + 'endpoint_type': 'publicURL', + 'region_name': '', + 'username': 'username', + 'password': 'password', + 'include_pass': False + } + http._construct_http_client(u'http://heat.example.com', **kwargs) + heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg()) + + self.m.ReplayAll() + heatclient.shell.main(('stack-list',)) + + def test_endpoint_type_admin_url(self): + self.register_keystone_auth_fixture() + kwargs = { + 'auth_url': 'http://keystone.example.com:5000/', + 'session': mox.IgnoreArg(), + 'auth': mox.IgnoreArg(), + 'service_type': 'orchestration', + 'endpoint_type': 'adminURL', + 'region_name': '', + 'username': 'username', + 'password': 'password', + 'include_pass': False + } + http._construct_http_client(u'http://heat-admin.localdomain', **kwargs) + heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg()) + + self.m.ReplayAll() + heatclient.shell.main(('--os-endpoint-type=adminURL', 'stack-list',)) + + def test_endpoint_type_internal_url(self): + self.register_keystone_auth_fixture() + self.useFixture(fixtures.EnvironmentVariable('OS_ENDPOINT_TYPE', + 'internalURL')) + kwargs = { + 'auth_url': 'http://keystone.example.com:5000/', + 'session': mox.IgnoreArg(), + 'auth': mox.IgnoreArg(), + 'service_type': 'orchestration', + 'endpoint_type': 'internalURL', + 'region_name': '', + 'username': 'username', + 'password': 'password', + 'include_pass': False + } + http._construct_http_client(u'http://heat.localdomain', **kwargs) + heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg()) + + self.m.ReplayAll() + heatclient.shell.main(('stack-list',)) + + class ShellTestCommon(ShellBase): def setUp(self):