From 1070b661f745ef28cd8b81f7f0c17e68e493628d Mon Sep 17 00:00:00 2001 From: abhishekkekane Date: Thu, 9 Apr 2015 04:58:04 -0700 Subject: [PATCH] Store pid of processes Added callback_method to execute call to store the pid of processes. It is useful to kill the processes like rsync/scp if instance is deleted while resize is in progress. Change-Id: Ifc23325eddb523f6449ba06a2deb0885a8a7009d Closes-bug: #1387543 --- oslo_concurrency/processutils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/oslo_concurrency/processutils.py b/oslo_concurrency/processutils.py index ba61cba..3ea385e 100644 --- a/oslo_concurrency/processutils.py +++ b/oslo_concurrency/processutils.py @@ -163,6 +163,7 @@ def execute(*cmd, **kwargs): shell = kwargs.pop('shell', False) loglevel = kwargs.pop('loglevel', logging.DEBUG) log_errors = kwargs.pop('log_errors', None) + callback_method = kwargs.pop('callback_method', None) if isinstance(check_exit_code, bool): ignore_exit_code = not check_exit_code @@ -216,6 +217,9 @@ def execute(*cmd, **kwargs): cwd=cwd, env=env_variables) + if callback_method: + callback_method(pid=obj.pid) + result = obj.communicate(process_input) obj.stdin.close() # pylint: disable=E1101 @@ -223,6 +227,10 @@ def execute(*cmd, **kwargs): end_time = time.time() - start_time LOG.log(loglevel, 'CMD "%s" returned: %s in %0.3fs' % (sanitized_cmd, _returncode, end_time)) + + if callback_method: + callback_method(cleanup=True) + if not ignore_exit_code and _returncode not in check_exit_code: (stdout, stderr) = result sanitized_stdout = strutils.mask_password(stdout) -- 1.9.1