Sync latest processutils from oslo-incubator
This sync is primarily being done to pull in commit 63c99a0f so that passwords are masked in exception and error messages. ------------------------------------------------ oslo-incubator head: commit 80a08a413fb0f23a056eca2d273b167f0a09bab6 Merge: 83c4098 d73f3b1 Author: Jenkins <jenkins@review.openstack.org> Date: Mon Aug 25 14:32:36 2014 +0000 Merge "Remove unused/mutable default args" ----------------------------------------------- The sync pulls in the following changes (newest to oldest): 63c99a0f - Mask passwords in exceptions and error messages e184dd36 - Fix exception message in openstack.common.processutils.execute d6b55fb2 - Remove `processutils` dependency on `log` ----------------------------------------------- Change-Id: Ia92aab76fa83d01c5fbf6f9d31df2463fc26ba5c Partial-bug: 1343604
This commit is contained in:
parent
296a32c169
commit
ff0f112bb4
|
@ -18,7 +18,7 @@ System-level utilities and helper functions.
|
|||
"""
|
||||
|
||||
import errno
|
||||
import logging as stdlib_logging
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
|
@ -30,7 +30,7 @@ from eventlet import greenthread
|
|||
import six
|
||||
|
||||
from cinder.openstack.common.gettextutils import _
|
||||
from cinder.openstack.common import log as logging
|
||||
from cinder.openstack.common import strutils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -115,8 +115,7 @@ def execute(*cmd, **kwargs):
|
|||
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)
|
||||
:type loglevel: int. (Should be logging.DEBUG or logging.INFO)
|
||||
:returns: (stdout, stderr) from process execution
|
||||
:raises: :class:`UnknownArgumentError` on
|
||||
receiving unknown arguments
|
||||
|
@ -132,7 +131,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)
|
||||
loglevel = kwargs.pop('loglevel', logging.DEBUG)
|
||||
|
||||
if isinstance(check_exit_code, bool):
|
||||
ignore_exit_code = not check_exit_code
|
||||
|
@ -141,8 +140,7 @@ def execute(*cmd, **kwargs):
|
|||
check_exit_code = [check_exit_code]
|
||||
|
||||
if kwargs:
|
||||
raise UnknownArgumentError(_('Got unknown keyword args '
|
||||
'to utils.execute: %r') % kwargs)
|
||||
raise UnknownArgumentError(_('Got unknown keyword args: %r') % kwargs)
|
||||
|
||||
if run_as_root and hasattr(os, 'geteuid') and os.geteuid() != 0:
|
||||
if not root_helper:
|
||||
|
@ -152,12 +150,12 @@ def execute(*cmd, **kwargs):
|
|||
cmd = shlex.split(root_helper) + list(cmd)
|
||||
|
||||
cmd = map(str, cmd)
|
||||
sanitized_cmd = strutils.mask_password(' '.join(cmd))
|
||||
|
||||
while attempts > 0:
|
||||
attempts -= 1
|
||||
try:
|
||||
LOG.log(loglevel, 'Running cmd (subprocess): %s',
|
||||
logging.mask_password(' '.join(cmd)))
|
||||
LOG.log(loglevel, _('Running cmd (subprocess): %s'), sanitized_cmd)
|
||||
_PIPE = subprocess.PIPE # pylint: disable=E1101
|
||||
|
||||
if os.name == 'nt':
|
||||
|
@ -194,16 +192,18 @@ def execute(*cmd, **kwargs):
|
|||
LOG.log(loglevel, 'Result was %s' % _returncode)
|
||||
if not ignore_exit_code and _returncode not in check_exit_code:
|
||||
(stdout, stderr) = result
|
||||
sanitized_stdout = strutils.mask_password(stdout)
|
||||
sanitized_stderr = strutils.mask_password(stderr)
|
||||
raise ProcessExecutionError(exit_code=_returncode,
|
||||
stdout=stdout,
|
||||
stderr=stderr,
|
||||
cmd=' '.join(cmd))
|
||||
stdout=sanitized_stdout,
|
||||
stderr=sanitized_stderr,
|
||||
cmd=sanitized_cmd)
|
||||
return result
|
||||
except ProcessExecutionError:
|
||||
if not attempts:
|
||||
raise
|
||||
else:
|
||||
LOG.log(loglevel, '%r failed. Retrying.', cmd)
|
||||
LOG.log(loglevel, _('%r failed. Retrying.'), sanitized_cmd)
|
||||
if delay_on_retry:
|
||||
greenthread.sleep(random.randint(20, 200) / 100.0)
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue