From ac8b75857e2c27a04b7458e487b91899dae14f0e Mon Sep 17 00:00:00 2001 From: Guillaume Boutry Date: Tue, 22 Apr 2025 10:16:20 +0200 Subject: [PATCH] Ensure context templating doesn't fail on incomplete relation data This is a rebuild/make sync for charms to pickup the fix in charmhelpers to fix a change in netaddr library not allowing falsy addresses anymore. Fix in charmhelpers is in [1]. [1] https://github.com/juju/charm-helpers/pull/921 Change-Id: Ie347a1adf7f971f7860e774f0c3cab5974a17c25 Signed-off-by: Guillaume Boutry --- charmhelpers/contrib/network/ip.py | 2 ++ charmhelpers/core/host.py | 9 ++++++--- charmhelpers/fetch/ubuntu.py | 7 ++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/charmhelpers/contrib/network/ip.py b/charmhelpers/contrib/network/ip.py index f3b4864..4d472ca 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: 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..0b2f229 100644 --- a/charmhelpers/fetch/ubuntu.py +++ b/charmhelpers/fetch/ubuntu.py @@ -341,7 +341,7 @@ UBUNTU_OPENSTACK_RELEASE = OrderedDict([ ]) -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 +464,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 +1023,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 = {}