configure_horizon: allow to parse ipv6 url
First of all, 'configure_horizon' function has a bad assumption that Horizon host is the same as Keystone host. But this patch won't fix it. The function was parsing the url without properly using urllib. Using netloc allows to get the actual host + port, and then we can remove the port part to build the horizon URL. That way, IPv6 hosts can be parsed, with brackets. In the future, we should make configure_horizon function working with external horizon hosts but it's unrelated to this ipv6 issue. Also, this patch adds unit tests so we now make sure both ipv4 and ipv6 can be used to configure horizon URL. Change-Id: I93530db89a0f8ac2bd5c10ae38e6b61e318a7c87
This commit is contained in:
parent
30a45d048e
commit
31b3465159
@ -989,8 +989,8 @@ def configure_horizon(conf):
|
||||
"""Derive the horizon URIs from the identity's URI."""
|
||||
uri = conf.get('identity', 'uri')
|
||||
u = urllib2.urlparse.urlparse(uri)
|
||||
host = u.netloc.split(":")[0]
|
||||
base = '%s://%s%s' % (u.scheme, host, '/dashboard')
|
||||
base = '%s://%s%s' % (u.scheme, u.netloc.replace(
|
||||
':' + str(u.port), ''), '/dashboard')
|
||||
assert base.startswith('http:') or base.startswith('https:')
|
||||
has_horizon = True
|
||||
try:
|
||||
|
@ -416,7 +416,7 @@ class TestConfigTempest(BaseConfigTempestTest):
|
||||
self.assertEqual(self.conf.get("boto", "ec2_url"), expected_url)
|
||||
self.assertEqual(self.conf.get("boto", "s3_url"), expected_url)
|
||||
|
||||
def test_configure_horizon(self):
|
||||
def test_configure_horizon_ipv4(self):
|
||||
mock_function = mock.Mock(return_value=True)
|
||||
self.useFixture(MonkeyPatch('urllib2.urlopen', mock_function))
|
||||
tool.configure_horizon(self.conf)
|
||||
@ -426,6 +426,17 @@ class TestConfigTempest(BaseConfigTempestTest):
|
||||
self.assertEqual(self.conf.get('dashboard', 'login_url'),
|
||||
"http://172.16.52.151/dashboard/auth/login/")
|
||||
|
||||
def test_configure_horizon_ipv6(self):
|
||||
mock_function = mock.Mock(return_value=True)
|
||||
self.useFixture(MonkeyPatch('urllib2.urlopen', mock_function))
|
||||
self.conf.set('identity', 'uri', 'http://[::1]:5000/v3', priority=True)
|
||||
tool.configure_horizon(self.conf)
|
||||
self.assertEqual(self.conf.get('service_available', 'horizon'), "True")
|
||||
self.assertEqual(self.conf.get('dashboard', 'dashboard_url'),
|
||||
"http://[::1]/dashboard/")
|
||||
self.assertEqual(self.conf.get('dashboard', 'login_url'),
|
||||
"http://[::1]/dashboard/auth/login/")
|
||||
|
||||
def test_discovered_services(self):
|
||||
self._mock_get_identity_v3_extensions()
|
||||
tool.configure_discovered_services(self.conf, self.FAKE_SERVICES)
|
||||
|
Loading…
x
Reference in New Issue
Block a user