Browse Source

Don't make a no-op DB call

drivers_uuid can be empty, but we are still doing a DB call. This is causing
a sqlalchemy SAWarning.

SAWarning: The IN-predicate on "instances.uuid" was invoked with an
empty sequence. This results in a contradiction, which nonetheless can
be expensive to evaluate.  Consider alternative strategies for improved
performance.

Change-Id: Ib8c9b85e84800c9e2ddcdf204851f1b51101926c
Closes-Bug: #1383617
tags/2015.1.0b1
Joe Gordon 5 years ago
parent
commit
150428f76e
2 changed files with 15 additions and 0 deletions
  1. +3
    -0
      nova/compute/manager.py
  2. +12
    -0
      nova/tests/unit/compute/test_compute_mgr.py

+ 3
- 0
nova/compute/manager.py View File

@@ -686,6 +686,9 @@ class ComputeManager(manager.Manager):
filters = {}
try:
driver_uuids = self.driver.list_instance_uuids()
if len(driver_uuids) == 0:
# Short circuit, don't waste a DB call
return objects.InstanceList()
filters['uuid'] = driver_uuids
local_instances = objects.InstanceList.get_by_filters(
context, filters, use_slave=True)

+ 12
- 0
nova/tests/unit/compute/test_compute_mgr.py View File

@@ -842,6 +842,18 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.assertEqual([x['uuid'] for x in driver_instances],
[x['uuid'] for x in result])

@mock.patch('nova.virt.driver.ComputeDriver.list_instance_uuids')
@mock.patch('nova.db.api.instance_get_all_by_filters')
def test_get_instances_on_driver_empty(self, mock_list, mock_db):
fake_context = context.get_admin_context()
mock_list.return_value = []

result = self.compute._get_instances_on_driver(fake_context)
# instance_get_all_by_filters should not be called
self.assertEqual(0, mock_db.call_count)
self.assertEqual([],
[x['uuid'] for x in result])

def test_get_instances_on_driver_fallback(self):
# Test getting instances when driver doesn't support
# 'list_instance_uuids'

Loading…
Cancel
Save