122 Commits

Author SHA1 Message Date
Zuul
f7383fe40d Merge "deprecate eventlet monkey patch within lockutils" 2025-02-06 18:19:23 +00:00
Hervé Beraud
1da88a61a8 deprecate eventlet monkey patch within lockutils
Change-Id: I83352849192489e6918898969b92ee3f8e2bca55
2025-02-06 15:08:00 +00:00
Takashi Kajinami
d49bfca815 Remove support for running unit tests in Windows
Support for Windows OS was already removed[1].

[1] 3df106fa34080ab32e9a1ee334c93e0df29b68e7

Change-Id: I8fef84147c2d409f3875a7bbad69a5bc0456fb2f
2025-01-18 16:37:28 +09:00
Takashi Kajinami
3df106fa34 Remove windows support
This allows us to remove a few codes dependent on eventlet.

Change-Id: I24fa76abbe11a221fceea232a7266b53752c75ec
2024-11-02 16:22:26 +00:00
Takashi Kajinami
2fe6b92906 Check if subprocess module is patched directly
eventlet patches subprocess module since 0.35.2[1]. So we no longer
need that old workaround.

[1] 614a20462a

Change-Id: I75088e04cc3ba9a8bbb0a7af74650fc1ebff4c95
2024-11-02 13:56:21 +00:00
Takashi Kajinami
1f5ba0ca87 Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by
 $ pyupgrade --py3-only $(git ls-files | grep ".py$")
to modernize the code according to Python 3 syntaxes.

Also add the pyupgrade hook to pre-commit to avoid merging additional
Python 2 syntaxes.

Change-Id: I9d54c11642acb341cc5db1267f5a91d4740f932c
2024-10-21 19:21:49 +09:00
Takashi Kajinami
dcc891427a Remove workaround for eventlet bug #592
This code worked around a bug in eventlet[1] that has been fixed in
6533958f5fcec8b1577f56834ea2dc75a4f211e3. The fix has been available in
every eventlet release since v0.27.0.

[1] https://github.com/eventlet/eventlet/issues/592

Co-Authored-By: Cyril Roelandt <cyril@redhat.com>
Change-Id: I377f664b4e5092ee0e2a95a7e277f1c8a1e18953
2024-09-28 09:51:30 +09:00
Takashi Kajinami
925c2a241f Fix wrong stacklevel
We don't have to look for upper call layers for that specific warning
messages.

Change-Id: Ifdc568c29e29c049dede280b76010a2c69928e76
2024-02-22 00:02:38 +09:00
Takashi Kajinami
d51723fa64 Drop fallback to DEFAULT section
The fallback was added 9 years ago, in 0.1.0 release[1].

[1] c98d5edc44ad44da7196afa4b6bba0a2afea1f8e

Change-Id: I3b66c5f9df58eaeea9fc51a6c0b83af2e39a525b
2024-02-07 23:17:36 +00:00
Takashi Kajinami
bd96105622 Deprecate Windows support
Because WinStackers project has been retired, running OpenStack on
Windows operating systems is no longer maintained.

Change-Id: If4ad14a9f7f974c120c6d70c826a1bba358052a3
2023-11-18 17:37:43 +00:00
Balazs Gibizer
ee3f73a133 Fix fair internal lock used from eventlet.spawn_n
The fasteners lib in version 0.15.0 removed the
threading.current_thread workaround for eventlet[1] because eventlet
seemed to fixed the current_thread issues tracked in [2]. However the
fix for [2] only fixed half of the problem. The threading.current_thread
call works if it is called from thread created by eventlet.spawn.
However if the thread is created with eventlet.spawn_n then
threading.current_thread is still broken and returns the ID of the
python native thread.

The fasteners' ReaderWriterLock depends heavily on
threading.current_thread to decide which thread holds a lock and to
allow re-entry of that thread. This leads to the situation that
multiple threads created from spawn_n could take the same
ReaderWriterLock at the same time.

The fair internal lock in oslo.concurrency uses ReaderWriterLock and
as a result such lock is broken for threads created with spawn_n.

Note that this issue was raised with eventlet in [3] when the nova team
detected it via a direct usage of ReaderWriterLock in the nova test
code. As [3] did not lead to a solution in eventlet nova implemented a
nova local fix for the test code in [4].

However now we detected that oslo.concurrency is affected by this issue
as well.

This patch restores the workaround that was removed by [1].

Note that a fasteners issue [5] also opened to restore the
workaround[1].

[1] 467ed75ee1
[2] https://github.com/eventlet/eventlet/issues/172
[3] https://github.com/eventlet/eventlet/issues/731
[4] https://review.opendev.org/c/openstack/nova/+/813114
[5] https://github.com/harlowja/fasteners/issues/96

Closes-Bug: #1988311
Change-Id: Ia873bcc6b07121c9bd0b94c593567d537b4c1112
2022-09-05 13:29:04 +02:00
Balazs Gibizer
796203c948 Prove that spawn_n with fair lock is broken
The fasteners lib in version 0.15.0 removed the
threading.current_thread workaround for eventlet[1] because eventlet
seemed to fixed the current_thread issues tracked in [2]. However the
fix for [2] only fixed half of the problem. The threading.current_thread
call works if it is called from thread created by eventlet.spawn.
However if the thread is created with eventlet.spawn_n then
threading.current_thread is still broken and returns the ID of the
python native thread.

The fasteners' ReaderWriterLock depends heavily on
threading.current_thread to decide which thread holds a lock and to
allow re-entry of that thread. This leads to the situation that
multiple threads created from spawn_n could take the same
ReaderWriterLock at the same time.

The fair internal lock in oslo.concurrency uses ReaderWriterLock and
as a result such lock is broken for threads created with spawn_n.

Note that this issue was raised with eventlet in [3] when the nova team
detected it via a direct usage of ReaderWriterLock in the nova test
code. As [3] did not lead to a solution in eventlet nova implemented a
nova local fix for the test code in [4].

However now we detected that oslo.concurrency is affected by this issue
as well.

This patch adds tests to show the scope of the problem.

Note that the coverage tox target is changed to explicitly enable native
threading otherwise it runs eventlet specific tests in a native
environment.

Also note that [5] was opened to reintroduce the workaround[1] in fasteners.

[1] 467ed75ee1
[2] https://github.com/eventlet/eventlet/issues/172
[3] https://github.com/eventlet/eventlet/issues/731
[4] https://review.opendev.org/c/openstack/nova/+/813114
[5] https://github.com/harlowja/fasteners/issues/96

Related-Bug: #1988311
Change-Id: Ibc193c855b49b95b46ebd2aac82ea89e33f885f0
2022-09-05 13:27:37 +02:00
Gorka Eguileor
9800d58cb3 Log when waiting to acquire lock
We currently have no log entry when we start trying to acquire a lock.

In general this is ok, but there are cases where it can be problematic,
for example if we have a deadlock situation or if a lock takes a very
long time to be acquired.

In those scenarios looking at the logs we would see the operation
proceed normally and suddenly go completely silent without knowing that
it's waiting for a lock to be freed.

This patch adds a debug log message right before trying to acquire the
lock so we can detect those situations.

Change-Id: I1354dfb98b0927ae167802ecc4ab1d34f6b4d720
2022-07-07 20:01:48 +02:00
OpenStack Proposal Bot
e158ca49be Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: Ic6a8cb3efdddaa809b1381a7d9b96e50b7e9da9f
2022-06-21 03:42:17 +00:00
Zuul
5d17e5fb44 Merge "Allow python_exec kwarg to be None" 2022-04-05 12:04:56 +00:00
Thiago Brito
11210a957c Fix RequiredOptError when missing lock_path
When lock_file is not present on the [oslo_concurrency] section of the
config file, we are getting a misleading error saying that it is not
preset on the DEFAULT group. This commit fixes it by providing the group
arg to the RequiredOptError constructor.

Closes-Bug: #1966320

Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Change-Id: Idee6987739917c7eae4faee15a66085a9ef7f6d2
2022-03-24 15:13:48 -03:00
Brian Rosmaita
a937c5562f Allow python_exec kwarg to be None
processutils.execute() is documented to take a python_exec kwarg and
default to using sys.executable if that argument isn't set.  It is
convenient (and more intuitive) for this behavior to also occur if
the argument is present with value None.

