From 79d7fc3b898a4ae3a2aef5e67a6a68aa9fab8d9e Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Fri, 10 Jun 2016 14:38:40 +0000 Subject: [PATCH] Change charm so that it works with assess_status() And also demo the function to choose the release charm to use. --- src/hooks/install | 1 + src/lib/charm/openstack/barbican.py | 21 +++++++++++++++++++++ src/reactive/barbican_handlers.py | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/hooks/install b/src/hooks/install index 780bb71..184c50e 100755 --- a/src/hooks/install +++ b/src/hooks/install @@ -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" diff --git a/src/lib/charm/openstack/barbican.py b/src/lib/charm/openstack/barbican.py index f2b3f3d..9828bb8 100644 --- a/src/lib/charm/openstack/barbican.py +++ b/src/lib/charm/openstack/barbican.py @@ -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') diff --git a/src/reactive/barbican_handlers.py b/src/reactive/barbican_handlers.py index f60b698..952ea50 100644 --- a/src/reactive/barbican_handlers.py +++ b/src/reactive/barbican_handlers.py @@ -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()