nova/nova/tests/unit/api/openstack/compute
Andrey Volkov c280d747fb AZ list performance optimization: avoid double service list DB fetch
Assume number of services can be large (10000 as in the bug description),
this patch removes second service_get_all call.

zone_hosts changed from dict of lists to dict of sets.

The HostAPI instance from the API controller is also passed to the
get_availability_zones method so it does not have to recreate it
per call (this is both for a slight performance gain but mostly also
for test sanity).

On devstack with 10000 services patch decreased response time twice.

openstack availability zone list --long --timing

...

Before:

+-------------------------------------------------------------------------------------------+-----------+
| URL                                                                                       |   Seconds |
+-------------------------------------------------------------------------------------------+-----------+
| GET http://192.168.0.45/identity                                                          |  0.006816 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.456708 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.087485 |
| GET http://172.18.237.203/compute/v2.1/os-availability-zone/detail                        | 95.667192 |
| GET http://172.18.237.203/volume/v2/e2671d37ee2c4374bd1533645261f1d4/os-availability-zone |  0.036528 |
| Total                                                                                     | 96.254729 |
+-------------------------------------------------------------------------------------------+-----------+

After:

+-------------------------------------------------------------------------------------------+-----------+
| URL                                                                                       |   Seconds |
+-------------------------------------------------------------------------------------------+-----------+
| GET http://192.168.0.45/identity                                                          |  0.020215 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.102987 |
| POST http://192.168.0.45/identity/v3/auth/tokens                                          |  0.111899 |
| GET http://172.18.237.203/compute/v2.1/os-availability-zone/detail                        | 39.346657 |
| GET http://172.18.237.203/volume/v2/e2671d37ee2c4374bd1533645261f1d4/os-availability-zone |  0.026403 |
| Total                                                                                     | 39.608161 |
+-------------------------------------------------------------------------------------------+-----------+

The test_availability_zone_detail unit test is updated to assert that
services are only retrieved twice (once for enabled, once for disabled).
While in there, the expected response dict is formatted for readability
and a duplicate zone/host is added to make sure duplicates are handled
for available services. To ensure service_get_all is called only twice,
the low-level DB API service_get_all stub is replaced with a mock and
the mock is changed to be on the HostAPI.service_get_all method which
is (1) what the API controller code is actually using and (2) allows the
test to only mock the instance of the HostAPI being tested - trying to
mock the DB API service_get_all method causes intermittent failures
in unrelated tests because of the global nature of that mock.

There is another opportunity for optimizing get_availability_zones which
is marked with a TODO but left for a separate patch.

Co-Authored-By: Matt Riedemann <mriedem.os@gmail.com>

