Fix get_endpoint 23/37023/5
authorLinda Wang <wangwulin@huawei.com>
Thu, 6 Jul 2017 16:01:32 +0000 (16:01 +0000)
committerLinda Wang <wangwulin@huawei.com>
Fri, 7 Jul 2017 15:17:14 +0000 (15:17 +0000)
One specific service type has the same endpoint url if interface is admin
or internal, while it is different from that with public interface, except
the admin and internal endpoint url for service identity has same ip but
different ports.

Change-Id: I19c260222286d8b4aa3f0d3b7d273e192b13a96b
Signed-off-by: Linda Wang <wangwulin@huawei.com>
snaps/openstack/utils/keystone_utils.py
snaps/openstack/utils/tests/keystone_utils_tests.py

index f0de567..3823914 100644 (file)
@@ -79,18 +79,18 @@ def keystone_client(os_creds):
         session=keystone_session(os_creds), interface=os_creds.interface)
 
 
-def get_endpoint(os_creds, service_type, endpoint_type='publicURL'):
+def get_endpoint(os_creds, service_type, interface='public'):
     """
     Returns the endpoint of specific service
     :param os_creds: the OpenStack credentials (OSCreds) object
     :param service_type: the type of specific service
-    :param endpoint_type: the type of endpoint
+    :param interface: the type of interface
     :return: the endpoint url
     """
     auth = get_session_auth(os_creds)
     key_session = keystone_session(os_creds)
     return key_session.get_endpoint(
-        auth=auth, service_type=service_type, endpoint_type=endpoint_type)
+        auth=auth, service_type=service_type, interface=interface)
 
 
 def get_project(keystone=None, os_creds=None, project_name=None):
index d9ff3ed..1fc9d38 100644 (file)
@@ -110,7 +110,7 @@ class KeystoneUtilsTests(OSComponentTestCase):
         succeed.
         """
         endpoint = keystone_utils.get_endpoint(self.os_creds,
-                                               service_type="identity")
+                                               service_type='identity')
         self.assertIsNotNone(endpoint)
 
     def test_get_endpoint_fail_without_proper_service(self):
@@ -119,7 +119,7 @@ class KeystoneUtilsTests(OSComponentTestCase):
         cannot succeed.
         """
         with self.assertRaises(Exception):
-            keystone_utils.get_endpoint(self.os_creds, service_type="glance")
+            keystone_utils.get_endpoint(self.os_creds, service_type='glance')
 
     def test_get_endpoint_fail_without_proper_credentials(self):
         """
@@ -132,4 +132,22 @@ class KeystoneUtilsTests(OSComponentTestCase):
             keystone_utils.get_endpoint(
                 OSCreds(username='user', password='pass', auth_url='url',
                         project_name='project'),
-                service_type="image")
+                service_type='image')
+
+    def test_get_endpoint_with_different_interface(self):
+        """
+        Tests to ensure that different endpoint urls are obtained with
+        'public', 'internal' and 'admin' interface
+        """
+        endpoint_public = keystone_utils.get_endpoint(self.os_creds,
+                                                      service_type='image',
+                                                      interface='public')
+        endpoint_internal = keystone_utils.get_endpoint(self.os_creds,
+                                                        service_type='image',
+                                                        interface='internal')
+        endpoint_admin = keystone_utils.get_endpoint(self.os_creds,
+                                                     service_type='image',
+                                                     interface='admin')
+        self.assertNotEqual(endpoint_public, endpoint_internal)
+        self.assertNotEqual(endpoint_public, endpoint_admin)
+        self.assertEqual(endpoint_admin, endpoint_internal)