Use int enumerations for log error constants
Change-Id: Iac6f4d860c220c653bbae17e7b1d69249259bd88
This commit is contained in:
parent
4ff6635921
commit
ed7472e954
@ -26,6 +26,7 @@ import shlex
|
|||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import enum
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
@ -96,8 +97,24 @@ def _subprocess_setup(on_preexec_fn):
|
|||||||
on_preexec_fn()
|
on_preexec_fn()
|
||||||
|
|
||||||
|
|
||||||
LOG_ALL_ERRORS = 1
|
@enum.unique
|
||||||
LOG_FINAL_ERROR = 2
|
class LogErrors(enum.IntEnum):
|
||||||
|
"""Enumerations that affect if stdout and stderr are logged on error."""
|
||||||
|
|
||||||
|
#: No logging on errors.
|
||||||
|
DEFAULT = 0
|
||||||
|
|
||||||
|
#: Log an error on **each** occurence of an error.
|
||||||
|
ALL = 1
|
||||||
|
|
||||||
|
#: Log an error on the last attempt that errored **only**.
|
||||||
|
FINAL = 2
|
||||||
|
|
||||||
|
|
||||||
|
# Retain these aliases for a number of releases...
|
||||||
|
LOG_ALL_ERRORS = LogErrors.ALL
|
||||||
|
LOG_FINAL_ERROR = LogErrors.FINAL
|
||||||
|
LOG_DEFAULT_ERROR = LogErrors.DEFAULT
|
||||||
|
|
||||||
|
|
||||||
def execute(*cmd, **kwargs):
|
def execute(*cmd, **kwargs):
|
||||||
@ -137,17 +154,16 @@ def execute(*cmd, **kwargs):
|
|||||||
:param loglevel: log level for execute commands.
|
:param loglevel: log level for execute commands.
|
||||||
:type loglevel: int. (Should be logging.DEBUG or logging.INFO)
|
:type loglevel: int. (Should be logging.DEBUG or logging.INFO)
|
||||||
:param log_errors: Should stdout and stderr be logged on error?
|
:param log_errors: Should stdout and stderr be logged on error?
|
||||||
Possible values are None=default,
|
Possible values are
|
||||||
LOG_FINAL_ERROR, or LOG_ALL_ERRORS. None
|
:py:attr:`~.LogErrors.DEFAULT`,
|
||||||
implies no logging on errors. The values
|
:py:attr:`~.LogErrors.FINAL`, or
|
||||||
LOG_FINAL_ERROR and LOG_ALL_ERRORS are
|
:py:attr:`~.LogErrors.ALL`. Note that the
|
||||||
relevant when multiple attempts of command
|
values :py:attr:`~.LogErrors.FINAL` and
|
||||||
execution are requested using the
|
:py:attr:`~.LogErrors.ALL`
|
||||||
'attempts' parameter. If LOG_FINAL_ERROR
|
are **only** relevant when multiple attempts of
|
||||||
is specified then only log an error on the
|
command execution are requested using the
|
||||||
last attempt, and LOG_ALL_ERRORS requires
|
``attempts`` parameter.
|
||||||
logging on each occurence of an error.
|
:type log_errors: :py:class:`~.LogErrors`
|
||||||
:type log_errors: integer.
|
|
||||||
:param binary: On Python 3, return stdout and stderr as bytes if
|
:param binary: On Python 3, return stdout and stderr as bytes if
|
||||||
binary is True, as Unicode otherwise.
|
binary is True, as Unicode otherwise.
|
||||||
:type binary: boolean
|
:type binary: boolean
|
||||||
@ -188,6 +204,8 @@ def execute(*cmd, **kwargs):
|
|||||||
shell = kwargs.pop('shell', False)
|
shell = kwargs.pop('shell', False)
|
||||||
loglevel = kwargs.pop('loglevel', logging.DEBUG)
|
loglevel = kwargs.pop('loglevel', logging.DEBUG)
|
||||||
log_errors = kwargs.pop('log_errors', None)
|
log_errors = kwargs.pop('log_errors', None)
|
||||||
|
if log_errors is None:
|
||||||
|
log_errors = LogErrors.DEFAULT
|
||||||
binary = kwargs.pop('binary', False)
|
binary = kwargs.pop('binary', False)
|
||||||
on_execute = kwargs.pop('on_execute', None)
|
on_execute = kwargs.pop('on_execute', None)
|
||||||
on_completion = kwargs.pop('on_completion', None)
|
on_completion = kwargs.pop('on_completion', None)
|
||||||
@ -202,7 +220,9 @@ def execute(*cmd, **kwargs):
|
|||||||
if kwargs:
|
if kwargs:
|
||||||
raise UnknownArgumentError(_('Got unknown keyword args: %r') % kwargs)
|
raise UnknownArgumentError(_('Got unknown keyword args: %r') % kwargs)
|
||||||
|
|
||||||
if log_errors not in [None, LOG_ALL_ERRORS, LOG_FINAL_ERROR]:
|
if isinstance(log_errors, six.integer_types):
|
||||||
|
log_errors = LogErrors(log_errors)
|
||||||
|
if not isinstance(log_errors, LogErrors):
|
||||||
raise InvalidArgumentError(_('Got invalid arg log_errors: %r') %
|
raise InvalidArgumentError(_('Got invalid arg log_errors: %r') %
|
||||||
log_errors)
|
log_errors)
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
pbr<2.0,>=1.3
|
pbr<2.0,>=1.3
|
||||||
Babel>=1.3
|
Babel>=1.3
|
||||||
|
enum34;python_version=='2.7' or python_version=='2.6'
|
||||||
iso8601>=0.1.9
|
iso8601>=0.1.9
|
||||||
oslo.config>=1.11.0 # Apache-2.0
|
oslo.config>=1.11.0 # Apache-2.0
|
||||||
oslo.i18n>=1.5.0 # Apache-2.0
|
oslo.i18n>=1.5.0 # Apache-2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user