10 Commits

Author SHA1 Message Date
Victor Stinner
c05c8c37be Port processutils to Python 3
On Python 3, execute() and ssh_execute() now return stdout and stderr as
Unicode. os.fsdecode() is used to stdout and stderr, it uses the locale
encoding with the surrogateescape error handler.
subprocess.Popen(universal_encoding=True) uses the same encoding and
error handler.

This change breaks the backward compatibility, but I believe that
Unicode is more convinient in Python 3 and it is what users expect. In
practice, there is no known (OpenStack) application compatible with
Python 3 using oslo_concurrency.processutils yet.

Add new tests.

This changeset does not change the behaviour on Python 2, only Python 3
is impacted.

Change-Id: Ibb510642c1440e2fbe7ad53d797bc7c32a3cbddf
2015-04-18 00:11:28 +02:00
Jenkins
2f510962ab Merge "processutils: execute(): fix option incompatibility" 2015-02-17 18:38:41 +00:00
Csaba Henk
c20a86d550 processutils: execute(): fix option incompatibility
Issue: simultaneous usage of 'shell' and 'run_as_root' options led
to error.

Cause: it's actually a concealed TypeError: in 'shell'
mode the command argument is assumed to be a string, elsewhere
a list/tuple.

Fix: the command editing implied by 'run_as_root' is performed
with care taken of above tacit type assumption.

Change-Id: Iaba33e6fda67793ae2874ba278c990271ee5e47f
Closes-Bug: #1382873
2015-02-14 02:00:04 +01:00
Davanum Srinivas
3d6e372ea4 Ability to set working directory
Currently folks end up using os.chdir() (see bug listed below) as
we are not exposing the subprocess.Popen's cwd parameter. It's
better to add a cwd parameter in processutils.execute so folks
do not have to issue chdir() before and after the processutils.
execute and there's less scope for problem as documented in
the bug.

Closes-Bug: #1414530
Change-Id: Ia4c77593c0f8301e059b349290e8663614a7ccfd
2015-02-13 16:17:55 -05:00
Doug Hellmann
da8176dbdf Update Oslo imports to remove namespace package
Change-Id: I4ec9b2a310471e4e07867073e9577731ac34027d
Blueprint: drop-namespace-packages
2015-01-21 18:00:50 -05:00
Jenkins
f034bd2877 Merge "Revert "Port processutils to Python 3"" 2015-01-14 00:43:37 +00:00
Doug Hellmann
acb55ef279 Revert "Port processutils to Python 3"
This reverts commit 7c7493feb53429577efca2c4b0380af03ddc149b.

This change breaks the API of execute() and breaks nova's tests.

Closes-Bug: #1410348
Change-Id: I33fa9b4e6099f521e0de3cb4585016fd694c4548
2015-01-13 17:54:43 +00:00
Sean Dague
234b007b75 make time format for processutils match lockutils
Lockutils uses %0.3fs for time format, which gives us a convenient
time in milliseconds. Process utils was an unbounded string which
gives us times like:

CMD "cat /proc/31599/cmdline" returned: 0 in 0.00526595115662s execute

The super long time strings are mostly confusing, and millisecond
accuracy should be sufficient for processutils.

Change-Id: I57f21b18ab060a36c3d88b0c5a94430eafeb02a2
2015-01-07 08:18:56 -05:00
Victor Stinner
7c7493feb5 Port processutils to Python 3
Add encoding and errors parameters to execute() and ssh_execute(). By
default, use the locale encoding in strict mode on Python 2, or the
locale encoding with the 'surrogateescape' error handler on Python 3.

Fix also unit tests to use bytes strings for stdin, stdout and stderr.

Without this change, tests are failing with Python 3 when run with:
PYTHON="python -bb" testr run

Using -bb, Python 3 raises a TypeError when a bytes string is casted
to a text string, which occurred in many places.

Change-Id: I655d5abf932c9a104e3ab487e23c372377f7096a
2014-12-12 00:09:55 +01:00
Doug Hellmann
bca4a0d827 Move out of the oslo namespace package
Move the public API out of oslo.concurrency to oslo_concurrency. Retain
the ability to import from the old namespace package for backwards
compatibility for this release cycle.

bp/drop-namespace-packages

Change-Id: I20d1647b1c3ef8cab3b69eccfe168eeb01703b72
2014-11-14 17:17:25 -05:00