From f3532fe560d6c17bf4faa129e9a7b15b15761d61 Mon Sep 17 00:00:00 2001 From: Adam Collard Date: Fri, 28 Aug 2015 11:21:17 +0100 Subject: [PATCH] Move helpers to utils --- hooks/swift_storage_hooks.py | 21 +++------------------ lib/misc_utils.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/hooks/swift_storage_hooks.py b/hooks/swift_storage_hooks.py index 9d00d6e..5a3f2cc 100755 --- a/hooks/swift_storage_hooks.py +++ b/hooks/swift_storage_hooks.py @@ -18,11 +18,12 @@ from lib.swift_storage_utils import ( setup_rsync, ) +from lib.misc_utils import pause_aware_restart_on_change + from charmhelpers.core.hookenv import ( Hooks, UnregisteredHookError, config, log, - status_get, relation_get, relation_set, relations_of_type, @@ -33,7 +34,7 @@ from charmhelpers.fetch import ( apt_update, filter_installed_packages ) -from charmhelpers.core.host import restart_on_change, rsync +from charmhelpers.core.host import rsync from charmhelpers.payload.execd import execd_preinstall from charmhelpers.contrib.openstack.utils import ( @@ -53,22 +54,6 @@ NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins' SUDOERS_D = '/etc/sudoers.d' -def is_paused(status_get=status_get): - """Is the unit paused?""" - status, message = status_get() - return status == "maintenance" and message.startswith("Paused") - - -def pause_aware_restart_on_change(restart_map): - """Avoids restarting services if config changes when unit is paused.""" - def wrapper(f): - if is_paused(): - return f - else: - return restart_on_change(restart_map)(f) - return wrapper - - @hooks.hook() def install(): execd_preinstall() diff --git a/lib/misc_utils.py b/lib/misc_utils.py index 43b8e4d..cf81fb8 100644 --- a/lib/misc_utils.py +++ b/lib/misc_utils.py @@ -16,12 +16,14 @@ from charmhelpers.contrib.storage.linux.lvm import ( from charmhelpers.core.host import ( mounts, umount, + restart_on_change, ) from charmhelpers.core.hookenv import ( log, INFO, ERROR, + status_get, ) DEFAULT_LOOPBACK_SIZE = '5G' @@ -83,3 +85,19 @@ def clean_storage(block_device): remove_lvm_physical_volume(block_device) else: zap_disk(block_device) + + +def is_paused(status_get=status_get): + """Is the unit paused?""" + status, message = status_get() + return status == "maintenance" and message.startswith("Paused") + + +def pause_aware_restart_on_change(restart_map): + """Avoids restarting services if config changes when unit is paused.""" + def wrapper(f): + if is_paused(): + return f + else: + return restart_on_change(restart_map)(f) + return wrapper