summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-09-14 19:09:30 +0000
committerGerrit Code Review <review@openstack.org>2015-09-14 19:09:30 +0000
commit24cf1005467f5d59db83b3c59bdfb58590079010 (patch)
treedeb15aad88df985f66307e5d8fd21315274ef59e
parentefb6c06557a437ef982b83261abe2fccb22b96f8 (diff)
parented7472e9545db9e0d41f15783ca3bdda49b439c8 (diff)
downloadoslo-concurrency-24cf1005467f5d59db83b3c59bdfb58590079010.tar.gz
Merge "Use int enumerations for log error constants"
-rw-r--r--oslo_concurrency/processutils.py48
-rw-r--r--requirements.txt1
2 files changed, 35 insertions, 14 deletions
diff --git a/oslo_concurrency/processutils.py b/oslo_concurrency/processutils.py
index 36ac9b0..ef4c14f 100644
--- a/oslo_concurrency/processutils.py
+++ b/oslo_concurrency/processutils.py
@@ -26,6 +26,7 @@ import shlex
import signal
import time
+import enum
from oslo_utils import importutils
from oslo_utils import strutils
from oslo_utils import timeutils
@@ -96,8 +97,24 @@ def _subprocess_setup(on_preexec_fn):
on_preexec_fn()
-LOG_ALL_ERRORS = 1
-LOG_FINAL_ERROR = 2
+@enum.unique
+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):
@@ -137,17 +154,16 @@ def execute(*cmd, **kwargs):
:param loglevel: log level for execute commands.
:type loglevel: int. (Should be logging.DEBUG or logging.INFO)
:param log_errors: Should stdout and stderr be logged on error?
- Possible values are None=default,
- LOG_FINAL_ERROR, or LOG_ALL_ERRORS. None
- implies no logging on errors. The values
- LOG_FINAL_ERROR and LOG_ALL_ERRORS are
- relevant when multiple attempts of command
- execution are requested using the
- 'attempts' parameter. If LOG_FINAL_ERROR
- is specified then only log an error on the
- last attempt, and LOG_ALL_ERRORS requires
- logging on each occurence of an error.
- :type log_errors: integer.
+ Possible values are
+ :py:attr:`~.LogErrors.DEFAULT`,
+ :py:attr:`~.LogErrors.FINAL`, or
+ :py:attr:`~.LogErrors.ALL`. Note that the
+ values :py:attr:`~.LogErrors.FINAL` and
+ :py:attr:`~.LogErrors.ALL`
+ are **only** relevant when multiple attempts of
+ command execution are requested using the
+ ``attempts`` parameter.
+ :type log_errors: :py:class:`~.LogErrors`
:param binary: On Python 3, return stdout and stderr as bytes if
binary is True, as Unicode otherwise.
:type binary: boolean
@@ -188,6 +204,8 @@ def execute(*cmd, **kwargs):
shell = kwargs.pop('shell', False)
loglevel = kwargs.pop('loglevel', logging.DEBUG)
log_errors = kwargs.pop('log_errors', None)
+ if log_errors is None:
+ log_errors = LogErrors.DEFAULT
binary = kwargs.pop('binary', False)
on_execute = kwargs.pop('on_execute', None)
on_completion = kwargs.pop('on_completion', None)
@@ -202,7 +220,9 @@ def execute(*cmd, **kwargs):
if 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') %
log_errors)
diff --git a/requirements.txt b/requirements.txt
index 9ac5e1c..7c673da 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,6 +4,7 @@
pbr<2.0,>=1.6
Babel>=1.3
+enum34;python_version=='2.7' or python_version=='2.6'
iso8601>=0.1.9
oslo.config>=2.3.0 # Apache-2.0
oslo.i18n>=1.5.0 # Apache-2.0