Change charm so that it works with assess_status()

And also demo the function to choose the release charm to use.
This commit is contained in:
Alex Kavanagh 2016-06-10 14:38:40 +00:00
parent 87566760c2
commit 79d7fc3b89
3 changed files with 33 additions and 0 deletions

View File

@ -8,6 +8,7 @@ check_and_install() {
apt-get -y install ${pkg}
fi
}
status-set maintenance "Install hook running"
if [[ $(lsb_release -sc) -eq "trusty" ]]; then
juju-log "Enabling cloud archive to work around old trusty tools"

View File

@ -48,6 +48,13 @@ def render_configs(interfaces_list):
BarbicanCharm.singleton.render_with_interfaces(interfaces_list)
def assess_status():
"""Just call the BarbicanCharm.singleton.assess_status() command to update
status on the unit.
"""
BarbicanCharm.singleton.assess_status()
###
# Implementation of the Barbican Charm classes
@ -108,6 +115,8 @@ class BarbicanCharm(charms_openstack.charm.OpenStackCharm):
default_service = 'barbican-api'
services = ['barbican-api', 'barbican-worker']
required_relations = ['shared-db', 'amqp', 'identity-service']
restart_map = {
"{}/{}".format(BARBICAN_DIR, BARBICAN_API_CONF): services,
"{}/{}".format(BARBICAN_DIR, BARBICAN_ADMIN_PASTE_CONF): services,
@ -121,6 +130,9 @@ class BarbicanCharm(charms_openstack.charm.OpenStackCharm):
If no release is passed, then the charm determines the release from the
ch_utils.os_release() function.
Note that the release_selector can be used to control which class is
instantiated.
"""
if release is None:
# release = ch_utils.os_release('barbican-common')
@ -135,3 +147,12 @@ class BarbicanCharm(charms_openstack.charm.OpenStackCharm):
self.configure_source()
# and do the actual install
super(BarbicanCharm, self).install()
# Determine the charm class by the supported release
@charms_openstack.charm.register_os_release_selector
def select_release():
"""Determine the release based on the python-keystonemiddleware that is
installed.
"""
return ch_utils.os_release('python-keystonemiddleware')

View File

@ -24,6 +24,7 @@ def setup_amqp_req(amqp):
"""
amqp.request_access(username=hookenv.config('rabbit-user'),
vhost=hookenv.config('rabbit-vhost'))
barbican.assess_status()
@reactive.when('shared-db.connected')
@ -34,11 +35,13 @@ def setup_database(database):
database.configure(hookenv.config('database'),
hookenv.config('database-user'),
hookenv.unit_private_ip())
barbican.assess_status()
@reactive.when('identity-service.connected')
def setup_endpoint(keystone):
barbican.setup_endpoint(keystone)
barbican.assess_status()
@reactive.when('shared-db.available')
@ -46,3 +49,11 @@ def setup_endpoint(keystone):
@reactive.when('amqp.available')
def render_stuff(*args):
barbican.render_configs(args)
barbican.assess_status()
@reactive.when('config.changed')
def config_changed():
"""When the configuration changes, assess the unit's status to update any
juju state required"""
barbican.assess_status()