Default keystone endpoint type is hard coded

The default url should be of type "OPENSTACK_ENDPOINT_TYPE"
parameter as specified in settings.

Closes-Bug: #1873353

Change-Id: I05ce933e5bd01bf59a52e7d49facce26efa693aa
This commit is contained in:
Gayathri Devi Kathiri 2020-05-26 12:38:54 +00:00
parent 1e7dc763b7
commit 7bde77fad1
2 changed files with 37 additions and 3 deletions
openstack_dashboard

@ -77,7 +77,8 @@ class Service(base.APIDictWrapper):
super(Service, self).__init__(service, *args, **kwargs)
self.public_url = base.get_url_for_service(service, region,
'publicURL')
self.url = base.get_url_for_service(service, region, 'internalURL')
self.url = base.get_url_for_service(service, region,
settings.OPENSTACK_ENDPOINT_TYPE)
if self.url:
self.host = parse.urlparse(self.url).hostname
else:

@ -20,6 +20,7 @@ from __future__ import absolute_import
from unittest import mock
from django.test.utils import override_settings
from openstack_dashboard import api
from openstack_dashboard.test import helpers as test
@ -71,7 +72,8 @@ class RoleAPITests(test.APIMockTestCase):
class ServiceAPITests(test.APIMockTestCase):
def test_service_wrapper(self):
@override_settings(OPENSTACK_ENDPOINT_TYPE='internalURL')
def test_service_wrapper_for_internal_endpoint_type(self):
catalog = self.service_catalog
identity_data = api.base.get_service_from_catalog(catalog, "identity")
# 'Service' class below requires 'id', so populate it here.
@ -85,7 +87,23 @@ class ServiceAPITests(test.APIMockTestCase):
service.public_url)
self.assertEqual("int.keystone.example.com", service.host)
def test_service_wrapper_service_in_region(self):
@override_settings(OPENSTACK_ENDPOINT_TYPE='publicURL')
def test_service_wrapper_for_public_endpoint_type(self):
catalog = self.service_catalog
identity_data = api.base.get_service_from_catalog(catalog, "identity")
# 'Service' class below requires 'id', so populate it here.
identity_data['id'] = 1
service = api.keystone.Service(identity_data, "RegionOne")
self.assertEqual(u"identity (native backend)", str(service))
self.assertEqual("RegionOne", service.region)
self.assertEqual("http://public.keystone.example.com/identity/v3",
service.url)
self.assertEqual("http://public.keystone.example.com/identity/v3",
service.public_url)
self.assertEqual("public.keystone.example.com", service.host)
@override_settings(OPENSTACK_ENDPOINT_TYPE='internalURL')
def test_service_wrapper_in_region_for_internal_endpoint_type(self):
catalog = self.service_catalog
compute_data = api.base.get_service_from_catalog(catalog, "compute")
# 'Service' class below requires 'id', so populate it here.
@ -99,6 +117,21 @@ class ServiceAPITests(test.APIMockTestCase):
service.public_url)
self.assertEqual("int.nova2.example.com", service.host)
@override_settings(OPENSTACK_ENDPOINT_TYPE='publicURL')
def test_service_wrapper_service_in_region_for_public_endpoint_type(self):
catalog = self.service_catalog
compute_data = api.base.get_service_from_catalog(catalog, "compute")
# 'Service' class below requires 'id', so populate it here.
compute_data['id'] = 1
service = api.keystone.Service(compute_data, 'RegionTwo')
self.assertEqual(u"compute", str(service))
self.assertEqual("RegionTwo", service.region)
self.assertEqual("http://public.nova2.example.com:8774/v2",
service.url)
self.assertEqual("http://public.nova2.example.com:8774/v2",
service.public_url)
self.assertEqual("public.nova2.example.com", service.host)
class APIVersionTests(test.APIMockTestCase):
@mock.patch.object(api.keystone, 'keystoneclient')