Closes-bug: #1962603
Related-bug: #1962581
Change-Id: I2e1f187feaf4bf9fbfaf04fce78efa0cba49fc07
2022-03-01 13:05:22 -05:00
Romain Poupin
a9ccf0a64d Add support for non-blocking locks
This adds support for a non-blocking behavior of the lock : the context-based
lock now raises an AcquireLockFailedException if the lock can't be acquired on
the first try.

At a higher layer, we just caught this exception inside the 'synchronized'
decorator to prevent calling the wrapped function. In which case, we then
trace this acquisition failure.

For now at least, disabling blocking is not supported when using fair locks
because the ReaderWriterLock.write_lock() provided by the fasteners module
doesn't implements this behavior.

Change-Id: I409da79007c9ba4fb8585da881e3d56998b0b98b
2021-06-24 09:45:48 +02:00
dengzhaosen
0139c6ccac Remove references to 'sys.version_info'
We support Python 3.6 as a minimum now, making these checks no-ops.

Change-Id: I1ff344d345b56246e6a86f7761ef900e42daefa2
2021-04-27 02:53:57 +00:00
Rodolfo Alonso Hernandez
6533958f5f Monkey patch original current_thread _active in processutils
Monkey patch the original current_thread to use the up-to-date _active
global variable. This solution is based on that documented at:
https://github.com/eventlet/eventlet/issues/592

Change-Id: I0a2c1e0d8a8cad99d68100d25e88e0d3a2eb8f5c
Related-Bug: #1863021
2020-09-30 11:28:12 +00:00
Dmitry Tantsur
35e4df4677 Add support for timeout to processutils.execute
This is a standard Python feature since 3.3.

Change-Id: Ib13af5aab0ebbae532f1e46309ad6023ca94d6b9
2020-06-24 10:53:21 +02:00
Zuul
80a6e1d489 Merge "Don't warn on lock removal if file doesn't exist" 2020-06-08 17:05:16 +00:00
Zuul
174b29162d Merge "Stop to use the __future__ module." 2020-06-03 17:38:55 +00:00
Zuul
e7f54d3ee8 Merge "Monkey patch original current_thread _active" 2020-06-03 11:46:52 +00:00
Hervé Beraud
8244a8a69e Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: I11cc9e15a26cfc663296d6a99a5705d764654b3f
2020-06-02 20:38:50 +02:00
Andreas Jaeger
dd5a141771 Remove six usage
Remove the usage of six, the python2-python3 compatibility lib.

Change-Id: I56e479d0749504d65be1cf2b5235d454b0b90a1a
2020-05-09 16:42:30 +02:00
Arthur Dayne
9168889dba Monkey patch original current_thread _active
Monkey patch the original current_thread to use the up-to-date _active
global variable. This solution is based on that documented at:
https://github.com/eventlet/eventlet/issues/592

Change-Id: I876e2825da628d51c9977a4eec0c2ef05aed3229
Closes-Bug: #1863021
2020-05-08 19:42:26 +08:00
OpenStack Proposal Bot
463b32d343 Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: I87ec1f7fc4fb7a70b748905d5dad4e7ffc132aa8
2020-04-29 09:03:41 +00:00
Sean McGinnis
60a157a09b
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I792a17f4b2667713503e6bc10cfabed9905d8535
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-03-31 14:44:19 -05:00
Gorka Eguileor
e57a1c829d Don't warn on lock removal if file doesn't exist
There may be cases were library users want to request the removal of an
external lock that may not have been created and don't want to pollute
the logs when the file is not present.

We raise the log level from info to warning, but we don't log it if the
file didn't exist, since the end result the caller wanted is there.

Change-Id: I5ce8be34c9f2c4c59ea99dabc6760c3300f743a3
2020-03-18 14:57:49 +01:00
Zuul
27f8a5d01c Merge "Fix remove_lock test" 2019-12-20 16:31:35 +00:00
Gorka Eguileor
e2c71e9937 Fix remove_lock test
Current external lock removal unit tests are not really testing the
removal as they don't bother to check that we are calling os.remove

