Merge "Enable IPv6 check in haproxy template file"

This commit is contained in:
Zuul 2017-10-23 09:06:03 +00:00 committed by Gerrit Code Review
commit 5b1c2c7a8c
2 changed files with 21 additions and 0 deletions

View File

@ -572,6 +572,13 @@ class APIConfigurationAdapter(ConfigurationAdapter):
"""
return getattr(self, 'prefer_ipv6', False)
@property
def ipv6_enabled(self):
"""
@return True if IPv6 is enabled
"""
return not ch_ip.is_ipv6_disabled()
@property
def local_address(self):
"""Return remotely accessible address of charm (not localhost)

View File

@ -501,6 +501,20 @@ class TestAPIConfigurationAdapter(unittest.TestCase):
self.assertEqual(c.local_host, 'ip6-localhost')
self.assertEqual(c.haproxy_host, '::')
def test_ipv6_enabled(self):
with mock.patch.object(adapters.ch_ip,
'is_ipv6_disabled') as is_ipv6_disabled:
# IPv6 disabled
is_ipv6_disabled.return_value = True
a = adapters.APIConfigurationAdapter()
self.assertEqual(a.ipv6_enabled, False)
# IPv6 enabled
is_ipv6_disabled.return_value = False
b = adapters.APIConfigurationAdapter()
self.assertEqual(b.ipv6_enabled, True)
def test_external_ports(self):
c = adapters.APIConfigurationAdapter(port_map=self.api_ports)
self.assertEqual(c.external_ports, {9001, 9002, 9003})