Move helpers to utils
This commit is contained in:
parent
d4a90969c1
commit
f3532fe560
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue