From 61d3a4d9aeab893b1dad890db7c67813aaa9bfad Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Fri, 15 Jan 2021 16:09:28 +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 Change-Id: I4a1e9239e40d27d48e48b9e5241240eff9689a3d --- charmhelpers/contrib/openstack/cert_utils.py | 8 ++++---- charmhelpers/contrib/openstack/context.py | 8 ++++---- charmhelpers/contrib/openstack/ip.py | 21 +++++++++++++++++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/charmhelpers/contrib/openstack/cert_utils.py b/charmhelpers/contrib/openstack/cert_utils.py index fc36d0f..2486749 100644 --- a/charmhelpers/contrib/openstack/cert_utils.py +++ b/charmhelpers/contrib/openstack/cert_utils.py @@ -30,7 +30,6 @@ from charmhelpers.core.hookenv import ( relation_get, relation_ids, remote_service_name, - unit_get, NoNetworkBinding, log, WARNING, @@ -41,6 +40,7 @@ from charmhelpers.contrib.openstack.ip import ( get_vip_in_network, ADDRESS_MAP, get_default_api_bindings, + local_address, ) from charmhelpers.contrib.network.ip import ( get_relation_ip, @@ -81,7 +81,7 @@ class CertRequest(object): def add_hostname_cn(self): """Add a request for the hostname of the machine""" - ip = unit_get('private-address') + ip = local_address(unit_get_fallback='private-address') addresses = [ip] # If a vip is being used without os-hostname config or # network spaces then we need to ensure the local units @@ -194,7 +194,7 @@ def get_certificate_sans(bindings=None): :returns: List of binding string names :rtype: List[str] """ - _sans = [unit_get('private-address')] + _sans = [local_address(unit_get_fallback='private-address')] if bindings: # Add default API bindings to bindings list bindings = list(bindings + get_default_api_bindings()) @@ -260,7 +260,7 @@ def create_ip_cert_links(ssl_dir, custom_hostname_link=None, bindings=None): os.symlink(requested_key, key) # Handle custom hostnames - hostname = get_hostname(unit_get('private-address')) + hostname = get_hostname(local_address(unit_get_fallback='private-address')) hostname_cert = os.path.join( ssl_dir, 'cert_{}'.format(hostname)) diff --git a/charmhelpers/contrib/openstack/context.py b/charmhelpers/contrib/openstack/context.py index 6255dac..c242d18 100644 --- a/charmhelpers/contrib/openstack/context.py +++ b/charmhelpers/contrib/openstack/context.py @@ -49,7 +49,6 @@ from charmhelpers.core.hookenv import ( relation_ids, related_units, relation_set, - unit_get, unit_private_ip, charm_name, DEBUG, @@ -98,6 +97,7 @@ from charmhelpers.contrib.openstack.ip import ( ADMIN, PUBLIC, ADDRESS_MAP, + local_address, ) from charmhelpers.contrib.network.ip import ( get_address_in_network, @@ -247,7 +247,7 @@ class SharedDBContext(OSContextGenerator): hostname_key = "hostname" access_hostname = get_address_in_network( access_network, - unit_get('private-address')) + local_address(unit_get_fallback='private-address')) set_hostname = relation_get(attribute=hostname_key, unit=local_unit()) if set_hostname != access_hostname: @@ -1088,7 +1088,7 @@ class ApacheSSLContext(OSContextGenerator): # NOTE(jamespage): Fallback must always be private address # as this is used to bind services on the # local unit. - fallback = unit_get("private-address") + fallback = local_address(unit_get_fallback="private-address") if net_config: addr = get_address_in_network(net_config, fallback) @@ -1260,7 +1260,7 @@ class NeutronContext(OSContextGenerator): if is_clustered(): host = config('vip') else: - host = unit_get('private-address') + host = local_address(unit_get_fallback='private-address') ctxt = {'network_manager': self.network_manager, 'neutron_url': '%s://%s:%s' % (proto, host, '9696')} diff --git a/charmhelpers/contrib/openstack/ip.py b/charmhelpers/contrib/openstack/ip.py index 89cf276..6557330 100644 --- a/charmhelpers/contrib/openstack/ip.py +++ b/charmhelpers/contrib/openstack/ip.py @@ -123,6 +123,25 @@ 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. + + :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: + return unit_get(unit_get_fallback) + + def resolve_address(endpoint_type=PUBLIC, override=True): """Return unit address depending on net config. @@ -176,7 +195,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)