Commit Graph

227 Commits

Author SHA1 Message Date
Terry Wilson d026081ca4 Make signal handling order predictable
Due to the unordered nature of sets, it is possible for signal
handlers like _gracefull_shutdown() to run first and clear the
_signal_handlers before other registered handlers have run.

This patch converts _signal_handlers from a set to a list and
then runs the handlers LIFO similar to how atexit functions are
run. Given that the handlers added in service.py are added after
clearing the signal_handlers, they are guaranteed to be the first
in the list and the last run.

Change-Id: Ief3ab2f56fa3d805296709e12e5f7a71560f7b6e
Closes-Bug: #2057809
Related-Bug: #2056366
Signed-off-by: Terry Wilson <twilson@redhat.com>
2024-03-13 16:00:38 +00:00
Zuul 3900aa7db5 Merge "Fix native threads on child process" 2023-12-19 19:14:19 +00:00
Takashi Natsume 845fc45fab Fix misuse of assertTrue
Replace assertTrue with assertEqual.

Change-Id: I918930a6fd3980297ee7d68dd6c9397416fb3335
Closes-Bug: 1988308
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2022-09-19 01:12:30 +00:00
Gorka Eguileor 67daa4b3c2 Fix native threads on child process
When the parent process used eventlet tpool to run code in native
threads then anything the child tries to run in a native thread will
hang forever.

The reason for that is that the parent has initialize the pool of
threads and use a flag to mark that it has been initialized, and when
the child is forked then it will have the flag saying that it has been
initialized and expects the threads to be running, but they are not.  So
there is no thread to pick up the job when a greenlet queues the job, so
the greenthread waits forever to get the result of the operation.

This patch tells eventlet's tpool to clean things up on the child just
after forking, that way if the child uses native threads tpool will
spawn all the threads again.

Closes-Bug: #1983949
Change-Id: If2421427c48faa976d6c6ee9bafe4d563288037b
2022-08-08 17:56:13 +02:00
OpenStack Proposal Bot a27acfe23f Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: I67eae9c8e73bac373f6c86e256f508c1fe1ff1db
2022-06-21 03:50:34 +00:00
Bence Romsics 6552b9a820 Make debug option of wsgi server configurable
Because in some deployments tracebacks in API responses are unwanted
for security reasons.

Change-Id: I8a2acea7393c369bfa7d7822f21b4d40d56d6739
Needed-By: https://review.opendev.org/c/openstack/neutron/+/818391
Partial-Bug: #1951429
2021-12-21 11:23:23 +00:00
Zuul 7a62271de3 Merge "Fix fo() backdoor command for non-class objects" 2021-10-13 15:29:08 +00:00
Sebastian Lohff eb191548cf Fix fo() backdoor command for non-class objects
The backdoor command fo() uses isinstance() to check if an object is an
instance of a class. This only works with objects that have a __class__
attribute, else an AttributeError is raised by isinstance(). This is
seldomly the case, though if there is one such object fo() will cease to
work. Therefore we need to protect us against this case by checking for
a __class__ attribute before calling isinstance().

An example for an object without __class__ would be
functools._lru_list_elem.

Change-Id: Ia4c5cbdc249535d36f6e71f7b2a7359bc6fdf219
Closes-Bug: #1946072
2021-10-05 08:29:50 +00:00
Julia Kreger d3ee8ef00a Fix BackOffLoopingCall error so it is not misleading
The backoff looping call logging was previously making
a decision on if timeout had or was going to be exceeded
by including idle time and it's internal time, however
this is misleading as the overall operation may take
30 seconds externally, a user initiated timeout of 30
seconds is requested, and the error might say something
like 18 seconds has passed, when that is incorrect.

The logic is actualy correct, the logging was just
misleading.

Fixes the exception message to use the total time.

Change-Id: Ie9ef5a53abb24f6ab7de0ad57a672c0a8d7ff0ee
2021-09-16 10:18:35 -07:00
dengzhaosen aea7627eb0 Remove references to 'sys.version_info'
We support Python 3.6 as a minimum now, making these checks no-ops.

Change-Id: Ibaa2cdb7cc27f541aeb778782813354df2911156
2021-04-29 09:10:24 +08:00
Corey Bryant 383701e231 Drop custom implementation of EVENTLET_HUB
Eventlet uses monotonic clocks by default since 0.21, hence no need
to patch that anymore.

Closes-Bug: #1906262
Co-Authored-By: Dimitri John Ledkov <xnox@ubuntu.com>
Co-Authored-By: Michael Hudson-Doyle <michael.hudson@ubuntu.com>
Change-Id: I72106068d99cc174412aa3026082ec63f1d895fe
2020-11-30 09:00:47 -05:00
Hervé Beraud 10ce88ed2b Adding pre-commit
Introduced changes:
- pre-commit config and rules
- Add pre-commit to pep8 gate, Flake8 is covered in the pre-commit hooks.
- Applying fixes for pre-commit compliance in all code.

Also commit hash will be used instead of version tags in pre-commit to
prevend arbitrary code from running in developer's machines.

pre-commit will be used to:
- trailing whitespace;
- Replaces or checks mixed line ending (mixed-line-ending);
- Forbid files which have a UTF-8 byte-order marker
  (check-byte-order-marker);
- Checks that non-binary executables have a proper
  shebang (check-executables-have-shebangs);
- Check for files that contain merge conflict strings
  (check-merge-conflict);
- Check for debugger imports and py37+ breakpoint()
  calls in python source (debug-statements);
- Attempts to load all yaml files to verify syntax (check-yaml);
- Run flake8 checks (flake8) (local)

For further details about tests please refer to:
https://github.com/pre-commit/pre-commit-hooks

Change-Id: Ib18f38dbec90c62e870307bf22a8b4f193237bce
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-09-08 14:26:37 +02:00
Rodolfo Alonso Hernandez 91d4eee90f Do not import "oslo.log" in the main module
The LOG instance is not being used and there is no need to import
"oslo_log". This will also prevent the circular import detected
in the related bug.

Change-Id: Id560ba80472b9efbcfbc289a18d4df312961fdb1
Related-Bug: #1888213
2020-07-20 15:49:54 +00:00
Zuul 585768b94d Merge "Fix wsgi SSL tests for wsgi module under python 3" 2020-06-23 18:30:37 +00:00
Zuul 8fd3ce22da Merge "Reactivate wsgi test related to socket option under python 3" 2020-06-23 18:30:36 +00:00
Zuul ce6262437d Merge "Align tests with monkey patch original current_thread _active" 2020-06-22 17:22:56 +00:00
Hervé Beraud caf66be763 Fix wsgi SSL tests for wsgi module under python 3
Previously some tests were ignored under python 3 environment, this was
due to some design changes introduced by python 3.7 [1] in the SSL
module of the stdlib. These changes reactivate some of them (some other
are still skipped and needs further works).

Indeed, when we try to use requests with SSL in a monkey patched
environment we faced the following issue:

```
TypeError: wrap_socket() got an unexpected keyword argument '_context'
```

This is due to the fact that we are in a monkey patched environment
where `requests` is monkey patched too.

We don't need `request` for our needs. Indeed we can easily send
http requests through low level socket. Our main goal is to test
our wsgi server and not to test the `requests` library, and `requests`
was just used to make the code more simpler.

In our case we can implement a code dedicated to send request to our green
server, unlock our tests and move away from this bug/side effect.

Also this reactivated test will check WSGI server with and without SSL,
so these changes add changes that allow us to submit a request without
wrapping the socket with SSL.

These changes move away from `requests` which is badly monkey patched by
eventlet [1]. Now we use monkey patched socket and ssl to
request the green server which is executed in background. Low level
(monkey patched) modules could help us to skirt layers that are possibly
badly monkey patched on higher level modules (urllib, requests, etc...).

[1] https://github.com/eventlet/eventlet/issues/526#issuecomment-482694279
[2] https://github.com/eventlet/eventlet/issues/526

Change-Id: I3a018d507d102266c1e2fc9b6732a9c09fa2bb49
Closes-Bug: #1482633
2020-06-17 12:23:42 +02:00
Hervé Beraud fb1ed4085b Reactivate wsgi test related to socket option under python 3
Previously these tests was ignored surely because the WSGI tests
with SSL were broken due to some design changes introduced by python 3.7 [1]
in the SSL module of the stdlib.

However, unlike the other WSGI/SSL tests these changes don't use
the `requests` module or high level modules which are broken by
the monkey patching of the stdlib.

I suppose previous developers simply turned off all of tests related to
WSGI/SSL without much more details than "SSL tests with python 3 and eventlet
is broken" but some of them don't need much more work than just reactivate
them to be ran successfully.

This test seems to work without change, and it run successfully locally.

Let reactivate this test.

Change-Id: Ie0257af10a9439de8ec124a698ca75778bdf90b5
Partial-Bug: #1482633
2020-06-16 14:34:30 +02:00
Hervé Beraud ebc2d8a42f Fix wsgi/SSL/ipv6 tests for wsgi module under python 3
Previously some tests were ignored under python 3 environment, this was
due to some design changes introduced by python 3.7 [1] in the SSL
module of the stdlib. These changes reactivate some of them (some other
are still skipped and needs further works).

