Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pausable_restart_on_change as cntxt manager #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions charmhelpers/contrib/openstack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
service_resume,
service_stop,
service_start,
restart_on_change,
restart_on_change_helper,
)

Expand Down Expand Up @@ -1796,11 +1797,7 @@ def _assess_status_func():
return _assess_status_func


def pausable_restart_on_change(restart_map, stopstart=False,
restart_functions=None,
can_restart_now_f=None,
post_svc_restart_f=None,
pre_restarts_wait_f=None):
class pausable_restart_on_change(restart_on_change):
"""A restart_on_change decorator that checks to see if the unit is
paused. If it is paused then the decorated function doesn't fire.

Expand Down Expand Up @@ -1849,7 +1846,7 @@ def some_hook(...):


"""
def wrap(f):
def __call__(self, f):
# py27 compatible nonlocal variable. When py3 only, replace with
# nonlocal keyword
__restart_map_cache = {'cache': None}
Expand All @@ -1859,19 +1856,18 @@ def wrapped_f(*args, **kwargs):
if is_unit_paused_set():
return f(*args, **kwargs)
if __restart_map_cache['cache'] is None:
__restart_map_cache['cache'] = restart_map() \
if callable(restart_map) else restart_map
__restart_map_cache['cache'] = self.restart_map() \
if callable(self.restart_map) else self.restart_map
# otherwise, normal restart_on_change functionality
return restart_on_change_helper(
(lambda: f(*args, **kwargs)),
__restart_map_cache['cache'],
stopstart,
restart_functions,
can_restart_now_f,
post_svc_restart_f,
pre_restarts_wait_f)
self.stopstart,
self.restart_functions,
self.can_restart_now_f,
self.post_svc_restart_f,
self.pre_restarts_wait_f)
return wrapped_f
return wrap


def ordered(orderme):
Expand Down