diff --git a/charms_openstack/adapters.py b/charms_openstack/adapters.py index d75d3e2..087619b 100644 --- a/charms_openstack/adapters.py +++ b/charms_openstack/adapters.py @@ -567,6 +567,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) diff --git a/unit_tests/test_charms_openstack_adapters.py b/unit_tests/test_charms_openstack_adapters.py index e88567e..fadb4f1 100644 --- a/unit_tests/test_charms_openstack_adapters.py +++ b/unit_tests/test_charms_openstack_adapters.py @@ -494,6 +494,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})