diff --git a/charmhelpers/contrib/network/ip.py b/charmhelpers/contrib/network/ip.py index f3b4864..1460266 100644 --- a/charmhelpers/contrib/network/ip.py +++ b/charmhelpers/contrib/network/ip.py @@ -134,6 +134,8 @@ def get_address_in_network(network, fallback=None, fatal=False): def is_ipv6(address): """Determine whether provided address is IPv6 or not.""" + if not address: + return False try: address = netaddr.IPAddress(address) except netaddr.AddrFormatError: @@ -467,9 +469,21 @@ def ns_query(address): return None try: - answers = dns.resolver.query(address, rtype) + resolv = dns.resolver.Resolver() + # The dnspython library sets a default DNS query lifetime of 5.0 seconds, + # as defined in BaseResolver.reset() (see https://github.com/rthalley/ + # dnspython/blob/7ed1648b/dns/resolver.py#L709, commit 7ed1648b). + resolv.lifetime = config('dns-query-timeout') or 5.0 + if hasattr(resolv, 'resolve'): + answers = resolv.resolve(address, rtype) + else: + answers = resolv.query(address, rtype) except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers): return None + except dns.exception.Timeout: + log("DNS query timed out for address {} with rtype {} and timeout " + "{}".format(address, rtype, resolv.lifetime), level=WARNING) + return None if answers: return str(answers[0]) @@ -618,7 +632,7 @@ def get_relation_ip(interface, cidr_network=None): # Currently IPv6 has priority, eventually we want IPv6 to just be # another network space. assert_charm_supports_ipv6() - return get_ipv6_addr()[0] + return get_ipv6_addr(dynamic_only=False)[0] elif cidr_network: # If a specific CIDR network is passed get the address from that # network. diff --git a/charmhelpers/contrib/openstack/context.py b/charmhelpers/contrib/openstack/context.py index cd70b55..9082348 100644 --- a/charmhelpers/contrib/openstack/context.py +++ b/charmhelpers/contrib/openstack/context.py @@ -25,7 +25,10 @@ import socket import time from base64 import b64decode -from distutils.version import LooseVersion +try: + from distutils.version import LooseVersion +except ImportError: + from looseversion import LooseVersion from subprocess import ( check_call, check_output, diff --git a/charmhelpers/contrib/openstack/utils.py b/charmhelpers/contrib/openstack/utils.py index ac52d79..79e1e7b 100644 --- a/charmhelpers/contrib/openstack/utils.py +++ b/charmhelpers/contrib/openstack/utils.py @@ -164,6 +164,8 @@ OPENSTACK_CODENAMES = OrderedDict([ ('2024.1', 'caracal'), ('2024.2', 'dalmatian'), ('2025.1', 'epoxy'), + ('2025.2', 'flamingo'), + ('2026.1', 'gazpacho'), ]) # The ugly duckling - must list releases oldest to newest diff --git a/charmhelpers/core/host.py b/charmhelpers/core/host.py index def403c..8371daa 100644 --- a/charmhelpers/core/host.py +++ b/charmhelpers/core/host.py @@ -357,7 +357,7 @@ def init_is_systemd(service_name=None): return os.path.isdir(SYSTEMD_SYSTEM) -def adduser(username, password=None, shell='/bin/bash', +def adduser(username, password=None, shell=None, system_user=False, primary_group=None, secondary_groups=None, uid=None, home_dir=None): """Add a user to the system. @@ -389,11 +389,14 @@ def adduser(username, password=None, shell='/bin/bash', if home_dir: cmd.extend(['--home', str(home_dir)]) if system_user or password is None: - cmd.append('--system') + cmd.extend([ + '--system', + '--shell', shell if shell else '/usr/sbin/nologin' + ]) else: cmd.extend([ '--create-home', - '--shell', shell, + '--shell', shell if shell else '/bin/bash', '--password', password, ]) if not primary_group: diff --git a/charmhelpers/fetch/ubuntu.py b/charmhelpers/fetch/ubuntu.py index fdcad02..57a84cd 100644 --- a/charmhelpers/fetch/ubuntu.py +++ b/charmhelpers/fetch/ubuntu.py @@ -270,6 +270,22 @@ CLOUD_ARCHIVE_POCKETS = { 'epoxy/proposed': 'noble-proposed/epoxy', 'noble-epoxy/proposed': 'noble-proposed/epoxy', 'noble-proposed/epoxy': 'noble-proposed/epoxy', + # flamingo + 'flamingo': 'noble-updates/flamingo', + 'noble-flamingo': 'noble-updates/flamingo', + 'noble-flamingo/updates': 'noble-updates/flamingo', + 'noble-updates/flamingo': 'noble-updates/flamingo', + 'flamingo/proposed': 'noble-proposed/flamingo', + 'noble-flamingo/proposed': 'noble-proposed/flamingo', + 'noble-proposed/flamingo': 'noble-proposed/flamingo', + # gazpacho + 'gazpacho': 'noble-updates/gazpacho', + 'noble-gazpacho': 'noble-updates/gazpacho', + 'noble-gazpacho/updates': 'noble-updates/gazpacho', + 'noble-updates/gazpacho': 'noble-updates/gazpacho', + 'gazpacho/proposed': 'noble-proposed/gazpacho', + 'noble-gazpacho/proposed': 'noble-proposed/gazpacho', + 'noble-proposed/gazpacho': 'noble-proposed/gazpacho', # OVN 'focal-ovn-22.03': 'focal-updates/ovn-22.03', @@ -306,6 +322,8 @@ OPENSTACK_RELEASES = ( 'caracal', 'dalmatian', 'epoxy', + 'flamingo', + 'gazpacho', ) @@ -338,10 +356,12 @@ UBUNTU_OPENSTACK_RELEASE = OrderedDict([ ('noble', 'caracal'), ('oracular', 'dalmatian'), ('plucky', 'epoxy'), + ('questing', 'flamingo'), + ('resolute', 'gazpacho'), ]) -APT_NO_LOCK = 100 # The return code for "couldn't acquire lock" in APT. +APT_ERROR_CODE = 100 # The return code for APT errors. CMD_RETRY_DELAY = 10 # Wait 10 seconds between command retries. CMD_RETRY_COUNT = 10 # Retry a failing fatal command X times. @@ -464,6 +484,8 @@ def apt_upgrade(options=None, fatal=False, dist=False): def apt_update(fatal=False): """Update local apt cache.""" cmd = ['apt-get', 'update'] + if fatal: + cmd.append("--error-on=any") _run_apt_command(cmd, fatal) @@ -1021,8 +1043,7 @@ def _run_apt_command(cmd, fatal=False, quiet=False): """ if fatal: _run_with_retries( - cmd, retry_exitcodes=(1, APT_NO_LOCK,), - retry_message="Couldn't acquire DPKG lock", + cmd, retry_exitcodes=(1, APT_ERROR_CODE,), quiet=quiet) else: kwargs = {}