From af9c467e353ca8e9254809f8f289fc383284da5e Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Fri, 15 Jan 2021 16:07:37 +0000 Subject: [PATCH] Updates for testing period for 20.01 release Includes updates to charmhelpers/charms.openstack for cert_utils and unit-get for the install hook error on Juju 2.9 * charm-helpers sync for classic charms * rebuild for reactive charms * ensure tox.ini is from release-tools * ensure requirements.txt files are from release-tools * On reactive charms: - ensure master branch for charms.openstack - ensure master branch for charm-helpers * Include NoNetworkBinding late fix. func-test-pr: https://github.com/openstack-charmers/zaza/pull/409 Change-Id: I1a97004410c5cf4ef98164281137bce46756b12c --- charmhelpers/contrib/openstack/ip.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/charmhelpers/contrib/openstack/ip.py b/charmhelpers/contrib/openstack/ip.py index 89cf276..b8c94c5 100644 --- a/charmhelpers/contrib/openstack/ip.py +++ b/charmhelpers/contrib/openstack/ip.py @@ -123,6 +123,28 @@ def _get_address_override(endpoint_type=PUBLIC): return addr_override.format(service_name=service_name()) +def local_address(unit_get_fallback='public-address'): + """Return a network address for this unit. + + Attempt to retrieve a 'default' IP address for this unit + from network-get. If this is running with an old version of Juju then + fallback to unit_get. + + Note on juju < 2.9 the binding to juju-info may not exist, so fall back to + the unit-get. + + :param unit_get_fallback: Either 'public-address' or 'private-address'. + Only used with old versions of Juju. + :type unit_get_fallback: str + :returns: IP Address + :rtype: str + """ + try: + return network_get_primary_address('juju-info') + except (NotImplementedError, NoNetworkBinding): + return unit_get(unit_get_fallback) + + def resolve_address(endpoint_type=PUBLIC, override=True): """Return unit address depending on net config. @@ -176,7 +198,7 @@ def resolve_address(endpoint_type=PUBLIC, override=True): if config('prefer-ipv6'): fallback_addr = get_ipv6_addr(exc_list=vips)[0] else: - fallback_addr = unit_get(net_fallback) + fallback_addr = local_address(unit_get_fallback=net_fallback) if net_addr: resolved_address = get_address_in_network(net_addr, fallback_addr)