Indeed, when we try to use requests with SSL in a monkey patched
environment we faced the following issue:

```
TypeError: wrap_socket() got an unexpected keyword argument '_context'
```

This is due to the fact that we are in a monkey patched environment
where `requests` is monkey patched too.

We don't need `request` for our needs. Indeed we can easily send
http requests through low level socket. Our main goal is to test
our wsgi server and not to test the `requests` library, and `requests`
was just used to make the code more simpler.

In our case we can implement a code dedicated to send request to our green
server, unlock our tests and move away from this bug/side effect.

These changes move away from `requests` which is badly monkey patched by
eventlet [1]. Now we use monkey patched socket and ssl to
request the green server which is executed in background. Low level
(monkey patched) modules could help us to skirt layers that are possibly
badly monkey patched on higher level modules (urllib, requests, etc...).

[1] https://github.com/eventlet/eventlet/issues/526#issuecomment-482694279
[2] https://github.com/eventlet/eventlet/issues/526

Change-Id: Iacdde51d2d923bafa3263fa3dc12de8d501d471a
Partial-Bug: #1482633
2020-06-16 13:35:48 +02:00
Hervé Beraud bfc8172942 Fix some SSL tests for wsgi module under python 3
Previously some tests were ignored under python 3 environment, this was
due to some design changes introduced by python 3.7 [1] in the SSL
module of the stdlib. These changes reactivate some of them (some other
are still skipped and needs further works).

Indeed, when we try to use requests with SSL in a monkey patched
environment we faced the following issue:

```
TypeError: wrap_socket() got an unexpected keyword argument '_context'
```

This is due to the fact that we are in a monkey patched environment
where `requests` is monkey patched too.

We don't need `request` for our needs. Indeed we can easily send
http requests through low level socket. Our main goal is to test
our wsgi server and not to test the `requests` library, and `requests`
was just used to make the code more simpler.

In our case we can implement a code dedicated to send request to our green
server, unlock our tests and move away from this bug/side effect.

These changes move away from `requests` which is badly monkey patched by
eventlet [1]. Now we use monkey patched socket and ssl to
request the green server which is executed in background. Low level
(monkey patched) modules could help us to skirt layers that are possibly
badly monkey patched on higher level modules (urllib, requests, etc...).

[1] https://github.com/eventlet/eventlet/issues/526#issuecomment-482694279
[2] https://github.com/eventlet/eventlet/issues/526

Change-Id: Id44ad12a1cf3fd7090a67bb6e8e42bfdc47502cf
Partial-Bug: #1482633
2020-06-16 12:58:13 +02:00
Hervé Beraud d6f72ec70b 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: I42e2fc25eaec2e79540c3ab60d8752141637f7b8
2020-06-02 20:40:55 +02:00
Hervé Beraud d08727effa Drop six usages
Support of python 2.7 was dropped during the Ussuri cycle so we can now
drop six usages too.

Change-Id: I56a9c0641fd9bce613943ff938d33178d263eedf
2020-05-26 15:20:01 +02:00
Hervé Beraud b9f8224006 Align tests with monkey patch original current_thread _active
Recent changes [1] introduced an eventlet fix to monkey patch original
current_thread _active.

The goal was to monkey patch the original current_thread to use the
up-to-date _active global variable. This solution is based on that
documented at: eventlet/eventlet#592

I think we need this patch on unit test too to ensure a consistent
behavior, so these changes doing that.

[1] https://review.opendev.org/#/c/725359/

Change-Id: I7b6cca86e44261bf2f953be74e9738ac09507649
2020-05-11 15:58:22 +02:00
Zuul 38306c8319 Merge "Remove monotonic usage" 2020-05-07 16:58:27 +00:00
Sean McGinnis 6793fe15b3
Remove monotonic usage
The monotonic package was needed for monotonic time operations when
running under Python runtimes older than 3.3. Since we now only support
versions higher than this, this third party package requirement can now
be removed.

Change-Id: Ie99411882822a5db47462fcb2748c6e978587b8c
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-05-05 09:37:02 -05:00
Corey Bryant b83ce33831 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: Icc2277b72f6f8f7812be22c43bbc281334aa2373
Closes-Bug: #1863021
2020-05-04 14:07:31 -04:00
Sean McGinnis 7d3578827d
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: Ic18f03681c14131217e3025e2cb0cca46ada84ee
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-20 09:29:01 -05:00
Stephen Finucane e86fb9dcce Add 'is_available' function
Resolves the following warnings seen in the likes of nova:

    DeprecationWarning: Please provide `is_available()` function in your
    custom Eventlet hub <module 'oslo_service' from
    '../oslo_service/__init__.py'>."

    It must return bool: whether hub supports current platform. See
    eventlet/hubs/{epoll,kqueue} for example.

