From 5f68160354d240b191bcbaabca7d3c0684758cc6 Mon Sep 17 00:00:00 2001 From: Hans Lindgren Date: Thu, 11 Apr 2013 11:33:38 +0200 Subject: Remove unnecessary db call in scheduler driver live-migration code When the scheduler selects a destination host for live-migration, a db call is made to get instance_type info for the instance. To avoid the db call, this should instead call instance_types.extract_instance_type on the instance. Resolves bug 1167811. Change-Id: I2025fdf1d34e70158360ff71e8545c8e3bc6bc80 --- nova/scheduler/driver.py | 4 ++-- nova/tests/scheduler/test_scheduler.py | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 3426c484c..44960a856 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -25,6 +25,7 @@ import sys from oslo.config import cfg +from nova.compute import instance_types from nova.compute import power_state from nova.compute import rpcapi as compute_rpcapi from nova.compute import utils as compute_utils @@ -256,8 +257,7 @@ class Scheduler(object): # If dest is not specified, have scheduler pick one. if dest is None: - instance_type = db.instance_type_get( - context, instance_ref['instance_type_id']) + instance_type = instance_types.extract_instance_type(instance_ref) image = self.image_service.show(context, instance_ref['image_ref']) request_spec = {'instance_properties': instance_ref, 'instance_type': instance_type, diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 8c8181cb1..5246bbd16 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -746,11 +746,10 @@ class SchedulerTestCase(test.TestCase): # Confirm dest is picked by scheduler if not set. self.mox.StubOutWithMock(self.driver, 'select_hosts') - self.mox.StubOutWithMock(db, 'instance_type_get') + self.mox.StubOutWithMock(instance_types, 'extract_instance_type') - instance_type = instance_types.extract_instance_type(instance) request_spec = {'instance_properties': instance, - 'instance_type': instance_type, + 'instance_type': {}, 'instance_uuids': [instance['uuid']], 'image': self.image_service.show(self.context, instance['image_ref']) @@ -758,8 +757,7 @@ class SchedulerTestCase(test.TestCase): ignore_hosts = [instance['host']] filter_properties = {'ignore_hosts': ignore_hosts} - db.instance_type_get(self.context, instance_type['id']).AndReturn( - instance_type) + instance_types.extract_instance_type(instance).AndReturn({}) self.driver.select_hosts(self.context, request_spec, filter_properties).AndReturn(['fake_host2']) @@ -772,7 +770,7 @@ class SchedulerTestCase(test.TestCase): instance = self._live_migration_instance() # Confirm scheduler picks target host if none given. - self.mox.StubOutWithMock(db, 'instance_type_get') + self.mox.StubOutWithMock(instance_types, 'extract_instance_type') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(self.driver, 'select_hosts') self.mox.StubOutWithMock(self.driver, '_live_migration_common_check') @@ -782,9 +780,8 @@ class SchedulerTestCase(test.TestCase): dest = None block_migration = False disk_over_commit = False - instance_type = instance_types.extract_instance_type(instance) request_spec = {'instance_properties': instance, - 'instance_type': instance_type, + 'instance_type': {}, 'instance_uuids': [instance['uuid']], 'image': self.image_service.show(self.context, instance['image_ref']) @@ -792,9 +789,8 @@ class SchedulerTestCase(test.TestCase): self.driver._live_migration_src_check(self.context, instance) - db.instance_type_get(self.context, - instance_type['id']).MultipleTimes().AndReturn( - instance_type) + instance_types.extract_instance_type( + instance).MultipleTimes().AndReturn({}) # First selected host raises exception.InvalidHypervisorType self.driver.select_hosts(self.context, request_spec, -- cgit