Sync charm helpers for NoNetworkBinding fix
Please review and merge CH change first: https://github.com/juju/charm-helpers/pull/298 Change-Id: I6960e6860cdaf6f7c293558aadea557a227357dc
This commit is contained in:
parent
865e961067
commit
f80b94b9a3
|
@ -19,9 +19,16 @@ from charmhelpers.core import unitdata
|
|||
@cmdline.subcommand_builder('unitdata', description="Store and retrieve data")
|
||||
def unitdata_cmd(subparser):
|
||||
nested = subparser.add_subparsers()
|
||||
|
||||
get_cmd = nested.add_parser('get', help='Retrieve data')
|
||||
get_cmd.add_argument('key', help='Key to retrieve the value of')
|
||||
get_cmd.set_defaults(action='get', value=None)
|
||||
|
||||
getrange_cmd = nested.add_parser('getrange', help='Retrieve multiple data')
|
||||
getrange_cmd.add_argument('key', metavar='prefix',
|
||||
help='Prefix of the keys to retrieve')
|
||||
getrange_cmd.set_defaults(action='getrange', value=None)
|
||||
|
||||
set_cmd = nested.add_parser('set', help='Store data')
|
||||
set_cmd.add_argument('key', help='Key to set')
|
||||
set_cmd.add_argument('value', help='Value to store')
|
||||
|
@ -30,6 +37,8 @@ def unitdata_cmd(subparser):
|
|||
def _unitdata_cmd(action, key, value):
|
||||
if action == 'get':
|
||||
return unitdata.kv().get(key)
|
||||
elif action == 'getrange':
|
||||
return unitdata.kv().getrange(key)
|
||||
elif action == 'set':
|
||||
unitdata.kv().set(key, value)
|
||||
unitdata.kv().flush()
|
||||
|
|
|
@ -159,7 +159,7 @@ def resolve_address(endpoint_type=PUBLIC, override=True):
|
|||
if is_address_in_network(bound_cidr, vip):
|
||||
resolved_address = vip
|
||||
break
|
||||
except NotImplementedError:
|
||||
except (NotImplementedError, NoNetworkBinding):
|
||||
# If no net-splits configured and no support for extra
|
||||
# bindings/network spaces so we expect a single vip
|
||||
resolved_address = vips[0]
|
||||
|
|
|
@ -656,7 +656,7 @@ def openstack_upgrade_available(package):
|
|||
else:
|
||||
avail_vers = get_os_version_install_source(src)
|
||||
apt.init()
|
||||
return apt.version_compare(avail_vers, cur_vers) == 1
|
||||
return apt.version_compare(avail_vers, cur_vers) >= 1
|
||||
|
||||
|
||||
def ensure_block_device(block_device):
|
||||
|
|
|
@ -17,12 +17,53 @@ import re
|
|||
from stat import S_ISBLK
|
||||
|
||||
from subprocess import (
|
||||
CalledProcessError,
|
||||
check_call,
|
||||
check_output,
|
||||
call
|
||||
)
|
||||
|
||||
|
||||
def _luks_uuid(dev):
|
||||
"""
|
||||
Check to see if dev is a LUKS encrypted volume, returning the UUID
|
||||
of volume if it is.
|
||||
|
||||
:param: dev: path to block device to check.
|
||||
:returns: str. UUID of LUKS device or None if not a LUKS device
|
||||
"""
|
||||
try:
|
||||
cmd = ['cryptsetup', 'luksUUID', dev]
|
||||
return check_output(cmd).decode('UTF-8').strip()
|
||||
except CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
def is_luks_device(dev):
|
||||
"""
|
||||
Determine if dev is a LUKS-formatted block device.
|
||||
|
||||
:param: dev: A full path to a block device to check for LUKS header
|
||||
presence
|
||||
:returns: boolean: indicates whether a device is used based on LUKS header.
|
||||
"""
|
||||
return True if _luks_uuid(dev) else False
|
||||
|
||||
|
||||
def is_mapped_luks_device(dev):
|
||||
"""
|
||||
Determine if dev is a mapped LUKS device
|
||||
:param: dev: A full path to a block device to be checked
|
||||
:returns: boolean: indicates whether a device is mapped
|
||||
"""
|
||||
_, dirs, _ = next(os.walk(
|
||||
'/sys/class/block/{}/holders/'
|
||||
.format(os.path.basename(os.path.realpath(dev))))
|
||||
)
|
||||
is_held = len(dirs) > 0
|
||||
return is_held and is_luks_device(dev)
|
||||
|
||||
|
||||
def is_block_device(path):
|
||||
'''
|
||||
Confirm device at path is a valid block device node.
|
||||
|
|
|
@ -47,6 +47,7 @@ if __platform__ == "ubuntu":
|
|||
cmp_pkgrevno,
|
||||
CompareHostReleases,
|
||||
get_distrib_codename,
|
||||
arch
|
||||
) # flake8: noqa -- ignore F401 for this import
|
||||
elif __platform__ == "centos":
|
||||
from charmhelpers.core.host_factory.centos import ( # NOQA:F401
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import subprocess
|
||||
|
||||
from charmhelpers.core.hookenv import cached
|
||||
from charmhelpers.core.strutils import BasicStringComparator
|
||||
|
||||
|
||||
|
@ -97,3 +98,16 @@ def cmp_pkgrevno(package, revno, pkgcache=None):
|
|||
pkgcache = apt_cache()
|
||||
pkg = pkgcache[package]
|
||||
return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
|
||||
|
||||
|
||||
@cached
|
||||
def arch():
|
||||
"""Return the package architecture as a string.
|
||||
|
||||
:returns: the architecture
|
||||
:rtype: str
|
||||
:raises: subprocess.CalledProcessError if dpkg command fails
|
||||
"""
|
||||
return subprocess.check_output(
|
||||
['dpkg', '--print-architecture']
|
||||
).rstrip().decode('UTF-8')
|
||||
|
|
|
@ -20,10 +20,8 @@ import six
|
|||
import time
|
||||
import subprocess
|
||||
|
||||
from charmhelpers.core.host import (
|
||||
get_distrib_codename,
|
||||
CompareHostReleases,
|
||||
)
|
||||
from charmhelpers.core.host import get_distrib_codename
|
||||
|
||||
from charmhelpers.core.hookenv import (
|
||||
log,
|
||||
DEBUG,
|
||||
|
@ -362,14 +360,8 @@ def _get_keyid_by_gpg_key(key_material):
|
|||
:returns: A GPG key fingerprint
|
||||
:rtype: str
|
||||
"""
|
||||
# trusty, xenial and bionic handling differs due to gpg 1.x to 2.x change
|
||||
release = get_distrib_codename()
|
||||
is_gpgv2_distro = CompareHostReleases(release) >= "bionic"
|
||||
if is_gpgv2_distro:
|
||||
# --import is mandatory, otherwise fingerprint is not printed
|
||||
cmd = 'gpg --with-colons --import-options show-only --import --dry-run'
|
||||
else:
|
||||
cmd = 'gpg --with-colons --with-fingerprint'
|
||||
# Use the same gpg command for both Xenial and Bionic
|
||||
cmd = 'gpg --with-colons --with-fingerprint'
|
||||
ps = subprocess.Popen(cmd.split(),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
|
|
Loading…
Reference in New Issue