This patch fixes this situation by mocking the appropriate methods and
checking that they are being called (or not) as expected.

Change-Id: I25efc1638106431ee36e760c0c213a1a675ec908
2019-12-20 13:35:20 +01:00
Eric Fried
c08159119e Spiff up docs for *_with_prefix
Following up on comments in [1], clarify and unify the docs for the
following lockutils methods:

- lock_with_prefix
- synchronized_with_prefix
- remove_external_lock_file_with_prefix

[1] I4e723ee3be1e57c543684390b607c84388c6e930

Change-Id: I4179e8732dba7367bd0c835cbd11939ca7b8cc42
2019-11-04 15:28:27 -06:00
Eric Fried
fec03875e9 Add lock_with_prefix convenience utility
There's a convenience wrapper around the lockutils.synchronized
decorator that lets oslo.concurrency consumers set up a prefix to use
for all lock files (presumably to obviate collisions with other
consumers when using jejune lock names, like 'lock'). This commit adds
an equivalent wrapper around lockutils.lock, the context manager
counterpart to the lockutils.synchronized decorator.

Note that the unit test added for lock_with_prefix is pretty bare; but
it follows the precedent set by the existing tests. Future commits
should make all these tests more thorough/robust.

Change-Id: I4e723ee3be1e57c543684390b607c84388c6e930
2019-09-17 16:23:01 -05:00
Eric Fried
fe86f5e4ae Some test cleanup
- Tests are based on oslotest.base.BaseTestCase, which uses the
  NestedTempFile fixture, which uses the TempDir fixture, which adds a
  cleanup routine to remove the base temporary directory it creates.
  There's therefore no need for tests to clean up this directory, so all
  the code that does that is removed.
- The eventlet incarnation of tests was trying to make use of the `env`
  external without whitelisting it, resulting in an ugly red deprecation
  warning. This commit adds `env` to whitelist_externals in [testenv].
- A handful of typos in the Beowulf quote are corrected.

Change-Id: I91cc52e00e0a918dadd2a3a771bd322b0f165ed2
2019-09-17 16:13:30 -05:00
jacky06
443ed81b43 Replace git.openstack.org URLs with opendev.org URLs
1. Thorough replacement of git.openstack.org URLs with their
opendev.org counterparts.
2. dict_object.keys() is not required for *in* operator

Change-Id: Ie1d0c828522ae92b01f28e7017fd7fd42c2e91e7
2019-05-05 13:01:11 +08:00
ZhijunWei
3ea7c472cf Update hacking version
Use latest release 1.1.0 and compatible changes w.r.t pep8

Change-Id: Iec0c74ab679d6046b12f1d16ecd5cb6dfa74b3ed
2019-01-21 19:32:38 -05:00
Zuul
0767ddf4c2 Merge "Add support for fair locks" 2018-11-05 23:22:41 +00:00
Chris Friesen
2b55da68ae Add support for fair locks
This adds support for a "fair" variant of the lock.  When there are
multiple entities within a single process that are blocked waiting
for the lock the fair lock will ensure that they acquire the lock
in FIFO order.

For now at least, when fair locks are in use we don't support
the "semaphores" argument.

If external locks are enabled, the inter-process ordering will be
determined by the underlying OS lock ordering and process scheduling.

Change-Id: I37577becff4978bf643c65fa9bc2d78d342ea35a
2018-11-02 10:40:23 -06:00
Doug Hellmann
9a4dea3600 ignore warning from bandit for using shell=
The functions in this library are meant to wrap subprocess, and
sometimes we do want to allow passing shell=True, so mark that line
with nosec to ignore B604.

Change-Id: Iab676449e543a4fdabee62efa9283940d30e3398
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-08-16 15:40:59 -04:00
Vu Cong Tuan
a9d728b71e Switch to stestr
According to Openstack summit session [1],
stestr is maintained project to which all Openstack projects should migrate.
Let's switch to stestr as other projects have already moved to it.

[1] https://etherpad.openstack.org/p/YVR-python-pti

Change-Id: I753f32ecf3275cf49d8c93bf648a6a26bc6da8e7
2018-07-04 08:18:31 +07:00
Ben Nemec
ca3c45044b Switch pep8 job to python 3
pep8 under python 3 is more strict than under python 2, so to make
sure our projects meet the more strict standards we want to run the
pep8 jobs using python 3 by default.

