nova/nova/tests/functional
Matthew Booth d0f540742e Eventlet monkey patching should be as early as possible
We were seeing infinite recursion opening an ssl socket when running
various combinations of python3, eventlet, and urllib3. It is not
clear exactly what combination of versions are affected, but for
background there is an example of this issue documented here:

https://github.com/eventlet/eventlet/issues/371

The immediate cause in nova's case was that we were calling
eventlet.monkey_patch() after importing urllib3. Specifically, change
Ie7bf5d012e2ccbcd63c262ddaf739782afcdaf56 introduced the
nova.utils.monkey_patch() method to make monkey patching common
between WSGI and non-WSGI services. Unfortunately, before executing
this method you must first import nova.utils, which imports a large
number of modules itself. Anything imported (transitively) by
nova.utils would therefore be imported before monkey patching, which
included urllib3. This triggers the infinite recursion problem
described above if you have an affected combination of library
versions.

While this specific issue may eventually be worked around or fixed in
eventlet or urllib3, it remains true that eventlet best practises are
to monkey patch as early as possible, which we were not doing. To
avoid this and hopefully future similar issues, this change ensures
that monkey patching happens as early as possible, and only a minimum
number of modules are imported first.

This change fixes monkey patching for both non-wsgi and wsgi callers:

* Non-WSGI services (nova/cmd)

  This is fixed by using the new monkey_patch module, which has minimal
  dependencies.

* WSGI services (nova/api/openstack)

  This is fixed both by using the new monkey_patch module, and by moving
  the patching point up one level so that it is done before importing
  anything in nova/api/openstack/__init__.py.

  This move causes issues for some external tools which load this path
  from nova and now monkey patch where they previously did not. However,
  it is unfortunately unavoidable to enable monkey patching for the wsgi
  entry point without major restructuring. This change includes a
  workaround for sphinx to avoid this issue.

This change has been through several iterations. I started with what
seemed like the simplest and most obvious change, and moved on as I
discovered more interactions which broke. It is clear that eventlet
monkey patching is extremely fragile, especially when done implicitly at
module load time as we do. I would advocate a code restructure to
improve this situation, but I think the time would be better spent
removing the eventlet dependency entirely.

Co-authored-by: Lee Yarwood <lyarwood@redhat.com>

Closes-Bug: #1808975
Closes-Bug: #1808951
Change-Id: Id46e76666b553a10ec4654d4418a9884975b5b95
(cherry picked from commit 3c5e2b0e9f)
2019-03-25 09:22:01 +01:00
..
api Use external placement in functional tests 2018-12-12 18:46:49 +00:00
api_sample_tests Move slight bonkers IP management to privsep. 2019-03-17 23:19:08 +00:00
compute Switch to using os-resource-classes 2019-02-07 11:11:09 +00:00
db Add online data migration for populating user_id 2019-03-08 19:01:41 -05:00
libvirt Merge "tests: Create PCI tests for NUMA'y tests" 2019-03-07 18:34:04 +00:00
notification_sample_tests Merge "Fix race in test_volume_swap_server_with_error" 2019-02-23 06:33:07 +00:00
regressions Don't register placement opts mutiple times in a test 2019-03-20 22:33:32 +00:00
wsgi Switch to using os-resource-classes 2019-02-07 11:11:09 +00:00
__init__.py Eventlet monkey patching should be as early as possible 2019-03-25 09:22:01 +01:00
api_paste_fixture.py Use external placement in functional tests 2018-12-12 18:46:49 +00:00
api_samples_test_base.py Merge "Fix os-simple-tenant-usage result order" 2018-10-27 08:57:52 +00:00
fixtures.py Convert driver supported capabilities to compute node provider traits 2019-02-28 23:28:19 +00:00
integrated_helpers.py Add functional test to delete a server while in VERIFY_RESIZE 2019-03-12 21:42:07 +00:00
test_aggregates.py Check hosts have no instances for AZ rename 2019-03-01 12:25:16 -05:00
test_availability_zones.py Update instance.availability_zone during live migration 2018-12-19 22:10:33 -05:00
test_boot_from_volume.py Properly track local root disk usage during moves 2018-10-08 17:33:49 -04:00
test_compute_mgr.py Fup for the bandwidth series 2019-02-27 10:23:15 +01:00
test_conf_max_attach_disk_devices.py Add configuration of maximum disk devices to attach 2019-01-30 15:47:10 +00:00
test_images.py Share snapshot image membership with instance owner 2019-02-08 18:06:27 -05:00
test_instance_actions.py Improve NeutronFixture and remove unncessary stubbing 2018-08-02 15:15:03 +02:00
test_legacy_v2_compatible_wrapper.py Improve NeutronFixture and remove unncessary stubbing 2018-08-02 15:15:03 +02:00
test_list_servers_ip_filter.py Use external placement in functional tests 2018-12-12 18:46:49 +00:00
test_login.py update api_samples code to use better variables 2015-12-14 11:23:26 +08:00
test_metadata.py Use external placement in functional tests 2018-12-12 18:46:49 +00:00
test_middleware.py Removes unnecessary utf-8 encoding 2016-12-20 10:27:01 +07:00
test_multiattach.py Improve NeutronFixture and remove unncessary stubbing 2018-08-02 15:15:03 +02:00
test_nova_manage.py Use external placement in functional tests 2018-12-12 18:46:49 +00:00
test_report_client.py Use a placement conf when testing report client 2019-03-04 20:43:48 +00:00
test_server_group.py Remove duplicate cleanup in functional tests 2019-03-07 23:58:58 +00:00
test_servers.py Merge "Add functional test to delete a server while in VERIFY_RESIZE" 2019-03-15 04:13:23 +00:00