From e57d8793e56647f6ff993d4db5b76546a1150432 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Fri, 9 Oct 2015 03:47:26 +0000 Subject: [PATCH] Move to using REQUIRED_INTERFACES and check for swift-hash. --- hooks/swift_storage_hooks.py | 5 ++++- lib/swift_storage_utils.py | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hooks/swift_storage_hooks.py b/hooks/swift_storage_hooks.py index ba0e11c..cb0caaf 100755 --- a/hooks/swift_storage_hooks.py +++ b/hooks/swift_storage_hooks.py @@ -17,6 +17,7 @@ from lib.swift_storage_utils import ( setup_storage, assert_charm_supports_ipv6, setup_rsync, + REQUIRED_INTERFACES, ) from lib.misc_utils import pause_aware_restart_on_change @@ -42,6 +43,7 @@ from charmhelpers.payload.execd import execd_preinstall from charmhelpers.contrib.openstack.utils import ( configure_installation_source, openstack_upgrade_available, + set_os_workload_status, ) from charmhelpers.contrib.network.ip import ( get_ipv6_addr @@ -165,7 +167,8 @@ def main(): hooks.execute(sys.argv) except UnregisteredHookError as e: log('Unknown hook {} - skipping.'.format(e)) - assess_status() + set_os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=assess_status) if __name__ == '__main__': diff --git a/lib/swift_storage_utils.py b/lib/swift_storage_utils.py index 404e998..ef4cdb9 100644 --- a/lib/swift_storage_utils.py +++ b/lib/swift_storage_utils.py @@ -39,7 +39,6 @@ from charmhelpers.core.hookenv import ( ERROR, unit_private_ip, relation_ids, - status_set, ) from charmhelpers.contrib.storage.linux.utils import ( @@ -70,6 +69,10 @@ PACKAGES = [ TEMPLATES = 'templates/' +REQUIRED_INTERFACES = { + 'proxy': ['swift-storage'], +} + ACCOUNT_SVCS = [ 'swift-account', 'swift-account-auditor', 'swift-account-reaper', 'swift-account-replicator' @@ -343,10 +346,13 @@ socket options = SO_KEEPALIVE f.close() -def assess_status(): +def assess_status(configs): """Assess status of current unit""" - # Check for required swift-storage relation to swift-proxy + # Verify swift-hash received from swift-proxy + ctxt = SwiftStorageContext()() if len(relation_ids('swift-storage')) < 1: - status_set('blocked', 'Missing relation: proxy') + return '', '' + elif not ctxt or not ctxt['swift_hash']: + return 'blocked', 'Missing swift-hash from proxy relation' else: - status_set('active', 'Unit is ready') + return 'active', 'Unit is ready'