Refactor to assess status after every hook execution, add update-status hook

This commit is contained in:
James Page 2015-10-07 16:45:20 -07:00
commit 0a603e2c7e
2 changed files with 4 additions and 39 deletions

View File

@ -66,7 +66,7 @@ from charmhelpers.contrib.openstack.utils import (
openstack_upgrade_available, openstack_upgrade_available,
sync_db_with_multi_ipv6_addresses, sync_db_with_multi_ipv6_addresses,
os_release, os_release,
os_workload_status, set_os_workload_status,
) )
from charmhelpers.contrib.storage.linux.ceph import ( from charmhelpers.contrib.storage.linux.ceph import (
@ -104,8 +104,6 @@ CONFIGS = register_configs()
@hooks.hook('install.real') @hooks.hook('install.real')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def install(): def install():
status_set('maintenance', 'Executing pre-install') status_set('maintenance', 'Executing pre-install')
execd_preinstall() execd_preinstall()
@ -125,8 +123,6 @@ def install():
@hooks.hook('config-changed') @hooks.hook('config-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map(), stopstart=True) @restart_on_change(restart_map(), stopstart=True)
def config_changed(): def config_changed():
conf = config() conf = config()
@ -179,8 +175,6 @@ def config_changed():
@hooks.hook('shared-db-relation-joined') @hooks.hook('shared-db-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def db_joined(): def db_joined():
if is_relation_made('pgsql-db'): if is_relation_made('pgsql-db'):
# error, postgresql is used # error, postgresql is used
@ -201,8 +195,6 @@ def db_joined():
@hooks.hook('pgsql-db-relation-joined') @hooks.hook('pgsql-db-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def pgsql_db_joined(): def pgsql_db_joined():
if is_relation_made('shared-db'): if is_relation_made('shared-db'):
# raise error # raise error
@ -216,8 +208,6 @@ def pgsql_db_joined():
@hooks.hook('shared-db-relation-changed') @hooks.hook('shared-db-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def db_changed(): def db_changed():
if 'shared-db' not in CONFIGS.complete_contexts(): if 'shared-db' not in CONFIGS.complete_contexts():
@ -238,8 +228,6 @@ def db_changed():
@hooks.hook('pgsql-db-relation-changed') @hooks.hook('pgsql-db-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def pgsql_db_changed(): def pgsql_db_changed():
if 'pgsql-db' not in CONFIGS.complete_contexts(): if 'pgsql-db' not in CONFIGS.complete_contexts():
@ -252,8 +240,6 @@ def pgsql_db_changed():
@hooks.hook('amqp-relation-joined') @hooks.hook('amqp-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def amqp_joined(relation_id=None): def amqp_joined(relation_id=None):
conf = config() conf = config()
relation_set(relation_id=relation_id, relation_set(relation_id=relation_id,
@ -261,8 +247,6 @@ def amqp_joined(relation_id=None):
@hooks.hook('amqp-relation-changed') @hooks.hook('amqp-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def amqp_changed(): def amqp_changed():
if 'amqp' not in CONFIGS.complete_contexts(): if 'amqp' not in CONFIGS.complete_contexts():
@ -272,8 +256,6 @@ def amqp_changed():
@hooks.hook('amqp-relation-departed') @hooks.hook('amqp-relation-departed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def amqp_departed(): def amqp_departed():
if 'amqp' not in CONFIGS.complete_contexts(): if 'amqp' not in CONFIGS.complete_contexts():
@ -283,8 +265,6 @@ def amqp_departed():
@hooks.hook('identity-service-relation-joined') @hooks.hook('identity-service-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def identity_joined(rid=None): def identity_joined(rid=None):
public_url = '{}:{}/v1/$(tenant_id)s'.format( public_url = '{}:{}/v1/$(tenant_id)s'.format(
canonical_url(CONFIGS, PUBLIC), canonical_url(CONFIGS, PUBLIC),
@ -335,8 +315,6 @@ def identity_joined(rid=None):
@hooks.hook('identity-service-relation-changed') @hooks.hook('identity-service-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def identity_changed(): def identity_changed():
if 'identity-service' not in CONFIGS.complete_contexts(): if 'identity-service' not in CONFIGS.complete_contexts():
@ -347,8 +325,6 @@ def identity_changed():
@hooks.hook('ceph-relation-joined') @hooks.hook('ceph-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ceph_joined(): def ceph_joined():
if not os.path.isdir('/etc/ceph'): if not os.path.isdir('/etc/ceph'):
os.mkdir('/etc/ceph') os.mkdir('/etc/ceph')
@ -364,8 +340,6 @@ def get_ceph_request():
@hooks.hook('ceph-relation-changed') @hooks.hook('ceph-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def ceph_changed(relation_id=None): def ceph_changed(relation_id=None):
if 'ceph' not in CONFIGS.complete_contexts(): if 'ceph' not in CONFIGS.complete_contexts():
@ -391,8 +365,6 @@ def ceph_changed(relation_id=None):
@hooks.hook('ceph-relation-broken') @hooks.hook('ceph-relation-broken')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ceph_broken(): def ceph_broken():
service = service_name() service = service_name()
delete_keyring(service=service) delete_keyring(service=service)
@ -430,8 +402,6 @@ def cluster_changed():
@hooks.hook('ha-relation-joined') @hooks.hook('ha-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ha_joined(relation_id=None): def ha_joined(relation_id=None):
cluster_config = get_hacluster_config() cluster_config = get_hacluster_config()
@ -489,8 +459,6 @@ def ha_joined(relation_id=None):
@hooks.hook('ha-relation-changed') @hooks.hook('ha-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ha_changed(): def ha_changed():
clustered = relation_get('clustered') clustered = relation_get('clustered')
if not clustered or clustered in [None, 'None', '']: if not clustered or clustered in [None, 'None', '']:
@ -503,8 +471,6 @@ def ha_changed():
@hooks.hook('image-service-relation-changed') @hooks.hook('image-service-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def image_service_changed(): def image_service_changed():
CONFIGS.write(CINDER_CONF) CONFIGS.write(CINDER_CONF)
@ -515,8 +481,6 @@ def image_service_changed():
'image-service-relation-broken', 'image-service-relation-broken',
'shared-db-relation-broken', 'shared-db-relation-broken',
'pgsql-db-relation-broken') 'pgsql-db-relation-broken')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map(), stopstart=True) @restart_on_change(restart_map(), stopstart=True)
def relation_broken(): def relation_broken():
CONFIGS.write_all() CONFIGS.write_all()
@ -554,8 +518,6 @@ def upgrade_charm():
@hooks.hook('storage-backend-relation-changed') @hooks.hook('storage-backend-relation-changed')
@hooks.hook('storage-backend-relation-broken') @hooks.hook('storage-backend-relation-broken')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def storage_backend(): def storage_backend():
CONFIGS.write(CINDER_CONF) CONFIGS.write(CINDER_CONF)
@ -580,3 +542,5 @@ if __name__ == '__main__':
hooks.execute(sys.argv) hooks.execute(sys.argv)
except UnregisteredHookError as e: except UnregisteredHookError as e:
juju_log('Unknown hook {} - skipping.'.format(e)) juju_log('Unknown hook {} - skipping.'.format(e))
set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)

1
hooks/update-status Symbolic link
View File

@ -0,0 +1 @@
cinder_hooks.py