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
This commit is contained in:
parent
f15bb1f01f
commit
e439f168a8
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue