Stop getting {public,private}-address from unit-get
In Juju 2.8rc3 unit-get public-address became unreliable (Bug #1910973). Since getting an address this was is deprecated switch the OpenStack functions to prefer network-get. However, fallback to the old method to support old versions of Juju for the time being. Change-Id: I33020deefa1f814b77767653dad34c228def91fa
This commit is contained in:
parent
d37b622a7b
commit
bf521e6d5b
|
@ -26,6 +26,7 @@ import charms.reactive.bus
|
|||
import charmhelpers.contrib.hahelpers.cluster as ch_cluster
|
||||
import charmhelpers.contrib.network.ip as ch_ip
|
||||
import charmhelpers.contrib.openstack.context as ch_context
|
||||
import charmhelpers.contrib.openstack.ip as ch_os_ip
|
||||
import charmhelpers.contrib.openstack.utils as ch_utils
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
import charmhelpers.core.host as ch_host
|
||||
|
@ -793,7 +794,7 @@ class APIConfigurationAdapter(ConfigurationAdapter):
|
|||
addr = ch_ip.get_ipv6_addr(exc_list=[self.vip])[0]
|
||||
else:
|
||||
addr = ch_utils.get_host_ip(
|
||||
hookenv.unit_get('private-address'))
|
||||
ch_os_ip.local_address(unit_get_fallback='private-address'))
|
||||
return addr
|
||||
|
||||
@property
|
||||
|
@ -987,7 +988,8 @@ class APIConfigurationAdapter(ConfigurationAdapter):
|
|||
if hookenv.config(net_cfg_opt):
|
||||
addr = ch_ip.get_address_in_network(
|
||||
config_cidr,
|
||||
hookenv.unit_get('private-address'))
|
||||
ch_os_ip.local_address(
|
||||
unit_get_fallback='private-address'))
|
||||
else:
|
||||
addr = ch_ip.get_relation_ip(
|
||||
os_ip.ADDRESS_MAP[net_type]['binding'])
|
||||
|
|
|
@ -13,6 +13,7 @@ import charmhelpers.contrib.openstack.utils as os_utils
|
|||
import charmhelpers.contrib.openstack.ha as os_ha
|
||||
import charmhelpers.contrib.openstack.ha.utils as os_ha_utils
|
||||
import charmhelpers.contrib.openstack.cert_utils as cert_utils
|
||||
import charmhelpers.contrib.openstack.ip as ch_os_ip
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
import charmhelpers.core.host as ch_host
|
||||
import charmhelpers.fetch as fetch
|
||||
|
@ -354,7 +355,8 @@ class OpenStackCharm(BaseOpenStackCharm,
|
|||
:rtype: List[str]
|
||||
"""
|
||||
addresses = [
|
||||
os_utils.get_host_ip(hookenv.unit_get('private-address'))]
|
||||
os_utils.get_host_ip(ch_os_ip.local_address(
|
||||
unit_get_fallback='private-address'))]
|
||||
for addr_type in os_ip.ADDRESS_MAP.keys():
|
||||
laddr = os_ip.resolve_address(endpoint_type=addr_type)
|
||||
if laddr:
|
||||
|
|
|
@ -17,6 +17,7 @@ import netaddr
|
|||
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
import charmhelpers.contrib.network.ip as net_ip
|
||||
import charmhelpers.contrib.openstack.ip as ch_os_ip
|
||||
import charms.reactive.bus
|
||||
|
||||
PUBLIC = 'public'
|
||||
|
@ -162,7 +163,8 @@ def resolve_address(endpoint_type=PUBLIC, override=True):
|
|||
if hookenv.config('prefer-ipv6'):
|
||||
fallback_addr = net_ip.get_ipv6_addr(exc_list=vips)[0]
|
||||
else:
|
||||
fallback_addr = hookenv.unit_get(net_fallback)
|
||||
fallback_addr = ch_os_ip.local_address(
|
||||
unit_get_fallback=net_fallback)
|
||||
|
||||
if net_addr:
|
||||
resolved_address = net_ip.get_address_in_network(net_addr,
|
||||
|
|
|
@ -29,6 +29,8 @@ sys.modules['charmhelpers.contrib'] = charmhelpers.contrib
|
|||
sys.modules['charmhelpers.contrib.openstack'] = charmhelpers.contrib.openstack
|
||||
sys.modules['charmhelpers.contrib.openstack.ha'] = (
|
||||
charmhelpers.contrib.openstack.ha)
|
||||
sys.modules['charmhelpers.contrib.openstack.ip'] = (
|
||||
charmhelpers.contrib.openstack.ip)
|
||||
sys.modules['charmhelpers.contrib.openstack.ha.utils'] = (
|
||||
charmhelpers.contrib.openstack.ha.utils)
|
||||
sys.modules['charmhelpers.contrib.openstack.cert_utils'] = (
|
||||
|
|
|
@ -601,7 +601,7 @@ class TestAPIConfigurationAdapter(unittest.TestCase):
|
|||
return_value='10.0.0.10'), \
|
||||
mock.patch.object(adapters.hookenv, 'config',
|
||||
new=lambda: test_config), \
|
||||
mock.patch.object(adapters.hookenv, 'unit_get',
|
||||
mock.patch.object(adapters.ch_os_ip, 'local_address',
|
||||
return_value='10.0.0.20'), \
|
||||
mock.patch.object(adapters.APIConfigurationAdapter,
|
||||
'get_network_addresses'):
|
||||
|
|
|
@ -56,6 +56,7 @@ class TestCharmOpenStackIp(utils.BaseTestCase):
|
|||
self.patch_object(ip.net_ip, 'get_ipv6_addr')
|
||||
self.patch_object(ip.hookenv, 'unit_get')
|
||||
self.patch_object(ip.net_ip, 'get_address_in_network')
|
||||
self.patch_object(ip.ch_os_ip, 'local_address')
|
||||
|
||||
# define a fake_config() that returns predictable results and remembers
|
||||
# what it was called with.
|
||||
|
@ -78,11 +79,11 @@ class TestCharmOpenStackIp(utils.BaseTestCase):
|
|||
# Juju pre 2.0 behaviour where network-get is not implemented
|
||||
self.network_get_primary_address.side_effect = NotImplementedError
|
||||
|
||||
# first test, if no VIP, that the function uses unit_get() and
|
||||
# first test, if no VIP, that the function uses local_address() and
|
||||
# get_address_in_network to get a real address.
|
||||
# for the default PUBLIC endpoint
|
||||
self.get_address_in_network.return_value = 'got-address'
|
||||
self.unit_get.return_value = 'unit-get-address'
|
||||
self.local_address.return_value = 'unit-get-address'
|
||||
addr = ip.resolve_address()
|
||||
self.assertEqual(addr, 'got-address')
|
||||
self.assertEqual(calls_list,
|
||||
|
@ -90,7 +91,8 @@ class TestCharmOpenStackIp(utils.BaseTestCase):
|
|||
('vip',),
|
||||
('os-public-network',),
|
||||
('prefer-ipv6',)])
|
||||
self.unit_get.assert_called_once_with('public-address')
|
||||
self.local_address.assert_called_once_with(
|
||||
unit_get_fallback='public-address')
|
||||
self.get_address_in_network.assert_called_once_with(
|
||||
'the-public-network', 'unit-get-address')
|
||||
|
||||
|
@ -142,9 +144,9 @@ class TestCharmOpenStackIp(utils.BaseTestCase):
|
|||
self.patch_object(ip.hookenv, 'network_get_primary_address')
|
||||
self.patch_object(ip.net_ip, 'is_address_in_network')
|
||||
self.patch_object(ip.net_ip, 'get_ipv6_addr')
|
||||
self.patch_object(ip.hookenv, 'unit_get')
|
||||
self.patch_object(ip.net_ip, 'get_address_in_network')
|
||||
self.patch_object(ip, '_resolve_network_cidr')
|
||||
self.patch_object(ip.ch_os_ip, 'local_address')
|
||||
|
||||
# define a fake_config() that returns predictable results and remembers
|
||||
# what it was called with.
|
||||
|
@ -169,7 +171,7 @@ class TestCharmOpenStackIp(utils.BaseTestCase):
|
|||
# for the default PUBLIC endpoint
|
||||
self.network_get_primary_address.return_value = 'got-address'
|
||||
self._resolve_network_cidr.return_value = 'cidr'
|
||||
self.unit_get.return_value = 'unit-get-address'
|
||||
self.local_address.return_value = 'unit-get-address'
|
||||
addr = ip.resolve_address()
|
||||
self.assertEqual(addr, 'got-address')
|
||||
self.assertEqual(calls_list,
|
||||
|
@ -177,7 +179,8 @@ class TestCharmOpenStackIp(utils.BaseTestCase):
|
|||
('vip',),
|
||||
('os-public-network',),
|
||||
('prefer-ipv6',)])
|
||||
self.unit_get.assert_called_once_with('public-address')
|
||||
self.local_address.assert_called_once_with(
|
||||
unit_get_fallback='public-address')
|
||||
self.network_get_primary_address.assert_called_with(
|
||||
'public'
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue