From 1cacf425bc10c1dc9b029854baf15030e4c9c4b2 Mon Sep 17 00:00:00 2001 From: gbenhaim Date: Wed, 1 Nov 2017 21:18:20 +0200 Subject: [PATCH 1/3] docs: Adding el7.4-base Adding el7.4-base to the list of available images. Signed-off-by: gbenhaim --- docs/Templates.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/Templates.rst b/docs/Templates.rst index 72b0816e..dc3b2b54 100644 --- a/docs/Templates.rst +++ b/docs/Templates.rst @@ -20,6 +20,8 @@ Available templates +------------------+--------------+ | el7.3-base | CentOS 7.3 | +------------------+--------------+ +| el7.4-base | CentOS 7.4 | ++------------------+--------------+ | fc23-base | Fedora 23 | +------------------+--------------+ | fc24-base | Fedora 24 | From 79ce6397eaa1a97b4acebd1989420da1a242aaf9 Mon Sep 17 00:00:00 2001 From: gbenhaim Date: Sun, 12 Nov 2017 14:39:47 +0200 Subject: [PATCH 2/3] utils: Improve Lock Context manager 1. Verify the the lock is locked before trying to release it. 2. Add log messages which helps debugging. Signed-off-by: gbenhaim --- lago/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lago/utils.py b/lago/utils.py index 526e01dd..2486380f 100644 --- a/lago/utils.py +++ b/lago/utils.py @@ -390,6 +390,7 @@ def __enter__(self): with ExceptionTimer(timeout=self.timeout): LOGGER.debug('Acquiring lock for {}'.format(self.path)) self.lock.acquire() + LOGGER.debug('Holding the lock for {}'.format(self.path)) except TimerException: raise TimerException( 'Unable to acquire lock for %s in %s secs', @@ -398,7 +399,10 @@ def __enter__(self): ) def __exit__(self, *_): - self.lock.release() + if self.lock.is_locked(): + LOGGER.debug('Trying to release lock {}'.format(self.path)) + self.lock.release() + LOGGER.debug('Lock {} was released') def read_nonblocking(file_descriptor): From e6c55e41e1b6f4e282acd5f448dd1132270a3eda Mon Sep 17 00:00:00 2001 From: gbenhaim Date: Sun, 12 Nov 2017 15:59:10 +0200 Subject: [PATCH 3/3] Catch SIGTERM/SIGHUP in order to run cleanup code This change will require lago to run cleanup code defined in "ContextMangers" and "finally" statements even when SIGTERM or SIGHUP was sent to the process. This is done by calling "sys.exit" which raises "SystemExit" that triggers the cleanup. The exit status will be 128 + the value of the signal, which is common to Unix programs. Signed-off-by: gbenhaim --- lago/cmd.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lago/cmd.py b/lago/cmd.py index 70e07dbc..b1c46029 100755 --- a/lago/cmd.py +++ b/lago/cmd.py @@ -27,6 +27,7 @@ import sys from textwrap import dedent import warnings +from signal import signal, SIGTERM, SIGHUP import lago import lago.plugins @@ -899,7 +900,30 @@ def create_parser(cli_plugins, out_plugins): return parser +def exit_handler(signum, frame): + """ + Catch SIGTERM and SIGHUP and call "sys.exit" which raises + "SystemExit" exception. + This will trigger all the cleanup code defined in ContextManagers + and "finally" statements. + + For more details about the arguments see "signal" documentation. + + Args: + signum(int): The signal's number + frame(frame): The current stack frame, can be None + """ + + LOGGER.debug('signal {} was caught'.format(signum)) + sys.exit(128 + signum) + + def main(): + + # Trigger cleanup on SIGTERM and SIGHUP + signal(SIGTERM, exit_handler) + signal(SIGHUP, exit_handler) + cli_plugins = lago.plugins.load_plugins( lago.plugins.PLUGIN_ENTRY_POINTS['cli'] )