From e439f168a8c38261a3c9d24ba16f6aab6a402bdf Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Fri, 14 Jul 2017 17:25:58 +0100 Subject: [PATCH] Fix multiple vips for external endpoints This was manifested in the designate bug (linked) which resulted in charm breakage when the vip was configured with more than one vip. This fix enables multiple vips to be used with the external_endpoints property that the APIConfigurationAdapter provides. Change-Id: I1ad564946bfc3df53990e14ce5fe889c35cddf38 Related-Bug: #1691452 --- charms_openstack/adapters.py | 11 +++------ unit_tests/test_charms_openstack_adapters.py | 26 +++----------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/charms_openstack/adapters.py b/charms_openstack/adapters.py index 8f035bb..d8630f4 100644 --- a/charms_openstack/adapters.py +++ b/charms_openstack/adapters.py @@ -491,12 +491,12 @@ class APIConfigurationAdapter(ConfigurationAdapter): 'svc1': { 'admin': 9001, 'public': 9001, - 'internal': 9001, + 'int': 9001, }, 'svc2': { 'admin': 9002, 'public': 9002, - 'internal': 9002, + 'int': 9002, }, } :param service_name: Name of service being deployed @@ -721,17 +721,14 @@ class APIConfigurationAdapter(ConfigurationAdapter): """ info = {} - # Bug #1640393. Return self.local_address if vip is undefined, None or - # an empty string. - ip = getattr(self, 'vip', None) or self.local_address proto = 'https' if self.apache_enabled else 'http' if self.port_map: for service in self.port_map.keys(): key = service.replace('-', '_') info[key] = { 'proto': proto, - 'ip': ip, - 'port': self.port_map[service]['admin']} + 'ip': os_ip.resolve_address(os_ip.ADMIN), + 'port': self.port_map[service][os_ip.ADMIN]} info[key]['url'] = '{proto}://{ip}:{port}'.format(**info[key]) return info diff --git a/unit_tests/test_charms_openstack_adapters.py b/unit_tests/test_charms_openstack_adapters.py index 4a65621..17fc4c3 100644 --- a/unit_tests/test_charms_openstack_adapters.py +++ b/unit_tests/test_charms_openstack_adapters.py @@ -459,18 +459,8 @@ class TestAPIConfigurationAdapter(unittest.TestCase): self.assertEqual(c.service_name, 'svc1') def test_external_endpoints(self): - test_config = { - 'prefer-ipv6': False, - 'vip': None, - } - with mock.patch.object(adapters.hookenv, 'config', - new=lambda: test_config), \ - mock.patch.object(adapters.ch_utils, 'get_host_ip', - return_value='10.0.0.10'), \ - mock.patch.object(adapters.APIConfigurationAdapter, - 'get_network_addresses'), \ - mock.patch.object(adapters.hookenv, 'local_unit', - return_value='my-unit/0'): + with mock.patch.object(adapters.os_ip, 'resolve_address', + return_value="10.0.0.10"): c = adapters.APIConfigurationAdapter(port_map=self.api_ports) self.assertEqual( c.external_endpoints, { @@ -553,12 +543,6 @@ class TestAPIConfigurationAdapter(unittest.TestCase): def local_address(self): return '10.0.0.10' - test_config = { - 'prefer-ipv6': False, - 'vip': '10.10.10.10', - 'private-address': 'privaddr', - } - def _determine_apache_port(port, singlenode_mode=None): return port - 10 @@ -567,10 +551,8 @@ class TestAPIConfigurationAdapter(unittest.TestCase): mock.patch.object(adapters.APIConfigurationAdapter, 'determine_service_port', side_effect=_determine_apache_port), \ - mock.patch.object(adapters.APIConfigurationAdapter, - 'get_network_addresses'), \ - mock.patch.object(adapters.hookenv, 'config', - new=lambda: test_config): + mock.patch.object(adapters.os_ip, 'resolve_address', + return_value="10.10.10.10"): with mock.patch.object(adapters.APIConfigurationAdapter, 'apache_enabled', new=False):