Since we're simply taking the default hub provided by eventlet and
overriding a single attribute, we will always have support so set the
attribute.

Change-Id: I219cf652526802b8212fe8a8f6c499e9aa24a3cf
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2019-11-27 16:56:08 +00:00
Bernhard M. Wiedemann af8e8c2593 Extend test cert validity to 2049
to make tests pass after 2023

Background:
As part of my work on reproducible builds for openSUSE, I check
that software still gives identical build results in the future.
The usual offset is +15 years, because that is how long I expect
some software will be used in some places.
This showed up failing tests in our package build.

See https://reproducible-builds.org/ for why this matters.

Note: I tested that i586 builds still pass tests on 2037-12-01
so this change introduces no year2038 problem.

Change-Id: I0110914432c4b557dcabcac0fad1ba54bcd8be85
2019-10-10 10:26:00 +02:00
Zuul 41186e6163 Merge "restart: don't stop process on sighup when mutating" 2019-08-30 11:51:58 +00:00
Mohammed Naser e7dd291689 restart: don't stop process on sighup when mutating
It seems that the code for handling SIGHUP currently calls stop()
on the service, then calls reset(), then calls start() on it again.

This is effectively a full service restart, which breaks the whole
point behind using SIGHUP for hot and quick reloads.  It also breaks
our downstream projects in a few ways where they lose RPC on reload
due to the fact that they don't expect to have stop() called on a
reset().

This patch removes the stop and start when the restart_method is
set to 'mutate' because in that case we should just be signaling
the service to check for changes in its mutable config options.
It also changes the signal sent to children in that case to
SIGHUP, since SIGTERM will cause unnecessary restarts of child
processes.

The previous behavior is maintained for the 'reload' restart_method
since that does a complete reload of the service config, which is
not safe to do without restarting the service completely.

Change-Id: I86a34c22d41d87a9cce2d4ac6d95562d05823ecf
Closes-Bug: #1794708
Co-Authored-By: Ben Nemec <bnemec@redhat.com>
2019-08-29 14:30:58 -05:00
Zuul ac29c82699 Merge "Make PID availabe as formatstring in backdoor path" 2019-05-30 01:29:43 +00:00
Sebastian Lohff dd174fbfde Make PID availabe as formatstring in backdoor path
When multiple processes are spawned with the same configuration
each process has the same backdoor_socket path configured and
only the first process able to bind to the socket can later be
accessed via the backdoor. To give each process a unique socket path
we now expose the PID of the process as a format string argument,
which can then be used like this:

backdoor_socket = /var/lib/neutron/backdoor-{pid}

Change-Id: I3f86f4867eb0cd5010abadf68620aa3450d3e64d
2019-05-22 16:21:44 +02:00
chenke 60e160367d Add workers' type check before launching the services
If user set the type of worker to str or others, there will
be no error here, but a lot of processes will be created,
which may cause the system to crash.

I recommend adding a type check here.

Change-Id: I3ad0f7ec59f29a3106d23b057327c3dfef19a98f
2019-05-09 18:23:07 +02:00
Zuul 4ac1da03fb Merge "Update hacking version" 2019-02-19 19:21:07 +00:00
ZhijunWei 671cbd6024 Update hacking version
Use latest release 1.1.0 and compatible changes w.r.t pep8

Change-Id: I8bb814f8db8c87ba6b757be482d79d40548a137d
2019-02-13 17:08:38 +08:00
Zuul fdcfd0fcff Merge "Profile Oslo Service processes" 2019-02-11 21:31:19 +00:00
Zuul 3c645a77ec Merge "Avoid eventlet_backdoor listing on same port" 2019-01-17 13:52:22 +00:00
venkata anil a04daefbb1 Profile Oslo Service processes
This patch enables profiling (capturing function call trace like
cProfile [1]) worker processes on the fly while service is running.
User requests the oslo service process to start profiling by writing
"prof()" command to backdoor socket, once the service (like
neutron-server) finishes expected processing (example finishing API
call), user again writes "prof()" command with file name as argument
to dump the function calltrace stats. Stats file (in pstat format
with user provided filename by adding .prof) will be generated in
temp directory.

For example, to profile neutron server process,
1) echo "prof()" | nc localhost 8002
2) Issue neutron command (or run rally scenarios tests)
   neutron net-create n1
   neutron port-create --name p1 n1
   neutron port-delete p1
   neutron net-delete n1
