Browse Source

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
tags/0.4.0
Adrien Vergé 4 years ago
parent
commit
4cda08d91c
2 changed files with 81 additions and 4 deletions
  1. 2
    2
      heatclient/shell.py
  2. 79
    2
      heatclient/tests/test_shell.py

+ 2
- 2
heatclient/shell.py View File

@@ -612,6 +612,7 @@ class HeatShell(object):
612 612
             keystone_session = self._get_keystone_session(**kwargs)
613 613
             project_id = args.os_project_id or args.os_tenant_id
614 614
             project_name = args.os_project_name or args.os_tenant_name
615
+            endpoint_type = args.os_endpoint_type or 'publicURL'
615 616
             kwargs = {
616 617
                 'username': args.os_username,
617 618
                 'user_id': args.os_user_id,
@@ -632,9 +633,8 @@ class HeatShell(object):
632 633
                 region_name = args.os_region_name
633 634
                 endpoint = keystone_auth.get_endpoint(keystone_session,
634 635
                                                       service_type=svc_type,
636
+                                                      interface=endpoint_type,
635 637
                                                       region_name=region_name)
636
-
637
-            endpoint_type = args.os_endpoint_type or 'publicURL'
638 638
             kwargs = {
639 639
                 'auth_url': args.os_auth_url,
640 640
                 'session': keystone_session,

+ 79
- 2
heatclient/tests/test_shell.py View File

@@ -39,6 +39,7 @@ from heatclient.common import utils
39 39
 from heatclient import exc
40 40
 import heatclient.shell
41 41
 from heatclient.tests import fakes
42
+import heatclient.v1.shell
42 43
 
43 44
 load_tests = testscenarios.load_tests_apply_scenarios
44 45
 TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
@@ -123,13 +124,18 @@ class TestCase(testtools.TestCase):
123 124
     def register_keystone_v2_token_fixture(self):
124 125
         v2_token = keystone_fixture.V2Token(token_id=self.tokenid)
125 126
         service = v2_token.add_service('orchestration')
126
-        service.add_endpoint('http://heat.example.com', region='RegionOne')
127
+        service.add_endpoint('http://heat.example.com',
128
+                             admin='http://heat-admin.localdomain',
129
+                             internal='http://heat.localdomain',
130
+                             region='RegionOne')
127 131
         self.requests.post('%s/tokens' % V2_URL, json=v2_token)
128 132
 
129 133
     def register_keystone_v3_token_fixture(self):
130 134
         v3_token = keystone_fixture.V3Token()
131 135
         service = v3_token.add_service('orchestration')
132
-        service.add_standard_endpoints(public='http://heat.example.com')
136
+        service.add_standard_endpoints(public='http://heat.example.com',
137
+                                       admin='http://heat-admin.localdomain',
138
+                                       internal='http://heat.localdomain')
133 139
         self.requests.post('%s/auth/tokens' % V3_URL,
134 140
                            json=v3_token,
135 141
                            headers={'X-Subject-Token': self.tokenid})
@@ -425,6 +431,77 @@ class ShellTestNoMoxV3(ShellTestNoMox):
425 431
         self.set_fake_env(FAKE_ENV_KEYSTONE_V3)
426 432
 
427 433
 
434
+class ShellTestEndpointType(TestCase):
435
+
436
+    def setUp(self):
437
+        super(ShellTestEndpointType, self).setUp()
438
+        self.m = mox.Mox()
439
+        self.m.StubOutWithMock(http, '_construct_http_client')
440
+        self.m.StubOutWithMock(heatclient.v1.shell, 'do_stack_list')
441
+        self.addCleanup(self.m.VerifyAll)
442
+        self.addCleanup(self.m.UnsetStubs)
443
+        self.set_fake_env(FAKE_ENV_KEYSTONE_V2)
444
+
445
+    def test_endpoint_type_public_url(self):
446
+        self.register_keystone_auth_fixture()
447
+        kwargs = {
448
+            'auth_url': 'http://keystone.example.com:5000/',
449
+            'session': mox.IgnoreArg(),
450
+            'auth': mox.IgnoreArg(),
451
+            'service_type': 'orchestration',
452
+            'endpoint_type': 'publicURL',
453
+            'region_name': '',
454
+            'username': 'username',
455
+            'password': 'password',
456
+            'include_pass': False
457
+        }
458
+        http._construct_http_client(u'http://heat.example.com', **kwargs)
459
+        heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg())
460
+
461
+        self.m.ReplayAll()
462
+        heatclient.shell.main(('stack-list',))
463
+
464
+    def test_endpoint_type_admin_url(self):
465
+        self.register_keystone_auth_fixture()
466
+        kwargs = {
467
+            'auth_url': 'http://keystone.example.com:5000/',
468
+            'session': mox.IgnoreArg(),
469
+            'auth': mox.IgnoreArg(),
470
+            'service_type': 'orchestration',
471
+            'endpoint_type': 'adminURL',
472
+            'region_name': '',
473
+            'username': 'username',
474
+            'password': 'password',
475
+            'include_pass': False
476
+        }
477
+        http._construct_http_client(u'http://heat-admin.localdomain', **kwargs)
478
+        heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg())
479
+
480
+        self.m.ReplayAll()
481
+        heatclient.shell.main(('--os-endpoint-type=adminURL', 'stack-list',))
482
+
483
+    def test_endpoint_type_internal_url(self):
484
+        self.register_keystone_auth_fixture()
485
+        self.useFixture(fixtures.EnvironmentVariable('OS_ENDPOINT_TYPE',
486
+                                                     'internalURL'))
487
+        kwargs = {
488
+            'auth_url': 'http://keystone.example.com:5000/',
489
+            'session': mox.IgnoreArg(),
490
+            'auth': mox.IgnoreArg(),
491
+            'service_type': 'orchestration',
492
+            'endpoint_type': 'internalURL',
493
+            'region_name': '',
494
+            'username': 'username',
495
+            'password': 'password',
496
+            'include_pass': False
497
+        }
498
+        http._construct_http_client(u'http://heat.localdomain', **kwargs)
499
+        heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg())
500
+
501
+        self.m.ReplayAll()
502
+        heatclient.shell.main(('stack-list',))
503
+
504
+
428 505
 class ShellTestCommon(ShellBase):
429 506
 
430 507
     def setUp(self):

Loading…
Cancel
Save