Sync charm-helpers

Several charm-helpers updates were made that unblock work on
Charmed OpenStack Epoxy on s390x.

Change-Id: I96924faf57b7b6135c4ca1cda4395d2a02dcff89
This commit is contained in:
Myles Penner
2025-06-04 15:53:46 -07:00
parent 56b48115c5
commit f22b4503a5
4 changed files with 17 additions and 8 deletions

View File

@@ -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:
@@ -618,7 +620,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.

View File

@@ -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,

View File

@@ -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:

View File

@@ -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 = {}