Change-Id: Ice3cffa36e9167f2f1f30337372cf9187af5e02e
2018-04-12 16:28:07 +00:00
OpenStack Proposal Bot
e1483af309 Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: I38a631e8a24e8807dc59b14f368ab21caa02aba5
2018-03-01 07:17:38 +00:00
prashkre
21ae27e66d Mask passwords only when command execution fails
At many places, processutils.ssh_execute() is being invoked to run
a command over ssh and output returned is parsed to get appropriate
information. In this flow, unsanitized output is being expected
where processutils.ssh_execute() was invoked but found that
output like volume details(containing "password" string in its name)
is being masked away with strutils.mask_password(stdout) even though
no error occured during command execution.

This is regression issue from patch[0]. In this fix, stdout and stderr
in processutils.ssh_execute() will be masked only when
ProcessExecutionError exception is thrown i.e. command execution failed
due to some reasons.

[0] https://github.com/openstack/oslo.concurrency/commit/
ae9e05bfc3d7ec867bd6ec78c301f11c2bdd0d5f

Change-Id: I2ce344330905eef437ef3f89a2a01169a30df8ab
Closes-Bug: #1482382
2018-02-22 06:31:01 +00:00
Matthew Treinish
55e06261aa
Add python_exec kwarg to processutils.execute()
This commit adds a new kwarg to the process_utils.execute() function to
specify the python executable to use when launching python to check
prlimits. This is necessary when processutils.execute() is called from
inside an API server running with uwsgi. In this case sys.executable is
uwsgi (because uwsgi links libpython.so and is actually the interpreter)
This doesn't work with the execute() function because it assumes the
cpython interpreter CLI is used for the arguments it uses to call the
prlimits module. To workaround this and enable API servers that may run
under uwsgi to use this those applications can simply pass in an
executable to use.

Longer term it might be better to migrate the prlimits usage to call
multiprocessing instead of subprocessing python. But that would require
a more significant rewrite of both processutils and prlimit to
facilitate that.

Change-Id: I0ae60f0b4cc3700c783f6018e837358f0e053a09
Closes-Bug: #1712463
2018-01-09 10:22:45 -05:00
Brian Rosmaita
a7d35ccd81 Minor correction to docstrings
Noticed that the generated docs were displaying the parameter
to trycmd() in a misleading way, fixed the syntax there and for
get_worker_count().

Change-Id: If989523be81e917ed62f525f2431f368dcf13c7a
2017-08-30 07:05:34 -04:00
Lucian Petrut
3ac3c169ad Windows: ensure exec calls don't block other greenthreads
eventlet.green.subprocess is not actually greenthread friendly on
Windows. It just uses the native subprocess.Popen in this case.

For this reason, exec calls do not yield on Windows, blocking other
greenthreads.

This change avoids this issue by wrapping the 'communicate' call
using eventlet.tpool.

We're also ensuring that subprocess.Popen uses *native* threads
internally in order to avoid deadlocks when passing data through
stdin.

Change-Id: Ic25fd1b61b5498f16e6049cbbe0877492f8aab4d
Closes-Bug: #1709586
2017-08-16 13:59:02 +03:00
Gary Kotton
9b3c8f34a9 Add debug log to indicate when external lock is taken
In a case when a number of threads are concurrently accessing a
resource that has a external lock there is no indication when
one of the threads has taken the external lock.

This patch adds in a debug log to try and add some clarity.

Change-Id: Ibd7cfd3b39370b1a54f2ab50c75c6b92a876ae1a
2017-07-26 17:54:27 +03:00
Jenkins
88583edbb4 Merge "Remove log translations" 2017-07-12 21:13:07 +00:00
OpenStack Proposal Bot
2e08f5d9a5 Imported Translations from Zanata
For more information about this automatic import see:
http://docs.openstack.org/developer/i18n/reviewing-translation-import.html

Change-Id: Ia11093f4fd2fa12077a202872b3ed6ce79e34e83
2017-07-12 07:34:06 +00:00