3) echo "prof('neutron')" | nc localhost 8002
where 8002 is the port which we set like below in neutron.conf
backdoor_port=8002

We can later print the stats from the trace file like below
stats = pstats.Stats('/tmp/neutron.prof')
stats.print_stats()
The trace file will look like in (for above neutron API calls) [2].

We use Yappi with context set to greenlet [3] to profile greenlets.
We can't use GreenletProfiler [4], which does the same [5]
1) as it is no more maintained
2) Also compiling yappi source inside GreenletProfiler is failing for
   python3.

[1] https://docs.python.org/2/library/profile.html
[2] https://gist.github.com/venkataanil/64d5e672bf0206dc151e73fc1058a983
[3] https://bitbucket.org/sumerc/yappi/pull-requests/3
[4] https://pypi.org/project/GreenletProfiler/
[5] https://emptysqua.re/blog/greenletprofiler/

Depends-On: Ibea0cdb732923f1b53d5cb6aeeb4041fb5973494
Change-Id: Id2418093494f1e233a653f6c73bd6894e4a40184
2019-01-16 07:38:13 -05:00
Ben Nemec 4c0d4490e8 Use eventletutils Event class
Instead of having a copy-pasted version in this project, let's just
use the original directly. It is added to the public API of
oslo.utils in the dependency.

Depends-On: https://review.openstack.org/614806
Change-Id: If0dfac2505d097c117ef94c99399b1614f1e1f8f
2019-01-10 22:06:11 +00:00
venkata anil 811650783d Avoid eventlet_backdoor listing on same port
Oslo.service is binding to same port when we provide a port range
as eventlet is internally setting SO_REUSEPORT flag (starting from
eventlet version v0.20). And there is a flag (reuse_port)
introduced in v0.22 to give control to user to avoid SO_REUSEPORT.
In this patch, first we try passing reuse_port=False, if this fails
then directly open socket and listen instead of eventlist.listen.

Closes-Bug: #1810280
Change-Id: Idc842acc7e430199c76fe12785b0bf0e7a58e121
2019-01-03 23:41:30 -05:00
Zuul d987a4a84c Merge "Actually test child SIGHUP signal" 2018-12-24 10:42:49 +00:00
Zane Bitter fef1c1543b Deprecate the ThreadGroup.cancel() API
This API is awkward, inefficient, incoherent, and unintuitive. The bug
fix for which it was originally added was abandoned in favour of a
different approach, so it was never used. It appears that no consumers
are currently calling it. It would be best if none started.

Add a deprecation warning to discourage its use and allow us to remove
it altogether at some point in the future.

Change-Id: I9559c7051024019fac957385faced645920b815c
2018-12-20 11:11:23 +13:00
Zuul fdd65ed5e9 Merge "Document the threadgroup module" 2018-12-19 14:15:35 +00:00
Zuul 230aa89477 Merge "Add stop_on_exception to TG timers" 2018-12-19 14:15:34 +00:00
Zuul b7e697ae4b Merge "Add better timer APIs to ThreadGroup" 2018-12-19 14:15:34 +00:00
Zuul 2c44e7fe43 Merge "Restore correct signal handling in Python3" 2018-12-19 14:10:30 +00:00
Zane Bitter 55f897c613 Document the threadgroup module
There were no docstrings for this API, which as a bonus is extremely
subtle and poorly-designed. Document it so that users at least have a
fighting chance of using it to do the things they intended.

Change-Id: Id6677a7e5aaf8ec9ddeb597c6d5e8f97806e2248
2018-12-12 20:15:46 +13:00
Zane Bitter 130e49feac Actually test child SIGHUP signal
The intention of this test was to wait 5s after sending SIGHUP to a
child process to make sure that it doesn't exit. However, due to a logic
error, it just stopped checking and declared success immediately. Fix
the logic so that we have a better chance of seeing if SIGHUP
incorrectly kills the process.

Change-Id: I1f320a8dfdd7a922b461d070491ad53e6cd2b20d
Related-Bug: #1803731
2018-12-10 20:46:28 +13:00
Zane Bitter 159ef2e1d2 Restore correct signal handling in Python3
The patch 2ee3894f49 broke the original
fix cad75e4e13 that ensured eventlet could
be interrupted while sleeping after PEP475 was implemented in Python
3.5. Eventlet monkey-patches the signal module with its own version, so
we have to look up the original module to determine whether the
underlying OS actually supports the poll() function.

Change-Id: Ia712c9a83d8081bf0b5e6fe36f169f9028aae3dc
Closes-Bug: #1803731
Related-Bug: #1788022
Related-Bug: #1705047
2018-12-10 20:46:28 +13:00