Move helpers to utils

This commit is contained in:
Adam Collard 2015-08-28 11:21:17 +01:00
parent d4a90969c1
commit f3532fe560
2 changed files with 21 additions and 18 deletions

View File

@ -18,11 +18,12 @@ from lib.swift_storage_utils import (
setup_rsync, setup_rsync,
) )
from lib.misc_utils import pause_aware_restart_on_change
from charmhelpers.core.hookenv import ( from charmhelpers.core.hookenv import (
Hooks, UnregisteredHookError, Hooks, UnregisteredHookError,
config, config,
log, log,
status_get,
relation_get, relation_get,
relation_set, relation_set,
relations_of_type, relations_of_type,
@ -33,7 +34,7 @@ from charmhelpers.fetch import (
apt_update, apt_update,
filter_installed_packages 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.payload.execd import execd_preinstall
from charmhelpers.contrib.openstack.utils import ( from charmhelpers.contrib.openstack.utils import (
@ -53,22 +54,6 @@ NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
SUDOERS_D = '/etc/sudoers.d' 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() @hooks.hook()
def install(): def install():
execd_preinstall() execd_preinstall()

View File

@ -16,12 +16,14 @@ from charmhelpers.contrib.storage.linux.lvm import (
from charmhelpers.core.host import ( from charmhelpers.core.host import (
mounts, mounts,
umount, umount,
restart_on_change,
) )
from charmhelpers.core.hookenv import ( from charmhelpers.core.hookenv import (
log, log,
INFO, INFO,
ERROR, ERROR,
status_get,
) )
DEFAULT_LOOPBACK_SIZE = '5G' DEFAULT_LOOPBACK_SIZE = '5G'
@ -83,3 +85,19 @@ def clean_storage(block_device):
remove_lvm_physical_volume(block_device) remove_lvm_physical_volume(block_device)
else: else:
zap_disk(block_device) 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