Allow overriding of source configuration option key

The charms.openstack library contains lots of useful code for
reactive charms which is reusable for other charms.

Allow direct consumers of the OpenStackCharm class to override
the key used for package source selection.  This is usefull for
non-OpenStack charms deploying binaries from UCA (for example
Ceph)

Retain 'openstack-origin' as a default.

Also add and default to a `py3` target in tox for developer
friendliness.

Change-Id: I67d2e5d68bc4da87bcaba813f99d3f782f1d9907
This commit is contained in:
Frode Nordahl 2019-01-10 16:12:35 +01:00
parent 8ce4de38cd
commit 34bc40a2f8
4 changed files with 27 additions and 13 deletions

View File

@ -113,6 +113,12 @@ class OpenStackCharm(BaseOpenStackCharm,
# package_codenames = {}
# The name of the repository source configuration option.
# Useful for charms managing software from UCA and consuming the
# `openstack` layer directly for re-use of common code, but not being a
# OpenStack component.
source_config_key = 'openstack-origin'
@property
def region(self):
"""Return the OpenStack Region as contained in the config item 'region'
@ -159,7 +165,7 @@ class OpenStackCharm(BaseOpenStackCharm,
fatal=False)
if not version:
version = os_utils.get_os_codename_install_source(
self.config['openstack-origin']
self.config[self.source_config_key]
)
else:
if not self.version_package:
@ -452,7 +458,7 @@ class OpenStackAPICharm(OpenStackCharm):
"""
if not release:
release = os_utils.get_os_codename_install_source(
self.config['openstack-origin'])
self.config[self.source_config_key])
if release not in os_utils.OPENSTACK_RELEASES:
return ValueError("Unkown release {}".format(release))
return (os_utils.OPENSTACK_RELEASES.index(release) >=

View File

@ -624,7 +624,7 @@ class BaseOpenStackCharmActions(object):
os_utils.install_os_snaps(
os_utils.get_snaps_install_info_from_origin(
self.all_snaps,
self.config['openstack-origin'],
self.config[self.source_config_key],
mode=self.snap_mode)
)
@ -636,12 +636,14 @@ class BaseOpenStackCharmActions(object):
def configure_source(self):
"""Configure installation source using the config item
'openstack-origin'
indicated in the source_config_key class variable
(default: 'openstack-origin')
This configures the installation source for deb packages and then
updates the packages list on the unit.
"""
os_utils.configure_installation_source(self.config['openstack-origin'])
os_utils.configure_installation_source(
self.config[self.source_config_key])
fetch.apt_update(fatal=True)
@property
@ -896,7 +898,7 @@ class BaseOpenStackCharmActions(object):
if not snap:
snap = self.release_snap
src = self.config['openstack-origin']
src = self.config[self.source_config_key]
cur_vers = self.get_os_version_package(package)
avail_vers = os_utils.get_os_version_install_source(src)
if os_utils.snap_install_requested():
@ -913,7 +915,7 @@ class BaseOpenStackCharmActions(object):
:returns: None
"""
hookenv.status_set('maintenance', 'Running openstack upgrade')
new_src = self.config['openstack-origin']
new_src = self.config[self.source_config_key]
new_os_rel = os_utils.get_os_codename_install_source(new_src)
unitdata.kv().set(OPENSTACK_RELEASE_KEY, new_os_rel)
target_charm = get_charm_instance(new_os_rel)
@ -940,7 +942,7 @@ class BaseOpenStackCharmActions(object):
:returns: None
"""
new_src = self.config['openstack-origin']
new_src = self.config[self.source_config_key]
new_os_rel = os_utils.get_os_codename_install_source(new_src)
hookenv.log('Performing OpenStack upgrade to %s.' % (new_os_rel))
@ -949,7 +951,7 @@ class BaseOpenStackCharmActions(object):
os_utils.install_os_snaps(
snaps=os_utils.get_snaps_install_info_from_origin(
self.all_snaps,
self.config['openstack-origin'],
self.config[self.source_config_key],
mode=self.snap_mode),
refresh=True)
@ -1013,11 +1015,12 @@ class BaseOpenStackCharmActions(object):
# NOTE(jamespage): Not currently used - switch from c-h function for perf?
def snap_install_requested(self):
"""Determine whether a snap based install is configured
via the openstack-origin configuration option
via the configuration option indicated in the source_config_key
class variable. (deafult: 'openstack-origin')
:returns: None
"""
return self.options.openstack_origin.startswith('snap:')
return self.config[self.source_config_key].startswith('snap:')
class BaseOpenStackCharmAssessStatus(object):

View File

@ -109,7 +109,8 @@ def make_default_select_package_type_handler():
@register_package_type_selector
def default_select_package_type():
"""Determine the package type (snap or deb) based on the
openstack-origin setting.
configuration option indicated in the source_config_key
class variable. (deafult: 'openstack-origin')
Note that this function caches the package type after the first
install so that it doesn't need to keep going and getting it from

View File

@ -1,5 +1,5 @@
[tox]
envlist = pep8,py27,py34,py35
envlist = pep8,py27,py3
skipsdist = True
skip_missing_interpreters = True
@ -17,6 +17,10 @@ deps = -r{toxinidir}/test-requirements.txt
# However, we can't yet remove the actually py27 test from the gate.
commands = python -c "print('Py27 testing disabled.')" && /bin/true
[testenv:py3]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
[testenv:py34]
basepython = python3.4
deps = -r{toxinidir}/test-requirements.txt