Partial-Bug: #1801897
Change-Id: Ib9a9a9a79499272d740a64cc0b909f0299a237d1
(cherry picked from commit 74cefe4266)
2019-04-29 19:05:05 +00:00
..
__init__.py
admin_only_action_common.py Fail to live migration if instance has a NUMA topology 2018-12-14 14:08:35 -05:00
dummy_schema.py
microversions.py Remove the extensions framework from wsgi.py 2018-10-18 02:01:03 +00:00
test_access_ips.py Update compute API.get() stubs in test_access_ips 2018-11-05 14:10:11 -05:00
test_admin_actions.py Remove mox in tests/unit/api/openstack/compute 2018-05-24 21:31:44 +00:00
test_admin_password.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_agents.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
test_aggregates.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_api.py Remove unnecessary setUp function in testcase 2017-03-30 12:55:16 +08:00
test_attach_interfaces.py Add unit tests for missing VirtualInterface in 2.70 os-interface 2019-02-25 10:57:37 -05:00
test_auth.py Tests: use fakes.HTTPRequest in compute tests 2016-08-24 19:03:54 +03:00
test_availability_zone.py AZ list performance optimization: avoid double service list DB fetch 2019-04-29 19:05:05 +00:00
test_baremetal_nodes.py Deprecate Baremetal and fping API 2016-07-26 14:14:44 +08:00
test_cells.py Add offset & limit docs & tests 2017-02-02 12:28:06 -05:00
test_certificates.py Remove nova-cert 2017-04-27 22:28:01 -04:00
test_cloudpipe.py Replaces uuid.uuid4 with uuidutils.generate_uuid() 2017-07-25 10:45:03 +05:30
test_cloudpipe_update.py Remove cloudpipe APIs 2017-05-04 16:13:45 +08:00
test_console_auth_tokens.py Use nova-consoleauth only if workaround enabled 2018-10-11 18:23:02 +00:00
test_console_output.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_consoles.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_create_backup.py Limit the min length of string for integer JSON-Schema 2017-05-27 10:14:28 +00:00
test_deferred_delete.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_disk_config.py Update compute API.get() stubs for test_disk_config 2018-11-05 14:10:11 -05:00
test_evacuate.py Follow up (#2) for the bw resource provider series 2019-02-11 14:35:15 -05:00
test_extended_hypervisors.py Handle uuids in os-hypervisors API 2017-07-18 17:08:01 -04:00
test_extended_ips.py Merge "Remove unused init_only kwarg from wsgi app init" 2017-01-11 04:13:39 +00:00
test_extended_ips_mac.py Merge "Remove unused init_only kwarg from wsgi app init" 2017-01-11 04:13:39 +00:00
test_extension_info.py Totally freeze the extension_info API 2017-05-08 16:32:48 +08:00
test_flavor_access.py Remove the caching the resource on Request object 2018-10-18 01:59:55 +00:00
test_flavor_disabled.py Remove the caching the resource on Request object 2018-10-18 01:59:55 +00:00
test_flavor_manage.py Fix a missing policy in test policy data 2019-02-14 15:01:03 +00:00
test_flavorextradata.py Remove unused init_only kwarg from wsgi app init 2016-12-29 21:51:03 -05:00
test_flavors.py Remove more code related to extensions and testing 2018-10-18 02:00:15 +00:00
test_flavors_extra_specs.py Mock.side_effects does not exist, use Mock.side_effect instead 2016-09-23 15:44:33 +08:00
test_floating_ip_pools.py Make test_floating_ip* pass with CONF.use_neutron=True by default 2017-01-03 20:59:36 -05:00
test_floating_ips.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_hosts.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_hypervisor_status.py
test_hypervisors.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_image_metadata.py [proxy-api] microversion 2.39 deprecates image-metadata proxy API 2016-12-07 19:22:43 +03:00
test_images.py Merge image_size extension response into image view builder 2018-10-18 01:59:34 +00:00
test_instance_actions.py Fix an error when generating a host ID 2019-03-04 14:51:13 +09:00
test_instance_usage_audit_log.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
test_keypairs.py Merge keypair extension response into server view builder 2018-08-23 09:04:00 -04:00
test_limits.py Remove more code related to extensions and testing 2018-10-18 02:00:15 +00:00
test_lock_server.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_microversions.py Remove more code related to extensions and testing 2018-10-18 02:00:15 +00:00
test_migrate_server.py Follow up (#2) for the bw resource provider series 2019-02-11 14:35:15 -05:00
test_migrations.py Add restrictions on updated_at when getting migrations 2018-10-24 11:11:49 -04:00
test_multinic.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_networks.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_neutron_security_groups.py Update compute API.get() stubs for test_*security_groups 2018-11-05 14:10:11 -05:00
test_pause_server.py Remove mox in tests/unit/api/openstack/compute 2018-05-24 21:31:44 +00:00
test_quota_classes.py Deprecate file injection 2017-12-12 09:22:21 -05:00
test_quotas.py quota: remove QuotaDriver.destroy_all_by_project() 2018-10-24 11:14:31 -04:00
test_remote_consoles.py Stop using mox stubs in test_remote_consoles.py 2017-07-18 00:39:01 +00:00
test_rescue.py Merge "Remove mox from api/openstack/compute/test_rescue.py" 2017-01-03 17:06:30 +00:00
test_security_group_default_rules.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
test_security_groups.py Update compute API.get() stubs for test_*security_groups 2018-11-05 14:10:11 -05:00
test_server_actions.py Flavor extra spec and image properties validation from API 2019-03-05 12:05:06 -06:00
test_server_diagnostics.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_server_external_events.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_server_group_quotas.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_server_groups.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_server_metadata.py Update compute API.get() mocks in test_server_metadata 2018-11-05 14:10:08 -05:00
test_server_migrations.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_server_password.py Remove mox in unit/api/*/test_server_password.py 2018-04-09 16:28:08 +09:00
test_server_reset_state.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00
test_server_start_stop.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_server_tags.py Use nova.db.api directly 2018-07-10 14:56:27 +00:00
test_serversV21.py Handle missing exception in instance creation code 2019-03-05 11:04:06 -06:00
test_services.py Provide a useful error message when trying to update non-compute services 2019-02-11 15:04:12 -05:00
test_shelve.py Follow up (#2) for the bw resource provider series 2019-02-11 14:35:15 -05:00
test_simple_tenant_usage.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_snapshots.py Implement query param schema for volume, snapshot API 2017-11-19 16:15:39 +03:00
test_suspend_server.py Remove mox in tests/unit/api/openstack/compute 2018-05-24 21:31:44 +00:00
test_tenant_networks.py Count networks to check quota 2017-06-19 21:51:46 +00:00
test_urlmap.py Remove the test for the route '/resources.:(format)' 2017-07-12 20:57:16 +08:00
test_versions.py Use uuidsentinel from oslo.utils 2018-09-05 09:08:54 -05:00
test_volumes.py Minimal construct plumbing for nova show when a cell is down 2018-10-31 15:22:09 -04:00