summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorDavid Ripton <dripton@redhat.com>2013-08-08 10:21:55 -0400
committerDavid Ripton <dripton@redhat.com>2013-08-08 10:28:04 -0400
commitaa5b6588292e804557c7ff7f24a88f0ea97acca8 (patch)
tree39d951e3c6ba4f528948f3f503142f9f017fd6fc /openstack
parent2fc4def480ade1da20e9d29f365ffa4b7e8415e8 (diff)
downloadoslo-aa5b6588292e804557c7ff7f24a88f0ea97acca8.tar.gz
oslo-aa5b6588292e804557c7ff7f24a88f0ea97acca8.tar.xz
oslo-aa5b6588292e804557c7ff7f24a88f0ea97acca8.zip
Allow passing a logging level to processutils.execute
Previously, processutils.execute always logged what commands were run at DEBUG level. This is usually fine, but sometimes the caller wants to log particularly important commands at INFO level instead, and oslo should allow that. Change-Id: I89af6fdc0bb11a4134aaaca417a54ba3b515ca7e
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/processutils.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/openstack/common/processutils.py b/openstack/common/processutils.py
index 13f6222..06fe411 100644
--- a/openstack/common/processutils.py
+++ b/openstack/common/processutils.py
@@ -19,6 +19,7 @@
System-level utilities and helper functions.
"""
+import logging as stdlib_logging
import os
import random
import shlex
@@ -102,6 +103,9 @@ def execute(*cmd, **kwargs):
:param shell: whether or not there should be a shell used to
execute this command. Defaults to false.
:type shell: boolean
+ :param loglevel: log level for execute commands.
+ :type loglevel: int. (Should be stdlib_logging.DEBUG or
+ stdlib_logging.INFO)
:returns: (stdout, stderr) from process execution
:raises: :class:`UnknownArgumentError` on
receiving unknown arguments
@@ -116,6 +120,7 @@ def execute(*cmd, **kwargs):
run_as_root = kwargs.pop('run_as_root', False)
root_helper = kwargs.pop('root_helper', '')
shell = kwargs.pop('shell', False)
+ loglevel = kwargs.pop('loglevel', stdlib_logging.DEBUG)
if isinstance(check_exit_code, bool):
ignore_exit_code = not check_exit_code
@@ -139,7 +144,7 @@ def execute(*cmd, **kwargs):
while attempts > 0:
attempts -= 1
try:
- LOG.debug(_('Running cmd (subprocess): %s'), ' '.join(cmd))
+ LOG.log(loglevel, _('Running cmd (subprocess): %s'), ' '.join(cmd))
_PIPE = subprocess.PIPE # pylint: disable=E1101
if os.name == 'nt':
@@ -164,7 +169,7 @@ def execute(*cmd, **kwargs):
obj.stdin.close() # pylint: disable=E1101
_returncode = obj.returncode # pylint: disable=E1101
if _returncode:
- LOG.debug(_('Result was %s') % _returncode)
+ LOG.log(loglevel, _('Result was %s') % _returncode)
if not ignore_exit_code and _returncode not in check_exit_code:
(stdout, stderr) = result
raise ProcessExecutionError(exit_code=_returncode,
@@ -176,7 +181,7 @@ def execute(*cmd, **kwargs):
if not attempts:
raise
else:
- LOG.debug(_('%r failed. Retrying.'), cmd)
+ LOG.log(loglevel, _('%r failed. Retrying.'), cmd)
if delay_on_retry:
greenthread.sleep(random.randint(20, 200) / 100.0)
finally: